mobile_dialysis_service.go 538KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "XT_New/models"
  8. "github.com/jinzhu/gorm"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. //err := db.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  38. // return db.Order("dialysis_date desc").Where(" status = 1 AND user_org_id = ? and dialysis_date>=1672502400 && dialysis_date < ?", orgID, scheduleDate)
  39. //}).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  40. return vms, err
  41. }
  42. func GetMonitDialysisOrder(user_org_id int64, patient_id int64, scheduleDate int64) (*models.MDialysisOrderForList, error) {
  43. order := models.MDialysisOrderForList{}
  44. err := XTReadDB().Where("user_org_id = ? and status =1 and patient_id = ?", user_org_id, patient_id).Order("id desc").Last(&order).Error
  45. return &order, err
  46. }
  47. func GetMonitDialysisSolution(user_org_id int64, patient_id int64, mode_id int64) (*models.DialysisSolution, error) {
  48. solution := models.DialysisSolution{}
  49. err := XTReadDB().Where("user_org_id = ? and patient_id =? and solution_status = 1 and mode_id = ? and status=1", user_org_id, patient_id, mode_id).Find(&solution).Error
  50. return &solution, err
  51. }
  52. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  53. var vms []*MDialysisScheduleVM
  54. db := readDb.
  55. Table("xt_schedule as sch").
  56. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  60. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  61. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  62. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  63. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  64. Preload("TreatmentMode", "status = 1").
  65. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  66. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  67. if scheduleDate != 0 {
  68. db = db.Where("schedule_date = ?", scheduleDate)
  69. }
  70. err := db.Find(&vms).Error
  71. return vms, err
  72. }
  73. type VMTreatmentSummary struct {
  74. ID int64 `gorm:"column:id" json:"id"`
  75. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  77. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  78. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  79. }
  80. func (VMTreatmentSummary) TableName() string {
  81. return "xt_treatment_summary"
  82. }
  83. type AssessmentAfterDislysis struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  88. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  89. Status int64 `gorm:"column:status" json:"status"`
  90. }
  91. func (AssessmentAfterDislysis) TableName() string {
  92. return "xt_assessment_after_dislysis"
  93. }
  94. type MDialysisScheduleVM struct {
  95. ID int64 `gorm:"column:id" json:"id"`
  96. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  97. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  98. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  99. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  100. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  101. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  102. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  103. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  104. Status int64 `gorm:"column:status" json:"status"`
  105. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  106. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  107. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  108. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  109. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  110. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  111. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  112. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  113. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  114. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  115. }
  116. func (MDialysisScheduleVM) TableName() string {
  117. return "xt_schedule"
  118. }
  119. type MDialysisScheduleVMForList struct {
  120. ID int64 `gorm:"column:id" json:"id"`
  121. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  125. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  126. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  127. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  128. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  129. Status int64 `gorm:"column:status" json:"status"`
  130. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  131. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  132. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  133. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  134. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  135. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  136. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  137. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  138. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  139. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  140. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  141. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  142. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  143. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  144. }
  145. func (MDialysisScheduleVMForList) TableName() string {
  146. return "xt_schedule"
  147. }
  148. type MDeviceNumberVM struct {
  149. models.DeviceNumber
  150. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  151. }
  152. func (MDeviceNumberVM) TableName() string {
  153. return "xt_device_number"
  154. }
  155. type MSchedualPatientVMList struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  159. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  160. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  161. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  162. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  163. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  164. Age int64 `gorm:"column:age" json:"age"`
  165. Name string `gorm:"column:name" json:"name" form:"name"`
  166. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  167. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  168. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  169. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  170. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  171. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  172. }
  173. func (MSchedualPatientVMList) TableName() string {
  174. return "xt_patients"
  175. }
  176. type MSchedualPatientVM struct {
  177. ID int64 `gorm:"column:id" json:"id" form:"id"`
  178. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  179. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  180. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  181. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  182. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  183. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  184. Source int64 `gorm:"column:source" json:"source" form:"source"`
  185. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  186. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  187. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  188. Name string `gorm:"column:name" json:"name" form:"name"`
  189. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  190. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  191. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  192. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  193. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  194. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  195. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  196. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  197. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  198. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  199. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  200. Height int64 `gorm:"column:height" json:"height" form:"height"`
  201. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  202. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  203. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  204. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  205. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  206. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  207. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  208. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  209. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  210. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  211. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  212. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  213. Children int64 `gorm:"column:children" json:"children" form:"children"`
  214. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  215. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  216. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  217. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  218. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  219. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  220. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  221. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  222. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  223. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  224. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  225. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  226. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  227. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  228. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  229. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  230. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  231. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  232. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  233. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  234. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  235. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  236. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  237. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  238. Status int64 `gorm:"column:status" json:"status" form:"status"`
  239. Age int64 `gorm:"column:age" json:"age"`
  240. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  241. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  242. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  243. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  244. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  245. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  246. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  247. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  248. }
  249. func (MSchedualPatientVM) TableName() string {
  250. return "xt_patients"
  251. }
  252. type MDialysisOrderVM struct {
  253. ID int64 `gorm:"column:id" json:"id"`
  254. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  255. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  256. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  257. Stage int64 `gorm:"column:stage" json:"stage"`
  258. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  259. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  260. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  261. Status int64 `gorm:"column:status" json:"status"`
  262. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  263. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  264. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  265. Creator int64 `gorm:"column:creator" json:"creator"`
  266. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  267. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  268. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  269. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  270. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  271. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  272. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  273. }
  274. func (MDialysisOrderVM) TableName() string {
  275. return "xt_dialysis_order"
  276. }
  277. type MDialysisOrderVMList struct {
  278. ID int64 `gorm:"column:id" json:"id"`
  279. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  280. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  281. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  282. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  283. Stage int64 `gorm:"column:stage" json:"stage"`
  284. // Remark string `gorm:"column:remark" json:"remark"`
  285. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  286. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  287. Status int64 `gorm:"column:status" json:"status"`
  288. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  289. Creator int64 `gorm:"column:creator" json:"creator"`
  290. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  291. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  292. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  293. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  294. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  295. }
  296. func (MDialysisOrderVMList) TableName() string {
  297. return "xt_dialysis_order"
  298. }
  299. type VMDoctorAdvice struct {
  300. ID int64 `gorm:"column:id" json:"id" form:"id"`
  301. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  302. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  303. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  304. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  305. Status int64 `gorm:"column:status" json:"status" form:"status"`
  306. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  307. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  308. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  309. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  310. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  311. }
  312. func (VMDoctorAdvice) TableName() string {
  313. return "xt_doctor_advice"
  314. }
  315. type VMHisDoctorAdviceInfo struct {
  316. ID int64 `gorm:"column:id" json:"id" form:"id"`
  317. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  318. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  319. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  320. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  321. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  322. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  323. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  324. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  325. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  326. }
  327. func (VMHisDoctorAdviceInfo) TableName() string {
  328. return "his_doctor_advice_info"
  329. }
  330. type VMAssessmentAfterDislysis struct {
  331. ID int64 `gorm:"column:id" json:"id"`
  332. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  333. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  334. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  335. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  336. Status int64 `gorm:"column:status" json:"status"`
  337. }
  338. func (VMAssessmentAfterDislysis) TableName() string {
  339. return "xt_assessment_after_dislysis"
  340. }
  341. type NewDeviceInformation struct {
  342. ID int64 `gorm:"column:id" json:"id" form:"id"`
  343. Date int64 `gorm:"column:date" json:"date" form:"date"`
  344. Class int64 `gorm:"column:class" json:"class" form:"class"`
  345. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  346. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  347. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  348. Status int64 `gorm:"column:status" json:"status" form:"status"`
  349. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  350. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  351. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  352. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  353. }
  354. func (NewDeviceInformation) TableName() string {
  355. return "xt_device_information"
  356. }
  357. // 获取透析记录
  358. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  359. var record models.DialysisOrder
  360. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  361. if err != nil {
  362. if err == gorm.ErrRecordNotFound {
  363. return nil, nil
  364. } else {
  365. return nil, err
  366. }
  367. }
  368. return &record, nil
  369. }
  370. // 用户基本信息
  371. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  372. var patient MPatient
  373. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  374. //if err != nil {
  375. // if err == gorm.ErrRecordNotFound {
  376. // return nil, nil
  377. // } else {
  378. // return nil, err
  379. // }
  380. //}
  381. //return &patient, nil
  382. redis := RedisClient()
  383. defer redis.Close()
  384. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  385. patient_info_str, _ := redis.Get(key).Result()
  386. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  387. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  388. if err != nil {
  389. if err == gorm.ErrRecordNotFound {
  390. return &patient, nil
  391. } else {
  392. return &patient, err
  393. }
  394. } else {
  395. if patient.ID > 0 {
  396. //缓存数据
  397. patient_info_json, err := json.Marshal(&patient)
  398. if err == nil {
  399. redis.Set(key, patient_info_json, time.Second*60*60*18)
  400. }
  401. }
  402. return &patient, nil
  403. }
  404. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  405. json.Unmarshal([]byte(patient_info_str), &patient)
  406. return &patient, nil
  407. }
  408. }
  409. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  410. var vm MDialysisScheduleVM
  411. err := readDb.
  412. Table("xt_schedule").
  413. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  414. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  415. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  416. First(&vm).Error
  417. return &vm, err
  418. }
  419. // 用户排班信息
  420. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  421. var vm MDialysisScheduleVM
  422. err := readDb.
  423. Table("xt_schedule").
  424. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  426. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  427. First(&vm).Error
  428. if err != nil {
  429. if err == gorm.ErrRecordNotFound {
  430. return nil, nil
  431. } else {
  432. return nil, err
  433. }
  434. }
  435. return &vm, err
  436. }
  437. // 用户排班信息
  438. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  439. redis := RedisClient()
  440. defer redis.Close()
  441. var vm MDialysisScheduleVM
  442. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  443. redis.Set(key, "", time.Second)
  444. schedual_detail_str, _ := redis.Get(key).Result()
  445. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  446. err := readDb.
  447. Table("xt_schedule").
  448. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  449. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  450. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  451. First(&vm).Error
  452. if err != nil {
  453. if err == gorm.ErrRecordNotFound {
  454. return nil, nil
  455. } else {
  456. return nil, err
  457. }
  458. } else {
  459. if vm.ID > 0 {
  460. //缓存数据
  461. schedual_detail_str, err := json.Marshal(vm)
  462. if err == nil {
  463. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  464. }
  465. } else {
  466. redis.Set(key, "null", time.Second*60*60*18)
  467. }
  468. return &vm, nil
  469. }
  470. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  471. if schedual_detail_str == "null" {
  472. return &vm, nil
  473. }
  474. json.Unmarshal([]byte(schedual_detail_str), &vm)
  475. return &vm, nil
  476. }
  477. }
  478. // 用户排班信息
  479. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  480. var schedule models.Schedule
  481. err := readDb.
  482. Table("xt_schedule").
  483. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  484. First(&schedule).Error
  485. if err != nil {
  486. if err == gorm.ErrRecordNotFound {
  487. return nil, nil
  488. } else {
  489. return nil, err
  490. }
  491. }
  492. return &schedule, nil
  493. }
  494. type MPatient struct {
  495. ID int64 `gorm:"column:id" json:"id" form:"id"`
  496. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  497. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  498. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  499. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  500. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  501. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  502. Source int64 `gorm:"column:source" json:"source" form:"source"`
  503. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  504. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  505. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  506. Name string `gorm:"column:name" json:"name" form:"name"`
  507. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  508. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  509. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  510. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  511. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  512. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  513. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  514. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  515. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  516. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  517. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  518. Height int64 `gorm:"column:height" json:"height" form:"height"`
  519. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  520. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  521. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  522. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  523. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  524. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  525. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  526. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  527. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  528. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  529. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  530. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  531. Children int64 `gorm:"column:children" json:"children" form:"children"`
  532. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  533. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  534. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  535. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  536. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  537. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  538. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  539. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  540. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  541. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  542. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  543. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  544. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  545. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  546. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  547. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  548. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  549. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  550. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  551. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  552. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  553. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  554. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  555. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  556. Status int64 `gorm:"column:status" json:"status" form:"status"`
  557. Age int64 `gorm:"column:age" json:"age"`
  558. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  559. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  560. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  561. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  562. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  563. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  564. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  565. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  566. }
  567. func (MPatient) TableName() string {
  568. return "xt_patients"
  569. }
  570. // 接诊评估
  571. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  572. var record models.ReceiveTreatmentAsses
  573. redis := RedisClient()
  574. defer redis.Close()
  575. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  576. receive_treatment_asses_str, _ := redis.Get(key).Result()
  577. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  578. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  579. if err != nil {
  580. if err == gorm.ErrRecordNotFound {
  581. if record.ID <= 0 {
  582. redis.Set(key, "", time.Second*60*60*18)
  583. }
  584. return nil, nil
  585. } else {
  586. return nil, err
  587. }
  588. } else {
  589. if record.ID > 0 {
  590. //缓存数据
  591. receive_treatment_asses_str, err := json.Marshal(record)
  592. if err == nil {
  593. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  594. }
  595. } else {
  596. redis.Set(key, "null", time.Second*60*60*18)
  597. }
  598. return &record, nil
  599. }
  600. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  601. if receive_treatment_asses_str == "null" {
  602. return &record, nil
  603. }
  604. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  605. return &record, nil
  606. }
  607. }
  608. // 透前评估
  609. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  610. var record models.PredialysisEvaluation
  611. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  612. if err != nil {
  613. if err == gorm.ErrRecordNotFound {
  614. return nil, nil
  615. } else {
  616. return nil, err
  617. }
  618. }
  619. return &record, nil
  620. }
  621. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  622. var record models.PredialysisEvaluation
  623. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  624. return record, err
  625. }
  626. // 透前评估
  627. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  628. var record models.PredialysisEvaluation
  629. redis := RedisClient()
  630. defer redis.Close()
  631. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  632. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  633. redis.Set(key, "", time.Second)
  634. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  635. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  636. if err != nil {
  637. if err == gorm.ErrRecordNotFound {
  638. if record.ID <= 0 {
  639. redis.Set(key, "", time.Second*60*60*18)
  640. }
  641. return nil, nil
  642. } else {
  643. return nil, err
  644. }
  645. } else {
  646. if record.ID > 0 {
  647. //缓存数据
  648. assessment_before_dislysis_str, err := json.Marshal(record)
  649. if err == nil {
  650. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  651. }
  652. } else {
  653. redis.Set(key, "null", time.Second*60*60*18)
  654. }
  655. return &record, nil
  656. }
  657. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  658. if assessment_before_dislysis_str == "null" {
  659. return &record, nil
  660. } else {
  661. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  662. return &record, nil
  663. }
  664. }
  665. }
  666. // 获取 maxDate 之前一次的透前评估记录
  667. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  668. var record models.PredialysisEvaluation
  669. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  670. if err != nil {
  671. if err == gorm.ErrRecordNotFound {
  672. return nil, nil
  673. } else {
  674. return nil, err
  675. }
  676. }
  677. return &record, nil
  678. }
  679. // 获取 maxDate 之前一次的透前评估记录
  680. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  681. var record models.PredialysisEvaluation
  682. redis := RedisClient()
  683. defer redis.Close()
  684. // cur_date := time.Now().Format("2006-01-02")
  685. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  686. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  687. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  688. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  689. if err != nil {
  690. if err == gorm.ErrRecordNotFound {
  691. if record.ID <= 0 {
  692. redis.Set(key, "", time.Second*60*60*18)
  693. }
  694. return nil, nil
  695. } else {
  696. return nil, err
  697. }
  698. } else {
  699. if record.ID > 0 {
  700. //缓存数据
  701. assessment_before_dislysis_last_str, err := json.Marshal(record)
  702. if err == nil {
  703. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  704. }
  705. } else {
  706. redis.Set(key, "null", time.Second*60*60*18)
  707. }
  708. return &record, nil
  709. }
  710. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  711. if assessment_before_dislysis_last_str == "null" {
  712. return &record, nil
  713. } else {
  714. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  715. return &record, nil
  716. }
  717. }
  718. }
  719. // 临时医嘱
  720. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  721. var records []*models.DoctorAdvice
  722. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  723. err := readDb.
  724. Model(&models.DoctorAdvice{}).
  725. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  726. Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno,is_medicine").
  727. Order("start_time asc, groupno desc, advice_order desc, id").
  728. Scan(&records).Error
  729. if err != nil {
  730. return nil, err
  731. }
  732. return records, nil
  733. }
  734. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  735. var records []*models.DoctorAdvice
  736. redis := RedisClient()
  737. defer redis.Close()
  738. // cur_date := time.Now().Format("2006-01-02")
  739. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  740. //fmt.Println("key23233232323323wi", key)
  741. redis.Set(key, "", time.Second)
  742. doctor_advices_str, _ := redis.Get(key).Result()
  743. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  744. err := readDb.Model(&models.DoctorAdvice{}).
  745. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  746. Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,is_medicine,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  747. Order("start_time asc, groupno desc, advice_order desc, id asc").
  748. Scan(&records).Error
  749. if err != nil {
  750. if err == gorm.ErrRecordNotFound {
  751. if len(records) <= 0 {
  752. redis.Set(key, "", time.Second*60*60*18)
  753. }
  754. return nil, nil
  755. } else {
  756. return nil, err
  757. }
  758. } else {
  759. if len(records) > 0 {
  760. //缓存数据
  761. doctor_advices_str, err := json.Marshal(records)
  762. if err == nil {
  763. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  764. return records, nil
  765. }
  766. } else {
  767. redis.Set(key, "null", time.Second*60*60*18)
  768. return records, nil
  769. }
  770. return records, nil
  771. }
  772. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  773. if doctor_advices_str == "null" {
  774. return records, nil
  775. } else {
  776. json.Unmarshal([]byte(doctor_advices_str), &records)
  777. return records, nil
  778. }
  779. }
  780. }
  781. // 透析记录
  782. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  783. var record models.DialysisOrder
  784. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ?", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  785. if err != nil {
  786. if err == gorm.ErrRecordNotFound {
  787. return nil, nil
  788. } else {
  789. return nil, err
  790. }
  791. }
  792. return &record, nil
  793. }
  794. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  795. // var record models.DialysisOrder
  796. //
  797. // err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  798. //
  799. //
  800. // return &record,err
  801. //}
  802. // 透析记录
  803. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  804. var record models.DialysisOrder
  805. redis := RedisClient()
  806. defer redis.Close()
  807. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  808. dialysis_order_str, _ := redis.Get(key).Result()
  809. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  810. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  811. if err != nil {
  812. if err == gorm.ErrRecordNotFound {
  813. return nil, nil
  814. } else {
  815. return nil, err
  816. }
  817. } else {
  818. if record.ID > 0 {
  819. //缓存数据
  820. dialysis_order_str, err := json.Marshal(record)
  821. if err == nil {
  822. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  823. }
  824. } else {
  825. redis.Set(key, "null", time.Second*60*60*18)
  826. }
  827. return &record, nil
  828. }
  829. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  830. if dialysis_order_str == "null" {
  831. err = readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  832. return &record, nil
  833. } else {
  834. json.Unmarshal([]byte(dialysis_order_str), &record)
  835. return &record, nil
  836. }
  837. }
  838. }
  839. // 双人核对
  840. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  841. var record models.DoubleCheck
  842. redis := RedisClient()
  843. defer redis.Close()
  844. // cur_date := time.Now().Format("2006-01-02")
  845. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  846. double_check_str, _ := redis.Get(key).Result()
  847. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  848. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  849. if err != nil {
  850. if err == gorm.ErrRecordNotFound {
  851. if record.ID <= 0 {
  852. redis.Set(key, "null", time.Second*60*60*18)
  853. }
  854. return nil, nil
  855. } else {
  856. return nil, err
  857. }
  858. } else {
  859. if record.ID > 0 {
  860. //缓存数据
  861. double_check_str, err := json.Marshal(record)
  862. if err == nil {
  863. redis.Set(key, double_check_str, time.Second*60*60*18)
  864. }
  865. } else {
  866. redis.Set(key, "null", time.Second*60*60*18)
  867. }
  868. return &record, nil
  869. }
  870. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  871. if double_check_str == "null" {
  872. return &record, nil
  873. } else {
  874. json.Unmarshal([]byte(double_check_str), &record)
  875. return &record, nil
  876. }
  877. }
  878. }
  879. // 透析监测记录
  880. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  881. var records []*models.MonitoringRecord
  882. redis := RedisClient()
  883. defer redis.Close()
  884. // cur_date := time.Now().Format("2006-01-02")
  885. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  886. redis.Set(key, "", time.Second)
  887. monitor_records_str, _ := redis.Get(key).Result()
  888. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  889. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
  890. if err != nil {
  891. if err == gorm.ErrRecordNotFound {
  892. //if len(records) <= 0 {
  893. // redis.Set(key, "null", time.Second*60*60*18)
  894. //}
  895. return nil, nil
  896. } else {
  897. return nil, err
  898. }
  899. } else {
  900. if len(records) > 0 {
  901. //缓存数据
  902. monitor_records_str, err := json.Marshal(records)
  903. if err == nil {
  904. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  905. }
  906. } else {
  907. redis.Set(key, "null", time.Second*60*60*18)
  908. }
  909. return records, nil
  910. }
  911. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  912. if monitor_records_str == "null" {
  913. return records, nil
  914. } else {
  915. json.Unmarshal([]byte(monitor_records_str), &records)
  916. return records, nil
  917. }
  918. }
  919. }
  920. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  921. var records models.MonitoringRecord
  922. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").First(&records).Error
  923. if err != nil {
  924. return nil, err
  925. }
  926. return &records, nil
  927. }
  928. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  929. var record models.MonitoringRecord
  930. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  931. if err != nil {
  932. if err == gorm.ErrRecordNotFound {
  933. return nil, nil
  934. } else {
  935. return nil, err
  936. }
  937. }
  938. return &record, nil
  939. }
  940. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  941. var record models.MonitoringRecord
  942. redis := RedisClient()
  943. defer redis.Close()
  944. // cur_date := time.Now().Format("2006-01-02")
  945. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  946. monitor_record_last_str, _ := redis.Get(key).Result()
  947. redis.Set(key, "", time.Second)
  948. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  949. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  950. if err != nil {
  951. if err == gorm.ErrRecordNotFound {
  952. if record.ID <= 0 {
  953. redis.Set(key, "null", time.Second*60*60*18)
  954. }
  955. return nil, nil
  956. } else {
  957. return nil, err
  958. }
  959. } else {
  960. if record.ID > 0 {
  961. //缓存数据
  962. monitor_record_last_str, err := json.Marshal(record)
  963. if err == nil {
  964. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  965. }
  966. } else {
  967. redis.Set(key, "null", time.Second*60*60*18)
  968. }
  969. return &record, nil
  970. }
  971. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  972. if monitor_record_last_str == "null" {
  973. return &record, nil
  974. } else {
  975. json.Unmarshal([]byte(monitor_record_last_str), &record)
  976. return &record, nil
  977. }
  978. }
  979. }
  980. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  981. var record models.AssessmentAfterDislysis
  982. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  983. if err != nil {
  984. if err == gorm.ErrRecordNotFound {
  985. return nil, nil
  986. } else {
  987. return nil, err
  988. }
  989. }
  990. return &record, nil
  991. }
  992. // 透后评估
  993. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  994. var record models.AssessmentAfterDislysis
  995. redis := RedisClient()
  996. defer redis.Close()
  997. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  998. redis.Set(key, "", time.Second)
  999. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  1000. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1001. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1002. if err != nil {
  1003. if err == gorm.ErrRecordNotFound {
  1004. if record.ID <= 0 {
  1005. redis.Set(key, "null", time.Second*60*60*18)
  1006. }
  1007. return nil, nil
  1008. } else {
  1009. return nil, err
  1010. }
  1011. } else {
  1012. if record.ID > 0 {
  1013. //缓存数据
  1014. assessment_after_dislysis_str, err := json.Marshal(record)
  1015. if err == nil {
  1016. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1017. }
  1018. } else {
  1019. redis.Set(key, "null", time.Second*60*60*18)
  1020. }
  1021. return &record, nil
  1022. }
  1023. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1024. if assessment_after_dislysis_str == "null" {
  1025. return &record, nil
  1026. } else {
  1027. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1028. return &record, nil
  1029. }
  1030. }
  1031. }
  1032. // 获取 maxDate 之前一次的透后评估记录
  1033. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1034. var record models.AssessmentAfterDislysis
  1035. redis := RedisClient()
  1036. defer redis.Close()
  1037. // cur_date := time.Now().Format("2006-01-02")
  1038. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1039. redis.Set(key, "", time.Second)
  1040. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1041. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1042. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where(" patient_id = ? and user_org_id = ? and status = 1 and assessment_date>=1725120000 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1043. if err != nil {
  1044. if err == gorm.ErrRecordNotFound {
  1045. if record.ID <= 0 {
  1046. redis.Set(key, "null", time.Second*60*60*18)
  1047. }
  1048. return nil, nil
  1049. } else {
  1050. return nil, err
  1051. }
  1052. } else {
  1053. if record.ID > 0 {
  1054. //缓存数据
  1055. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1056. if err == nil {
  1057. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1058. }
  1059. } else {
  1060. redis.Set(key, "null", time.Second*60*60*18)
  1061. }
  1062. return &record, nil
  1063. }
  1064. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1065. if assessment_after_dislysis_last_str == "null" {
  1066. return &record, nil
  1067. } else {
  1068. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1069. return &record, nil
  1070. }
  1071. }
  1072. }
  1073. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1074. var record models.AssessmentAfterDislysis
  1075. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1076. if err != nil {
  1077. if err == gorm.ErrRecordNotFound {
  1078. return nil, nil
  1079. } else {
  1080. return nil, err
  1081. }
  1082. }
  1083. return &record, nil
  1084. }
  1085. func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1086. var record models.AssessmentAfterDislysis
  1087. err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1088. return &record, nil
  1089. }
  1090. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1091. dislysis := models.AssessmentAfterDislysis{}
  1092. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&dislysis).Error
  1093. return dislysis, err
  1094. }
  1095. // 治疗小结
  1096. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1097. var record models.TreatmentSummary
  1098. redis := RedisClient()
  1099. defer redis.Close()
  1100. // cur_date := time.Now().Format("2006-01-02")
  1101. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1102. treatment_summary_str, _ := redis.Get(key).Result()
  1103. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1104. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1105. if err != nil {
  1106. if err == gorm.ErrRecordNotFound {
  1107. if record.ID <= 0 {
  1108. redis.Set(key, "null", time.Second*60*60*18)
  1109. }
  1110. return nil, nil
  1111. } else {
  1112. return nil, err
  1113. }
  1114. } else {
  1115. if record.ID > 0 {
  1116. //缓存数据
  1117. treatment_summary_str, err := json.Marshal(record)
  1118. if err == nil {
  1119. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1120. }
  1121. } else {
  1122. redis.Set(key, "null", time.Second*60*60*18)
  1123. }
  1124. return &record, nil
  1125. }
  1126. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1127. if treatment_summary_str == "null" {
  1128. return &record, nil
  1129. } else {
  1130. json.Unmarshal([]byte(treatment_summary_str), &record)
  1131. return &record, nil
  1132. }
  1133. }
  1134. }
  1135. // 透析处方
  1136. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1137. var record models.DialysisPrescription
  1138. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1139. if err != nil {
  1140. if err == gorm.ErrRecordNotFound {
  1141. return nil, nil
  1142. } else {
  1143. return nil, err
  1144. }
  1145. }
  1146. return &record, nil
  1147. }
  1148. func MobileGetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  1149. var record models.DialysisPrescription
  1150. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1151. return record, nil
  1152. }
  1153. func UpdateMobileGetDialysisPrescribe(id int64, dewater_amount float64) error {
  1154. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
  1155. return err
  1156. }
  1157. func UpdateMobileGetDialysisPrescribeOne(id int64, dewater_amount float64) error {
  1158. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount}).Error
  1159. return err
  1160. }
  1161. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1162. var schedule models.XtSchedule
  1163. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1164. if err != nil {
  1165. if err == gorm.ErrRecordNotFound {
  1166. return nil, nil
  1167. } else {
  1168. return nil, err
  1169. }
  1170. }
  1171. return &schedule, nil
  1172. }
  1173. // 透析方案
  1174. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1175. var record models.DialysisSolution
  1176. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1177. if err != nil {
  1178. if err == gorm.ErrRecordNotFound {
  1179. return nil, nil
  1180. } else {
  1181. return nil, err
  1182. }
  1183. }
  1184. return &record, nil
  1185. }
  1186. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1187. var patient models.Patients
  1188. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1189. if err != nil {
  1190. if err == gorm.ErrRecordNotFound {
  1191. return nil, nil
  1192. } else {
  1193. return nil, err
  1194. }
  1195. }
  1196. return &patient, nil
  1197. }
  1198. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1199. fmt.Println()
  1200. tx := writeDb.Begin()
  1201. updateTime := time.Now().Unix()
  1202. err := tx.Model(&models.MonitoringRecord{}).Where("user_org_id = ? AND patient_id = ? AND id = ? AND status = 1 ", orgID, patientID, recordID).Updates(map[string]interface{}{"status": 0, "updated_time": updateTime, "modify": admin_user_id}).Error
  1203. if err != nil {
  1204. tx.Rollback()
  1205. return err
  1206. }
  1207. tx.Commit()
  1208. return nil
  1209. }
  1210. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1211. record := models.MonitoringRecord{}
  1212. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1213. return record, err
  1214. }
  1215. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1216. var monitor models.MonitoringRecord
  1217. var err error
  1218. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1219. if err == gorm.ErrRecordNotFound {
  1220. return nil, nil
  1221. }
  1222. if err != nil {
  1223. return nil, err
  1224. }
  1225. return &monitor, nil
  1226. }
  1227. type MScheduleDoctorAdviceVM struct {
  1228. ID int64 `gorm:"column:id" json:"id"`
  1229. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1230. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1231. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1232. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1233. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1234. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1235. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1236. Status int64 `gorm:"column:status" json:"status"`
  1237. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1238. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1239. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1240. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1241. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1242. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1243. }
  1244. func (MScheduleDoctorAdviceVM) TableName() string {
  1245. return "xt_schedule"
  1246. }
  1247. type MScheduleDoctorAdviceVMOne struct {
  1248. ID int64 `gorm:"column:id" json:"id"`
  1249. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1250. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1251. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1252. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1253. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1254. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1255. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1256. Status int64 `gorm:"column:status" json:"status"`
  1257. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1258. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1259. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1260. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1261. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1262. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1263. }
  1264. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1265. return "xt_schedule"
  1266. }
  1267. type MDoctorAdviceVM struct {
  1268. ID int64 `gorm:"column:id" json:"id"`
  1269. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1270. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1271. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1272. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1273. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1274. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1275. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1276. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1277. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1278. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1279. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1280. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1281. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1282. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1283. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1284. Status int64 `gorm:"column:status" json:"status"`
  1285. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1286. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1287. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1288. Remark string `gorm:"column:remark" json:"remark"`
  1289. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1290. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1291. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1292. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1293. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1294. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1295. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1296. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1297. Checker int64 `gorm:"column:checker" json:"checker"`
  1298. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1299. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1300. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1301. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1302. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1303. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1304. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1305. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1306. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1307. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1308. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1309. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1310. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1311. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1312. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1313. }
  1314. func (MDoctorAdviceVM) TableName() string {
  1315. return "xt_doctor_advice"
  1316. }
  1317. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1318. var vms []*MScheduleDoctorAdviceVM
  1319. adviceWhere := ""
  1320. adviceCondition := []interface{}{}
  1321. if adviceType == 0 {
  1322. if patientType == 0 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1325. } else if patientType == 1 {
  1326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1328. } else if patientType == 2 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1331. }
  1332. } else if adviceType == 1 {
  1333. if patientType == 0 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1336. } else if patientType == 1 {
  1337. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1339. } else if patientType == 2 {
  1340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1342. }
  1343. } else if adviceType == 3 {
  1344. if patientType == 0 {
  1345. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1347. } else if patientType == 1 {
  1348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1350. } else if patientType == 2 {
  1351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1353. }
  1354. } else if adviceType == 2 && len(deliverWay) > 0 {
  1355. if patientType == 0 {
  1356. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1358. } else if patientType == 1 {
  1359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1361. } else if patientType == 2 {
  1362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1364. }
  1365. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1366. if patientType == 0 {
  1367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1369. } else if patientType == 1 {
  1370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1372. } else if patientType == 2 {
  1373. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1375. }
  1376. }
  1377. db := readDb.
  1378. Table("xt_schedule").
  1379. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1380. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1381. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1382. }).
  1383. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1384. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1385. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1386. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1387. Preload("DoctorAdvices", adviceCondition...).
  1388. Where("status = 1 AND user_org_id = ?", orgID)
  1389. if scheduleDate != 0 {
  1390. db = db.Where("schedule_date = ?", scheduleDate)
  1391. }
  1392. err := db.Find(&vms).Error
  1393. return vms, err
  1394. }
  1395. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1396. var vms []*MScheduleDoctorAdviceVMOne
  1397. adviceWhere := ""
  1398. adviceCondition := []interface{}{}
  1399. if adviceType == 0 {
  1400. if patientType == 0 {
  1401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1403. } else if patientType == 1 {
  1404. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1406. } else if patientType == 2 {
  1407. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1409. } else if patientType == 3 {
  1410. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = 1"
  1411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1412. } else if patientType == 4 {
  1413. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and (is_settle = 0 or is_settle = 2)"
  1414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1415. }
  1416. } else if adviceType == 1 {
  1417. if patientType == 0 {
  1418. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1420. } else if patientType == 1 {
  1421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1423. } else if patientType == 2 {
  1424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1426. } else if patientType == 3 {
  1427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1429. } else if patientType == 4 {
  1430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1432. }
  1433. } else if adviceType == 3 {
  1434. if patientType == 0 {
  1435. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1437. } else if patientType == 1 {
  1438. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1440. } else if patientType == 2 {
  1441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1443. } else if patientType == 3 {
  1444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1446. } else if patientType == 4 {
  1447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1449. }
  1450. } else if adviceType == 2 && len(deliverWay) > 0 {
  1451. if patientType == 0 {
  1452. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1454. } else if patientType == 1 {
  1455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1457. } else if patientType == 2 {
  1458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1460. } else if patientType == 3 {
  1461. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1463. } else if patientType == 4 {
  1464. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and (is_settle = 0 or is_settle =2)"
  1465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1466. }
  1467. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1468. if patientType == 0 {
  1469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1471. } else if patientType == 1 {
  1472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1474. } else if patientType == 2 {
  1475. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1477. } else if patientType == 3 {
  1478. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1480. } else if patientType == 4 {
  1481. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1483. }
  1484. }
  1485. db := readDb.
  1486. Table("xt_schedule").
  1487. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1488. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1489. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1490. //}).
  1491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1494. Preload("DoctorAdvices", adviceCondition...).
  1495. Where("status = 1 AND user_org_id = ?", orgID)
  1496. if scheduleDate != 0 {
  1497. db = db.Where("schedule_date = ?", scheduleDate)
  1498. }
  1499. err := db.Find(&vms).Error
  1500. return vms, err
  1501. }
  1502. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1503. var vms []*HisMScheduleDoctorAdviceVM
  1504. if len(deliverWay) > 0 {
  1505. if patientType == 0 {
  1506. db := readDb.
  1507. Table("xt_schedule").
  1508. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1509. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1510. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1511. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1512. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1513. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1514. }).
  1515. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1516. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1517. Where("status = 1 AND user_org_id = ?", orgID)
  1518. if scheduleDate != 0 {
  1519. db = db.Where("schedule_date = ?", scheduleDate)
  1520. }
  1521. err = db.Find(&vms).Error
  1522. }
  1523. if patientType > 0 {
  1524. db := readDb.
  1525. Table("xt_schedule").
  1526. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1527. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1528. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1529. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1530. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1532. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1533. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1534. }).Where("status = 1 AND user_org_id = ?", orgID)
  1535. if scheduleDate != 0 {
  1536. db = db.Where("schedule_date = ?", scheduleDate)
  1537. }
  1538. err = db.Find(&vms).Error
  1539. }
  1540. } else {
  1541. if patientType == 0 {
  1542. db := readDb.
  1543. Table("xt_schedule").
  1544. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1545. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1546. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1547. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1548. }).
  1549. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1550. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1551. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1552. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1553. Where("status = 1 AND user_org_id = ?", orgID)
  1554. if scheduleDate != 0 {
  1555. db = db.Where("schedule_date = ?", scheduleDate)
  1556. }
  1557. err = db.Find(&vms).Error
  1558. }
  1559. if patientType > 0 {
  1560. db := readDb.
  1561. Table("xt_schedule").
  1562. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1563. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1564. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1565. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1566. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1567. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1568. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1569. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1570. Where("status = 1 AND user_org_id = ?", orgID)
  1571. if scheduleDate != 0 {
  1572. db = db.Where("schedule_date = ?", scheduleDate)
  1573. }
  1574. err = db.Find(&vms).Error
  1575. }
  1576. }
  1577. return vms, err
  1578. }
  1579. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1580. var vms []*HisMScheduleDoctorAdviceVMOne
  1581. if len(deliverWay) > 0 {
  1582. if patientType == 0 {
  1583. db := readDb.
  1584. Table("xt_schedule").
  1585. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1586. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1587. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1588. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1589. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1590. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1591. }).
  1592. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1593. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1594. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1595. Where("status = 1 AND user_org_id = ?", orgID)
  1596. if scheduleDate != 0 {
  1597. db = db.Where("schedule_date = ?", scheduleDate)
  1598. }
  1599. err = db.Find(&vms).Error
  1600. }
  1601. if patientType > 0 {
  1602. if patientType == 1 {
  1603. db := readDb.
  1604. Table("xt_schedule").
  1605. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1606. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1607. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1608. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1609. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1610. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1611. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1612. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1613. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1614. Where("status = 1 AND user_org_id = ?", orgID)
  1615. if scheduleDate != 0 {
  1616. db = db.Where("schedule_date = ?", scheduleDate)
  1617. }
  1618. err = db.Find(&vms).Error
  1619. }
  1620. if patientType == 2 {
  1621. db := readDb.
  1622. Table("xt_schedule").
  1623. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1624. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1625. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?)", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1626. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1627. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1628. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1629. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1630. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1631. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1632. if scheduleDate != 0 {
  1633. db = db.Where("schedule_date = ?", scheduleDate)
  1634. }
  1635. err = db.Find(&vms).Error
  1636. }
  1637. if patientType == 3 {
  1638. db := readDb.
  1639. Table("xt_schedule").
  1640. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1641. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1642. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) and is_settle = 1", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1643. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1644. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1645. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1646. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1647. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1648. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1649. if scheduleDate != 0 {
  1650. db = db.Where("schedule_date = ?", scheduleDate)
  1651. }
  1652. err = db.Find(&vms).Error
  1653. }
  1654. if patientType == 4 {
  1655. db := readDb.
  1656. Table("xt_schedule").
  1657. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1658. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1659. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) and (is_settle = 0 or is_settle = 2)", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1660. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1661. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1662. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1663. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1664. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1665. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1666. if scheduleDate != 0 {
  1667. db = db.Where("schedule_date = ?", scheduleDate)
  1668. }
  1669. err = db.Find(&vms).Error
  1670. }
  1671. }
  1672. } else {
  1673. if patientType == 0 {
  1674. db := readDb.
  1675. Table("xt_schedule").
  1676. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1677. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1678. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1679. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1680. }).
  1681. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1682. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1683. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1684. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1685. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1686. Where("status = 1 AND user_org_id = ?", orgID)
  1687. if scheduleDate != 0 {
  1688. db = db.Where("schedule_date = ?", scheduleDate)
  1689. }
  1690. err = db.Find(&vms).Error
  1691. }
  1692. if patientType > 0 {
  1693. if patientType == 1 {
  1694. db := readDb.
  1695. Table("xt_schedule").
  1696. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1697. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1698. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1699. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1700. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1701. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1702. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1703. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1704. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1705. Where("status = 1 AND user_org_id = ?", orgID)
  1706. if scheduleDate != 0 {
  1707. db = db.Where("schedule_date = ?", scheduleDate)
  1708. }
  1709. err = db.Find(&vms).Error
  1710. }
  1711. if patientType == 2 {
  1712. db := readDb.
  1713. Table("xt_schedule").
  1714. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1715. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1716. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1717. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1718. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1719. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1720. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1721. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1722. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1723. Where("status = 1 AND user_org_id = ?", orgID)
  1724. if scheduleDate != 0 {
  1725. db = db.Where("schedule_date = ?", scheduleDate)
  1726. }
  1727. err = db.Find(&vms).Error
  1728. }
  1729. if patientType == 3 {
  1730. db := readDb.
  1731. Table("xt_schedule").
  1732. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1733. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) and is_settle = 1", orgID, scheduleDate, adminUserId, adminUserId).
  1734. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1735. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1736. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1737. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1738. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1739. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1740. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1741. Where("status = 1 AND user_org_id = ?", orgID)
  1742. if scheduleDate != 0 {
  1743. db = db.Where("schedule_date = ?", scheduleDate)
  1744. }
  1745. err = db.Find(&vms).Error
  1746. }
  1747. if patientType == 4 {
  1748. db := readDb.
  1749. Table("xt_schedule").
  1750. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1751. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) and (is_settle = 0 or is_settle =2) ", orgID, scheduleDate, adminUserId, adminUserId).
  1752. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1753. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1754. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1755. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1756. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1757. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1758. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1759. Where("status = 1 AND user_org_id = ?", orgID)
  1760. if scheduleDate != 0 {
  1761. db = db.Where("schedule_date = ?", scheduleDate)
  1762. }
  1763. err = db.Find(&vms).Error
  1764. }
  1765. }
  1766. }
  1767. return vms, err
  1768. }
  1769. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1770. var vms []*HisMScheduleProjectVM
  1771. //if patientType == 0 {
  1772. // db := readDb.
  1773. // Table("xt_schedule").
  1774. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1775. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1776. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1777. // }).
  1778. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1779. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1780. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1781. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1782. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1783. // }).
  1784. // Where("status = 1 AND user_org_id = ?", orgID)
  1785. // if scheduleDate != 0 {
  1786. // db = db.Where("schedule_date = ?", scheduleDate)
  1787. // }
  1788. // err = db.Find(&vms).Error
  1789. //}
  1790. //if patientType > 0 {
  1791. // db := readDb.
  1792. // Table("xt_schedule").
  1793. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1794. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1795. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1796. // }).
  1797. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1798. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1799. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1800. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1801. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1802. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1803. // }).
  1804. // Where("status = 1 AND user_org_id = ?", orgID)
  1805. // if scheduleDate != 0 {
  1806. // db = db.Where("schedule_date = ?", scheduleDate)
  1807. // }
  1808. // err = db.Find(&vms).Error
  1809. //}
  1810. db := readDb.Table("xt_schedule").Where("status = 1")
  1811. if orgID > 0 {
  1812. db = db.Where("user_org_id = ?", orgID)
  1813. }
  1814. if scheduleDate > 0 {
  1815. db = db.Where("schedule_date =?", scheduleDate)
  1816. }
  1817. err = db.Find(&vms).Error
  1818. if patientType == 0 {
  1819. db := readDb.
  1820. Table("xt_schedule").
  1821. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1822. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1823. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1824. }).
  1825. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1826. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1827. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1828. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1829. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1830. }).
  1831. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1832. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1833. }).
  1834. Where("status = 1 AND user_org_id = ?", orgID)
  1835. if scheduleDate != 0 {
  1836. db = db.Where("schedule_date = ?", scheduleDate)
  1837. }
  1838. err = db.Find(&vms).Error
  1839. }
  1840. if patientType > 0 {
  1841. db := readDb.
  1842. Table("xt_schedule").
  1843. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1844. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1845. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1846. }).
  1847. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1848. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1849. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1850. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1851. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1852. }).
  1853. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1854. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1855. }).
  1856. Where("status = 1 AND user_org_id = ?", orgID)
  1857. if scheduleDate != 0 {
  1858. db = db.Where("schedule_date = ?", scheduleDate)
  1859. }
  1860. err = db.Find(&vms).Error
  1861. }
  1862. return vms, err
  1863. }
  1864. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1865. now := time.Now()
  1866. tx := writeDb.Begin()
  1867. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1868. tx.Rollback()
  1869. return createOrderErr
  1870. }
  1871. // 更新透析记录 ID
  1872. // 透析处方
  1873. if err := tx.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1874. tx.Rollback()
  1875. return err
  1876. }
  1877. // 接诊评估
  1878. if err := tx.Model(&models.ReceiveTreatmentAsses{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "update_time": now.Unix()}).Error; err != nil {
  1879. tx.Rollback()
  1880. return err
  1881. }
  1882. // 透前评估
  1883. if err := tx.Model(&models.PredialysisEvaluation{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1884. tx.Rollback()
  1885. return err
  1886. }
  1887. // 临时医嘱
  1888. if err := tx.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND advice_type = 2", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1889. tx.Rollback()
  1890. return err
  1891. }
  1892. // 双人核对
  1893. if err := tx.Model(&models.DoubleCheck{}).Where("user_org_id = ? AND patient_id = ? AND check_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1894. tx.Rollback()
  1895. return err
  1896. }
  1897. // 透后评估
  1898. if err := tx.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1899. tx.Rollback()
  1900. return err
  1901. }
  1902. // 治疗小结
  1903. if err := tx.Model(&models.TreatmentSummary{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1904. tx.Rollback()
  1905. return err
  1906. }
  1907. // 透析监测
  1908. if err := tx.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientID, orgID, order.DialysisDate).Update(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1909. tx.Rollback()
  1910. return err
  1911. }
  1912. tx.Commit()
  1913. return nil
  1914. }
  1915. type MobileUrgentSchedulePatientVM struct {
  1916. ID int64 `gorm:"column:id" json:"id"`
  1917. Name string `gorm:"column:name" json:"name"`
  1918. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1919. }
  1920. func (MobileUrgentSchedulePatientVM) TableName() string {
  1921. return "xt_patients"
  1922. }
  1923. type MobileUrgentScheduleTreatmentModeVM struct {
  1924. ID int64 `gorm:"column:id" json:"id"`
  1925. Name string `gorm:"column:name" json:"name"`
  1926. }
  1927. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1928. return "xt_treatment_mode"
  1929. }
  1930. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1931. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1932. rows, err := readDb.Raw("SELECT p.* FROM xt_patients as p WHERE (p.user_org_id = ? AND p.status = 1 AND p.lapseto = 1) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = p.id AND d.user_org_id = p.user_org_id )", orgID, record_date).Rows()
  1933. defer rows.Close()
  1934. if err != nil {
  1935. return nil, err
  1936. }
  1937. for rows.Next() {
  1938. var vm MobileUrgentSchedulePatientVM
  1939. readDb.ScanRows(rows, &vm)
  1940. vms = append(vms, &vm)
  1941. }
  1942. return vms, nil
  1943. }
  1944. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1945. var modes []*MobileUrgentScheduleTreatmentModeVM
  1946. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1947. if err != nil {
  1948. return nil, err
  1949. }
  1950. return modes, nil
  1951. }
  1952. type MobileUrgentScheduleScheduleListVM struct {
  1953. ID int64 `gorm:"column:id" json:"id"`
  1954. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1955. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1956. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1957. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1958. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1959. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1960. }
  1961. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1962. return "xt_schedule"
  1963. }
  1964. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1965. db := readDb.
  1966. Model(&MobileUrgentScheduleScheduleListVM{}).
  1967. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1968. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1969. err = db.Find(&schedules).Error
  1970. if err != nil {
  1971. return nil, err
  1972. }
  1973. return schedules, nil
  1974. }
  1975. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1976. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1977. rows, err := readDb.Raw("SELECT * FROM xt_schedule as s WHERE s.user_org_id = ? AND s.status = 1 AND s.schedule_date = ? ", orgID, scheduleDate).Rows()
  1978. defer rows.Close()
  1979. if err != nil {
  1980. return nil, err
  1981. }
  1982. for rows.Next() {
  1983. var vm MobileUrgentScheduleScheduleListVM
  1984. readDb.ScanRows(rows, &vm)
  1985. vms = append(vms, &vm)
  1986. }
  1987. return vms, nil
  1988. }
  1989. type MobileUrgentScheduleDeviceNumberVM struct {
  1990. ID int64 `gorm:"column:id" json:"id"`
  1991. Number string `gorm:"column:number" json:"number"`
  1992. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1993. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1994. }
  1995. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1996. return "xt_device_number"
  1997. }
  1998. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1999. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2000. rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.user_org_id = n.org_id AND s.`bed_id` = n.id AND s.`schedule_type` = ? AND s.status = 1 )", orgID, record_date, schedule_type).Rows()
  2001. defer rows.Close()
  2002. if err != nil {
  2003. return nil, err
  2004. }
  2005. for rows.Next() {
  2006. var vm DeviceNumberViewModel
  2007. readDb.ScanRows(rows, &vm)
  2008. vms = append(vms, &vm)
  2009. }
  2010. return vms, nil
  2011. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2012. //db := readDb.
  2013. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2014. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2015. // Where("status = 1 AND org_id = ?", orgID)
  2016. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2017. //if err != nil {
  2018. // return nil, err
  2019. //}
  2020. //return deviceNumbers, nil
  2021. }
  2022. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2023. var total int64
  2024. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2025. return total, err
  2026. }
  2027. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2028. var monitors []*models.MonitoringRecord
  2029. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2030. if err != nil {
  2031. return nil, err
  2032. }
  2033. return monitors, nil
  2034. }
  2035. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2036. tx := writeDb.Begin()
  2037. for index := 0; index < len(monitors); index++ {
  2038. tx.Save(monitors[index])
  2039. }
  2040. return tx.Commit().Error
  2041. }
  2042. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2043. tx := writeDb.Begin()
  2044. updateTime := time.Now().Unix()
  2045. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType, "washpipe_nurse": order.WashpipeNurse, "change_nurse": order.ChangeNurse, "difficult_puncture_nurse": order.DifficultPunctureNurse, "new_fistula_nurse": order.NewFistulaNurse, "quality_nurse_id": order.QualityNurseId, "puncture_needle": order.PunctureNeedle, "puncture_way": order.PunctureWay, "dialysis_dialyszers": order.DialysisDialyszers, "dialysis_irrigation": order.DialysisIrrigation, "blood_access_id": order.BloodAccessId, "nuclein_date": order.NucleinDate, "schedule_remark": order.ScheduleRemark, "order_remark": order.OrderRemark, "catheter_operation": order.CatheterOperation, "blood_flow_volume": order.BloodFlowVolume, "blood_drawing": order.BloodDrawing, "dialysis_strainer": order.DialysisStrainer}).Error
  2046. if err != nil {
  2047. tx.Rollback()
  2048. return err
  2049. }
  2050. tx.Commit()
  2051. return err
  2052. }
  2053. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2054. err := XTWriteDB().Model(&models.XtSchedule{}).Where("patient_id = ? and schedule_date = ? and status=1", patient_id, schedule_date).Updates(map[string]interface{}{"bed_id": bed_id, "schedule_type": schedule_type, "partition_id": zone_id}).Error
  2055. return err
  2056. }
  2057. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2058. tx := writeDb.Begin()
  2059. updateTime := time.Now().Unix()
  2060. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"finish_nurse": order.FinishNurse, "updated_time": updateTime, "end_time": order.EndTime, "finish_modifier": order.FinishModifier, "puncture_point_haematoma": order.PuncturePointHaematoma, "blood_access_internal_fistula": order.BloodAccessInternalFistula, "catheter": order.Catheter, "cruor": order.Cruor, "mission": order.Mission, "condenser": order.Condenser}).Error
  2061. if err != nil {
  2062. tx.Rollback()
  2063. return err
  2064. }
  2065. tx.Commit()
  2066. return err
  2067. }
  2068. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2069. var record models.SgjPatientDryweight
  2070. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2071. if err != nil {
  2072. if err == gorm.ErrRecordNotFound {
  2073. return nil, nil
  2074. } else {
  2075. return nil, err
  2076. }
  2077. }
  2078. return &record, nil
  2079. }
  2080. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2081. // var record models.SgjPatientDryweight
  2082. // redis := RedisClient()
  2083. // defer redis.Close()
  2084. //
  2085. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2086. // last_dry_weight_str, _ := redis.Get(key).Result()
  2087. //
  2088. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2089. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2090. // if err != nil {
  2091. // if err == gorm.ErrRecordNotFound {
  2092. // if record.ID <= 0 {
  2093. // redis.Set(key, "null", time.Second*60*60*18)
  2094. // }
  2095. // return nil, nil
  2096. // } else {
  2097. // return nil, err
  2098. // }
  2099. // } else {
  2100. // if record.ID > 0 {
  2101. // //缓存数据
  2102. // last_dry_weight_str, err := json.Marshal(record)
  2103. // if err == nil {
  2104. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2105. // return nil, err
  2106. // }
  2107. // } else {
  2108. // redis.Set(key, "null", time.Second*60*60*18)
  2109. // return nil, err
  2110. // }
  2111. // return &record, nil
  2112. // }
  2113. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2114. // if last_dry_weight_str == "null" {
  2115. // return &record, nil
  2116. // } else {
  2117. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2118. // return &record, nil
  2119. // }
  2120. //
  2121. // }
  2122. //}
  2123. // 透析方案
  2124. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2125. var record models.DialysisSolution
  2126. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status =1", patientID, orgID, mode_id).Last(&record).Error
  2127. if err != nil {
  2128. if err == gorm.ErrRecordNotFound {
  2129. return nil, nil
  2130. } else {
  2131. return nil, err
  2132. }
  2133. }
  2134. return &record, nil
  2135. }
  2136. // 透析方案
  2137. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2138. var record models.DialysisSolution
  2139. err = readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status =1", patientID, orgID, mode_id).Last(&record).Error
  2140. return record, nil
  2141. }
  2142. // 透析方案
  2143. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2144. var record models.DialysisSolution
  2145. redis := RedisClient()
  2146. defer redis.Close()
  2147. // cur_date := time.Now().Format("2006-01-02")
  2148. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2149. dialysis_solution_str, _ := redis.Get(key).Result()
  2150. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2151. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? and solution_status=1", patientID, orgID, mode_id).Last(&record).Error
  2152. if err != nil {
  2153. if err == gorm.ErrRecordNotFound {
  2154. if record.ID <= 0 {
  2155. redis.Set(key, "null", time.Second*60*60*18)
  2156. }
  2157. return nil, nil
  2158. } else {
  2159. return nil, err
  2160. }
  2161. } else {
  2162. if record.ID > 0 {
  2163. //缓存数据
  2164. dialysis_solution_str, err := json.Marshal(record)
  2165. if err == nil {
  2166. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2167. }
  2168. } else {
  2169. redis.Set(key, "null", time.Second*60*60*18)
  2170. }
  2171. return &record, nil
  2172. }
  2173. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2174. if dialysis_solution_str == "null" {
  2175. return &record, nil
  2176. } else {
  2177. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2178. return &record, nil
  2179. }
  2180. }
  2181. }
  2182. // 透析处方
  2183. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2184. var record models.DialysisPrescription
  2185. redis := RedisClient()
  2186. defer redis.Close()
  2187. // cur_date := time.Now().Format("2006-01-02")
  2188. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2189. redis.Set(key, "", time.Second)
  2190. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2191. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  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. if record.ID <= 0 {
  2196. redis.Set(key, "null", time.Second*60*60*18)
  2197. }
  2198. return nil, nil
  2199. } else {
  2200. return nil, err
  2201. }
  2202. } else {
  2203. if record.ID > 0 {
  2204. //缓存数据
  2205. dialysis_prescribe_str, err := json.Marshal(record)
  2206. if err == nil {
  2207. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2208. }
  2209. } else {
  2210. redis.Set(key, "null", time.Second*60*60*18)
  2211. }
  2212. return &record, nil
  2213. }
  2214. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2215. if dialysis_prescribe_str == "null" {
  2216. return &record, nil
  2217. } else {
  2218. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2219. return &record, nil
  2220. }
  2221. }
  2222. }
  2223. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2224. var record models.DialysisPrescription
  2225. 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
  2226. if err != nil {
  2227. if err == gorm.ErrRecordNotFound {
  2228. return nil, nil
  2229. } else {
  2230. return nil, err
  2231. }
  2232. }
  2233. return &record, nil
  2234. }
  2235. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2236. var record models.DialysisPrescription
  2237. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2238. if err != nil {
  2239. if err == gorm.ErrRecordNotFound {
  2240. return nil, nil
  2241. } else {
  2242. return nil, err
  2243. }
  2244. }
  2245. return &record, nil
  2246. }
  2247. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2248. // var record models.DialysisPrescription
  2249. // redis := RedisClient()
  2250. // defer redis.Close()
  2251. //
  2252. // // cur_date := time.Now().Format("2006-01-02")
  2253. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2254. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2255. //
  2256. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2257. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2258. // if err != nil {
  2259. // if err == gorm.ErrRecordNotFound {
  2260. // if record.ID <= 0 {
  2261. // redis.Set(key, "null", time.Second*60*60*18)
  2262. // }
  2263. // return nil, nil
  2264. // } else {
  2265. // return nil, err
  2266. // }
  2267. // } else {
  2268. //
  2269. // if record.ID > 0 {
  2270. // //缓存数据
  2271. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2272. //
  2273. // if err == nil {
  2274. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2275. // return nil, err
  2276. // }
  2277. // } else {
  2278. // redis.Set(key, "null", time.Second*60*60*18)
  2279. // return nil, err
  2280. // }
  2281. // return &record, nil
  2282. // }
  2283. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2284. // if dialysis_prescribe_by_mode_str == "null" {
  2285. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2286. // return &record, nil
  2287. // } else {
  2288. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2289. // return &record, nil
  2290. // }
  2291. //
  2292. // }
  2293. //}
  2294. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2295. var record models.DialysisPrescription
  2296. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2297. if err != nil {
  2298. if err == gorm.ErrRecordNotFound {
  2299. return nil, nil
  2300. } else {
  2301. return nil, err
  2302. }
  2303. }
  2304. return &record, nil
  2305. }
  2306. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2307. var record models.DialysisPrescription
  2308. 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
  2309. //if err != nil {
  2310. // if err == gorm.ErrRecordNotFound {
  2311. // return nil, nil
  2312. // } else {
  2313. // return nil, err
  2314. // }
  2315. //}
  2316. return &record, err
  2317. }
  2318. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2319. var record models.DialysisPrescription
  2320. 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
  2321. if err != nil {
  2322. if err == gorm.ErrRecordNotFound {
  2323. return nil, nil
  2324. } else {
  2325. return nil, err
  2326. }
  2327. }
  2328. return &record, err
  2329. }
  2330. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2331. var record models.DialysisPrescription
  2332. redis := RedisClient()
  2333. defer redis.Close()
  2334. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2335. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2336. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2337. 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
  2338. if err != nil {
  2339. if err == gorm.ErrRecordNotFound {
  2340. if record.ID <= 0 {
  2341. redis.Set(key, "null", time.Second*60*60*18)
  2342. }
  2343. return nil, nil
  2344. } else {
  2345. return nil, err
  2346. }
  2347. } else {
  2348. if record.ID > 0 {
  2349. //缓存数据
  2350. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2351. if err == nil {
  2352. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2353. return nil, err
  2354. }
  2355. } else {
  2356. redis.Set(key, "null", time.Second*60*60*18)
  2357. return nil, err
  2358. }
  2359. return &record, nil
  2360. }
  2361. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2362. if dialysis_prescribe_by_mode_id == "null" {
  2363. return &record, nil
  2364. } else {
  2365. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2366. return &record, nil
  2367. }
  2368. }
  2369. }
  2370. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2371. var record models.DialysisPrescription
  2372. 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
  2373. return record, err
  2374. }
  2375. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2376. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2377. 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()
  2378. defer rows.Close()
  2379. if err != nil {
  2380. return nil, err
  2381. }
  2382. for rows.Next() {
  2383. var vm DeviceNumberViewModel
  2384. readDb.ScanRows(rows, &vm)
  2385. vms = append(vms, &vm)
  2386. }
  2387. return vms, nil
  2388. }
  2389. // 获取 maxDate 之前一次的透前评估记录
  2390. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2391. var record models.PredialysisEvaluation
  2392. 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
  2393. if err != nil {
  2394. if err == gorm.ErrRecordNotFound {
  2395. return nil, nil
  2396. } else {
  2397. return nil, err
  2398. }
  2399. }
  2400. return &record, nil
  2401. }
  2402. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2403. var record models.DialysisOrder
  2404. 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
  2405. if err != nil {
  2406. if err == gorm.ErrRecordNotFound {
  2407. return nil, nil
  2408. } else {
  2409. return nil, err
  2410. }
  2411. }
  2412. return &record, nil
  2413. }
  2414. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2415. var record models.MonitoringRecord
  2416. 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
  2417. if err != nil {
  2418. if err == gorm.ErrRecordNotFound {
  2419. return nil, nil
  2420. } else {
  2421. return nil, err
  2422. }
  2423. }
  2424. return &record, nil
  2425. }
  2426. func GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2427. var record models.MonitoringRecord
  2428. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and ultrafiltration_volume_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2429. return record, nil
  2430. }
  2431. func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2432. var record models.MonitoringRecord
  2433. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_systolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2434. return record, nil
  2435. }
  2436. func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2437. var record models.MonitoringRecord
  2438. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_diastolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2439. return record, nil
  2440. }
  2441. func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2442. var record models.MonitoringRecord
  2443. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and pulse_frequency_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2444. return record, nil
  2445. }
  2446. func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2447. var record models.MonitoringRecord
  2448. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and displacement_quantity_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2449. return record, nil
  2450. }
  2451. // 获取 maxDate 之前一次的透后评估记录
  2452. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2453. var record models.AssessmentAfterDislysis
  2454. 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
  2455. if err != nil {
  2456. if err == gorm.ErrRecordNotFound {
  2457. return nil, nil
  2458. } else {
  2459. return nil, err
  2460. }
  2461. }
  2462. return &record, nil
  2463. }
  2464. // 透析处方
  2465. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2466. var record models.DialysisPrescription
  2467. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2468. if err != nil {
  2469. if err == gorm.ErrRecordNotFound {
  2470. return nil, nil
  2471. } else {
  2472. return nil, err
  2473. }
  2474. }
  2475. return &record, nil
  2476. }
  2477. // 透析方案
  2478. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2479. var record models.DialysisSolution
  2480. 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
  2481. return record, err
  2482. }
  2483. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2484. var record models.DialysisSolution
  2485. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2486. if err != nil {
  2487. if err == gorm.ErrRecordNotFound {
  2488. return nil, nil
  2489. } else {
  2490. return nil, err
  2491. }
  2492. }
  2493. return &record, nil
  2494. }
  2495. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2496. var record models.DialysisPrescription
  2497. 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
  2498. if err != nil {
  2499. if err == gorm.ErrRecordNotFound {
  2500. return nil, nil
  2501. } else {
  2502. return nil, err
  2503. }
  2504. }
  2505. return &record, nil
  2506. }
  2507. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2508. var record models.SgjPatientDryweight
  2509. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2510. if err != nil {
  2511. if err == gorm.ErrRecordNotFound {
  2512. return nil, nil
  2513. } else {
  2514. return nil, err
  2515. }
  2516. }
  2517. return &record, nil
  2518. }
  2519. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2520. var record models.SystemPrescription
  2521. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2522. if err != nil {
  2523. if err == gorm.ErrRecordNotFound {
  2524. return nil, nil
  2525. } else {
  2526. return nil, err
  2527. }
  2528. }
  2529. return &record, nil
  2530. }
  2531. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2532. var record models.SystemPrescription
  2533. redis := RedisClient()
  2534. defer redis.Close()
  2535. // cur_date := time.Now().Format("2006-01-02")
  2536. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2537. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2538. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2539. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2540. if err != nil {
  2541. if err == gorm.ErrRecordNotFound {
  2542. if record.ID <= 0 {
  2543. redis.Set(key, "null", time.Second*60*60*18)
  2544. }
  2545. return nil, nil
  2546. } else {
  2547. return nil, err
  2548. }
  2549. } else {
  2550. if record.ID > 0 {
  2551. //缓存数据
  2552. system_dialysis_prescribe_str, err := json.Marshal(record)
  2553. if err == nil {
  2554. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2555. }
  2556. } else {
  2557. redis.Set(key, "null", time.Second*60*60*18)
  2558. }
  2559. return &record, nil
  2560. }
  2561. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2562. if system_dialysis_prescribe_str == "null" {
  2563. return &record, nil
  2564. } else {
  2565. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2566. return &record, nil
  2567. }
  2568. }
  2569. }
  2570. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2571. var record models.SystemPrescription
  2572. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2573. return record, err
  2574. }
  2575. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2576. var record models.SystemPrescription
  2577. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2578. if err != nil {
  2579. if err == gorm.ErrRecordNotFound {
  2580. return nil, nil
  2581. } else {
  2582. return nil, err
  2583. }
  2584. }
  2585. return &record, nil
  2586. }
  2587. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2588. 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
  2589. return
  2590. }
  2591. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2592. 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
  2593. return
  2594. }
  2595. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2596. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1704038400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2597. return
  2598. }
  2599. func GetFirstDateOfMonth(d time.Time) time.Time {
  2600. d = d.AddDate(0, 0, -d.Day()+1)
  2601. return GetZeroTime(d)
  2602. }
  2603. func GetZeroTime(d time.Time) time.Time {
  2604. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2605. }
  2606. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2607. db := XTReadDB().Table("xt_dialysis_order as o")
  2608. 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
  2609. return order, err
  2610. }
  2611. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2612. 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
  2613. return
  2614. }
  2615. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2616. 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
  2617. return
  2618. }
  2619. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2620. 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
  2621. return
  2622. }
  2623. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2624. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 and type =3", orgID, patient_id, recordDate).Find(&project).Error
  2625. return
  2626. }
  2627. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2628. // 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
  2629. // return
  2630. //}
  2631. //
  2632. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2633. 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
  2634. return
  2635. }
  2636. type GoodsType struct {
  2637. ID int64 `gorm:"column:id" json:"id"`
  2638. TypeName string `gorm:"column:type_name" json:"type_name"`
  2639. Remark string `gorm:"column:remark" json:"remark"`
  2640. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2641. Status int64 `gorm:"column:status" json:"status"`
  2642. Type int64 `gorm:"column:type" json:"type"`
  2643. }
  2644. func (GoodsType) TableName() string {
  2645. return "xt_goods_type"
  2646. }
  2647. type VMGoodInfo struct {
  2648. ID int64 `gorm:"column:id" json:"id"`
  2649. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2650. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2651. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2652. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2653. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2654. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2655. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2656. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2657. }
  2658. func (VMGoodInfo) TableName() string {
  2659. return "xt_good_information"
  2660. }
  2661. type AutomaticReduceDetail struct {
  2662. ID int64 `gorm:"column:id" json:"id"`
  2663. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2664. Status int64 `gorm:"column:status" json:"status"`
  2665. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2666. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2667. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2668. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2669. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2670. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2671. Count int64 `gorm:"column:count" json:"count"`
  2672. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2673. }
  2674. func (AutomaticReduceDetail) TableName() string {
  2675. return "xt_automatic_reduce_detail"
  2676. }
  2677. type DialysisBeforePrepare struct {
  2678. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2679. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2680. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2681. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2682. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2683. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2684. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2685. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2686. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2687. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2688. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2689. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2690. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2691. }
  2692. func (DialysisBeforePrepare) TableName() string {
  2693. return "dialysis_before_prepare"
  2694. }
  2695. type MDialysisGoodsVM struct {
  2696. ID int64 `gorm:"column:id" json:"id"`
  2697. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2698. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2699. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2700. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2701. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2702. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2703. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2704. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2705. Status int64 `gorm:"column:status" json:"status"`
  2706. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2707. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2708. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2709. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2710. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2711. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2712. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2713. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2714. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2715. }
  2716. func (MDialysisGoodsVM) TableName() string {
  2717. return "xt_schedule"
  2718. }
  2719. type VMWarehouseOutInfo struct {
  2720. ID int64 `gorm:"column:id" json:"id"`
  2721. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2722. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2723. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2724. Count int64 `gorm:"column:count" json:"count"`
  2725. Price float64 `gorm:"column:price" json:"price"`
  2726. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2727. Status int64 `gorm:"column:status" json:"status"`
  2728. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2729. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2730. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2731. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2732. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2733. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2734. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2735. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2736. }
  2737. func (VMWarehouseOutInfo) TableName() string {
  2738. return "xt_warehouse_out_info"
  2739. }
  2740. type DialysisGoodsDate struct {
  2741. RecordDate int64
  2742. }
  2743. type DialysisGoodsDetailDate struct {
  2744. RecordTime int64
  2745. }
  2746. 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) {
  2747. var vms []*MDialysisGoodsVM
  2748. var total int64
  2749. db := readDb.
  2750. Table("xt_schedule as sch").
  2751. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2752. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2753. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2754. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2755. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2756. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? 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)
  2757. }).
  2758. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2759. 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")
  2760. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2761. if scheduleDate != 0 {
  2762. db = db.Where("schedule_date = ?", scheduleDate)
  2763. }
  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 patient_id != 0 {
  2771. db = db.Where("patient_id = ?", patient_id)
  2772. }
  2773. err := db.Find(&vms).Error
  2774. return vms, err, total
  2775. }
  2776. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2777. var Id []*DialysisGoodsDetailDate
  2778. 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
  2779. if len(Id) > 0 {
  2780. 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
  2781. }
  2782. return
  2783. }
  2784. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2785. var Id []*DialysisGoodsDate
  2786. 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
  2787. if len(Id) > 0 {
  2788. 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
  2789. }
  2790. return
  2791. }
  2792. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2793. err = XTReadDB().Where("patient_id = ? and org_id = ? and record_time = ? and good_id =? and status=1", patient_id, orgID, record_time, good_id).Find(&auto).Error
  2794. return auto, err
  2795. }
  2796. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2797. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2798. return info, err
  2799. }
  2800. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2801. db := readDb.Model(&models.StockInfo{})
  2802. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2803. 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")
  2804. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2805. 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)
  2806. })
  2807. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2808. err = db.Order("ctime desc").Find(&list).Error
  2809. return
  2810. }
  2811. 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) {
  2812. var vms []*MDialysisGoodsVM
  2813. var total int64
  2814. db := readDb.
  2815. Model(&models.Schedule{}).
  2816. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2817. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2818. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2819. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2820. 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)
  2821. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2822. 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)
  2823. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2824. if scheduleDate != 0 {
  2825. db = db.Where("schedule_date = ?", scheduleDate)
  2826. }
  2827. if patient_id != 0 {
  2828. db = db.Where("patient_id = ?", patient_id)
  2829. }
  2830. if len(keywords) != 0 {
  2831. keywords = "%" + keywords + "%"
  2832. 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)
  2833. if schedule_type != 0 {
  2834. db = db.Where("schedule_type = ?", schedule_type)
  2835. }
  2836. if partition_id != 0 {
  2837. db = db.Where("partition_id = ?", partition_id)
  2838. }
  2839. if good_type == 1 {
  2840. db = db.Where("patient_id in(?)", ids)
  2841. }
  2842. if good_type == 2 {
  2843. if len(ids) > 0 {
  2844. db = db.Where("patient_id not in(?)", ids)
  2845. }
  2846. }
  2847. } else {
  2848. if schedule_type != 0 {
  2849. db = db.Where("schedule_type = ?", schedule_type)
  2850. }
  2851. if partition_id != 0 {
  2852. db = db.Where("partition_id = ?", partition_id)
  2853. }
  2854. if good_type == 1 {
  2855. db = db.Where("patient_id in(?)", ids)
  2856. }
  2857. if good_type == 2 {
  2858. if len(ids) > 0 {
  2859. db = db.Where("patient_id not in(?)", ids)
  2860. }
  2861. }
  2862. db = db.Count(&total)
  2863. offset := (page - 1) * limit
  2864. db = db.Offset(offset).Limit(limit)
  2865. }
  2866. err := db.Find(&vms).Error
  2867. return vms, err, total
  2868. }
  2869. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2870. var Id []*DialysisGoodsDetailDate
  2871. 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
  2872. if len(Id) > 0 {
  2873. 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
  2874. }
  2875. return
  2876. }
  2877. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2878. var Id []*DialysisGoodsDate
  2879. 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
  2880. if len(Id) > 0 {
  2881. 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
  2882. }
  2883. return
  2884. }
  2885. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2886. evaluation := models.PredialysisEvaluation{}
  2887. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2888. if err == gorm.ErrRecordNotFound {
  2889. return nil, err
  2890. }
  2891. if err != nil {
  2892. return nil, err
  2893. }
  2894. return &evaluation, nil
  2895. }
  2896. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2897. evaluation := models.PredialysisEvaluation{}
  2898. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2899. return evaluation, err
  2900. }
  2901. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2902. evaluation := models.XtAssessmentBeforeDislysis{}
  2903. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2904. return evaluation, err
  2905. }
  2906. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2907. redis := RedisClient()
  2908. defer redis.Close()
  2909. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2910. his_doctor_advice_str, _ := redis.Get(key).Result()
  2911. redis.Set(key, "", time.Second)
  2912. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2913. 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
  2914. if err != nil {
  2915. if err == gorm.ErrRecordNotFound {
  2916. if len(his) <= 0 {
  2917. redis.Set(key, "null", time.Second*60*60*18)
  2918. }
  2919. return his, nil
  2920. } else {
  2921. return his, err
  2922. }
  2923. } else {
  2924. if len(his) > 0 {
  2925. //缓存数据
  2926. his_doctor_advice_str, err := json.Marshal(his)
  2927. if err == nil {
  2928. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2929. }
  2930. } else {
  2931. redis.Set(key, "null", time.Second*60*60*18)
  2932. }
  2933. return his, nil
  2934. }
  2935. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2936. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2937. return his, nil
  2938. }
  2939. }
  2940. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2941. prescription := models.DialysisPrescription{}
  2942. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2943. if err == gorm.ErrRecordNotFound {
  2944. return nil, err
  2945. }
  2946. if err != nil {
  2947. return nil, err
  2948. }
  2949. return &prescription, nil
  2950. }
  2951. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2952. prescription := models.DialysisPrescription{}
  2953. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2954. return prescription, err
  2955. }
  2956. type HisMScheduleDoctorAdviceVM struct {
  2957. ID int64 `gorm:"column:id" json:"id"`
  2958. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2959. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2960. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2961. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2962. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2963. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2964. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2965. Status int64 `gorm:"column:status" json:"status"`
  2966. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2967. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2968. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2969. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2970. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2971. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2972. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2973. }
  2974. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2975. return "xt_schedule"
  2976. }
  2977. type HisMScheduleDoctorAdviceVMOne struct {
  2978. ID int64 `gorm:"column:id" json:"id"`
  2979. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2980. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2981. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2982. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2983. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2984. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2985. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2986. Status int64 `gorm:"column:status" json:"status"`
  2987. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2988. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2989. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2990. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2991. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2992. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2993. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2994. }
  2995. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2996. return "xt_schedule"
  2997. }
  2998. type HisMScheduleProjectVM struct {
  2999. ID int64 `gorm:"column:id" json:"id"`
  3000. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3001. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3002. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3003. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3004. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3005. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3006. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3007. Status int64 `gorm:"column:status" json:"status"`
  3008. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3009. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3010. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3011. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3012. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3013. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3014. }
  3015. func (HisMScheduleProjectVM) TableName() string {
  3016. return "xt_schedule"
  3017. }
  3018. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3019. config := models.XtHisConfig{}
  3020. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3021. return config, err
  3022. }
  3023. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3024. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3025. if orgid > 0 {
  3026. db = db.Where("x.user_org_id = ?", orgid)
  3027. }
  3028. if patientid > 0 {
  3029. db = db.Where("x.patient_id =?", patientid)
  3030. }
  3031. if recordtime > 0 {
  3032. db = db.Where("x.advice_date = ?", recordtime)
  3033. }
  3034. 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
  3035. return advice, err
  3036. }
  3037. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3038. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3039. if startime > 0 {
  3040. db = db.Where("x.advice_date >= ?", startime)
  3041. }
  3042. if endtime > 0 {
  3043. db = db.Where("x.advice_date<=?", endtime)
  3044. }
  3045. if orgid > 0 {
  3046. db = db.Where("x.user_org_id = ?", orgid)
  3047. }
  3048. if len(deliveway) > 0 {
  3049. db = db.Where("x.delivery_way = ?", deliveway)
  3050. }
  3051. 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
  3052. return advice, err
  3053. }
  3054. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3055. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3056. if startime > 0 {
  3057. db = db.Where("x.advice_date >= ?", startime)
  3058. }
  3059. if endtime > 0 {
  3060. db = db.Where("x.advice_date<=?", endtime)
  3061. }
  3062. if orgid > 0 {
  3063. db = db.Where("x.user_org_id = ?", orgid)
  3064. }
  3065. if len(deliveway) > 0 {
  3066. db = db.Where("x.delivery_way = ?", deliveway)
  3067. }
  3068. 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
  3069. return advice, err
  3070. }
  3071. 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) {
  3072. var vms []*MScheduleDoctorAdviceVM
  3073. adviceWhere := ""
  3074. adviceCondition := []interface{}{}
  3075. if adviceType == 0 {
  3076. if patientType == 0 {
  3077. if patient_id > 0 {
  3078. if execution_state > 0 {
  3079. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3081. } else {
  3082. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3084. }
  3085. } else {
  3086. if execution_state > 0 {
  3087. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3089. } else {
  3090. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3092. }
  3093. }
  3094. } else if patientType == 1 {
  3095. if patient_id > 0 {
  3096. if execution_state > 0 {
  3097. 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= ?"
  3098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3099. } else {
  3100. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3102. }
  3103. } else {
  3104. if execution_state > 0 {
  3105. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3107. } else {
  3108. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3110. }
  3111. }
  3112. } else if patientType == 2 {
  3113. if patient_id > 0 {
  3114. if execution_state > 0 {
  3115. 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 = ?"
  3116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3117. } else {
  3118. 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 = ?)"
  3119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3120. }
  3121. } else {
  3122. if execution_state > 0 {
  3123. 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 = ?"
  3124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3125. } else {
  3126. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3128. }
  3129. }
  3130. }
  3131. } else if adviceType == 1 {
  3132. if patientType == 0 {
  3133. if patient_id > 0 {
  3134. if execution_state > 0 {
  3135. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3137. } else {
  3138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3140. }
  3141. } else {
  3142. if execution_state > 0 {
  3143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3145. } else {
  3146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3148. }
  3149. }
  3150. } else if patientType == 1 {
  3151. if patient_id > 0 {
  3152. if execution_state > 0 {
  3153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3155. } else {
  3156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3158. }
  3159. } else {
  3160. if execution_state > 0 {
  3161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3163. } else {
  3164. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3166. }
  3167. }
  3168. } else if patientType == 2 {
  3169. if patient_id > 0 {
  3170. if execution_state > 0 {
  3171. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3173. } else {
  3174. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3176. }
  3177. } else {
  3178. if execution_state > 0 {
  3179. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3181. } else {
  3182. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3184. }
  3185. }
  3186. }
  3187. } else if adviceType == 3 {
  3188. if patientType == 0 {
  3189. if patient_id > 0 {
  3190. if execution_state > 0 {
  3191. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3193. } else {
  3194. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3196. }
  3197. } else {
  3198. if execution_state > 0 {
  3199. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3201. } else {
  3202. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3204. }
  3205. }
  3206. } else if patientType == 1 {
  3207. if patient_id > 0 {
  3208. if execution_state > 0 {
  3209. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3211. } else {
  3212. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3214. }
  3215. } else {
  3216. if execution_state > 0 {
  3217. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3219. } else {
  3220. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3222. }
  3223. }
  3224. } else if patientType == 2 {
  3225. if patient_id > 0 {
  3226. if execution_state > 0 {
  3227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3229. } else {
  3230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3232. }
  3233. } else {
  3234. if execution_state > 0 {
  3235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3237. } else {
  3238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3240. }
  3241. }
  3242. }
  3243. } else if adviceType == 2 && len(deliverWay) > 0 {
  3244. if patientType == 0 {
  3245. if patient_id > 0 {
  3246. if execution_state > 0 {
  3247. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3249. } else {
  3250. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3252. }
  3253. } else {
  3254. if execution_state > 0 {
  3255. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3257. } else {
  3258. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3260. }
  3261. }
  3262. } else if patientType == 1 {
  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 advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3267. } else {
  3268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, 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 advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3275. } else {
  3276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3278. }
  3279. }
  3280. } else if patientType == 2 {
  3281. if patient_id > 0 {
  3282. if execution_state > 0 {
  3283. 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 = ?"
  3284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3285. } else {
  3286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3288. }
  3289. } else {
  3290. if execution_state > 0 {
  3291. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3293. } else {
  3294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3296. }
  3297. }
  3298. }
  3299. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3300. if patientType == 0 {
  3301. if patient_id > 0 {
  3302. if execution_state > 0 {
  3303. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3305. } else {
  3306. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3308. }
  3309. } else {
  3310. if execution_state > 0 {
  3311. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3313. } else {
  3314. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3316. }
  3317. }
  3318. } else if patientType == 1 {
  3319. if patient_id > 0 {
  3320. if execution_state > 0 {
  3321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3323. } else {
  3324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3326. }
  3327. } else {
  3328. if execution_state > 0 {
  3329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3331. } else {
  3332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3334. }
  3335. }
  3336. } else if patientType == 2 {
  3337. if patient_id > 0 {
  3338. if execution_state > 0 {
  3339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3341. } else {
  3342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3344. }
  3345. } else {
  3346. if execution_state > 0 {
  3347. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3349. } else {
  3350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3352. }
  3353. }
  3354. }
  3355. }
  3356. db := readDb.Table("xt_schedule")
  3357. if scheduleType > 0 {
  3358. db = db.Where("schedule_type = ?", scheduleType)
  3359. }
  3360. if partitonType > 0 {
  3361. db = db.Where("partition_id = ?", partitonType)
  3362. }
  3363. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3364. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3365. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3366. }).
  3367. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3368. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3369. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3370. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3371. Preload("DoctorAdvices", adviceCondition...).
  3372. Where("status = 1 AND user_org_id = ?", orgID)
  3373. if scheduleDate != 0 {
  3374. db = db.Where("schedule_date = ?", scheduleDate)
  3375. }
  3376. err := db.Find(&vms).Error
  3377. return vms, err
  3378. }
  3379. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3380. var vms []*HisMScheduleDoctorAdviceVM
  3381. if len(deliverWay) > 0 {
  3382. db := readDb.Table("xt_schedule")
  3383. if scheduleType > 0 {
  3384. db = db.Where("schedule_type = ?", scheduleType)
  3385. }
  3386. if partitionType > 0 {
  3387. db = db.Where("partition_id = ?", partitionType)
  3388. }
  3389. if patient_id > 0 {
  3390. if execution_state > 0 {
  3391. if cost_type > 0 {
  3392. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3393. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3394. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3395. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3396. 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).
  3397. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3398. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3399. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3400. Where("status = 1 AND user_org_id = ?", orgID)
  3401. if scheduleDate != 0 {
  3402. db = db.Where("schedule_date = ?", scheduleDate)
  3403. }
  3404. err = db.Find(&vms).Error
  3405. } else {
  3406. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3407. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3408. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3409. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3410. 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).
  3411. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3412. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3413. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3414. Where("status = 1 AND user_org_id = ?", orgID)
  3415. if scheduleDate != 0 {
  3416. db = db.Where("schedule_date = ?", scheduleDate)
  3417. }
  3418. err = db.Find(&vms).Error
  3419. }
  3420. } else {
  3421. if cost_type > 0 {
  3422. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3423. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3424. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3425. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3426. 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).
  3427. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3428. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3429. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3430. Where("status = 1 AND user_org_id = ?", orgID)
  3431. if scheduleDate != 0 {
  3432. db = db.Where("schedule_date = ?", scheduleDate)
  3433. }
  3434. err = db.Find(&vms).Error
  3435. } else {
  3436. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3437. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3438. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3439. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3440. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3441. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3442. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3443. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3444. Where("status = 1 AND user_org_id = ?", orgID)
  3445. if scheduleDate != 0 {
  3446. db = db.Where("schedule_date = ?", scheduleDate)
  3447. }
  3448. err = db.Find(&vms).Error
  3449. }
  3450. }
  3451. } else {
  3452. if execution_state > 0 {
  3453. if cost_type > 0 {
  3454. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3455. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3456. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3457. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3458. 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).
  3459. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3460. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3461. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3462. Where("status = 1 AND user_org_id = ?", orgID)
  3463. if scheduleDate != 0 {
  3464. db = db.Where("schedule_date = ?", scheduleDate)
  3465. }
  3466. err = db.Find(&vms).Error
  3467. } else {
  3468. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3469. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3470. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3471. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3472. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3473. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3474. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3475. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3476. Where("status = 1 AND user_org_id = ?", orgID)
  3477. if scheduleDate != 0 {
  3478. db = db.Where("schedule_date = ?", scheduleDate)
  3479. }
  3480. err = db.Find(&vms).Error
  3481. }
  3482. } else {
  3483. if cost_type > 0 {
  3484. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3485. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3486. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3487. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3488. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3489. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3490. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3491. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3492. Where("status = 1 AND user_org_id = ?", orgID)
  3493. if scheduleDate != 0 {
  3494. db = db.Where("schedule_date = ?", scheduleDate)
  3495. }
  3496. err = db.Find(&vms).Error
  3497. } else {
  3498. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3499. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3500. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3501. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3502. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3503. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3504. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3505. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3506. Where("status = 1 AND user_org_id = ?", orgID)
  3507. if scheduleDate != 0 {
  3508. db = db.Where("schedule_date = ?", scheduleDate)
  3509. }
  3510. err = db.Find(&vms).Error
  3511. }
  3512. }
  3513. }
  3514. } else {
  3515. db := readDb.Table("xt_schedule")
  3516. if scheduleType > 0 {
  3517. db = db.Where("schedule_type = ?", scheduleType)
  3518. }
  3519. if partitionType > 0 {
  3520. db = db.Where("partition_id = ?", partitionType)
  3521. }
  3522. if patient_id > 0 {
  3523. if execution_state > 0 {
  3524. if cost_type > 0 {
  3525. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3526. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3527. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3528. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3529. 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).
  3530. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3531. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3532. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3533. Where("status = 1 AND user_org_id = ?", orgID)
  3534. if scheduleDate != 0 {
  3535. db = db.Where("schedule_date = ?", scheduleDate)
  3536. }
  3537. err = db.Find(&vms).Error
  3538. } else {
  3539. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3540. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3541. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3542. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3543. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3544. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3545. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3546. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3547. Where("status = 1 AND user_org_id = ?", orgID)
  3548. if scheduleDate != 0 {
  3549. db = db.Where("schedule_date = ?", scheduleDate)
  3550. }
  3551. err = db.Find(&vms).Error
  3552. }
  3553. } else {
  3554. if cost_type > 0 {
  3555. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3556. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3557. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3558. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3559. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3560. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3561. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3562. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3563. Where("status = 1 AND user_org_id = ?", orgID)
  3564. if scheduleDate != 0 {
  3565. db = db.Where("schedule_date = ?", scheduleDate)
  3566. }
  3567. err = db.Find(&vms).Error
  3568. } else {
  3569. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3570. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3571. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3572. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3573. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3574. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3575. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3576. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3577. Where("status = 1 AND user_org_id = ?", orgID)
  3578. if scheduleDate != 0 {
  3579. db = db.Where("schedule_date = ?", scheduleDate)
  3580. }
  3581. err = db.Find(&vms).Error
  3582. }
  3583. }
  3584. } else {
  3585. if execution_state > 0 {
  3586. if cost_type > 0 {
  3587. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3588. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3589. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3590. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3591. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3592. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3593. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3594. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3595. Where("status = 1 AND user_org_id = ?", orgID)
  3596. if scheduleDate != 0 {
  3597. db = db.Where("schedule_date = ?", scheduleDate)
  3598. }
  3599. err = db.Find(&vms).Error
  3600. } else {
  3601. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3602. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3603. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3604. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3605. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3606. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3607. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3608. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3609. Where("status = 1 AND user_org_id = ?", orgID)
  3610. if scheduleDate != 0 {
  3611. db = db.Where("schedule_date = ?", scheduleDate)
  3612. }
  3613. err = db.Find(&vms).Error
  3614. }
  3615. } else {
  3616. if cost_type > 0 {
  3617. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3618. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3619. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3620. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3621. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3622. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3623. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3624. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3625. Where("status = 1 AND user_org_id = ?", orgID)
  3626. if scheduleDate != 0 {
  3627. db = db.Where("schedule_date = ?", scheduleDate)
  3628. }
  3629. err = db.Find(&vms).Error
  3630. } else {
  3631. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3632. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3633. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3634. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3635. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3636. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3637. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3638. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3639. Where("status = 1 AND user_org_id = ?", orgID)
  3640. if scheduleDate != 0 {
  3641. db = db.Where("schedule_date = ?", scheduleDate)
  3642. }
  3643. err = db.Find(&vms).Error
  3644. }
  3645. }
  3646. }
  3647. }
  3648. return vms, err
  3649. }
  3650. func BatchDeleteMonitor(ids []string) (err error) {
  3651. if len(ids) == 1 {
  3652. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3653. } else {
  3654. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3655. }
  3656. return
  3657. }
  3658. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3659. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3660. //table := XTReadDB().Table("xt_schedule as s")
  3661. //fmt.Println(table)
  3662. if patientid > 0 {
  3663. db = db.Where("x.patient_id = ?", patientid)
  3664. }
  3665. if startime > 0 {
  3666. db = db.Where("x.dialysis_date>=?", startime)
  3667. }
  3668. if endtime > 0 {
  3669. db = db.Where("x.dialysis_date <= ?", endtime)
  3670. }
  3671. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Where("s.status=1").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Group("x.id").Scan(&order).Error
  3672. return order, err
  3673. }
  3674. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3675. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3676. //table := XTReadDB().Table("xt_schedule as s")
  3677. //fmt.Println(table)
  3678. if patientid > 0 {
  3679. db = db.Where("x.patient_id = ?", patientid)
  3680. }
  3681. if startime > 0 {
  3682. db = db.Where("x.schedule_date>=?", startime)
  3683. }
  3684. if endtime > 0 {
  3685. db = db.Where("x.schedule_date <= ?", endtime)
  3686. }
  3687. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3688. return order, err
  3689. }
  3690. func BatchDeleteAdvice(ids []string) (err error) {
  3691. if len(ids) == 1 {
  3692. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3693. } else {
  3694. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3695. }
  3696. return
  3697. }
  3698. func BatchDeleteHisAdvice(ids []string) (err error) {
  3699. if len(ids) == 1 {
  3700. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3701. } else {
  3702. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3703. }
  3704. return
  3705. }
  3706. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3707. detail := models.AutomaticReduceDetail{}
  3708. 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
  3709. return detail, err
  3710. }
  3711. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3712. detail := models.AutomaticReduceDetail{}
  3713. 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
  3714. return err
  3715. }
  3716. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3717. detail := models.DialysisBeforePrepare{}
  3718. 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
  3719. return err
  3720. }
  3721. func BatchAdviceCheck(ids []string, creator int64) error {
  3722. advice := models.XtDoctorAdvice{}
  3723. 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
  3724. return err
  3725. }
  3726. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3727. advice := models.HisDoctorAdviceInfo{}
  3728. 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
  3729. return err
  3730. }
  3731. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3732. advice := models.XtDoctorAdvice{}
  3733. 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
  3734. return err
  3735. }
  3736. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3737. advice := models.HisDoctorAdviceInfo{}
  3738. 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
  3739. return err
  3740. }
  3741. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3742. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3743. return doctor, err
  3744. }
  3745. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3746. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3747. return doctor, err
  3748. }
  3749. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3750. config := models.XtHisProjectConfig{}
  3751. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3752. return config, err
  3753. }
  3754. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3755. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3756. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3757. }).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
  3758. return
  3759. }
  3760. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3761. var vms []*HisMScheduleProjectVM
  3762. if patientType == 0 {
  3763. if patient_id > 0 {
  3764. if execution_state == 1 {
  3765. db := readDb.
  3766. Table("xt_schedule").
  3767. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3768. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3769. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3770. }).
  3771. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3772. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3773. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3774. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3775. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3776. }).
  3777. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3778. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3779. }).Where("status = 1 AND user_org_id = ?", orgID)
  3780. if scheduleDate != 0 {
  3781. db = db.Where("schedule_date = ?", scheduleDate)
  3782. }
  3783. err = db.Find(&vms).Error
  3784. } else if execution_state == 2 {
  3785. db := readDb.
  3786. Table("xt_schedule").
  3787. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3788. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3789. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3790. }).
  3791. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3792. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3793. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3794. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3795. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3796. }).
  3797. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3798. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3799. }).Where("status = 1 AND user_org_id = ?", orgID)
  3800. if scheduleDate != 0 {
  3801. db = db.Where("schedule_date = ?", scheduleDate)
  3802. }
  3803. err = db.Find(&vms).Error
  3804. } else if execution_state == 0 {
  3805. db := readDb.
  3806. Table("xt_schedule").
  3807. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3808. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3809. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3810. }).
  3811. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3812. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3813. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3814. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3815. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3816. }).
  3817. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3818. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3819. }).Where("status = 1 AND user_org_id = ?", orgID)
  3820. if scheduleDate != 0 {
  3821. db = db.Where("schedule_date = ?", scheduleDate)
  3822. }
  3823. err = db.Find(&vms).Error
  3824. }
  3825. } else {
  3826. if patient_id > 0 {
  3827. if execution_state == 1 {
  3828. db := readDb.
  3829. Table("xt_schedule").
  3830. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3831. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3832. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3833. }).
  3834. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3835. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3836. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3837. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3838. 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")
  3839. }).
  3840. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3841. 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")
  3842. }).Where("status = 1 AND user_org_id = ?", orgID)
  3843. if scheduleDate != 0 {
  3844. db = db.Where("schedule_date = ?", scheduleDate)
  3845. }
  3846. err = db.Find(&vms).Error
  3847. } else if execution_state == 2 {
  3848. db := readDb.
  3849. Table("xt_schedule").
  3850. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3851. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3852. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3853. }).
  3854. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3855. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3856. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3857. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3858. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3859. }).
  3860. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3861. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3862. }).Where("status = 1 AND user_org_id = ?", orgID)
  3863. if scheduleDate != 0 {
  3864. db = db.Where("schedule_date = ?", scheduleDate)
  3865. }
  3866. err = db.Find(&vms).Error
  3867. } else if execution_state == 0 {
  3868. db := readDb.
  3869. Table("xt_schedule").
  3870. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3871. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3872. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3873. }).
  3874. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3875. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3876. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3877. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3878. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3879. }).
  3880. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3881. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3882. }).Where("status = 1 AND user_org_id = ?", orgID)
  3883. if scheduleDate != 0 {
  3884. db = db.Where("schedule_date = ?", scheduleDate)
  3885. }
  3886. err = db.Find(&vms).Error
  3887. }
  3888. } else {
  3889. if execution_state == 1 {
  3890. db := readDb.
  3891. Table("xt_schedule").
  3892. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3893. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3894. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3895. }).
  3896. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3897. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3898. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3899. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3900. 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")
  3901. }).
  3902. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3903. 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")
  3904. }).Where("status = 1 AND user_org_id = ?", orgID)
  3905. if scheduleDate != 0 {
  3906. db = db.Where("schedule_date = ?", scheduleDate)
  3907. }
  3908. err = db.Find(&vms).Error
  3909. } else if execution_state == 2 {
  3910. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3911. db := readDb.
  3912. Table("xt_schedule").
  3913. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3914. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3915. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3916. }).
  3917. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3918. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3919. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3920. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3921. 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")
  3922. }).
  3923. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3924. 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")
  3925. }).Where("status = 1 AND user_org_id = ?", orgID)
  3926. if scheduleDate != 0 {
  3927. db = db.Where("schedule_date = ?", scheduleDate)
  3928. }
  3929. err = db.Find(&vms).Error
  3930. } else if execution_state == 0 {
  3931. db := readDb.
  3932. Table("xt_schedule").
  3933. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3934. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3935. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3936. }).
  3937. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3938. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3939. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3940. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3941. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3942. }).
  3943. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3944. 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")
  3945. }).Where("status = 1 AND user_org_id = ?", orgID)
  3946. if scheduleDate != 0 {
  3947. db = db.Where("schedule_date = ?", scheduleDate)
  3948. }
  3949. err = db.Find(&vms).Error
  3950. }
  3951. }
  3952. }
  3953. }
  3954. if patientType > 0 {
  3955. if execution_state == 1 {
  3956. db := readDb.
  3957. Table("xt_schedule").
  3958. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3959. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3960. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3961. }).
  3962. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3963. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3964. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3965. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3966. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3967. 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")
  3968. }).
  3969. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3970. 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")
  3971. }).Where("status = 1 AND user_org_id = ?", orgID)
  3972. if scheduleDate != 0 {
  3973. db = db.Where("schedule_date = ?", scheduleDate)
  3974. }
  3975. err = db.Find(&vms).Error
  3976. } else if execution_state == 2 {
  3977. db := readDb.
  3978. Table("xt_schedule").
  3979. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3980. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3981. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3982. }).
  3983. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3984. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3985. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3986. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3987. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3988. 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")
  3989. }).
  3990. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3991. 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")
  3992. }).Where("status = 1 AND user_org_id = ?", orgID)
  3993. if scheduleDate != 0 {
  3994. db = db.Where("schedule_date = ?", scheduleDate)
  3995. }
  3996. err = db.Find(&vms).Error
  3997. } else if execution_state == 0 {
  3998. db := readDb.
  3999. Table("xt_schedule").
  4000. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4001. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4002. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4003. }).
  4004. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4005. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4006. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4007. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4008. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4009. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4010. }).
  4011. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4012. 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")
  4013. }).Where("status = 1 AND user_org_id = ?", orgID)
  4014. if scheduleDate != 0 {
  4015. db = db.Where("schedule_date = ?", scheduleDate)
  4016. }
  4017. err = db.Find(&vms).Error
  4018. }
  4019. }
  4020. return vms, err
  4021. }
  4022. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4023. prepare := models.DialysisBeforePrepare{}
  4024. var err error
  4025. if count > 0 {
  4026. 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
  4027. }
  4028. if count <= 0 {
  4029. 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
  4030. }
  4031. return err
  4032. }
  4033. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4034. detail := models.AutomaticReduceDetail{}
  4035. 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
  4036. return err
  4037. }
  4038. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4039. var record models.DialysisSolution
  4040. 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
  4041. if err != nil {
  4042. if err == gorm.ErrRecordNotFound {
  4043. return nil, nil
  4044. } else {
  4045. return nil, err
  4046. }
  4047. }
  4048. return &record, nil
  4049. }
  4050. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4051. var record models.DialysisPrescription
  4052. 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
  4053. if err != nil {
  4054. if err == gorm.ErrRecordNotFound {
  4055. return nil, nil
  4056. } else {
  4057. return nil, err
  4058. }
  4059. }
  4060. return &record, nil
  4061. }
  4062. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4063. prescription := models.DialysisPrescriptionThrity{}
  4064. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4065. return prescription, err
  4066. }
  4067. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4068. var record models.SystemPrescription
  4069. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4070. if err != nil {
  4071. if err == gorm.ErrRecordNotFound {
  4072. return nil, nil
  4073. } else {
  4074. return nil, err
  4075. }
  4076. }
  4077. return &record, nil
  4078. }
  4079. // 透前评估
  4080. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4081. var record models.PredialysisEvaluation
  4082. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4083. if err != nil {
  4084. if err == gorm.ErrRecordNotFound {
  4085. return nil, nil
  4086. } else {
  4087. return nil, err
  4088. }
  4089. }
  4090. return &record, nil
  4091. }
  4092. //
  4093. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4094. //
  4095. // 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
  4096. // return prepare, err
  4097. //}
  4098. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4099. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4100. return auto, err
  4101. }
  4102. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4103. role := models.SgjUserAdminRole{}
  4104. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4105. return role, err
  4106. }
  4107. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4108. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4109. return auto, err
  4110. }
  4111. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4112. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4113. return outifno, err
  4114. }
  4115. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4116. order := models.DialysisOrder{}
  4117. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4118. return order, err
  4119. }
  4120. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4121. record := models.MonitoringRecord{}
  4122. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4123. return record, err
  4124. }
  4125. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4126. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4127. return record, err
  4128. }
  4129. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string, keyword string) ([]*MScheduleDoctorAdviceVM, error) {
  4130. var vms []*MScheduleDoctorAdviceVM
  4131. keyword = "%" + keyword + "%"
  4132. adviceWhere := ""
  4133. adviceCondition := []interface{}{}
  4134. if adviceType == 0 {
  4135. if patientType == 0 {
  4136. if patient_id > 0 {
  4137. if execution_state > 0 {
  4138. if cost_type > 0 {
  4139. if len(execution_frequency) > 0 {
  4140. if len(keyword) > 0 {
  4141. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4143. } else {
  4144. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4146. }
  4147. } else {
  4148. if len(keyword) > 0 {
  4149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and advice_name like ?"
  4150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4151. } else {
  4152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  4153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4154. }
  4155. }
  4156. } else {
  4157. if len(execution_frequency) > 0 {
  4158. if len(keyword) > 0 {
  4159. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4161. } else {
  4162. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ?"
  4163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4164. }
  4165. } else {
  4166. if len(keyword) > 0 {
  4167. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4169. } else {
  4170. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4172. }
  4173. }
  4174. }
  4175. } else {
  4176. if cost_type > 0 {
  4177. if len(execution_frequency) > 0 {
  4178. 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 = ?"
  4179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4180. } else {
  4181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4183. }
  4184. } else {
  4185. if len(execution_frequency) > 0 {
  4186. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4188. } else {
  4189. if len(keyword) > 0 {
  4190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and advice_name like ?"
  4191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4192. } else {
  4193. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4195. }
  4196. }
  4197. }
  4198. }
  4199. } else {
  4200. if execution_state > 0 {
  4201. if cost_type > 0 {
  4202. if len(execution_frequency) > 0 {
  4203. if len(keyword) > 0 {
  4204. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4206. } else {
  4207. 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 = ?"
  4208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4209. }
  4210. } else {
  4211. if len(keyword) > 0 {
  4212. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ? and advice_name like ?"
  4213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4214. } else {
  4215. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4217. }
  4218. }
  4219. } else {
  4220. if len(execution_frequency) > 0 {
  4221. if len(keyword) > 0 {
  4222. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4224. } else {
  4225. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4226. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4227. }
  4228. } else {
  4229. if len(keyword) > 0 {
  4230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and advice_name like ?"
  4231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4232. } else {
  4233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4235. }
  4236. }
  4237. }
  4238. } else {
  4239. if cost_type > 0 {
  4240. if len(execution_frequency) > 0 {
  4241. if len(keyword) > 0 {
  4242. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4244. } else {
  4245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4247. }
  4248. } else {
  4249. if len(keyword) > 0 {
  4250. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and advice_name like ?"
  4251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4252. } else {
  4253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4255. }
  4256. }
  4257. } else {
  4258. if len(execution_frequency) > 0 {
  4259. if len(keyword) > 0 {
  4260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4262. } else {
  4263. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4265. }
  4266. } else {
  4267. if len(keyword) > 0 {
  4268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4270. } else {
  4271. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4273. }
  4274. }
  4275. }
  4276. }
  4277. }
  4278. } else if patientType == 1 {
  4279. if patient_id > 0 {
  4280. if execution_state > 0 {
  4281. if cost_type > 0 {
  4282. if len(execution_frequency) > 0 {
  4283. if len(keyword) > 0 {
  4284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4286. } else {
  4287. 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 = ?"
  4288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4289. }
  4290. } else {
  4291. if len(keyword) > 0 {
  4292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and advice_name like ?"
  4293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4294. } else {
  4295. 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 = ?"
  4296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4297. }
  4298. }
  4299. } else {
  4300. if len(execution_frequency) > 0 {
  4301. if len(keyword) > 0 {
  4302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4304. } else {
  4305. 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 = ?"
  4306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4307. }
  4308. } else {
  4309. if len(keyword) > 0 {
  4310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4312. } else {
  4313. 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= ?"
  4314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4315. }
  4316. }
  4317. }
  4318. } else {
  4319. if cost_type > 0 {
  4320. if len(execution_frequency) > 0 {
  4321. if len(keyword) > 0 {
  4322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4324. } else {
  4325. 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 = ?"
  4326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4327. }
  4328. } else {
  4329. if len(keyword) > 0 {
  4330. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and advice_name like ?"
  4331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4332. } else {
  4333. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=?"
  4334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4335. }
  4336. }
  4337. } else {
  4338. if len(execution_frequency) > 0 {
  4339. if len(keyword) > 0 {
  4340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4342. } else {
  4343. 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 = ?"
  4344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4345. }
  4346. } else {
  4347. if len(keyword) > 0 {
  4348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and advice_name like ?"
  4349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4350. } else {
  4351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4353. }
  4354. }
  4355. }
  4356. }
  4357. } else {
  4358. if execution_state > 0 {
  4359. if cost_type > 0 {
  4360. if len(execution_frequency) > 0 {
  4361. if len(keyword) > 0 {
  4362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4364. } else {
  4365. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4367. }
  4368. } else {
  4369. if len(keyword) > 0 {
  4370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and advice_name like ?"
  4371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4372. } else {
  4373. 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=?"
  4374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4375. }
  4376. }
  4377. } else {
  4378. if len(execution_frequency) > 0 {
  4379. if len(keyword) > 0 {
  4380. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4382. } else {
  4383. 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 = ?"
  4384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4385. }
  4386. } else {
  4387. if len(keyword) > 0 {
  4388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and advice_name like ?"
  4389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4390. } else {
  4391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4393. }
  4394. }
  4395. }
  4396. } else {
  4397. if cost_type > 0 {
  4398. if len(execution_frequency) > 0 {
  4399. if len(keyword) > 0 {
  4400. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4402. } else {
  4403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and execution_frequency = ?"
  4404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4405. }
  4406. } else {
  4407. if len(keyword) > 0 {
  4408. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=? and advice_name like ?"
  4409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4410. } else {
  4411. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4413. }
  4414. }
  4415. } else {
  4416. if len(execution_frequency) > 0 {
  4417. if len(keyword) > 0 {
  4418. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4420. } else {
  4421. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4423. }
  4424. } else {
  4425. if len(keyword) > 0 {
  4426. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4428. } else {
  4429. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4431. }
  4432. }
  4433. }
  4434. }
  4435. }
  4436. } else if patientType == 2 {
  4437. if patient_id > 0 {
  4438. if execution_state > 0 {
  4439. if cost_type > 0 {
  4440. if len(execution_frequency) > 0 {
  4441. if len(keyword) > 0 {
  4442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4444. } else {
  4445. 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 = ?"
  4446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4447. }
  4448. } else {
  4449. if len(keyword) > 0 {
  4450. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and advice_name like ?"
  4451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4452. } else {
  4453. 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=?"
  4454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4455. }
  4456. }
  4457. } else {
  4458. if len(execution_frequency) > 0 {
  4459. if len(keyword) > 0 {
  4460. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?and execution_frequency = ? and advice_name like ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4462. } else {
  4463. 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 = ?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4465. }
  4466. } else {
  4467. if len(keyword) > 0 {
  4468. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and advice_name like ?"
  4469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4470. } else {
  4471. 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 = ?"
  4472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4473. }
  4474. }
  4475. }
  4476. } else {
  4477. if cost_type > 0 {
  4478. if len(execution_frequency) > 0 {
  4479. if len(keyword) > 0 {
  4480. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4482. } else {
  4483. 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 = ?"
  4484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4485. }
  4486. } else {
  4487. if len(keyword) > 0 {
  4488. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and advice_name like ?"
  4489. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4490. } else {
  4491. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=?"
  4492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4493. }
  4494. }
  4495. } else {
  4496. if len(execution_frequency) > 0 {
  4497. if len(keyword) > 0 {
  4498. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)and execution_frequency = ? and advice_name like ?"
  4499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4500. } else {
  4501. 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 = ?"
  4502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4503. }
  4504. } else {
  4505. if len(keyword) > 0 {
  4506. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and advice_name like ?"
  4507. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4508. } else {
  4509. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
  4510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4511. }
  4512. }
  4513. }
  4514. }
  4515. } else {
  4516. if execution_state > 0 {
  4517. if cost_type > 0 {
  4518. if len(execution_frequency) > 0 {
  4519. if len(keyword) > 0 {
  4520. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4522. } else {
  4523. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4525. }
  4526. } else {
  4527. if len(keyword) > 0 {
  4528. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=? and advice_name like ?"
  4529. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4530. } else {
  4531. 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=?"
  4532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4533. }
  4534. }
  4535. } else {
  4536. if len(execution_frequency) > 0 {
  4537. if len(keyword) > 0 {
  4538. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4540. } else {
  4541. 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 = ?"
  4542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4543. }
  4544. } else {
  4545. if len(keyword) > 0 {
  4546. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and advice_name like ?"
  4547. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4548. } else {
  4549. 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 = ?"
  4550. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4551. }
  4552. }
  4553. }
  4554. } else {
  4555. if cost_type > 0 {
  4556. if len(execution_frequency) > 0 {
  4557. if len(keyword) > 0 {
  4558. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4560. } else {
  4561. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4562. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4563. }
  4564. } else {
  4565. if len(keyword) > 0 {
  4566. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and is_settle = ? and advice_name like ?"
  4567. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4568. } else {
  4569. 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 = ?"
  4570. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4571. }
  4572. }
  4573. } else {
  4574. if len(execution_frequency) > 0 {
  4575. if len(keyword) > 0 {
  4576. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4578. } else {
  4579. 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 = ?"
  4580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4581. }
  4582. } else {
  4583. if len(keyword) > 0 {
  4584. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4585. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4586. } else {
  4587. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4588. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4589. }
  4590. }
  4591. }
  4592. }
  4593. }
  4594. }
  4595. } else if adviceType == 1 {
  4596. if patientType == 0 {
  4597. if patient_id > 0 {
  4598. if execution_state > 0 {
  4599. if cost_type > 0 {
  4600. if len(execution_frequency) > 0 {
  4601. if len(keyword) > 0 {
  4602. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4604. } else {
  4605. 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 = ?"
  4606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4607. }
  4608. } else {
  4609. if len(keyword) > 0 {
  4610. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4612. } else {
  4613. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4615. }
  4616. }
  4617. } else {
  4618. if len(execution_frequency) > 0 {
  4619. if len(keyword) > 0 {
  4620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4622. } else {
  4623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4625. }
  4626. } else {
  4627. if len(keyword) > 0 {
  4628. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4630. } else {
  4631. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4633. }
  4634. }
  4635. }
  4636. } else {
  4637. if cost_type > 0 {
  4638. if len(execution_frequency) > 0 {
  4639. if len(keyword) > 0 {
  4640. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4642. } else {
  4643. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4645. }
  4646. } else {
  4647. if len(keyword) > 0 {
  4648. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4650. } else {
  4651. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4653. }
  4654. }
  4655. } else {
  4656. if len(execution_frequency) > 0 {
  4657. if len(keyword) > 0 {
  4658. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4660. } else {
  4661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4663. }
  4664. }
  4665. }
  4666. }
  4667. } else {
  4668. if execution_state > 0 {
  4669. if cost_type > 0 {
  4670. if len(execution_frequency) > 0 {
  4671. if len(keyword) > 0 {
  4672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4674. } else {
  4675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4677. }
  4678. } else {
  4679. if len(keyword) > 0 {
  4680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4682. } else {
  4683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4685. }
  4686. }
  4687. } else {
  4688. if len(execution_frequency) > 0 {
  4689. if len(keyword) > 0 {
  4690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4692. } else {
  4693. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4695. }
  4696. } else {
  4697. if len(keyword) > 0 {
  4698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4700. } else {
  4701. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4703. }
  4704. }
  4705. }
  4706. } else {
  4707. if cost_type > 0 {
  4708. if len(keyword) > 0 {
  4709. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4711. } else {
  4712. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4714. }
  4715. } else {
  4716. if len(keyword) > 0 {
  4717. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4719. } else {
  4720. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4722. }
  4723. }
  4724. }
  4725. }
  4726. } else if patientType == 1 {
  4727. if patient_id > 0 {
  4728. if execution_state > 0 {
  4729. if cost_type > 0 {
  4730. if len(execution_frequency) > 0 {
  4731. if len(keyword) > 0 {
  4732. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4734. } else {
  4735. 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 = ?"
  4736. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4737. }
  4738. } else {
  4739. if len(keyword) > 0 {
  4740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4742. } else {
  4743. 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 = ?"
  4744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4745. }
  4746. }
  4747. } else {
  4748. if len(execution_frequency) > 0 {
  4749. if len(keyword) > 0 {
  4750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4751. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4752. } else {
  4753. 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 = ?"
  4754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4755. }
  4756. } else {
  4757. if len(keyword) > 0 {
  4758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4760. } else {
  4761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4763. }
  4764. }
  4765. }
  4766. } else {
  4767. if cost_type > 0 {
  4768. if len(execution_frequency) > 0 {
  4769. if len(keyword) > 0 {
  4770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4772. } else {
  4773. 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 = ?"
  4774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4775. }
  4776. } else {
  4777. if len(keyword) > 0 {
  4778. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  4779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4780. } else {
  4781. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4783. }
  4784. }
  4785. } else {
  4786. if len(execution_frequency) > 0 {
  4787. if len(keyword) > 0 {
  4788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4790. } else {
  4791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4793. }
  4794. } else {
  4795. if len(keyword) > 0 {
  4796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4798. } else {
  4799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4801. }
  4802. }
  4803. }
  4804. }
  4805. } else {
  4806. if execution_state > 0 {
  4807. if cost_type > 0 {
  4808. if len(execution_frequency) > 0 {
  4809. if len(keyword) > 0 {
  4810. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4812. } else {
  4813. 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 = ?"
  4814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4815. }
  4816. } else {
  4817. if len(keyword) > 0 {
  4818. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  4819. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4820. } else {
  4821. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4823. }
  4824. }
  4825. } else {
  4826. if len(execution_frequency) > 0 {
  4827. if len(keyword) > 0 {
  4828. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  4829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4830. } else {
  4831. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4833. }
  4834. } else {
  4835. if len(keyword) > 0 {
  4836. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4838. } else {
  4839. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4841. }
  4842. }
  4843. }
  4844. } else {
  4845. if cost_type > 0 {
  4846. if len(execution_frequency) > 0 {
  4847. if len(keyword) > 0 {
  4848. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4849. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4850. } else {
  4851. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4853. }
  4854. } else {
  4855. if len(keyword) > 0 {
  4856. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4857. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4858. } else {
  4859. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4860. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4861. }
  4862. }
  4863. } else {
  4864. if len(execution_frequency) > 0 {
  4865. if len(keyword) > 0 {
  4866. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4868. } else {
  4869. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4871. }
  4872. } else {
  4873. if len(keyword) > 0 {
  4874. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4876. } else {
  4877. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4878. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4879. }
  4880. }
  4881. }
  4882. }
  4883. }
  4884. } else if patientType == 2 {
  4885. if patient_id > 0 {
  4886. if execution_state > 0 {
  4887. if cost_type > 0 {
  4888. if len(execution_frequency) > 0 {
  4889. if len(keyword) > 0 {
  4890. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4892. } else {
  4893. 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 = ?"
  4894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4895. }
  4896. } else {
  4897. if len(keyword) > 0 {
  4898. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4900. } else {
  4901. 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 = ?"
  4902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4903. }
  4904. }
  4905. } else {
  4906. if len(execution_frequency) > 0 {
  4907. if len(keyword) > 0 {
  4908. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4909. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4910. } else {
  4911. 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 = ?"
  4912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4913. }
  4914. } else {
  4915. if len(keyword) > 0 {
  4916. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  4917. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4918. } else {
  4919. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4921. }
  4922. }
  4923. }
  4924. } else {
  4925. if cost_type > 0 {
  4926. if len(execution_frequency) > 0 {
  4927. if len(keyword) > 0 {
  4928. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4930. } else {
  4931. 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 = ?"
  4932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4933. }
  4934. } else {
  4935. if len(keyword) > 0 {
  4936. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  4937. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4938. } else {
  4939. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4941. }
  4942. }
  4943. } else {
  4944. if len(execution_frequency) > 0 {
  4945. if len(keyword) > 0 {
  4946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4948. } else {
  4949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4951. }
  4952. } else {
  4953. if len(keyword) > 0 {
  4954. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  4955. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4956. } else {
  4957. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4959. }
  4960. }
  4961. }
  4962. }
  4963. } else {
  4964. if execution_state > 0 {
  4965. if cost_type > 0 {
  4966. if len(execution_frequency) > 0 {
  4967. if len(keyword) > 0 {
  4968. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4970. } else {
  4971. 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 = ?"
  4972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4973. }
  4974. } else {
  4975. if len(keyword) > 0 {
  4976. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  4977. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4978. } else {
  4979. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4981. }
  4982. }
  4983. } else {
  4984. if len(execution_frequency) > 0 {
  4985. if len(keyword) > 0 {
  4986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4988. } else {
  4989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4991. }
  4992. } else {
  4993. if len(keyword) > 0 {
  4994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  4995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4996. } else {
  4997. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4999. }
  5000. }
  5001. }
  5002. } else {
  5003. if cost_type > 0 {
  5004. if len(execution_frequency) > 0 {
  5005. if len(keyword) > 0 {
  5006. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5008. } else {
  5009. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5011. }
  5012. } else {
  5013. if len(keyword) > 0 {
  5014. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  5015. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5016. } else {
  5017. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5019. }
  5020. }
  5021. } else {
  5022. if len(execution_frequency) > 0 {
  5023. if len(keyword) > 0 {
  5024. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  5025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5026. } else {
  5027. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5028. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5029. }
  5030. } else {
  5031. if len(keyword) > 0 {
  5032. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5033. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5034. } else {
  5035. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5036. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5037. }
  5038. }
  5039. }
  5040. }
  5041. }
  5042. }
  5043. } else if adviceType == 3 {
  5044. if patientType == 0 {
  5045. if patient_id > 0 {
  5046. if execution_state > 0 {
  5047. if cost_type > 0 {
  5048. if len(execution_frequency) > 0 {
  5049. if len(keyword) > 0 {
  5050. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5052. } else {
  5053. 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 =?"
  5054. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5055. }
  5056. } else {
  5057. if len(keyword) > 0 {
  5058. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5060. } else {
  5061. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5063. }
  5064. }
  5065. } else {
  5066. if len(execution_frequency) > 0 {
  5067. if len(keyword) > 0 {
  5068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =? and advice_name like ?"
  5069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5070. } else {
  5071. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5073. }
  5074. } else {
  5075. if len(keyword) > 0 {
  5076. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5078. } else {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5081. }
  5082. }
  5083. }
  5084. } else {
  5085. if cost_type > 0 {
  5086. if len(execution_frequency) > 0 {
  5087. if len(keyword) > 0 {
  5088. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5090. } else {
  5091. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5093. }
  5094. } else {
  5095. if len(keyword) > 0 {
  5096. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5098. } else {
  5099. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5101. }
  5102. }
  5103. } else {
  5104. if len(execution_frequency) > 0 {
  5105. if len(keyword) > 0 {
  5106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5108. } else {
  5109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5111. }
  5112. } else {
  5113. if len(keyword) > 0 {
  5114. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5116. } else {
  5117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5119. }
  5120. }
  5121. }
  5122. }
  5123. } else {
  5124. if execution_state > 0 {
  5125. if cost_type > 0 {
  5126. if len(execution_frequency) > 0 {
  5127. if len(keyword) > 0 {
  5128. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5130. } else {
  5131. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5133. }
  5134. } else {
  5135. if len(keyword) > 0 {
  5136. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5138. } else {
  5139. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5141. }
  5142. }
  5143. } else {
  5144. if len(execution_frequency) > 0 {
  5145. if len(keyword) > 0 {
  5146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5148. } else {
  5149. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5151. }
  5152. } else {
  5153. if len(keyword) > 0 {
  5154. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5156. } else {
  5157. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5159. }
  5160. }
  5161. }
  5162. } else {
  5163. if cost_type > 0 {
  5164. if len(execution_frequency) > 0 {
  5165. if len(keyword) > 0 {
  5166. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5168. } else {
  5169. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5171. }
  5172. } else {
  5173. if len(keyword) > 0 {
  5174. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5176. } else {
  5177. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5179. }
  5180. }
  5181. } else {
  5182. if len(execution_frequency) > 0 {
  5183. if len(keyword) > 0 {
  5184. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5186. } else {
  5187. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5189. }
  5190. } else {
  5191. if len(keyword) > 0 {
  5192. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5194. } else {
  5195. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5197. }
  5198. }
  5199. }
  5200. }
  5201. }
  5202. } else if patientType == 1 {
  5203. if patient_id > 0 {
  5204. if execution_state > 0 {
  5205. if cost_type > 0 {
  5206. if len(execution_frequency) > 0 {
  5207. if len(keyword) > 0 {
  5208. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5210. } else {
  5211. 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 = ?"
  5212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5213. }
  5214. } else {
  5215. if len(keyword) > 0 {
  5216. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5218. } else {
  5219. 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 = ?"
  5220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5221. }
  5222. }
  5223. } else {
  5224. if len(execution_frequency) > 0 {
  5225. if len(keyword) > 0 {
  5226. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5228. } else {
  5229. 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 = ?"
  5230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5231. }
  5232. } else {
  5233. if len(keyword) > 0 {
  5234. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5236. } else {
  5237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5239. }
  5240. }
  5241. }
  5242. } else {
  5243. if cost_type > 0 {
  5244. if len(execution_frequency) > 0 {
  5245. if len(keyword) > 0 {
  5246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5248. } else {
  5249. 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 = ?"
  5250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5251. }
  5252. } else {
  5253. if len(keyword) > 0 {
  5254. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5256. } else {
  5257. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5259. }
  5260. }
  5261. } else {
  5262. if len(execution_frequency) > 0 {
  5263. if len(keyword) > 0 {
  5264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5266. } else {
  5267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5269. }
  5270. } else {
  5271. if len(keyword) > 0 {
  5272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5274. } else {
  5275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5277. }
  5278. }
  5279. }
  5280. }
  5281. } else {
  5282. if execution_state > 0 {
  5283. if cost_type > 0 {
  5284. if len(execution_frequency) > 0 {
  5285. if len(keyword) > 0 {
  5286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5288. } else {
  5289. 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 = ?"
  5290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5291. }
  5292. } else {
  5293. if len(keyword) > 0 {
  5294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5296. } else {
  5297. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5299. }
  5300. }
  5301. } else {
  5302. if len(execution_frequency) > 0 {
  5303. if len(keyword) > 0 {
  5304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? and avice_name like ? "
  5305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5306. } else {
  5307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5309. }
  5310. } else {
  5311. if len(keyword) > 0 {
  5312. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5314. } else {
  5315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5317. }
  5318. }
  5319. }
  5320. } else {
  5321. if cost_type > 0 {
  5322. if len(execution_frequency) > 0 {
  5323. if len(keyword) > 0 {
  5324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5326. } else {
  5327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5329. }
  5330. } else {
  5331. if len(keyword) > 0 {
  5332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5334. } else {
  5335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5337. }
  5338. }
  5339. } else {
  5340. if len(execution_frequency) > 0 {
  5341. if len(keyword) > 0 {
  5342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5344. } else {
  5345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5347. }
  5348. } else {
  5349. if len(keyword) > 0 {
  5350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5352. } else {
  5353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5355. }
  5356. }
  5357. }
  5358. }
  5359. }
  5360. } else if patientType == 2 {
  5361. if patient_id > 0 {
  5362. if execution_state > 0 {
  5363. if cost_type > 0 {
  5364. if len(execution_frequency) > 0 {
  5365. if len(keyword) > 0 {
  5366. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5368. } else {
  5369. 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 = ?"
  5370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5371. }
  5372. } else {
  5373. if len(keyword) > 0 {
  5374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5376. } else {
  5377. 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 = ?"
  5378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5379. }
  5380. }
  5381. } else {
  5382. if len(execution_frequency) > 0 {
  5383. if len(keyword) > 0 {
  5384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5386. } else {
  5387. 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 = ?"
  5388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5389. }
  5390. } else {
  5391. if len(keyword) > 0 {
  5392. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  5393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5394. } else {
  5395. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5397. }
  5398. }
  5399. }
  5400. } else {
  5401. if cost_type > 0 {
  5402. if len(execution_frequency) > 0 {
  5403. if len(keyword) > 0 {
  5404. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5406. } else {
  5407. 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 = ?"
  5408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5409. }
  5410. } else {
  5411. if len(keyword) > 0 {
  5412. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  5413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5414. } else {
  5415. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5417. }
  5418. }
  5419. } else {
  5420. if len(execution_frequency) > 0 {
  5421. if len(keyword) > 0 {
  5422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5424. } else {
  5425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5427. }
  5428. } else {
  5429. if len(keyword) > 0 {
  5430. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  5431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5432. } else {
  5433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5435. }
  5436. }
  5437. }
  5438. }
  5439. } else {
  5440. if execution_state > 0 {
  5441. if cost_type > 0 {
  5442. if len(execution_frequency) > 0 {
  5443. if len(keyword) > 0 {
  5444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5446. } else {
  5447. 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 = ?"
  5448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5449. }
  5450. } else {
  5451. if len(keyword) > 0 {
  5452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ? and advice_name like ?"
  5453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5454. } else {
  5455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5457. }
  5458. }
  5459. } else {
  5460. if len(execution_frequency) > 0 {
  5461. if len(keyword) > 0 {
  5462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ? and advice_name like ?"
  5463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5464. } else {
  5465. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5467. }
  5468. } else {
  5469. if len(keyword) > 0 {
  5470. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and advice_name like ?"
  5471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5472. } else {
  5473. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5475. }
  5476. }
  5477. }
  5478. } else {
  5479. if cost_type > 0 {
  5480. if len(execution_frequency) > 0 {
  5481. if len(keyword) > 0 {
  5482. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5484. } else {
  5485. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5487. }
  5488. } else {
  5489. if len(keyword) > 0 {
  5490. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  5491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5492. } else {
  5493. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5495. }
  5496. }
  5497. } else {
  5498. if len(execution_frequency) > 0 {
  5499. if len(keyword) > 0 {
  5500. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  5501. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5502. } else {
  5503. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5504. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5505. }
  5506. } else {
  5507. if len(keyword) > 0 {
  5508. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5509. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5510. } else {
  5511. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5512. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5513. }
  5514. }
  5515. }
  5516. }
  5517. }
  5518. }
  5519. } else if adviceType == 2 && len(deliverWay) > 0 {
  5520. if patientType == 0 {
  5521. if patient_id > 0 {
  5522. if execution_state > 0 {
  5523. if cost_type > 0 {
  5524. if len(execution_frequency) > 0 {
  5525. if len(keyword) > 0 {
  5526. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5527. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5528. } else {
  5529. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5530. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5531. }
  5532. } else {
  5533. if len(keyword) > 0 {
  5534. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5536. } else {
  5537. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5538. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5539. }
  5540. }
  5541. } else {
  5542. if len(execution_frequency) > 0 {
  5543. if len(keyword) > 0 {
  5544. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5546. } else {
  5547. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5549. }
  5550. } else {
  5551. if len(keyword) > 0 {
  5552. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5553. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5554. } else {
  5555. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5557. }
  5558. }
  5559. }
  5560. } else {
  5561. if cost_type > 0 {
  5562. if len(execution_frequency) > 0 {
  5563. if len(keyword) > 0 {
  5564. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5566. } else {
  5567. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5569. }
  5570. } else {
  5571. if len(keyword) > 0 {
  5572. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5574. } else {
  5575. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5577. }
  5578. }
  5579. } else {
  5580. if len(execution_frequency) > 0 {
  5581. if len(keyword) > 0 {
  5582. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5584. } else {
  5585. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5587. }
  5588. } else {
  5589. if len(keyword) > 0 {
  5590. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5592. } else {
  5593. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5595. }
  5596. }
  5597. }
  5598. }
  5599. } else {
  5600. if execution_state > 0 {
  5601. if cost_type > 0 {
  5602. if len(execution_frequency) > 0 {
  5603. if len(keyword) > 0 {
  5604. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5606. } else {
  5607. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5608. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5609. }
  5610. } else {
  5611. if len(keyword) > 0 {
  5612. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5614. } else {
  5615. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5617. }
  5618. }
  5619. } else {
  5620. if len(execution_frequency) > 0 {
  5621. if len(keyword) > 0 {
  5622. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5624. } else {
  5625. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5626. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5627. }
  5628. } else {
  5629. if len(keyword) > 0 {
  5630. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5632. } else {
  5633. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5635. }
  5636. }
  5637. }
  5638. } else {
  5639. if cost_type > 0 {
  5640. if len(execution_frequency) > 0 {
  5641. if len(keyword) > 0 {
  5642. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5644. } else {
  5645. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5646. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5647. }
  5648. } else {
  5649. if len(keyword) > 0 {
  5650. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3)2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5652. } else {
  5653. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5655. }
  5656. }
  5657. } else {
  5658. if len(execution_frequency) > 0 {
  5659. if len(keyword) > 0 {
  5660. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5662. } else {
  5663. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5665. }
  5666. } else {
  5667. if len(keyword) > 0 {
  5668. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and advice_name like ?"
  5669. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5670. } else {
  5671. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5672. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5673. }
  5674. }
  5675. }
  5676. }
  5677. }
  5678. } else if patientType == 1 {
  5679. if patient_id > 0 {
  5680. if execution_state > 0 {
  5681. if cost_type > 0 {
  5682. if len(execution_frequency) > 0 {
  5683. if len(keyword) > 0 {
  5684. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5685. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5686. } else {
  5687. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5688. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5689. }
  5690. } else {
  5691. if len(keyword) > 0 {
  5692. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5694. } else {
  5695. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5697. }
  5698. }
  5699. } else {
  5700. if len(execution_frequency) > 0 {
  5701. if len(keyword) > 0 {
  5702. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5704. } else {
  5705. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5707. }
  5708. } else {
  5709. if len(keyword) > 0 {
  5710. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5712. } else {
  5713. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5715. }
  5716. }
  5717. }
  5718. } else {
  5719. if cost_type > 0 {
  5720. if len(execution_frequency) > 0 {
  5721. if len(keyword) > 0 {
  5722. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5724. } else {
  5725. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5727. }
  5728. } else {
  5729. if len(keyword) > 0 {
  5730. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5732. } else {
  5733. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5735. }
  5736. }
  5737. } else {
  5738. if len(execution_frequency) > 0 {
  5739. if len(keyword) > 0 {
  5740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5742. } else {
  5743. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5745. }
  5746. } else {
  5747. if len(keyword) > 0 {
  5748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5750. } else {
  5751. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5753. }
  5754. }
  5755. }
  5756. }
  5757. } else {
  5758. if execution_state > 0 {
  5759. if cost_type > 0 {
  5760. if len(execution_frequency) > 0 {
  5761. if len(keyword) > 0 {
  5762. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5763. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5764. } else {
  5765. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5766. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5767. }
  5768. } else {
  5769. if len(keyword) > 0 {
  5770. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5772. } else {
  5773. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5775. }
  5776. }
  5777. } else {
  5778. if len(execution_frequency) > 0 {
  5779. if len(keyword) > 0 {
  5780. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5782. } else {
  5783. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5785. }
  5786. } else {
  5787. if len(keyword) > 0 {
  5788. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5790. } else {
  5791. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5793. }
  5794. }
  5795. }
  5796. } else {
  5797. if cost_type > 0 {
  5798. if len(execution_frequency) > 0 {
  5799. if len(keyword) > 0 {
  5800. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND(advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5802. } else {
  5803. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5805. }
  5806. } else {
  5807. if len(keyword) > 0 {
  5808. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5810. } else {
  5811. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5813. }
  5814. }
  5815. } else {
  5816. if len(execution_frequency) > 0 {
  5817. if len(keyword) > 0 {
  5818. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5819. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5820. } else {
  5821. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5823. }
  5824. } else {
  5825. if len(keyword) > 0 {
  5826. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5828. } else {
  5829. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5831. }
  5832. }
  5833. }
  5834. }
  5835. }
  5836. } else if patientType == 2 {
  5837. if patient_id > 0 {
  5838. if execution_state > 0 {
  5839. if cost_type > 0 {
  5840. if len(execution_frequency) > 0 {
  5841. if len(keyword) > 0 {
  5842. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5844. } else {
  5845. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5846. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5847. }
  5848. } else {
  5849. if len(keyword) > 0 {
  5850. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5852. } else {
  5853. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5855. }
  5856. }
  5857. } else {
  5858. if len(execution_frequency) > 0 {
  5859. if len(keyword) > 0 {
  5860. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5862. } else {
  5863. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5865. }
  5866. } else {
  5867. if len(keyword) > 0 {
  5868. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5870. } else {
  5871. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  5872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5873. }
  5874. }
  5875. }
  5876. } else {
  5877. if cost_type > 0 {
  5878. if len(execution_frequency) > 0 {
  5879. if len(keyword) > 0 {
  5880. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5882. } else {
  5883. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5885. }
  5886. } else {
  5887. if len(keyword) > 0 {
  5888. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5890. } else {
  5891. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ?"
  5892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5893. }
  5894. }
  5895. } else {
  5896. if len(execution_frequency) > 0 {
  5897. if len(keyword) > 0 {
  5898. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5900. } else {
  5901. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5903. }
  5904. } else {
  5905. if len(keyword) > 0 {
  5906. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and advice_name like ?"
  5907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5908. } else {
  5909. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5911. }
  5912. }
  5913. }
  5914. }
  5915. } else {
  5916. if execution_state > 0 {
  5917. if cost_type > 0 {
  5918. if len(execution_frequency) > 0 {
  5919. if len(keyword) > 0 {
  5920. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5921. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5922. } else {
  5923. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5924. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5925. }
  5926. } else {
  5927. if len(keyword) > 0 {
  5928. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5930. } else {
  5931. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  5932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5933. }
  5934. }
  5935. } else {
  5936. if len(execution_frequency) > 0 {
  5937. if len(keyword) > 0 {
  5938. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5940. } else {
  5941. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5943. }
  5944. } else {
  5945. if len(keyword) > 0 {
  5946. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and advice_name like ?"
  5947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5948. } else {
  5949. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5951. }
  5952. }
  5953. }
  5954. } else {
  5955. if cost_type > 0 {
  5956. if len(execution_frequency) > 0 {
  5957. if len(keyword) > 0 {
  5958. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5960. } else {
  5961. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5963. }
  5964. } else {
  5965. if len(keyword) > 0 {
  5966. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5968. } else {
  5969. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5971. }
  5972. }
  5973. } else {
  5974. if len(keyword) > 0 {
  5975. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  5976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5977. } else {
  5978. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ?"
  5979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5980. }
  5981. }
  5982. }
  5983. }
  5984. }
  5985. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5986. if patientType == 0 {
  5987. if patient_id > 0 {
  5988. if execution_state > 0 {
  5989. if cost_type > 0 {
  5990. if len(execution_frequency) > 0 {
  5991. if len(keyword) > 0 {
  5992. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5993. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5994. } else {
  5995. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5996. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5997. }
  5998. } else {
  5999. if len(keyword) > 0 {
  6000. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6001. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6002. } else {
  6003. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6004. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6005. }
  6006. }
  6007. } else {
  6008. if len(execution_frequency) > 0 {
  6009. if len(keyword) > 0 {
  6010. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6012. } else {
  6013. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6015. }
  6016. } else {
  6017. if len(keyword) > 0 {
  6018. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6020. } else {
  6021. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6023. }
  6024. }
  6025. }
  6026. } else {
  6027. if cost_type > 0 {
  6028. if len(execution_frequency) > 0 {
  6029. if len(keyword) > 0 {
  6030. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6032. } else {
  6033. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6035. }
  6036. } else {
  6037. if len(keyword) > 0 {
  6038. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6040. } else {
  6041. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6043. }
  6044. }
  6045. } else {
  6046. if len(execution_frequency) > 0 {
  6047. if len(keyword) > 0 {
  6048. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6050. } else {
  6051. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6053. }
  6054. } else {
  6055. if len(keyword) > 0 {
  6056. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and advice_name like ?"
  6057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6058. } else {
  6059. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6061. }
  6062. }
  6063. }
  6064. }
  6065. } else {
  6066. if execution_state > 0 {
  6067. if cost_type > 0 {
  6068. if len(execution_frequency) > 0 {
  6069. if len(keyword) > 0 {
  6070. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6072. } else {
  6073. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6075. }
  6076. } else {
  6077. if len(keyword) > 0 {
  6078. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6080. } else {
  6081. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6083. }
  6084. }
  6085. } else {
  6086. if len(execution_frequency) > 0 {
  6087. if len(keyword) > 0 {
  6088. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6090. } else {
  6091. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6093. }
  6094. } else {
  6095. if len(keyword) > 0 {
  6096. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and advice_name like ?"
  6097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6098. } else {
  6099. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6101. }
  6102. }
  6103. }
  6104. } else {
  6105. if cost_type > 0 {
  6106. if len(execution_frequency) > 0 {
  6107. if len(keyword) > 0 {
  6108. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6110. } else {
  6111. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6113. }
  6114. }
  6115. } else {
  6116. if len(execution_frequency) > 0 {
  6117. if len(keyword) > 0 {
  6118. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6120. } else {
  6121. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6123. }
  6124. } else {
  6125. if len(keyword) > 0 {
  6126. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6128. } else {
  6129. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6131. }
  6132. }
  6133. }
  6134. }
  6135. }
  6136. } else if patientType == 1 {
  6137. if patient_id > 0 {
  6138. if execution_state > 0 {
  6139. if cost_type > 0 {
  6140. if len(execution_frequency) > 0 {
  6141. if len(keyword) > 0 {
  6142. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6144. } else {
  6145. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6147. }
  6148. } else {
  6149. if len(keyword) > 0 {
  6150. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6152. } else {
  6153. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6155. }
  6156. }
  6157. } else {
  6158. if len(execution_frequency) > 0 {
  6159. if len(keyword) > 0 {
  6160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6162. } else {
  6163. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6165. }
  6166. } else {
  6167. if len(keyword) > 0 {
  6168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6170. } else {
  6171. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6173. }
  6174. }
  6175. }
  6176. } else {
  6177. if cost_type > 0 {
  6178. if len(execution_frequency) > 0 {
  6179. if len(keyword) > 0 {
  6180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6182. } else {
  6183. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6185. }
  6186. } else {
  6187. if len(keyword) > 0 {
  6188. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6190. } else {
  6191. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6193. }
  6194. }
  6195. } else {
  6196. if len(execution_frequency) > 0 {
  6197. if len(keyword) > 0 {
  6198. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6200. } else {
  6201. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6203. }
  6204. } else {
  6205. if len(keyword) > 0 {
  6206. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6208. } else {
  6209. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6211. }
  6212. }
  6213. }
  6214. }
  6215. } else {
  6216. if execution_state > 0 {
  6217. if cost_type > 0 {
  6218. if len(execution_frequency) > 0 {
  6219. if len(keyword) > 0 {
  6220. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6222. } else {
  6223. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6225. }
  6226. } else {
  6227. if len(keyword) > 0 {
  6228. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6230. } else {
  6231. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6233. }
  6234. }
  6235. } else {
  6236. if len(execution_frequency) > 0 {
  6237. if len(keyword) > 0 {
  6238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6240. } else {
  6241. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6243. }
  6244. } else {
  6245. if len(keyword) > 0 {
  6246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6248. } else {
  6249. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6251. }
  6252. }
  6253. }
  6254. } else {
  6255. if cost_type > 0 {
  6256. if len(execution_frequency) > 0 {
  6257. if len(keyword) > 0 {
  6258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6260. } else {
  6261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6263. }
  6264. } else {
  6265. if len(keyword) > 0 {
  6266. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6268. } else {
  6269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6271. }
  6272. }
  6273. } else {
  6274. if len(execution_frequency) > 0 {
  6275. if len(keyword) > 0 {
  6276. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6278. } else {
  6279. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6281. }
  6282. } else {
  6283. if len(keyword) > 0 {
  6284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and advice_name like ?"
  6285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6286. } else {
  6287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6289. }
  6290. }
  6291. }
  6292. }
  6293. }
  6294. } else if patientType == 2 {
  6295. if patient_id > 0 {
  6296. if execution_state > 0 {
  6297. if cost_type > 0 {
  6298. if len(execution_frequency) > 0 {
  6299. if len(keyword) > 0 {
  6300. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6302. } else {
  6303. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6305. }
  6306. } else {
  6307. if len(keyword) > 0 {
  6308. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6310. } else {
  6311. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6313. }
  6314. }
  6315. } else {
  6316. if len(execution_frequency) > 0 {
  6317. if len(keyword) > 0 {
  6318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6320. } else {
  6321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6323. }
  6324. } else {
  6325. if len(keyword) > 0 {
  6326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  6327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6328. } else {
  6329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6331. }
  6332. }
  6333. }
  6334. } else {
  6335. if cost_type > 0 {
  6336. if len(execution_frequency) > 0 {
  6337. if len(keyword) > 0 {
  6338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6340. } else {
  6341. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6343. }
  6344. } else {
  6345. if len(keyword) > 0 {
  6346. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6348. } else {
  6349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6351. }
  6352. }
  6353. } else {
  6354. if len(execution_frequency) > 0 {
  6355. if len(keyword) > 0 {
  6356. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6358. } else {
  6359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6361. }
  6362. } else {
  6363. if len(keyword) > 0 {
  6364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6366. } else {
  6367. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ?"
  6368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6369. }
  6370. }
  6371. }
  6372. }
  6373. } else {
  6374. if execution_state > 0 {
  6375. if cost_type > 0 {
  6376. if len(execution_frequency) > 0 {
  6377. if len(keyword) > 0 {
  6378. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6380. } else {
  6381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6383. }
  6384. } else {
  6385. if len(keyword) > 0 {
  6386. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6387. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6388. } else {
  6389. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6391. }
  6392. }
  6393. } else {
  6394. if len(execution_frequency) > 0 {
  6395. if len(keyword) > 0 {
  6396. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6398. } else {
  6399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6401. }
  6402. } else {
  6403. if len(keyword) > 0 {
  6404. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6406. } else {
  6407. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND a(advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ?"
  6408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6409. }
  6410. }
  6411. }
  6412. } else {
  6413. if cost_type > 0 {
  6414. if len(execution_frequency) > 0 {
  6415. if len(keyword) > 0 {
  6416. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6418. } else {
  6419. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6421. }
  6422. } else {
  6423. if len(keyword) > 0 {
  6424. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6426. } else {
  6427. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ?"
  6428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6429. }
  6430. }
  6431. } else {
  6432. if len(execution_frequency) > 0 {
  6433. if len(keyword) > 0 {
  6434. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6436. } else {
  6437. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ?"
  6438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6439. }
  6440. } else {
  6441. if len(keyword) > 0 {
  6442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and advice_name like ?"
  6443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6444. } else {
  6445. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6447. }
  6448. }
  6449. }
  6450. }
  6451. }
  6452. }
  6453. }
  6454. db := readDb.Table("xt_schedule")
  6455. if scheduleType > 0 {
  6456. db = db.Where("schedule_type = ?", scheduleType)
  6457. }
  6458. if partitonType > 0 {
  6459. db = db.Where("partition_id = ?", partitonType)
  6460. }
  6461. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6462. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6463. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6464. }).
  6465. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6466. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6467. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6468. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6469. Preload("DoctorAdvices", adviceCondition...).
  6470. Where("status = 1 AND user_org_id = ?", orgID)
  6471. if scheduleDate != 0 {
  6472. db = db.Where("schedule_date = ?", scheduleDate)
  6473. }
  6474. err := db.Find(&vms).Error
  6475. return vms, err
  6476. }
  6477. 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) {
  6478. var vms []*MScheduleDoctorAdviceVM
  6479. adviceWhere := ""
  6480. adviceCondition := []interface{}{}
  6481. if adviceType == 0 {
  6482. if patientType == 0 {
  6483. if patient_id > 0 {
  6484. if execution_state > 0 {
  6485. if cost_type > 0 {
  6486. 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 = ?"
  6487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6488. } else {
  6489. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6491. }
  6492. } else {
  6493. if cost_type > 0 {
  6494. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6496. } else {
  6497. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6499. }
  6500. }
  6501. } else {
  6502. if execution_state > 0 {
  6503. if cost_type > 0 {
  6504. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6506. } else {
  6507. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6509. }
  6510. } else {
  6511. if cost_type > 0 {
  6512. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6514. } else {
  6515. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6517. }
  6518. }
  6519. }
  6520. } else if patientType == 1 {
  6521. if patient_id > 0 {
  6522. if execution_state > 0 {
  6523. if cost_type > 0 {
  6524. 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 = ?"
  6525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6526. } else {
  6527. 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= ?"
  6528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6529. }
  6530. } else {
  6531. if cost_type > 0 {
  6532. 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=?"
  6533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6534. } else {
  6535. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6537. }
  6538. }
  6539. } else {
  6540. if execution_state > 0 {
  6541. if cost_type > 0 {
  6542. 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=?"
  6543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6544. } else {
  6545. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6547. }
  6548. } else {
  6549. if cost_type > 0 {
  6550. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6552. } else {
  6553. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6555. }
  6556. }
  6557. }
  6558. } else if patientType == 2 {
  6559. if patient_id > 0 {
  6560. if execution_state > 0 {
  6561. if cost_type > 0 {
  6562. 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=?"
  6563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6564. } else {
  6565. 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 = ?"
  6566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6567. }
  6568. } else {
  6569. if cost_type > 0 {
  6570. 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=?"
  6571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6572. } else {
  6573. 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 = ?)"
  6574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6575. }
  6576. }
  6577. } else {
  6578. if execution_state > 0 {
  6579. if cost_type > 0 {
  6580. 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=?"
  6581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6582. } else {
  6583. 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 = ?"
  6584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6585. }
  6586. } else {
  6587. if cost_type > 0 {
  6588. 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 = ?"
  6589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6590. } else {
  6591. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6593. }
  6594. }
  6595. }
  6596. }
  6597. } else if adviceType == 1 {
  6598. if patientType == 0 {
  6599. if patient_id > 0 {
  6600. if execution_state > 0 {
  6601. if cost_type > 0 {
  6602. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6604. } else {
  6605. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6607. }
  6608. } else {
  6609. if cost_type > 0 {
  6610. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6612. } else {
  6613. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6615. }
  6616. }
  6617. } else {
  6618. if execution_state > 0 {
  6619. if cost_type > 0 {
  6620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6622. } else {
  6623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6625. }
  6626. } else {
  6627. if cost_type > 0 {
  6628. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6630. } else {
  6631. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6633. }
  6634. }
  6635. }
  6636. } else if patientType == 1 {
  6637. if patient_id > 0 {
  6638. if execution_state > 0 {
  6639. if cost_type > 0 {
  6640. 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 = ?"
  6641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6642. } else {
  6643. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6645. }
  6646. } else {
  6647. if cost_type > 0 {
  6648. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6650. } else {
  6651. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6653. }
  6654. }
  6655. } else {
  6656. if execution_state > 0 {
  6657. if cost_type > 0 {
  6658. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6660. } else {
  6661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6663. }
  6664. } else {
  6665. if cost_type > 0 {
  6666. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6668. } else {
  6669. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6671. }
  6672. }
  6673. }
  6674. } else if patientType == 2 {
  6675. if patient_id > 0 {
  6676. if execution_state > 0 {
  6677. if cost_type > 0 {
  6678. 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 = ?"
  6679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6680. } else {
  6681. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6683. }
  6684. } else {
  6685. if cost_type > 0 {
  6686. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6688. } else {
  6689. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6691. }
  6692. }
  6693. } else {
  6694. if execution_state > 0 {
  6695. if cost_type > 0 {
  6696. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6698. } else {
  6699. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6701. }
  6702. } else {
  6703. if cost_type > 0 {
  6704. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6706. } else {
  6707. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6709. }
  6710. }
  6711. }
  6712. }
  6713. } else if adviceType == 3 {
  6714. if patientType == 0 {
  6715. if patient_id > 0 {
  6716. if execution_state > 0 {
  6717. if cost_type > 0 {
  6718. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6720. } else {
  6721. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6723. }
  6724. } else {
  6725. if cost_type > 0 {
  6726. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6728. } else {
  6729. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6731. }
  6732. }
  6733. } else {
  6734. if execution_state > 0 {
  6735. if cost_type > 0 {
  6736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6738. } else {
  6739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6741. }
  6742. } else {
  6743. if cost_type > 0 {
  6744. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6746. } else {
  6747. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6749. }
  6750. }
  6751. }
  6752. } else if patientType == 1 {
  6753. if patient_id > 0 {
  6754. if execution_state > 0 {
  6755. if cost_type > 0 {
  6756. 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 = ?"
  6757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6758. } else {
  6759. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6761. }
  6762. } else {
  6763. if cost_type > 0 {
  6764. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6766. } else {
  6767. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6769. }
  6770. }
  6771. } else {
  6772. if execution_state > 0 {
  6773. if cost_type > 0 {
  6774. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6776. } else {
  6777. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6779. }
  6780. } else {
  6781. if cost_type > 0 {
  6782. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6784. } else {
  6785. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6787. }
  6788. }
  6789. }
  6790. } else if patientType == 2 {
  6791. if patient_id > 0 {
  6792. if execution_state > 0 {
  6793. if cost_type > 0 {
  6794. 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 = ?"
  6795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6796. } else {
  6797. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6798. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6799. }
  6800. } else {
  6801. if cost_type > 0 {
  6802. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6804. } else {
  6805. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6807. }
  6808. }
  6809. } else {
  6810. if execution_state > 0 {
  6811. if cost_type > 0 {
  6812. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6814. } else {
  6815. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6816. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6817. }
  6818. } else {
  6819. if cost_type > 0 {
  6820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6822. } else {
  6823. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6825. }
  6826. }
  6827. }
  6828. }
  6829. } else if adviceType == 2 && len(deliverWay) > 0 {
  6830. if patientType == 0 {
  6831. if patient_id > 0 {
  6832. if execution_state > 0 {
  6833. if cost_type > 0 {
  6834. 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 = ?"
  6835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6836. } else {
  6837. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6839. }
  6840. } else {
  6841. if cost_type > 0 {
  6842. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6844. } else {
  6845. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6846. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6847. }
  6848. }
  6849. } else {
  6850. if execution_state > 0 {
  6851. if cost_type > 0 {
  6852. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6854. } else {
  6855. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6857. }
  6858. } else {
  6859. if cost_type > 0 {
  6860. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6862. } else {
  6863. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6865. }
  6866. }
  6867. }
  6868. } else if patientType == 1 {
  6869. if patient_id > 0 {
  6870. if execution_state > 0 {
  6871. if cost_type > 0 {
  6872. 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 = ?"
  6873. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6874. } else {
  6875. 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 = ?"
  6876. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6877. }
  6878. } else {
  6879. if cost_type > 0 {
  6880. 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 = ?"
  6881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6882. } else {
  6883. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6885. }
  6886. }
  6887. } else {
  6888. if execution_state > 0 {
  6889. if cost_type > 0 {
  6890. 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 = ?"
  6891. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6892. } else {
  6893. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6895. }
  6896. } else {
  6897. if cost_type > 0 {
  6898. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6900. } else {
  6901. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6903. }
  6904. }
  6905. }
  6906. } else if patientType == 2 {
  6907. if patient_id > 0 {
  6908. if execution_state > 0 {
  6909. if cost_type > 0 {
  6910. 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 = ?"
  6911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6912. } else {
  6913. 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 = ?"
  6914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6915. }
  6916. } else {
  6917. if cost_type > 0 {
  6918. 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 = ?"
  6919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6920. } else {
  6921. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6923. }
  6924. }
  6925. } else {
  6926. if execution_state > 0 {
  6927. if cost_type > 0 {
  6928. 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 = ?"
  6929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6930. } else {
  6931. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6933. }
  6934. } else {
  6935. if cost_type > 0 {
  6936. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6937. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6938. } else {
  6939. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6941. }
  6942. }
  6943. }
  6944. }
  6945. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6946. if patientType == 0 {
  6947. if patient_id > 0 {
  6948. if execution_state > 0 {
  6949. if cost_type > 0 {
  6950. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6951. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6952. } else {
  6953. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  6954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6955. }
  6956. } else {
  6957. if cost_type > 0 {
  6958. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6960. } else {
  6961. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6963. }
  6964. }
  6965. } else {
  6966. if execution_state > 0 {
  6967. if cost_type > 0 {
  6968. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6970. } else {
  6971. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6973. }
  6974. } else {
  6975. if cost_type > 0 {
  6976. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  6977. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6978. } else {
  6979. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6980. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6981. }
  6982. }
  6983. }
  6984. } else if patientType == 1 {
  6985. if patient_id > 0 {
  6986. if execution_state > 0 {
  6987. if cost_type > 0 {
  6988. 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 = ?"
  6989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6990. } else {
  6991. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6993. }
  6994. } else {
  6995. if cost_type > 0 {
  6996. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6998. } else {
  6999. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7001. }
  7002. }
  7003. } else {
  7004. if execution_state > 0 {
  7005. if cost_type > 0 {
  7006. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7008. } else {
  7009. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7010. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7011. }
  7012. } else {
  7013. if cost_type > 0 {
  7014. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7015. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7016. } else {
  7017. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7019. }
  7020. }
  7021. }
  7022. } else if patientType == 2 {
  7023. if patient_id > 0 {
  7024. if execution_state > 0 {
  7025. if cost_type > 0 {
  7026. 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 = ?"
  7027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7028. } else {
  7029. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7031. }
  7032. } else {
  7033. if cost_type > 0 {
  7034. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7036. } else {
  7037. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7039. }
  7040. }
  7041. } else {
  7042. if execution_state > 0 {
  7043. if cost_type > 0 {
  7044. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7046. } else {
  7047. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7049. }
  7050. } else {
  7051. if cost_type > 0 {
  7052. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7054. } else {
  7055. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7057. }
  7058. }
  7059. }
  7060. }
  7061. }
  7062. db := readDb.Table("xt_schedule")
  7063. if scheduleType > 0 {
  7064. db = db.Where("schedule_type = ?", scheduleType)
  7065. }
  7066. if partitonType > 0 {
  7067. db = db.Where("partition_id = ?", partitonType)
  7068. }
  7069. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7070. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7071. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7072. }).
  7073. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7074. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7075. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7076. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7077. Preload("DoctorAdvices", adviceCondition...).
  7078. Where("status = 1 AND user_org_id = ?", orgID)
  7079. if scheduleDate != 0 {
  7080. db = db.Where("schedule_date = ?", scheduleDate)
  7081. }
  7082. err := db.Find(&vms).Error
  7083. return vms, err
  7084. }
  7085. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7086. order := models.XtDialysisOrder{}
  7087. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7088. return order, err
  7089. }
  7090. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7091. order := models.XtPatients{}
  7092. 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
  7093. 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
  7094. return err
  7095. }
  7096. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7097. order := models.BloodDialysisOrderCount{}
  7098. db := XTReadDB().Table("xt_dialysis_order as o")
  7099. 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
  7100. return order, err
  7101. }
  7102. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7103. order := models.BloodDialysisOrderCount{}
  7104. db := XTReadDB().Table("xt_dialysis_order as o")
  7105. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1704038400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7106. return order, err
  7107. }
  7108. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7109. order := models.DialysisOrder{}
  7110. 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
  7111. return order, err
  7112. }
  7113. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7114. information := models.DeviceInformation{}
  7115. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7116. return err
  7117. }
  7118. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7119. var record models.DoubleCheck
  7120. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7121. return record, err
  7122. }
  7123. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7124. record := models.MonitoringRecord{}
  7125. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7126. return record, err
  7127. }
  7128. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7129. record := models.MonitoringRecord{}
  7130. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7131. return record, err
  7132. }
  7133. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7134. record := models.MonitoringRecord{}
  7135. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7136. return record, err
  7137. }
  7138. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7139. record := models.MonitoringRecord{}
  7140. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7141. return record, err
  7142. }
  7143. 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) {
  7144. var vms []*HisMScheduleDoctorAdviceVM
  7145. if len(deliverWay) > 0 {
  7146. db := readDb.Table("xt_schedule")
  7147. if scheduleType > 0 {
  7148. db = db.Where("schedule_type = ?", scheduleType)
  7149. }
  7150. if partitionType > 0 {
  7151. db = db.Where("partition_id = ?", partitionType)
  7152. }
  7153. if patient_id > 0 {
  7154. if execution_state > 0 {
  7155. if cost_type > 0 {
  7156. if len(execution_frequency) > 0 {
  7157. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7158. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7159. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7160. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7161. 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).
  7162. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7163. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7164. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7165. Where("status = 1 AND user_org_id = ?", orgID)
  7166. if scheduleDate != 0 {
  7167. db = db.Where("schedule_date = ?", scheduleDate)
  7168. }
  7169. err = db.Find(&vms).Error
  7170. } else {
  7171. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7172. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7173. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7174. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7175. 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).
  7176. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7177. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7178. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7179. Where("status = 1 AND user_org_id = ?", orgID)
  7180. if scheduleDate != 0 {
  7181. db = db.Where("schedule_date = ?", scheduleDate)
  7182. }
  7183. err = db.Find(&vms).Error
  7184. }
  7185. } else {
  7186. if len(execution_frequency) > 0 {
  7187. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7188. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7189. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7190. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7191. 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).
  7192. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7193. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7194. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7195. Where("status = 1 AND user_org_id = ?", orgID)
  7196. if scheduleDate != 0 {
  7197. db = db.Where("schedule_date = ?", scheduleDate)
  7198. }
  7199. err = db.Find(&vms).Error
  7200. } else {
  7201. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7202. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7203. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7204. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7205. 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).
  7206. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7207. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7208. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7209. Where("status = 1 AND user_org_id = ?", orgID)
  7210. if scheduleDate != 0 {
  7211. db = db.Where("schedule_date = ?", scheduleDate)
  7212. }
  7213. err = db.Find(&vms).Error
  7214. }
  7215. }
  7216. } else {
  7217. if cost_type > 0 {
  7218. if len(execution_frequency) > 0 {
  7219. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7220. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7221. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7222. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7223. 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).
  7224. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7225. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7226. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7227. Where("status = 1 AND user_org_id = ?", orgID)
  7228. if scheduleDate != 0 {
  7229. db = db.Where("schedule_date = ?", scheduleDate)
  7230. }
  7231. err = db.Find(&vms).Error
  7232. } else {
  7233. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7234. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7235. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7236. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7237. 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).
  7238. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7239. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7240. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7241. Where("status = 1 AND user_org_id = ?", orgID)
  7242. if scheduleDate != 0 {
  7243. db = db.Where("schedule_date = ?", scheduleDate)
  7244. }
  7245. err = db.Find(&vms).Error
  7246. }
  7247. } else {
  7248. if len(execution_frequency) > 0 {
  7249. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7250. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7251. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7252. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7253. 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).
  7254. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7255. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7256. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7257. Where("status = 1 AND user_org_id = ?", orgID)
  7258. if scheduleDate != 0 {
  7259. db = db.Where("schedule_date = ?", scheduleDate)
  7260. }
  7261. err = db.Find(&vms).Error
  7262. } else {
  7263. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7264. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7265. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7266. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7267. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7268. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7269. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7270. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7271. Where("status = 1 AND user_org_id = ?", orgID)
  7272. if scheduleDate != 0 {
  7273. db = db.Where("schedule_date = ?", scheduleDate)
  7274. }
  7275. err = db.Find(&vms).Error
  7276. }
  7277. }
  7278. }
  7279. } else {
  7280. if execution_state > 0 {
  7281. if cost_type > 0 {
  7282. if len(execution_frequency) > 0 {
  7283. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7284. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7285. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7286. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7287. 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).
  7288. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7289. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7290. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7291. Where("status = 1 AND user_org_id = ?", orgID)
  7292. if scheduleDate != 0 {
  7293. db = db.Where("schedule_date = ?", scheduleDate)
  7294. }
  7295. err = db.Find(&vms).Error
  7296. } else {
  7297. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7298. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7299. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7300. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7301. 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).
  7302. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7303. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7304. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7305. Where("status = 1 AND user_org_id = ?", orgID)
  7306. if scheduleDate != 0 {
  7307. db = db.Where("schedule_date = ?", scheduleDate)
  7308. }
  7309. err = db.Find(&vms).Error
  7310. }
  7311. } else {
  7312. if len(execution_frequency) > 0 {
  7313. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7314. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7315. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7316. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7317. 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).
  7318. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7319. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7320. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7321. Where("status = 1 AND user_org_id = ?", orgID)
  7322. if scheduleDate != 0 {
  7323. db = db.Where("schedule_date = ?", scheduleDate)
  7324. }
  7325. err = db.Find(&vms).Error
  7326. } else {
  7327. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7328. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7329. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7330. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7331. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7332. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7333. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7334. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7335. Where("status = 1 AND user_org_id = ?", orgID)
  7336. if scheduleDate != 0 {
  7337. db = db.Where("schedule_date = ?", scheduleDate)
  7338. }
  7339. err = db.Find(&vms).Error
  7340. }
  7341. }
  7342. } else {
  7343. if cost_type > 0 {
  7344. if len(execution_frequency) > 0 {
  7345. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7346. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7347. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7348. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7349. 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).
  7350. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7351. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7352. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7353. Where("status = 1 AND user_org_id = ?", orgID)
  7354. if scheduleDate != 0 {
  7355. db = db.Where("schedule_date = ?", scheduleDate)
  7356. }
  7357. err = db.Find(&vms).Error
  7358. } else {
  7359. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7360. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7361. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7362. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7363. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7364. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7365. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7366. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7367. Where("status = 1 AND user_org_id = ?", orgID)
  7368. if scheduleDate != 0 {
  7369. db = db.Where("schedule_date = ?", scheduleDate)
  7370. }
  7371. err = db.Find(&vms).Error
  7372. }
  7373. } else {
  7374. if len(execution_frequency) > 0 {
  7375. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7376. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7377. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7378. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7379. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7380. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7381. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7382. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7383. Where("status = 1 AND user_org_id = ?", orgID)
  7384. if scheduleDate != 0 {
  7385. db = db.Where("schedule_date = ?", scheduleDate)
  7386. }
  7387. err = db.Find(&vms).Error
  7388. } else {
  7389. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7390. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7391. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7392. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7393. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7394. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7395. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7396. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7397. Where("status = 1 AND user_org_id = ?", orgID)
  7398. if scheduleDate != 0 {
  7399. db = db.Where("schedule_date = ?", scheduleDate)
  7400. }
  7401. err = db.Find(&vms).Error
  7402. }
  7403. }
  7404. }
  7405. }
  7406. } else {
  7407. db := readDb.Table("xt_schedule")
  7408. if scheduleType > 0 {
  7409. db = db.Where("schedule_type = ?", scheduleType)
  7410. }
  7411. if partitionType > 0 {
  7412. db = db.Where("partition_id = ?", partitionType)
  7413. }
  7414. if patient_id > 0 {
  7415. if execution_state > 0 {
  7416. fmt.Println("execution_state---------------------", execution_state)
  7417. if cost_type > 0 {
  7418. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7419. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7420. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7421. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7422. 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).
  7423. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7424. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7425. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7426. Where("status = 1 AND user_org_id = ?", orgID)
  7427. if scheduleDate != 0 {
  7428. db = db.Where("schedule_date = ?", scheduleDate)
  7429. }
  7430. err = db.Find(&vms).Error
  7431. } else {
  7432. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7433. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7434. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7435. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7436. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7437. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7438. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7439. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7440. Where("status = 1 AND user_org_id = ?", orgID)
  7441. if scheduleDate != 0 {
  7442. db = db.Where("schedule_date = ?", scheduleDate)
  7443. }
  7444. err = db.Find(&vms).Error
  7445. }
  7446. } else {
  7447. if cost_type > 0 {
  7448. if len(execution_frequency) > 0 {
  7449. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7450. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7451. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7452. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7453. 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).
  7454. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7455. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7456. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7457. Where("status = 1 AND user_org_id = ?", orgID)
  7458. if scheduleDate != 0 {
  7459. db = db.Where("schedule_date = ?", scheduleDate)
  7460. }
  7461. err = db.Find(&vms).Error
  7462. } else {
  7463. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7464. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7465. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7466. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7467. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7468. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7469. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7470. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7471. Where("status = 1 AND user_org_id = ?", orgID)
  7472. if scheduleDate != 0 {
  7473. db = db.Where("schedule_date = ?", scheduleDate)
  7474. }
  7475. err = db.Find(&vms).Error
  7476. }
  7477. } else {
  7478. if len(execution_frequency) > 0 {
  7479. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7480. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7481. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7482. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7483. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7484. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7485. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7486. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7487. Where("status = 1 AND user_org_id = ?", orgID)
  7488. if scheduleDate != 0 {
  7489. db = db.Where("schedule_date = ?", scheduleDate)
  7490. }
  7491. err = db.Find(&vms).Error
  7492. } else {
  7493. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7494. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7495. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7496. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7497. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7498. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7499. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7500. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7501. Where("status = 1 AND user_org_id = ?", orgID)
  7502. if scheduleDate != 0 {
  7503. db = db.Where("schedule_date = ?", scheduleDate)
  7504. }
  7505. err = db.Find(&vms).Error
  7506. }
  7507. }
  7508. }
  7509. } else {
  7510. if execution_state > 0 {
  7511. if cost_type > 0 {
  7512. if len(execution_frequency) > 0 {
  7513. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7514. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7515. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7516. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7517. 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).
  7518. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7519. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7520. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7521. Where("status = 1 AND user_org_id = ?", orgID)
  7522. if scheduleDate != 0 {
  7523. db = db.Where("schedule_date = ?", scheduleDate)
  7524. }
  7525. err = db.Find(&vms).Error
  7526. } else {
  7527. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7528. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7529. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7530. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7531. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7532. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7533. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7534. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7535. Where("status = 1 AND user_org_id = ?", orgID)
  7536. if scheduleDate != 0 {
  7537. db = db.Where("schedule_date = ?", scheduleDate)
  7538. }
  7539. err = db.Find(&vms).Error
  7540. }
  7541. } else {
  7542. if len(execution_frequency) > 0 {
  7543. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7544. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7545. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7546. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7547. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7548. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7549. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7550. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7551. Where("status = 1 AND user_org_id = ?", orgID)
  7552. if scheduleDate != 0 {
  7553. db = db.Where("schedule_date = ?", scheduleDate)
  7554. }
  7555. err = db.Find(&vms).Error
  7556. } else {
  7557. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7558. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7559. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7560. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7561. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7562. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7563. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7564. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7565. Where("status = 1 AND user_org_id = ?", orgID)
  7566. if scheduleDate != 0 {
  7567. db = db.Where("schedule_date = ?", scheduleDate)
  7568. }
  7569. err = db.Find(&vms).Error
  7570. }
  7571. }
  7572. } else {
  7573. if cost_type > 0 {
  7574. if len(execution_frequency) > 0 {
  7575. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7576. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7577. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7578. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7579. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7580. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7581. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7582. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7583. Where("status = 1 AND user_org_id = ?", orgID)
  7584. if scheduleDate != 0 {
  7585. db = db.Where("schedule_date = ?", scheduleDate)
  7586. }
  7587. err = db.Find(&vms).Error
  7588. } else {
  7589. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7590. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7591. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7592. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7593. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7594. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7595. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7596. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7597. Where("status = 1 AND user_org_id = ?", orgID)
  7598. if scheduleDate != 0 {
  7599. db = db.Where("schedule_date = ?", scheduleDate)
  7600. }
  7601. err = db.Find(&vms).Error
  7602. }
  7603. } else {
  7604. if len(execution_frequency) > 0 {
  7605. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7606. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7607. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7608. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7609. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7610. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7611. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7612. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7613. Where("status = 1 AND user_org_id = ?", orgID)
  7614. if scheduleDate != 0 {
  7615. db = db.Where("schedule_date = ?", scheduleDate)
  7616. }
  7617. err = db.Find(&vms).Error
  7618. } else {
  7619. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7620. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7621. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7622. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7623. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7624. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7625. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7626. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7627. Where("status = 1 AND user_org_id = ?", orgID)
  7628. if scheduleDate != 0 {
  7629. db = db.Where("schedule_date = ?", scheduleDate)
  7630. }
  7631. err = db.Find(&vms).Error
  7632. }
  7633. }
  7634. }
  7635. }
  7636. }
  7637. return vms, err
  7638. }
  7639. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7640. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7641. return weight, err
  7642. }
  7643. func MobileGetLongScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string, keyword string) ([]*MScheduleDoctorAdviceVM, error) {
  7644. fmt.Println("deliverWay-----------------", deliverWay)
  7645. fmt.Println("execution_frequency------------------", execution_frequency)
  7646. fmt.Println("adviceType-----------------", adviceType)
  7647. fmt.Println("patientType----------------", patientType)
  7648. fmt.Println("patient_id----------------", patient_id)
  7649. fmt.Println("execution_state----------------", execution_state)
  7650. fmt.Println("cost_type---------------------", cost_type)
  7651. fmt.Println("execution_frequency", execution_frequency)
  7652. var vms []*MScheduleDoctorAdviceVM
  7653. adviceWhere := ""
  7654. keyword = "%" + keyword + "%"
  7655. adviceCondition := []interface{}{}
  7656. if adviceType == 1 {
  7657. if patientType == 0 {
  7658. if patient_id > 0 {
  7659. if execution_state > 0 {
  7660. if cost_type > 0 {
  7661. if len(execution_frequency) > 0 {
  7662. if len(keyword) > 0 {
  7663. if len(deliverWay) > 0 {
  7664. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way = ? and advice_name like ?"
  7665. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7666. } else {
  7667. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7668. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7669. }
  7670. } else {
  7671. if len(deliverWay) > 0 {
  7672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7673. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7674. } else {
  7675. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7676. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7677. }
  7678. }
  7679. } else {
  7680. if len(keyword) > 0 {
  7681. if len(deliverWay) > 0 {
  7682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7683. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7684. } else {
  7685. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7686. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7687. }
  7688. } else {
  7689. if len(deliverWay) > 0 {
  7690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7691. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7692. } else {
  7693. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7694. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7695. }
  7696. }
  7697. }
  7698. } else {
  7699. if len(execution_frequency) > 0 {
  7700. if len(keyword) > 0 {
  7701. if len(deliverWay) > 0 {
  7702. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7703. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7704. } else {
  7705. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7706. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7707. }
  7708. } else {
  7709. if len(deliverWay) > 0 {
  7710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7711. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7712. } else {
  7713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7714. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7715. }
  7716. }
  7717. } else {
  7718. if len(keyword) > 0 {
  7719. if len(deliverWay) > 0 {
  7720. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7721. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7722. } else {
  7723. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7724. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7725. }
  7726. } else {
  7727. if len(deliverWay) > 0 {
  7728. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7729. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7730. } else {
  7731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7732. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7733. }
  7734. }
  7735. }
  7736. }
  7737. } else {
  7738. if cost_type > 0 {
  7739. if len(execution_frequency) > 0 {
  7740. if len(keyword) > 0 {
  7741. if len(deliverWay) > 0 {
  7742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7743. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7744. } else {
  7745. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7746. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7747. }
  7748. } else {
  7749. if len(deliverWay) > 0 {
  7750. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7751. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7752. } else {
  7753. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7754. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7755. }
  7756. }
  7757. } else {
  7758. if len(keyword) > 0 {
  7759. if len(deliverWay) > 0 {
  7760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7761. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7762. } else {
  7763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7764. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7765. }
  7766. } else {
  7767. if len(deliverWay) > 0 {
  7768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7769. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7770. } else {
  7771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7772. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7773. }
  7774. }
  7775. }
  7776. } else {
  7777. if len(execution_frequency) > 0 {
  7778. if len(keyword) > 0 {
  7779. if len(deliverWay) > 0 {
  7780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7781. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7782. } else {
  7783. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7784. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7785. }
  7786. } else {
  7787. if len(deliverWay) > 0 {
  7788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7789. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7790. } else {
  7791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7792. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7793. }
  7794. }
  7795. } else {
  7796. if len(keyword) > 0 {
  7797. if len(deliverWay) > 0 {
  7798. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7799. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7800. } else {
  7801. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7802. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7803. }
  7804. } else {
  7805. if len(deliverWay) > 0 {
  7806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7807. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7808. } else {
  7809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7810. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7811. }
  7812. }
  7813. }
  7814. }
  7815. }
  7816. } else {
  7817. if execution_state > 0 {
  7818. if cost_type > 0 {
  7819. if len(execution_frequency) > 0 {
  7820. if len(keyword) > 0 {
  7821. if len(deliverWay) > 0 {
  7822. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7823. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7824. } else {
  7825. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7826. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7827. }
  7828. } else {
  7829. if len(deliverWay) > 0 {
  7830. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7831. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7832. } else {
  7833. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7834. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7835. }
  7836. }
  7837. } else {
  7838. if len(keyword) > 0 {
  7839. if len(deliverWay) > 0 {
  7840. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7841. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7842. } else {
  7843. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7844. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7845. }
  7846. } else {
  7847. if len(deliverWay) > 0 {
  7848. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7849. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7850. } else {
  7851. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7852. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7853. }
  7854. }
  7855. }
  7856. } else {
  7857. if len(execution_frequency) > 0 {
  7858. if len(keyword) > 0 {
  7859. if len(deliverWay) > 0 {
  7860. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7861. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7862. } else {
  7863. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7864. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7865. }
  7866. } else {
  7867. if len(deliverWay) > 0 {
  7868. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7869. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7870. } else {
  7871. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7872. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7873. }
  7874. }
  7875. } else {
  7876. if len(keyword) > 0 {
  7877. if len(deliverWay) > 0 {
  7878. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7879. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7880. } else {
  7881. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7882. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7883. }
  7884. } else {
  7885. if len(deliverWay) > 0 {
  7886. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7887. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7888. } else {
  7889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7890. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7891. }
  7892. }
  7893. }
  7894. }
  7895. } else {
  7896. if cost_type > 0 {
  7897. if len(keyword) > 0 {
  7898. if len(deliverWay) > 0 {
  7899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7900. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7901. } else {
  7902. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7903. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7904. }
  7905. } else {
  7906. if len(deliverWay) > 0 {
  7907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7908. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7909. } else {
  7910. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7911. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7912. }
  7913. }
  7914. } else {
  7915. if len(keyword) > 0 {
  7916. if len(deliverWay) > 0 {
  7917. if len(execution_frequency) > 0 {
  7918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7919. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7920. } else {
  7921. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7922. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7923. }
  7924. } else {
  7925. if len(execution_frequency) > 0 {
  7926. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7927. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7928. } else {
  7929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7930. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7931. }
  7932. }
  7933. } else {
  7934. if len(deliverWay) > 0 {
  7935. if len(execution_frequency) > 0 {
  7936. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7937. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7938. } else {
  7939. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7940. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7941. }
  7942. } else {
  7943. if len(execution_frequency) > 0 {
  7944. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7945. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7946. } else {
  7947. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7948. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7949. }
  7950. }
  7951. }
  7952. }
  7953. }
  7954. }
  7955. } else if patientType == 1 {
  7956. if patient_id > 0 {
  7957. if execution_state > 0 {
  7958. if cost_type > 0 {
  7959. if len(execution_frequency) > 0 {
  7960. if len(keyword) > 0 {
  7961. if len(deliverWay) > 0 {
  7962. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7963. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7964. } else {
  7965. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7966. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7967. }
  7968. } else {
  7969. if len(keyword) > 0 {
  7970. if len(deliverWay) > 0 {
  7971. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7972. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7973. }
  7974. } else {
  7975. if len(deliverWay) > 0 {
  7976. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7977. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7978. } else {
  7979. 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 = ?"
  7980. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  7981. }
  7982. }
  7983. }
  7984. } else {
  7985. if len(keyword) > 0 {
  7986. if len(deliverWay) > 0 {
  7987. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7988. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  7989. } else {
  7990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7991. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  7992. }
  7993. } else {
  7994. if len(deliverWay) > 0 {
  7995. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7996. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  7997. } else {
  7998. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7999. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  8000. }
  8001. }
  8002. }
  8003. } else {
  8004. if len(execution_frequency) > 0 {
  8005. if len(keyword) > 0 {
  8006. if len(deliverWay) > 0 {
  8007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8008. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8009. } else {
  8010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8011. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  8012. }
  8013. } else {
  8014. if len(deliverWay) > 0 {
  8015. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8016. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  8017. } else {
  8018. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8019. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  8020. }
  8021. }
  8022. } else {
  8023. if len(keyword) > 0 {
  8024. if len(deliverWay) > 0 {
  8025. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  8026. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  8027. } else {
  8028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  8029. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  8030. }
  8031. } else {
  8032. if len(deliverWay) > 0 {
  8033. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  8034. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  8035. } else {
  8036. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  8037. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  8038. }
  8039. }
  8040. }
  8041. }
  8042. } else {
  8043. if cost_type > 0 {
  8044. if len(execution_frequency) > 0 {
  8045. if len(keyword) > 0 {
  8046. if len(deliverWay) > 0 {
  8047. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8048. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8049. } else {
  8050. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  8051. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  8052. }
  8053. } else {
  8054. if len(deliverWay) > 0 {
  8055. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8056. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8057. } else {
  8058. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8059. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  8060. }
  8061. }
  8062. } else {
  8063. if len(keyword) > 0 {
  8064. if len(deliverWay) > 0 {
  8065. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8066. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8067. } else {
  8068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8069. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8070. }
  8071. } else {
  8072. if len(deliverWay) > 0 {
  8073. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8074. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8075. } else {
  8076. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8077. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8078. }
  8079. }
  8080. }
  8081. } else {
  8082. if len(execution_frequency) > 0 {
  8083. if len(keyword) > 0 {
  8084. if len(deliverWay) > 0 {
  8085. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =? "
  8086. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8087. } else {
  8088. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8089. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8090. }
  8091. } else {
  8092. if len(deliverWay) > 0 {
  8093. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8094. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8095. } else {
  8096. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8097. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8098. }
  8099. }
  8100. } else {
  8101. if len(keyword) > 0 {
  8102. if len(deliverWay) > 0 {
  8103. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8104. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8105. } else {
  8106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8107. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8108. }
  8109. } else {
  8110. if len(deliverWay) > 0 {
  8111. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8112. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8113. } else {
  8114. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8115. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8116. }
  8117. }
  8118. }
  8119. }
  8120. }
  8121. } else {
  8122. if execution_state > 0 {
  8123. if cost_type > 0 {
  8124. if len(execution_frequency) > 0 {
  8125. if len(keyword) > 0 {
  8126. if len(deliverWay) > 0 {
  8127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8128. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8129. } else {
  8130. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  8131. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8132. }
  8133. } else {
  8134. if len(deliverWay) > 0 {
  8135. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8136. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8137. } else {
  8138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8139. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8140. }
  8141. }
  8142. } else {
  8143. if len(keyword) > 0 {
  8144. if len(deliverWay) > 0 {
  8145. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ? and delivery_way =?"
  8146. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8147. } else {
  8148. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8149. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8150. }
  8151. } else {
  8152. if len(deliverWay) > 0 {
  8153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8154. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8155. } else {
  8156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8157. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8158. }
  8159. }
  8160. }
  8161. } else {
  8162. if len(execution_frequency) > 0 {
  8163. if len(keyword) > 0 {
  8164. if len(deliverWay) > 0 {
  8165. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8166. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8167. } else {
  8168. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8169. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8170. }
  8171. } else {
  8172. if len(deliverWay) > 0 {
  8173. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8174. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8175. } else {
  8176. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8177. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8178. }
  8179. }
  8180. } else {
  8181. if len(keyword) > 0 {
  8182. if len(deliverWay) > 0 {
  8183. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8184. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8185. } else {
  8186. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8187. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8188. }
  8189. } else {
  8190. if len(deliverWay) > 0 {
  8191. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8192. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8193. } else {
  8194. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8195. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8196. }
  8197. }
  8198. }
  8199. }
  8200. } else {
  8201. if cost_type > 0 {
  8202. if len(execution_frequency) > 0 {
  8203. if len(keyword) > 0 {
  8204. if len(deliverWay) > 0 {
  8205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8206. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8207. } else {
  8208. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8209. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8210. }
  8211. } else {
  8212. if len(deliverWay) > 0 {
  8213. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8214. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8215. } else {
  8216. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8217. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8218. }
  8219. }
  8220. } else {
  8221. if len(keyword) > 0 {
  8222. if len(deliverWay) > 0 {
  8223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8224. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8225. } else {
  8226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8227. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8228. }
  8229. } else {
  8230. if len(deliverWay) > 0 {
  8231. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8232. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8233. } else {
  8234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8235. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8236. }
  8237. }
  8238. }
  8239. } else {
  8240. if len(execution_frequency) > 0 {
  8241. if len(keyword) > 0 {
  8242. if len(deliverWay) > 0 {
  8243. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8244. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8245. } else {
  8246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8247. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8248. }
  8249. } else {
  8250. if len(deliverWay) > 0 {
  8251. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8252. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8253. } else {
  8254. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8255. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8256. }
  8257. }
  8258. } else {
  8259. if len(keyword) > 0 {
  8260. if len(deliverWay) > 0 {
  8261. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8262. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8263. } else {
  8264. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8265. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8266. }
  8267. } else {
  8268. if len(deliverWay) > 0 {
  8269. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8270. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8271. } else {
  8272. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8273. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8274. }
  8275. }
  8276. }
  8277. }
  8278. }
  8279. }
  8280. } else if patientType == 2 {
  8281. if patient_id > 0 {
  8282. if execution_state > 0 {
  8283. if cost_type > 0 {
  8284. if len(execution_frequency) > 0 {
  8285. if len(keyword) > 0 {
  8286. if len(deliverWay) > 0 {
  8287. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8288. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8289. } else {
  8290. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  8291. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8292. }
  8293. } else {
  8294. if len(deliverWay) > 0 {
  8295. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and delivery_way =?"
  8296. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8297. } else {
  8298. 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 = ?"
  8299. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8300. }
  8301. }
  8302. } else {
  8303. if len(keyword) > 0 {
  8304. if len(deliverWay) > 0 {
  8305. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8306. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8307. } else {
  8308. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  8309. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8310. }
  8311. } else {
  8312. if len(deliverWay) > 0 {
  8313. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  8314. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8315. } else {
  8316. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8317. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8318. }
  8319. }
  8320. }
  8321. } else {
  8322. if len(execution_frequency) > 0 {
  8323. if len(keyword) > 0 {
  8324. if len(deliverWay) > 0 {
  8325. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8326. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8327. } else {
  8328. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8329. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8330. }
  8331. } else {
  8332. if len(deliverWay) > 0 {
  8333. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8334. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8335. } else {
  8336. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8337. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8338. }
  8339. }
  8340. } else {
  8341. if len(keyword) > 0 {
  8342. if len(deliverWay) > 0 {
  8343. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  8344. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8345. } else {
  8346. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  8347. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8348. }
  8349. } else {
  8350. if len(deliverWay) > 0 {
  8351. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8352. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8353. } else {
  8354. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8355. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8356. }
  8357. }
  8358. }
  8359. }
  8360. } else {
  8361. if cost_type > 0 {
  8362. if len(execution_frequency) > 0 {
  8363. if len(keyword) > 0 {
  8364. if len(deliverWay) > 0 {
  8365. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8366. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8367. } else {
  8368. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8369. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8370. }
  8371. } else {
  8372. if len(deliverWay) > 0 {
  8373. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8374. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8375. } else {
  8376. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8377. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8378. }
  8379. }
  8380. } else {
  8381. if len(keyword) > 0 {
  8382. if len(deliverWay) > 0 {
  8383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8384. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8385. } else {
  8386. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  8387. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8388. }
  8389. } else {
  8390. if len(deliverWay) > 0 {
  8391. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8392. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8393. } else {
  8394. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8395. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8396. }
  8397. }
  8398. }
  8399. } else {
  8400. if len(execution_frequency) > 0 {
  8401. if len(keyword) > 0 {
  8402. if len(deliverWay) > 0 {
  8403. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8404. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8405. } else {
  8406. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8407. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8408. }
  8409. } else {
  8410. if len(deliverWay) > 0 {
  8411. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8412. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8413. } else {
  8414. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8415. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8416. }
  8417. }
  8418. } else {
  8419. if len(keyword) > 0 {
  8420. if len(deliverWay) > 0 {
  8421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ? and delivery_way =?"
  8422. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8423. } else {
  8424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8425. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8426. }
  8427. } else {
  8428. if len(deliverWay) > 0 {
  8429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8430. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8431. } else {
  8432. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8433. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8434. }
  8435. }
  8436. }
  8437. }
  8438. }
  8439. } else {
  8440. if execution_state > 0 {
  8441. if cost_type > 0 {
  8442. if len(execution_frequency) > 0 {
  8443. if len(keyword) > 0 {
  8444. if len(deliverWay) > 0 {
  8445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8446. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8447. } else {
  8448. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8449. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8450. }
  8451. } else {
  8452. if len(deliverWay) > 0 {
  8453. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8454. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8455. } else {
  8456. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8457. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8458. }
  8459. }
  8460. } else {
  8461. if len(keyword) > 0 {
  8462. if len(deliverWay) > 0 {
  8463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8464. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8465. } else {
  8466. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8467. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8468. }
  8469. } else {
  8470. if len(deliverWay) > 0 {
  8471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8472. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8473. } else {
  8474. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8475. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8476. }
  8477. }
  8478. }
  8479. } else {
  8480. if len(execution_frequency) > 0 {
  8481. if len(keyword) > 0 {
  8482. if len(deliverWay) > 0 {
  8483. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8484. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8485. } else {
  8486. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  8487. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8488. }
  8489. } else {
  8490. if len(deliverWay) > 0 {
  8491. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8492. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8493. } else {
  8494. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8495. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8496. }
  8497. }
  8498. } else {
  8499. if len(keyword) > 0 {
  8500. if len(deliverWay) > 0 {
  8501. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ? and delivery_way =?"
  8502. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8503. } else {
  8504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8505. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8506. }
  8507. } else {
  8508. if len(deliverWay) > 0 {
  8509. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8510. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8511. } else {
  8512. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8513. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8514. }
  8515. }
  8516. }
  8517. }
  8518. } else {
  8519. if cost_type > 0 {
  8520. if len(execution_frequency) > 0 {
  8521. if len(keyword) > 0 {
  8522. if len(deliverWay) > 0 {
  8523. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8524. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8525. } else {
  8526. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8527. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8528. }
  8529. } else {
  8530. if len(deliverWay) > 0 {
  8531. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8532. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8533. } else {
  8534. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8535. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8536. }
  8537. }
  8538. } else {
  8539. if len(keyword) > 0 {
  8540. if len(deliverWay) > 0 {
  8541. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ? and delivery_way =?"
  8542. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8543. } else {
  8544. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8545. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8546. }
  8547. } else {
  8548. if len(deliverWay) > 0 {
  8549. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8550. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8551. } else {
  8552. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8553. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8554. }
  8555. }
  8556. }
  8557. } else {
  8558. if len(execution_frequency) > 0 {
  8559. if len(keyword) > 0 {
  8560. if len(deliverWay) > 0 {
  8561. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8562. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8563. } else {
  8564. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8565. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8566. }
  8567. } else {
  8568. if len(deliverWay) > 0 {
  8569. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8570. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8571. } else {
  8572. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8573. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8574. }
  8575. }
  8576. } else {
  8577. if len(keyword) > 0 {
  8578. if len(deliverWay) > 0 {
  8579. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8580. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8581. } else {
  8582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8583. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8584. }
  8585. } else {
  8586. if len(deliverWay) > 0 {
  8587. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8588. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8589. } else {
  8590. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8591. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8592. }
  8593. }
  8594. }
  8595. }
  8596. }
  8597. }
  8598. }
  8599. }
  8600. db := readDb.Table("xt_schedule")
  8601. if scheduleType > 0 {
  8602. db = db.Where("schedule_type = ?", scheduleType)
  8603. }
  8604. if partitonType > 0 {
  8605. db = db.Where("partition_id = ?", partitonType)
  8606. }
  8607. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8608. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8609. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8610. }).
  8611. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8612. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8613. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8614. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8615. Preload("DoctorAdvices", adviceCondition...).
  8616. Where("status = 1 AND user_org_id = ?", orgID)
  8617. if scheduleDate != 0 {
  8618. db = db.Where("schedule_date = ?", scheduleDate)
  8619. }
  8620. err := db.Find(&vms).Error
  8621. return vms, err
  8622. }
  8623. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8624. treatmentAsses := models.ReceiveTreatmentAsses{}
  8625. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8626. return treatmentAsses, err
  8627. }
  8628. func GetDrugIsShow(id int64, org_id int64) (models.XtBaseDrug, error) {
  8629. baseDrug := models.XtBaseDrug{}
  8630. err := XTReadDB().Where("id = ? and status =1 and org_id = ?", id, org_id).Find(&baseDrug).Error
  8631. return baseDrug, err
  8632. }