mobile_dialysis_service.go 530KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925
  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 = ?", 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 < ?", 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. if err != nil {
  1089. if err == gorm.ErrRecordNotFound {
  1090. return nil, nil
  1091. } else {
  1092. return nil, err
  1093. }
  1094. }
  1095. return &record, nil
  1096. }
  1097. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1098. dislysis := models.AssessmentAfterDislysis{}
  1099. 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
  1100. return dislysis, err
  1101. }
  1102. // 治疗小结
  1103. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1104. var record models.TreatmentSummary
  1105. redis := RedisClient()
  1106. defer redis.Close()
  1107. // cur_date := time.Now().Format("2006-01-02")
  1108. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1109. treatment_summary_str, _ := redis.Get(key).Result()
  1110. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1111. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1112. if err != nil {
  1113. if err == gorm.ErrRecordNotFound {
  1114. if record.ID <= 0 {
  1115. redis.Set(key, "null", time.Second*60*60*18)
  1116. }
  1117. return nil, nil
  1118. } else {
  1119. return nil, err
  1120. }
  1121. } else {
  1122. if record.ID > 0 {
  1123. //缓存数据
  1124. treatment_summary_str, err := json.Marshal(record)
  1125. if err == nil {
  1126. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1127. }
  1128. } else {
  1129. redis.Set(key, "null", time.Second*60*60*18)
  1130. }
  1131. return &record, nil
  1132. }
  1133. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1134. if treatment_summary_str == "null" {
  1135. return &record, nil
  1136. } else {
  1137. json.Unmarshal([]byte(treatment_summary_str), &record)
  1138. return &record, nil
  1139. }
  1140. }
  1141. }
  1142. // 透析处方
  1143. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1144. var record models.DialysisPrescription
  1145. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1146. if err != nil {
  1147. if err == gorm.ErrRecordNotFound {
  1148. return nil, nil
  1149. } else {
  1150. return nil, err
  1151. }
  1152. }
  1153. return &record, nil
  1154. }
  1155. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1156. var schedule models.XtSchedule
  1157. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1158. if err != nil {
  1159. if err == gorm.ErrRecordNotFound {
  1160. return nil, nil
  1161. } else {
  1162. return nil, err
  1163. }
  1164. }
  1165. return &schedule, nil
  1166. }
  1167. // 透析方案
  1168. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1169. var record models.DialysisSolution
  1170. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1171. if err != nil {
  1172. if err == gorm.ErrRecordNotFound {
  1173. return nil, nil
  1174. } else {
  1175. return nil, err
  1176. }
  1177. }
  1178. return &record, nil
  1179. }
  1180. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1181. var patient models.Patients
  1182. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1183. if err != nil {
  1184. if err == gorm.ErrRecordNotFound {
  1185. return nil, nil
  1186. } else {
  1187. return nil, err
  1188. }
  1189. }
  1190. return &patient, nil
  1191. }
  1192. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1193. fmt.Println()
  1194. tx := writeDb.Begin()
  1195. updateTime := time.Now().Unix()
  1196. 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
  1197. if err != nil {
  1198. tx.Rollback()
  1199. return err
  1200. }
  1201. tx.Commit()
  1202. return nil
  1203. }
  1204. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1205. record := models.MonitoringRecord{}
  1206. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1207. return record, err
  1208. }
  1209. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1210. var monitor models.MonitoringRecord
  1211. var err error
  1212. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1213. if err == gorm.ErrRecordNotFound {
  1214. return nil, nil
  1215. }
  1216. if err != nil {
  1217. return nil, err
  1218. }
  1219. return &monitor, nil
  1220. }
  1221. type MScheduleDoctorAdviceVM struct {
  1222. ID int64 `gorm:"column:id" json:"id"`
  1223. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1224. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1225. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1226. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1227. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1228. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1229. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1230. Status int64 `gorm:"column:status" json:"status"`
  1231. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1232. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1233. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1234. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1235. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1236. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1237. }
  1238. func (MScheduleDoctorAdviceVM) TableName() string {
  1239. return "xt_schedule"
  1240. }
  1241. type MScheduleDoctorAdviceVMOne struct {
  1242. ID int64 `gorm:"column:id" json:"id"`
  1243. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1244. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1245. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1246. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1247. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1248. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1249. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1250. Status int64 `gorm:"column:status" json:"status"`
  1251. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1252. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1253. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1254. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1255. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1256. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1257. }
  1258. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1259. return "xt_schedule"
  1260. }
  1261. type MDoctorAdviceVM struct {
  1262. ID int64 `gorm:"column:id" json:"id"`
  1263. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1264. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1265. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1266. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1267. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1268. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1269. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1270. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1271. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1272. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1273. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1274. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1275. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1276. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1277. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1278. Status int64 `gorm:"column:status" json:"status"`
  1279. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1280. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1281. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1282. Remark string `gorm:"column:remark" json:"remark"`
  1283. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1284. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1285. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1286. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1287. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1288. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1289. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1290. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1291. Checker int64 `gorm:"column:checker" json:"checker"`
  1292. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1293. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1294. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1295. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1296. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1297. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1298. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1299. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1300. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1301. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1302. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1303. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1304. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1305. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1306. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1307. }
  1308. func (MDoctorAdviceVM) TableName() string {
  1309. return "xt_doctor_advice"
  1310. }
  1311. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1312. var vms []*MScheduleDoctorAdviceVM
  1313. adviceWhere := ""
  1314. adviceCondition := []interface{}{}
  1315. if adviceType == 0 {
  1316. if patientType == 0 {
  1317. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1319. } else if patientType == 1 {
  1320. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1322. } else if patientType == 2 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1325. }
  1326. } else if adviceType == 1 {
  1327. if patientType == 0 {
  1328. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1329. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1330. } else if patientType == 1 {
  1331. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1333. } else if patientType == 2 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1336. }
  1337. } else if adviceType == 3 {
  1338. if patientType == 0 {
  1339. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1341. } else if patientType == 1 {
  1342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1344. } else if patientType == 2 {
  1345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1347. }
  1348. } else if adviceType == 2 && len(deliverWay) > 0 {
  1349. if patientType == 0 {
  1350. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1352. } else if patientType == 1 {
  1353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1355. } else if patientType == 2 {
  1356. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1358. }
  1359. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1360. if patientType == 0 {
  1361. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1363. } else if patientType == 1 {
  1364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1366. } else if patientType == 2 {
  1367. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1369. }
  1370. }
  1371. db := readDb.
  1372. Table("xt_schedule").
  1373. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1374. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1375. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1376. }).
  1377. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1378. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1379. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1380. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1381. Preload("DoctorAdvices", adviceCondition...).
  1382. Where("status = 1 AND user_org_id = ?", orgID)
  1383. if scheduleDate != 0 {
  1384. db = db.Where("schedule_date = ?", scheduleDate)
  1385. }
  1386. err := db.Find(&vms).Error
  1387. return vms, err
  1388. }
  1389. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1390. var vms []*MScheduleDoctorAdviceVMOne
  1391. adviceWhere := ""
  1392. adviceCondition := []interface{}{}
  1393. if adviceType == 0 {
  1394. if patientType == 0 {
  1395. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1397. } else if patientType == 1 {
  1398. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1400. } else if patientType == 2 {
  1401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1403. } else if patientType == 3 {
  1404. 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"
  1405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1406. } else if patientType == 4 {
  1407. 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)"
  1408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1409. }
  1410. } else if adviceType == 1 {
  1411. if patientType == 0 {
  1412. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1414. } else if patientType == 1 {
  1415. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1417. } else if patientType == 2 {
  1418. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1419. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1420. } else if patientType == 3 {
  1421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1422. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1423. } else if patientType == 4 {
  1424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1426. }
  1427. } else if adviceType == 3 {
  1428. if patientType == 0 {
  1429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1431. } else if patientType == 1 {
  1432. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1434. } else if patientType == 2 {
  1435. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1436. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1437. } else if patientType == 3 {
  1438. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1440. } else if patientType == 4 {
  1441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1443. }
  1444. } else if adviceType == 2 && len(deliverWay) > 0 {
  1445. if patientType == 0 {
  1446. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1448. } else if patientType == 1 {
  1449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1451. } else if patientType == 2 {
  1452. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1454. } else if patientType == 3 {
  1455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1457. } else if patientType == 4 {
  1458. 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)"
  1459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1460. }
  1461. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1462. if patientType == 0 {
  1463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1465. } else if patientType == 1 {
  1466. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1468. } else if patientType == 2 {
  1469. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1471. } else if patientType == 3 {
  1472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1474. } else if patientType == 4 {
  1475. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1477. }
  1478. }
  1479. db := readDb.
  1480. Table("xt_schedule").
  1481. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1482. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1483. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1484. //}).
  1485. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1486. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1487. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1488. Preload("DoctorAdvices", adviceCondition...).
  1489. Where("status = 1 AND user_org_id = ?", orgID)
  1490. if scheduleDate != 0 {
  1491. db = db.Where("schedule_date = ?", scheduleDate)
  1492. }
  1493. err := db.Find(&vms).Error
  1494. return vms, err
  1495. }
  1496. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1497. var vms []*HisMScheduleDoctorAdviceVM
  1498. if len(deliverWay) > 0 {
  1499. if patientType == 0 {
  1500. db := readDb.
  1501. Table("xt_schedule").
  1502. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1503. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1504. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1505. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1506. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1507. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1508. }).
  1509. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1510. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1511. Where("status = 1 AND user_org_id = ?", orgID)
  1512. if scheduleDate != 0 {
  1513. db = db.Where("schedule_date = ?", scheduleDate)
  1514. }
  1515. err = db.Find(&vms).Error
  1516. }
  1517. if patientType > 0 {
  1518. db := readDb.
  1519. Table("xt_schedule").
  1520. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1521. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1522. 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).
  1523. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1524. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1525. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1526. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1527. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1528. }).Where("status = 1 AND user_org_id = ?", orgID)
  1529. if scheduleDate != 0 {
  1530. db = db.Where("schedule_date = ?", scheduleDate)
  1531. }
  1532. err = db.Find(&vms).Error
  1533. }
  1534. } else {
  1535. if patientType == 0 {
  1536. db := readDb.
  1537. Table("xt_schedule").
  1538. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1539. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1540. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1541. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1542. }).
  1543. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1544. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1545. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1546. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1547. Where("status = 1 AND user_org_id = ?", orgID)
  1548. if scheduleDate != 0 {
  1549. db = db.Where("schedule_date = ?", scheduleDate)
  1550. }
  1551. err = db.Find(&vms).Error
  1552. }
  1553. if patientType > 0 {
  1554. db := readDb.
  1555. Table("xt_schedule").
  1556. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1557. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1558. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1559. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1560. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1561. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1562. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1563. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1564. Where("status = 1 AND user_org_id = ?", orgID)
  1565. if scheduleDate != 0 {
  1566. db = db.Where("schedule_date = ?", scheduleDate)
  1567. }
  1568. err = db.Find(&vms).Error
  1569. }
  1570. }
  1571. return vms, err
  1572. }
  1573. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1574. var vms []*HisMScheduleDoctorAdviceVMOne
  1575. if len(deliverWay) > 0 {
  1576. if patientType == 0 {
  1577. db := readDb.
  1578. Table("xt_schedule").
  1579. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1580. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1581. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1582. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1583. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1584. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1585. }).
  1586. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1587. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1588. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1589. Where("status = 1 AND user_org_id = ?", orgID)
  1590. if scheduleDate != 0 {
  1591. db = db.Where("schedule_date = ?", scheduleDate)
  1592. }
  1593. err = db.Find(&vms).Error
  1594. }
  1595. if patientType > 0 {
  1596. if patientType == 1 {
  1597. db := readDb.
  1598. Table("xt_schedule").
  1599. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1600. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1601. 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).
  1602. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1603. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1604. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1605. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1606. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1607. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1608. Where("status = 1 AND user_org_id = ?", orgID)
  1609. if scheduleDate != 0 {
  1610. db = db.Where("schedule_date = ?", scheduleDate)
  1611. }
  1612. err = db.Find(&vms).Error
  1613. }
  1614. if patientType == 2 {
  1615. db := readDb.
  1616. Table("xt_schedule").
  1617. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1618. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1619. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?)", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1620. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1621. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1622. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1623. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1624. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1625. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1626. if scheduleDate != 0 {
  1627. db = db.Where("schedule_date = ?", scheduleDate)
  1628. }
  1629. err = db.Find(&vms).Error
  1630. }
  1631. if patientType == 3 {
  1632. db := readDb.
  1633. Table("xt_schedule").
  1634. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1635. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1636. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) and is_settle = 1", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1637. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1638. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1639. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1640. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1641. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1642. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1643. if scheduleDate != 0 {
  1644. db = db.Where("schedule_date = ?", scheduleDate)
  1645. }
  1646. err = db.Find(&vms).Error
  1647. }
  1648. if patientType == 4 {
  1649. db := readDb.
  1650. Table("xt_schedule").
  1651. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1652. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1653. 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).
  1654. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1655. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1656. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1657. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1658. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1659. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1660. if scheduleDate != 0 {
  1661. db = db.Where("schedule_date = ?", scheduleDate)
  1662. }
  1663. err = db.Find(&vms).Error
  1664. }
  1665. }
  1666. } else {
  1667. if patientType == 0 {
  1668. db := readDb.
  1669. Table("xt_schedule").
  1670. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1671. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1672. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1673. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1674. }).
  1675. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1676. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1677. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1678. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1679. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1680. Where("status = 1 AND user_org_id = ?", orgID)
  1681. if scheduleDate != 0 {
  1682. db = db.Where("schedule_date = ?", scheduleDate)
  1683. }
  1684. err = db.Find(&vms).Error
  1685. }
  1686. if patientType > 0 {
  1687. if patientType == 1 {
  1688. db := readDb.
  1689. Table("xt_schedule").
  1690. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1691. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1692. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1693. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1694. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1695. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1696. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1697. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1698. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1699. Where("status = 1 AND user_org_id = ?", orgID)
  1700. if scheduleDate != 0 {
  1701. db = db.Where("schedule_date = ?", scheduleDate)
  1702. }
  1703. err = db.Find(&vms).Error
  1704. }
  1705. if patientType == 2 {
  1706. db := readDb.
  1707. Table("xt_schedule").
  1708. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1709. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1710. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1711. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1712. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1713. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1714. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1715. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1716. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1717. Where("status = 1 AND user_org_id = ?", orgID)
  1718. if scheduleDate != 0 {
  1719. db = db.Where("schedule_date = ?", scheduleDate)
  1720. }
  1721. err = db.Find(&vms).Error
  1722. }
  1723. if patientType == 3 {
  1724. db := readDb.
  1725. Table("xt_schedule").
  1726. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1727. 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).
  1728. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1729. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1730. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1731. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1732. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1733. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1734. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1735. Where("status = 1 AND user_org_id = ?", orgID)
  1736. if scheduleDate != 0 {
  1737. db = db.Where("schedule_date = ?", scheduleDate)
  1738. }
  1739. err = db.Find(&vms).Error
  1740. }
  1741. if patientType == 4 {
  1742. db := readDb.
  1743. Table("xt_schedule").
  1744. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1745. 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).
  1746. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1747. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1748. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1749. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1750. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1751. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1752. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1753. Where("status = 1 AND user_org_id = ?", orgID)
  1754. if scheduleDate != 0 {
  1755. db = db.Where("schedule_date = ?", scheduleDate)
  1756. }
  1757. err = db.Find(&vms).Error
  1758. }
  1759. }
  1760. }
  1761. return vms, err
  1762. }
  1763. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1764. var vms []*HisMScheduleProjectVM
  1765. //if patientType == 0 {
  1766. // db := readDb.
  1767. // Table("xt_schedule").
  1768. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1769. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1770. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1771. // }).
  1772. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1773. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1774. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1775. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1776. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1777. // }).
  1778. // Where("status = 1 AND user_org_id = ?", orgID)
  1779. // if scheduleDate != 0 {
  1780. // db = db.Where("schedule_date = ?", scheduleDate)
  1781. // }
  1782. // err = db.Find(&vms).Error
  1783. //}
  1784. //if patientType > 0 {
  1785. // db := readDb.
  1786. // Table("xt_schedule").
  1787. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1788. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1789. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1790. // }).
  1791. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1792. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1793. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1794. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1795. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1796. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1797. // }).
  1798. // Where("status = 1 AND user_org_id = ?", orgID)
  1799. // if scheduleDate != 0 {
  1800. // db = db.Where("schedule_date = ?", scheduleDate)
  1801. // }
  1802. // err = db.Find(&vms).Error
  1803. //}
  1804. db := readDb.Table("xt_schedule").Where("status = 1")
  1805. if orgID > 0 {
  1806. db = db.Where("user_org_id = ?", orgID)
  1807. }
  1808. if scheduleDate > 0 {
  1809. db = db.Where("schedule_date =?", scheduleDate)
  1810. }
  1811. err = db.Find(&vms).Error
  1812. if patientType == 0 {
  1813. db := readDb.
  1814. Table("xt_schedule").
  1815. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1816. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1817. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1818. }).
  1819. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1820. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1821. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1822. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1823. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1824. }).
  1825. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1826. 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")
  1827. }).
  1828. Where("status = 1 AND user_org_id = ?", orgID)
  1829. if scheduleDate != 0 {
  1830. db = db.Where("schedule_date = ?", scheduleDate)
  1831. }
  1832. err = db.Find(&vms).Error
  1833. }
  1834. if patientType > 0 {
  1835. db := readDb.
  1836. Table("xt_schedule").
  1837. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1838. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1839. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1840. }).
  1841. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1842. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1843. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1844. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1845. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1846. }).
  1847. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1848. 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")
  1849. }).
  1850. Where("status = 1 AND user_org_id = ?", orgID)
  1851. if scheduleDate != 0 {
  1852. db = db.Where("schedule_date = ?", scheduleDate)
  1853. }
  1854. err = db.Find(&vms).Error
  1855. }
  1856. return vms, err
  1857. }
  1858. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1859. now := time.Now()
  1860. tx := writeDb.Begin()
  1861. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1862. tx.Rollback()
  1863. return createOrderErr
  1864. }
  1865. // 更新透析记录 ID
  1866. // 透析处方
  1867. 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 {
  1868. tx.Rollback()
  1869. return err
  1870. }
  1871. // 接诊评估
  1872. 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 {
  1873. tx.Rollback()
  1874. return err
  1875. }
  1876. // 透前评估
  1877. 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 {
  1878. tx.Rollback()
  1879. return err
  1880. }
  1881. // 临时医嘱
  1882. 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 {
  1883. tx.Rollback()
  1884. return err
  1885. }
  1886. // 双人核对
  1887. 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 {
  1888. tx.Rollback()
  1889. return err
  1890. }
  1891. // 透后评估
  1892. 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 {
  1893. tx.Rollback()
  1894. return err
  1895. }
  1896. // 治疗小结
  1897. 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 {
  1898. tx.Rollback()
  1899. return err
  1900. }
  1901. // 透析监测
  1902. 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 {
  1903. tx.Rollback()
  1904. return err
  1905. }
  1906. tx.Commit()
  1907. return nil
  1908. }
  1909. type MobileUrgentSchedulePatientVM struct {
  1910. ID int64 `gorm:"column:id" json:"id"`
  1911. Name string `gorm:"column:name" json:"name"`
  1912. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1913. }
  1914. func (MobileUrgentSchedulePatientVM) TableName() string {
  1915. return "xt_patients"
  1916. }
  1917. type MobileUrgentScheduleTreatmentModeVM struct {
  1918. ID int64 `gorm:"column:id" json:"id"`
  1919. Name string `gorm:"column:name" json:"name"`
  1920. }
  1921. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1922. return "xt_treatment_mode"
  1923. }
  1924. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1925. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1926. 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()
  1927. defer rows.Close()
  1928. if err != nil {
  1929. return nil, err
  1930. }
  1931. for rows.Next() {
  1932. var vm MobileUrgentSchedulePatientVM
  1933. readDb.ScanRows(rows, &vm)
  1934. vms = append(vms, &vm)
  1935. }
  1936. return vms, nil
  1937. }
  1938. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1939. var modes []*MobileUrgentScheduleTreatmentModeVM
  1940. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1941. if err != nil {
  1942. return nil, err
  1943. }
  1944. return modes, nil
  1945. }
  1946. type MobileUrgentScheduleScheduleListVM struct {
  1947. ID int64 `gorm:"column:id" json:"id"`
  1948. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1949. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1950. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1951. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1952. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1953. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1954. }
  1955. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1956. return "xt_schedule"
  1957. }
  1958. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1959. db := readDb.
  1960. Model(&MobileUrgentScheduleScheduleListVM{}).
  1961. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1962. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1963. err = db.Find(&schedules).Error
  1964. if err != nil {
  1965. return nil, err
  1966. }
  1967. return schedules, nil
  1968. }
  1969. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1970. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1971. 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()
  1972. defer rows.Close()
  1973. if err != nil {
  1974. return nil, err
  1975. }
  1976. for rows.Next() {
  1977. var vm MobileUrgentScheduleScheduleListVM
  1978. readDb.ScanRows(rows, &vm)
  1979. vms = append(vms, &vm)
  1980. }
  1981. return vms, nil
  1982. }
  1983. type MobileUrgentScheduleDeviceNumberVM struct {
  1984. ID int64 `gorm:"column:id" json:"id"`
  1985. Number string `gorm:"column:number" json:"number"`
  1986. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1987. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1988. }
  1989. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1990. return "xt_device_number"
  1991. }
  1992. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1993. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1994. 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()
  1995. defer rows.Close()
  1996. if err != nil {
  1997. return nil, err
  1998. }
  1999. for rows.Next() {
  2000. var vm DeviceNumberViewModel
  2001. readDb.ScanRows(rows, &vm)
  2002. vms = append(vms, &vm)
  2003. }
  2004. return vms, nil
  2005. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2006. //db := readDb.
  2007. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2008. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2009. // Where("status = 1 AND org_id = ?", orgID)
  2010. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2011. //if err != nil {
  2012. // return nil, err
  2013. //}
  2014. //return deviceNumbers, nil
  2015. }
  2016. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2017. var total int64
  2018. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2019. return total, err
  2020. }
  2021. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2022. var monitors []*models.MonitoringRecord
  2023. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2024. if err != nil {
  2025. return nil, err
  2026. }
  2027. return monitors, nil
  2028. }
  2029. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2030. tx := writeDb.Begin()
  2031. for index := 0; index < len(monitors); index++ {
  2032. tx.Save(monitors[index])
  2033. }
  2034. return tx.Commit().Error
  2035. }
  2036. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2037. tx := writeDb.Begin()
  2038. updateTime := time.Now().Unix()
  2039. 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}).Error
  2040. if err != nil {
  2041. tx.Rollback()
  2042. return err
  2043. }
  2044. tx.Commit()
  2045. return err
  2046. }
  2047. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2048. 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
  2049. return err
  2050. }
  2051. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2052. tx := writeDb.Begin()
  2053. updateTime := time.Now().Unix()
  2054. 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
  2055. if err != nil {
  2056. tx.Rollback()
  2057. return err
  2058. }
  2059. tx.Commit()
  2060. return err
  2061. }
  2062. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2063. var record models.SgjPatientDryweight
  2064. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2065. if err != nil {
  2066. if err == gorm.ErrRecordNotFound {
  2067. return nil, nil
  2068. } else {
  2069. return nil, err
  2070. }
  2071. }
  2072. return &record, nil
  2073. }
  2074. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2075. // var record models.SgjPatientDryweight
  2076. // redis := RedisClient()
  2077. // defer redis.Close()
  2078. //
  2079. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2080. // last_dry_weight_str, _ := redis.Get(key).Result()
  2081. //
  2082. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2083. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2084. // if err != nil {
  2085. // if err == gorm.ErrRecordNotFound {
  2086. // if record.ID <= 0 {
  2087. // redis.Set(key, "null", time.Second*60*60*18)
  2088. // }
  2089. // return nil, nil
  2090. // } else {
  2091. // return nil, err
  2092. // }
  2093. // } else {
  2094. // if record.ID > 0 {
  2095. // //缓存数据
  2096. // last_dry_weight_str, err := json.Marshal(record)
  2097. // if err == nil {
  2098. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2099. // return nil, err
  2100. // }
  2101. // } else {
  2102. // redis.Set(key, "null", time.Second*60*60*18)
  2103. // return nil, err
  2104. // }
  2105. // return &record, nil
  2106. // }
  2107. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2108. // if last_dry_weight_str == "null" {
  2109. // return &record, nil
  2110. // } else {
  2111. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2112. // return &record, nil
  2113. // }
  2114. //
  2115. // }
  2116. //}
  2117. // 透析方案
  2118. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2119. var record models.DialysisSolution
  2120. 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
  2121. if err != nil {
  2122. if err == gorm.ErrRecordNotFound {
  2123. return nil, nil
  2124. } else {
  2125. return nil, err
  2126. }
  2127. }
  2128. return &record, nil
  2129. }
  2130. // 透析方案
  2131. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2132. var record models.DialysisSolution
  2133. 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
  2134. return record, nil
  2135. }
  2136. // 透析方案
  2137. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2138. var record models.DialysisSolution
  2139. redis := RedisClient()
  2140. defer redis.Close()
  2141. // cur_date := time.Now().Format("2006-01-02")
  2142. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2143. dialysis_solution_str, _ := redis.Get(key).Result()
  2144. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2145. 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
  2146. if err != nil {
  2147. if err == gorm.ErrRecordNotFound {
  2148. if record.ID <= 0 {
  2149. redis.Set(key, "null", time.Second*60*60*18)
  2150. }
  2151. return nil, nil
  2152. } else {
  2153. return nil, err
  2154. }
  2155. } else {
  2156. if record.ID > 0 {
  2157. //缓存数据
  2158. dialysis_solution_str, err := json.Marshal(record)
  2159. if err == nil {
  2160. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2161. }
  2162. } else {
  2163. redis.Set(key, "null", time.Second*60*60*18)
  2164. }
  2165. return &record, nil
  2166. }
  2167. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2168. if dialysis_solution_str == "null" {
  2169. return &record, nil
  2170. } else {
  2171. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2172. return &record, nil
  2173. }
  2174. }
  2175. }
  2176. // 透析处方
  2177. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2178. var record models.DialysisPrescription
  2179. redis := RedisClient()
  2180. defer redis.Close()
  2181. // cur_date := time.Now().Format("2006-01-02")
  2182. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2183. redis.Set(key, "", time.Second)
  2184. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2185. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2186. 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
  2187. if err != nil {
  2188. if err == gorm.ErrRecordNotFound {
  2189. if record.ID <= 0 {
  2190. redis.Set(key, "null", time.Second*60*60*18)
  2191. }
  2192. return nil, nil
  2193. } else {
  2194. return nil, err
  2195. }
  2196. } else {
  2197. if record.ID > 0 {
  2198. //缓存数据
  2199. dialysis_prescribe_str, err := json.Marshal(record)
  2200. if err == nil {
  2201. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2202. }
  2203. } else {
  2204. redis.Set(key, "null", time.Second*60*60*18)
  2205. }
  2206. return &record, nil
  2207. }
  2208. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2209. if dialysis_prescribe_str == "null" {
  2210. return &record, nil
  2211. } else {
  2212. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2213. return &record, nil
  2214. }
  2215. }
  2216. }
  2217. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2218. var record models.DialysisPrescription
  2219. 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
  2220. if err != nil {
  2221. if err == gorm.ErrRecordNotFound {
  2222. return nil, nil
  2223. } else {
  2224. return nil, err
  2225. }
  2226. }
  2227. return &record, nil
  2228. }
  2229. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2230. var record models.DialysisPrescription
  2231. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2232. if err != nil {
  2233. if err == gorm.ErrRecordNotFound {
  2234. return nil, nil
  2235. } else {
  2236. return nil, err
  2237. }
  2238. }
  2239. return &record, nil
  2240. }
  2241. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2242. // var record models.DialysisPrescription
  2243. // redis := RedisClient()
  2244. // defer redis.Close()
  2245. //
  2246. // // cur_date := time.Now().Format("2006-01-02")
  2247. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2248. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2249. //
  2250. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2251. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2252. // if err != nil {
  2253. // if err == gorm.ErrRecordNotFound {
  2254. // if record.ID <= 0 {
  2255. // redis.Set(key, "null", time.Second*60*60*18)
  2256. // }
  2257. // return nil, nil
  2258. // } else {
  2259. // return nil, err
  2260. // }
  2261. // } else {
  2262. //
  2263. // if record.ID > 0 {
  2264. // //缓存数据
  2265. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2266. //
  2267. // if err == nil {
  2268. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2269. // return nil, err
  2270. // }
  2271. // } else {
  2272. // redis.Set(key, "null", time.Second*60*60*18)
  2273. // return nil, err
  2274. // }
  2275. // return &record, nil
  2276. // }
  2277. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2278. // if dialysis_prescribe_by_mode_str == "null" {
  2279. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2280. // return &record, nil
  2281. // } else {
  2282. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2283. // return &record, nil
  2284. // }
  2285. //
  2286. // }
  2287. //}
  2288. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2289. var record models.DialysisPrescription
  2290. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2291. if err != nil {
  2292. if err == gorm.ErrRecordNotFound {
  2293. return nil, nil
  2294. } else {
  2295. return nil, err
  2296. }
  2297. }
  2298. return &record, nil
  2299. }
  2300. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2301. var record models.DialysisPrescription
  2302. 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
  2303. //if err != nil {
  2304. // if err == gorm.ErrRecordNotFound {
  2305. // return nil, nil
  2306. // } else {
  2307. // return nil, err
  2308. // }
  2309. //}
  2310. return &record, err
  2311. }
  2312. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2313. var record models.DialysisPrescription
  2314. 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
  2315. if err != nil {
  2316. if err == gorm.ErrRecordNotFound {
  2317. return nil, nil
  2318. } else {
  2319. return nil, err
  2320. }
  2321. }
  2322. return &record, err
  2323. }
  2324. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2325. var record models.DialysisPrescription
  2326. redis := RedisClient()
  2327. defer redis.Close()
  2328. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2329. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2330. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2331. 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
  2332. if err != nil {
  2333. if err == gorm.ErrRecordNotFound {
  2334. if record.ID <= 0 {
  2335. redis.Set(key, "null", time.Second*60*60*18)
  2336. }
  2337. return nil, nil
  2338. } else {
  2339. return nil, err
  2340. }
  2341. } else {
  2342. if record.ID > 0 {
  2343. //缓存数据
  2344. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2345. if err == nil {
  2346. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2347. return nil, err
  2348. }
  2349. } else {
  2350. redis.Set(key, "null", time.Second*60*60*18)
  2351. return nil, err
  2352. }
  2353. return &record, nil
  2354. }
  2355. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2356. if dialysis_prescribe_by_mode_id == "null" {
  2357. return &record, nil
  2358. } else {
  2359. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2360. return &record, nil
  2361. }
  2362. }
  2363. }
  2364. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2365. var record models.DialysisPrescription
  2366. 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
  2367. return record, err
  2368. }
  2369. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2370. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2371. 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()
  2372. defer rows.Close()
  2373. if err != nil {
  2374. return nil, err
  2375. }
  2376. for rows.Next() {
  2377. var vm DeviceNumberViewModel
  2378. readDb.ScanRows(rows, &vm)
  2379. vms = append(vms, &vm)
  2380. }
  2381. return vms, nil
  2382. }
  2383. // 获取 maxDate 之前一次的透前评估记录
  2384. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2385. var record models.PredialysisEvaluation
  2386. 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
  2387. if err != nil {
  2388. if err == gorm.ErrRecordNotFound {
  2389. return nil, nil
  2390. } else {
  2391. return nil, err
  2392. }
  2393. }
  2394. return &record, nil
  2395. }
  2396. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2397. var record models.DialysisOrder
  2398. 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
  2399. if err != nil {
  2400. if err == gorm.ErrRecordNotFound {
  2401. return nil, nil
  2402. } else {
  2403. return nil, err
  2404. }
  2405. }
  2406. return &record, nil
  2407. }
  2408. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2409. var record models.MonitoringRecord
  2410. 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
  2411. if err != nil {
  2412. if err == gorm.ErrRecordNotFound {
  2413. return nil, nil
  2414. } else {
  2415. return nil, err
  2416. }
  2417. }
  2418. return &record, nil
  2419. }
  2420. // 获取 maxDate 之前一次的透后评估记录
  2421. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2422. var record models.AssessmentAfterDislysis
  2423. 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
  2424. if err != nil {
  2425. if err == gorm.ErrRecordNotFound {
  2426. return nil, nil
  2427. } else {
  2428. return nil, err
  2429. }
  2430. }
  2431. return &record, nil
  2432. }
  2433. // 透析处方
  2434. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2435. var record models.DialysisPrescription
  2436. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2437. if err != nil {
  2438. if err == gorm.ErrRecordNotFound {
  2439. return nil, nil
  2440. } else {
  2441. return nil, err
  2442. }
  2443. }
  2444. return &record, nil
  2445. }
  2446. // 透析方案
  2447. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2448. var record models.DialysisSolution
  2449. 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
  2450. return record, err
  2451. }
  2452. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2453. var record models.DialysisSolution
  2454. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2455. if err != nil {
  2456. if err == gorm.ErrRecordNotFound {
  2457. return nil, nil
  2458. } else {
  2459. return nil, err
  2460. }
  2461. }
  2462. return &record, nil
  2463. }
  2464. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2465. var record models.DialysisPrescription
  2466. 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
  2467. if err != nil {
  2468. if err == gorm.ErrRecordNotFound {
  2469. return nil, nil
  2470. } else {
  2471. return nil, err
  2472. }
  2473. }
  2474. return &record, nil
  2475. }
  2476. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2477. var record models.SgjPatientDryweight
  2478. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2479. if err != nil {
  2480. if err == gorm.ErrRecordNotFound {
  2481. return nil, nil
  2482. } else {
  2483. return nil, err
  2484. }
  2485. }
  2486. return &record, nil
  2487. }
  2488. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2489. var record models.SystemPrescription
  2490. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2491. if err != nil {
  2492. if err == gorm.ErrRecordNotFound {
  2493. return nil, nil
  2494. } else {
  2495. return nil, err
  2496. }
  2497. }
  2498. return &record, nil
  2499. }
  2500. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2501. var record models.SystemPrescription
  2502. redis := RedisClient()
  2503. defer redis.Close()
  2504. // cur_date := time.Now().Format("2006-01-02")
  2505. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2506. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2507. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2508. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2509. if err != nil {
  2510. if err == gorm.ErrRecordNotFound {
  2511. if record.ID <= 0 {
  2512. redis.Set(key, "null", time.Second*60*60*18)
  2513. }
  2514. return nil, nil
  2515. } else {
  2516. return nil, err
  2517. }
  2518. } else {
  2519. if record.ID > 0 {
  2520. //缓存数据
  2521. system_dialysis_prescribe_str, err := json.Marshal(record)
  2522. if err == nil {
  2523. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2524. }
  2525. } else {
  2526. redis.Set(key, "null", time.Second*60*60*18)
  2527. }
  2528. return &record, nil
  2529. }
  2530. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2531. if system_dialysis_prescribe_str == "null" {
  2532. return &record, nil
  2533. } else {
  2534. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2535. return &record, nil
  2536. }
  2537. }
  2538. }
  2539. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2540. var record models.SystemPrescription
  2541. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2542. return record, err
  2543. }
  2544. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2545. var record models.SystemPrescription
  2546. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2547. if err != nil {
  2548. if err == gorm.ErrRecordNotFound {
  2549. return nil, nil
  2550. } else {
  2551. return nil, err
  2552. }
  2553. }
  2554. return &record, nil
  2555. }
  2556. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2557. 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
  2558. return
  2559. }
  2560. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2561. 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
  2562. return
  2563. }
  2564. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2565. 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
  2566. return
  2567. }
  2568. func GetFirstDateOfMonth(d time.Time) time.Time {
  2569. d = d.AddDate(0, 0, -d.Day()+1)
  2570. return GetZeroTime(d)
  2571. }
  2572. func GetZeroTime(d time.Time) time.Time {
  2573. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2574. }
  2575. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2576. db := XTReadDB().Table("xt_dialysis_order as o")
  2577. 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
  2578. return order, err
  2579. }
  2580. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2581. 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
  2582. return
  2583. }
  2584. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2585. 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
  2586. return
  2587. }
  2588. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2589. 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
  2590. return
  2591. }
  2592. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2593. // 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
  2594. // return
  2595. //}
  2596. //
  2597. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2598. 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
  2599. return
  2600. }
  2601. type GoodsType struct {
  2602. ID int64 `gorm:"column:id" json:"id"`
  2603. TypeName string `gorm:"column:type_name" json:"type_name"`
  2604. Remark string `gorm:"column:remark" json:"remark"`
  2605. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2606. Status int64 `gorm:"column:status" json:"status"`
  2607. Type int64 `gorm:"column:type" json:"type"`
  2608. }
  2609. func (GoodsType) TableName() string {
  2610. return "xt_goods_type"
  2611. }
  2612. type VMGoodInfo struct {
  2613. ID int64 `gorm:"column:id" json:"id"`
  2614. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2615. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2616. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2617. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2618. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2619. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2620. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2621. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2622. }
  2623. func (VMGoodInfo) TableName() string {
  2624. return "xt_good_information"
  2625. }
  2626. type AutomaticReduceDetail struct {
  2627. ID int64 `gorm:"column:id" json:"id"`
  2628. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2629. Status int64 `gorm:"column:status" json:"status"`
  2630. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2631. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2632. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2633. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2634. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2635. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2636. Count int64 `gorm:"column:count" json:"count"`
  2637. }
  2638. func (AutomaticReduceDetail) TableName() string {
  2639. return "xt_automatic_reduce_detail"
  2640. }
  2641. type DialysisBeforePrepare struct {
  2642. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2643. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2644. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2645. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2646. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2647. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2648. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2649. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2650. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2651. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2652. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2653. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2654. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2655. }
  2656. func (DialysisBeforePrepare) TableName() string {
  2657. return "dialysis_before_prepare"
  2658. }
  2659. type MDialysisGoodsVM struct {
  2660. ID int64 `gorm:"column:id" json:"id"`
  2661. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2662. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2663. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2664. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2665. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2666. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2667. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2668. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2669. Status int64 `gorm:"column:status" json:"status"`
  2670. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2671. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2672. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2673. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2674. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2675. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2676. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2677. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2678. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2679. }
  2680. func (MDialysisGoodsVM) TableName() string {
  2681. return "xt_schedule"
  2682. }
  2683. type VMWarehouseOutInfo struct {
  2684. ID int64 `gorm:"column:id" json:"id"`
  2685. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2686. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2687. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2688. Count int64 `gorm:"column:count" json:"count"`
  2689. Price float64 `gorm:"column:price" json:"price"`
  2690. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2691. Status int64 `gorm:"column:status" json:"status"`
  2692. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2693. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2694. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2695. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2696. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2697. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2698. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2699. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2700. }
  2701. func (VMWarehouseOutInfo) TableName() string {
  2702. return "xt_warehouse_out_info"
  2703. }
  2704. type DialysisGoodsDate struct {
  2705. RecordDate int64
  2706. }
  2707. type DialysisGoodsDetailDate struct {
  2708. RecordTime int64
  2709. }
  2710. 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) {
  2711. var vms []*MDialysisGoodsVM
  2712. var total int64
  2713. db := readDb.
  2714. Table("xt_schedule as sch").
  2715. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2716. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2717. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2718. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2719. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2720. 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)
  2721. }).
  2722. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2723. 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")
  2724. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2725. if scheduleDate != 0 {
  2726. db = db.Where("schedule_date = ?", scheduleDate)
  2727. }
  2728. if schedule_type != 0 {
  2729. db = db.Where("schedule_type = ?", schedule_type)
  2730. }
  2731. if partition_id != 0 {
  2732. db = db.Where("partition_id = ?", partition_id)
  2733. }
  2734. if patient_id != 0 {
  2735. db = db.Where("patient_id = ?", patient_id)
  2736. }
  2737. err := db.Find(&vms).Error
  2738. return vms, err, total
  2739. }
  2740. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2741. var Id []*DialysisGoodsDetailDate
  2742. 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
  2743. if len(Id) > 0 {
  2744. 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
  2745. }
  2746. return
  2747. }
  2748. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2749. var Id []*DialysisGoodsDate
  2750. 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
  2751. if len(Id) > 0 {
  2752. 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
  2753. }
  2754. return
  2755. }
  2756. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2757. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2758. return info, err
  2759. }
  2760. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2761. db := readDb.Model(&models.StockInfo{})
  2762. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2763. 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")
  2764. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2765. 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)
  2766. })
  2767. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2768. err = db.Order("ctime desc").Find(&list).Error
  2769. return
  2770. }
  2771. 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) {
  2772. var vms []*MDialysisGoodsVM
  2773. var total int64
  2774. db := readDb.
  2775. Model(&models.Schedule{}).
  2776. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2777. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2778. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2779. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2780. 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)
  2781. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2782. 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)
  2783. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2784. if scheduleDate != 0 {
  2785. db = db.Where("schedule_date = ?", scheduleDate)
  2786. }
  2787. if patient_id != 0 {
  2788. db = db.Where("patient_id = ?", patient_id)
  2789. }
  2790. if len(keywords) != 0 {
  2791. keywords = "%" + keywords + "%"
  2792. 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)
  2793. if schedule_type != 0 {
  2794. db = db.Where("schedule_type = ?", schedule_type)
  2795. }
  2796. if partition_id != 0 {
  2797. db = db.Where("partition_id = ?", partition_id)
  2798. }
  2799. if good_type == 1 {
  2800. db = db.Where("patient_id in(?)", ids)
  2801. }
  2802. if good_type == 2 {
  2803. if len(ids) > 0 {
  2804. db = db.Where("patient_id not in(?)", ids)
  2805. }
  2806. }
  2807. } else {
  2808. if schedule_type != 0 {
  2809. db = db.Where("schedule_type = ?", schedule_type)
  2810. }
  2811. if partition_id != 0 {
  2812. db = db.Where("partition_id = ?", partition_id)
  2813. }
  2814. if good_type == 1 {
  2815. db = db.Where("patient_id in(?)", ids)
  2816. }
  2817. if good_type == 2 {
  2818. if len(ids) > 0 {
  2819. db = db.Where("patient_id not in(?)", ids)
  2820. }
  2821. }
  2822. db = db.Count(&total)
  2823. offset := (page - 1) * limit
  2824. db = db.Offset(offset).Limit(limit)
  2825. }
  2826. err := db.Find(&vms).Error
  2827. return vms, err, total
  2828. }
  2829. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2830. var Id []*DialysisGoodsDetailDate
  2831. 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
  2832. if len(Id) > 0 {
  2833. 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
  2834. }
  2835. return
  2836. }
  2837. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2838. var Id []*DialysisGoodsDate
  2839. 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
  2840. if len(Id) > 0 {
  2841. 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
  2842. }
  2843. return
  2844. }
  2845. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2846. evaluation := models.PredialysisEvaluation{}
  2847. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2848. if err == gorm.ErrRecordNotFound {
  2849. return nil, err
  2850. }
  2851. if err != nil {
  2852. return nil, err
  2853. }
  2854. return &evaluation, nil
  2855. }
  2856. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2857. evaluation := models.PredialysisEvaluation{}
  2858. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2859. return evaluation, err
  2860. }
  2861. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2862. evaluation := models.XtAssessmentBeforeDislysis{}
  2863. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2864. return evaluation, err
  2865. }
  2866. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2867. redis := RedisClient()
  2868. defer redis.Close()
  2869. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2870. his_doctor_advice_str, _ := redis.Get(key).Result()
  2871. redis.Set(key, "", time.Second)
  2872. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2873. 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
  2874. if err != nil {
  2875. if err == gorm.ErrRecordNotFound {
  2876. if len(his) <= 0 {
  2877. redis.Set(key, "null", time.Second*60*60*18)
  2878. }
  2879. return his, nil
  2880. } else {
  2881. return his, err
  2882. }
  2883. } else {
  2884. if len(his) > 0 {
  2885. //缓存数据
  2886. his_doctor_advice_str, err := json.Marshal(his)
  2887. if err == nil {
  2888. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2889. }
  2890. } else {
  2891. redis.Set(key, "null", time.Second*60*60*18)
  2892. }
  2893. return his, nil
  2894. }
  2895. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2896. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2897. return his, nil
  2898. }
  2899. }
  2900. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2901. prescription := models.DialysisPrescription{}
  2902. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2903. if err == gorm.ErrRecordNotFound {
  2904. return nil, err
  2905. }
  2906. if err != nil {
  2907. return nil, err
  2908. }
  2909. return &prescription, nil
  2910. }
  2911. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2912. prescription := models.DialysisPrescription{}
  2913. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2914. return prescription, err
  2915. }
  2916. type HisMScheduleDoctorAdviceVM struct {
  2917. ID int64 `gorm:"column:id" json:"id"`
  2918. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2919. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2920. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2921. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2922. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2923. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2924. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2925. Status int64 `gorm:"column:status" json:"status"`
  2926. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2927. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2928. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2929. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2930. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2931. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2932. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2933. }
  2934. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2935. return "xt_schedule"
  2936. }
  2937. type HisMScheduleDoctorAdviceVMOne struct {
  2938. ID int64 `gorm:"column:id" json:"id"`
  2939. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2940. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2941. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2942. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2943. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2944. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2945. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2946. Status int64 `gorm:"column:status" json:"status"`
  2947. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2948. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2949. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2950. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2951. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2952. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2953. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2954. }
  2955. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2956. return "xt_schedule"
  2957. }
  2958. type HisMScheduleProjectVM struct {
  2959. ID int64 `gorm:"column:id" json:"id"`
  2960. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2961. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2962. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2963. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2964. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2965. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2966. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2967. Status int64 `gorm:"column:status" json:"status"`
  2968. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2969. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2970. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2971. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2972. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2973. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2974. }
  2975. func (HisMScheduleProjectVM) TableName() string {
  2976. return "xt_schedule"
  2977. }
  2978. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2979. config := models.XtHisConfig{}
  2980. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2981. return config, err
  2982. }
  2983. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2984. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2985. if orgid > 0 {
  2986. db = db.Where("x.user_org_id = ?", orgid)
  2987. }
  2988. if patientid > 0 {
  2989. db = db.Where("x.patient_id =?", patientid)
  2990. }
  2991. if recordtime > 0 {
  2992. db = db.Where("x.advice_date = ?", recordtime)
  2993. }
  2994. 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
  2995. return advice, err
  2996. }
  2997. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2998. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2999. if startime > 0 {
  3000. db = db.Where("x.advice_date >= ?", startime)
  3001. }
  3002. if endtime > 0 {
  3003. db = db.Where("x.advice_date<=?", endtime)
  3004. }
  3005. if orgid > 0 {
  3006. db = db.Where("x.user_org_id = ?", orgid)
  3007. }
  3008. if len(deliveway) > 0 {
  3009. db = db.Where("x.delivery_way = ?", deliveway)
  3010. }
  3011. 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
  3012. return advice, err
  3013. }
  3014. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3015. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3016. if startime > 0 {
  3017. db = db.Where("x.advice_date >= ?", startime)
  3018. }
  3019. if endtime > 0 {
  3020. db = db.Where("x.advice_date<=?", endtime)
  3021. }
  3022. if orgid > 0 {
  3023. db = db.Where("x.user_org_id = ?", orgid)
  3024. }
  3025. if len(deliveway) > 0 {
  3026. db = db.Where("x.delivery_way = ?", deliveway)
  3027. }
  3028. 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
  3029. return advice, err
  3030. }
  3031. 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) {
  3032. var vms []*MScheduleDoctorAdviceVM
  3033. adviceWhere := ""
  3034. adviceCondition := []interface{}{}
  3035. if adviceType == 0 {
  3036. if patientType == 0 {
  3037. if patient_id > 0 {
  3038. if execution_state > 0 {
  3039. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3041. } else {
  3042. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3044. }
  3045. } else {
  3046. if execution_state > 0 {
  3047. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3049. } else {
  3050. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3052. }
  3053. }
  3054. } else if patientType == 1 {
  3055. if patient_id > 0 {
  3056. if execution_state > 0 {
  3057. 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= ?"
  3058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3059. } else {
  3060. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3062. }
  3063. } else {
  3064. if execution_state > 0 {
  3065. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3067. } else {
  3068. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3070. }
  3071. }
  3072. } else if patientType == 2 {
  3073. if patient_id > 0 {
  3074. if execution_state > 0 {
  3075. 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 = ?"
  3076. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3077. } else {
  3078. 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 = ?)"
  3079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3080. }
  3081. } else {
  3082. if execution_state > 0 {
  3083. 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 = ?"
  3084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3085. } else {
  3086. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3088. }
  3089. }
  3090. }
  3091. } else if adviceType == 1 {
  3092. if patientType == 0 {
  3093. if patient_id > 0 {
  3094. if execution_state > 0 {
  3095. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3097. } else {
  3098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3100. }
  3101. } else {
  3102. if execution_state > 0 {
  3103. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3105. } else {
  3106. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3108. }
  3109. }
  3110. } else if patientType == 1 {
  3111. if patient_id > 0 {
  3112. if execution_state > 0 {
  3113. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3115. } else {
  3116. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3117. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3118. }
  3119. } else {
  3120. if execution_state > 0 {
  3121. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3123. } else {
  3124. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3125. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3126. }
  3127. }
  3128. } else if patientType == 2 {
  3129. if patient_id > 0 {
  3130. if execution_state > 0 {
  3131. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3133. } else {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3136. }
  3137. } else {
  3138. if execution_state > 0 {
  3139. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3140. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3141. } else {
  3142. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3144. }
  3145. }
  3146. }
  3147. } else if adviceType == 3 {
  3148. if patientType == 0 {
  3149. if patient_id > 0 {
  3150. if execution_state > 0 {
  3151. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3153. } else {
  3154. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3156. }
  3157. } else {
  3158. if execution_state > 0 {
  3159. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3161. } else {
  3162. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3164. }
  3165. }
  3166. } else if patientType == 1 {
  3167. if patient_id > 0 {
  3168. if execution_state > 0 {
  3169. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3171. } else {
  3172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3174. }
  3175. } else {
  3176. if execution_state > 0 {
  3177. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3179. } else {
  3180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3182. }
  3183. }
  3184. } else if patientType == 2 {
  3185. if patient_id > 0 {
  3186. if execution_state > 0 {
  3187. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3188. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3189. } else {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3192. }
  3193. } else {
  3194. if execution_state > 0 {
  3195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3197. } else {
  3198. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3200. }
  3201. }
  3202. }
  3203. } else if adviceType == 2 && len(deliverWay) > 0 {
  3204. if patientType == 0 {
  3205. if patient_id > 0 {
  3206. if execution_state > 0 {
  3207. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3209. } else {
  3210. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3212. }
  3213. } else {
  3214. if execution_state > 0 {
  3215. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3217. } else {
  3218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3220. }
  3221. }
  3222. } else if patientType == 1 {
  3223. if patient_id > 0 {
  3224. if execution_state > 0 {
  3225. 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 = ?"
  3226. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3227. } else {
  3228. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3230. }
  3231. } else {
  3232. if execution_state > 0 {
  3233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3235. } else {
  3236. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3238. }
  3239. }
  3240. } else if patientType == 2 {
  3241. if patient_id > 0 {
  3242. if execution_state > 0 {
  3243. 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 = ?"
  3244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3245. } else {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3248. }
  3249. } else {
  3250. if execution_state > 0 {
  3251. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3253. } else {
  3254. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3256. }
  3257. }
  3258. }
  3259. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3260. if patientType == 0 {
  3261. if patient_id > 0 {
  3262. if execution_state > 0 {
  3263. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3265. } else {
  3266. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3268. }
  3269. } else {
  3270. if execution_state > 0 {
  3271. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3273. } else {
  3274. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3276. }
  3277. }
  3278. } else if patientType == 1 {
  3279. if patient_id > 0 {
  3280. if execution_state > 0 {
  3281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3283. } else {
  3284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3286. }
  3287. } else {
  3288. if execution_state > 0 {
  3289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3291. } else {
  3292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3294. }
  3295. }
  3296. } else if patientType == 2 {
  3297. if patient_id > 0 {
  3298. if execution_state > 0 {
  3299. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3301. } else {
  3302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3304. }
  3305. } else {
  3306. if execution_state > 0 {
  3307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3309. } else {
  3310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3312. }
  3313. }
  3314. }
  3315. }
  3316. db := readDb.Table("xt_schedule")
  3317. if scheduleType > 0 {
  3318. db = db.Where("schedule_type = ?", scheduleType)
  3319. }
  3320. if partitonType > 0 {
  3321. db = db.Where("partition_id = ?", partitonType)
  3322. }
  3323. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3324. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3325. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3326. }).
  3327. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3328. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3329. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3330. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3331. Preload("DoctorAdvices", adviceCondition...).
  3332. Where("status = 1 AND user_org_id = ?", orgID)
  3333. if scheduleDate != 0 {
  3334. db = db.Where("schedule_date = ?", scheduleDate)
  3335. }
  3336. err := db.Find(&vms).Error
  3337. return vms, err
  3338. }
  3339. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3340. var vms []*HisMScheduleDoctorAdviceVM
  3341. if len(deliverWay) > 0 {
  3342. db := readDb.Table("xt_schedule")
  3343. if scheduleType > 0 {
  3344. db = db.Where("schedule_type = ?", scheduleType)
  3345. }
  3346. if partitionType > 0 {
  3347. db = db.Where("partition_id = ?", partitionType)
  3348. }
  3349. if patient_id > 0 {
  3350. if execution_state > 0 {
  3351. if cost_type > 0 {
  3352. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3353. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3354. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3355. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3356. 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).
  3357. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3358. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3359. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3360. Where("status = 1 AND user_org_id = ?", orgID)
  3361. if scheduleDate != 0 {
  3362. db = db.Where("schedule_date = ?", scheduleDate)
  3363. }
  3364. err = db.Find(&vms).Error
  3365. } else {
  3366. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  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 = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3370. 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).
  3371. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3372. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3373. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3374. Where("status = 1 AND user_org_id = ?", orgID)
  3375. if scheduleDate != 0 {
  3376. db = db.Where("schedule_date = ?", scheduleDate)
  3377. }
  3378. err = db.Find(&vms).Error
  3379. }
  3380. } else {
  3381. if cost_type > 0 {
  3382. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3383. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3384. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3385. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3386. 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).
  3387. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3388. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3389. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3390. Where("status = 1 AND user_org_id = ?", orgID)
  3391. if scheduleDate != 0 {
  3392. db = db.Where("schedule_date = ?", scheduleDate)
  3393. }
  3394. err = db.Find(&vms).Error
  3395. } else {
  3396. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3397. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3398. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3399. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3400. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3401. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3402. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3403. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3404. Where("status = 1 AND user_org_id = ?", orgID)
  3405. if scheduleDate != 0 {
  3406. db = db.Where("schedule_date = ?", scheduleDate)
  3407. }
  3408. err = db.Find(&vms).Error
  3409. }
  3410. }
  3411. } else {
  3412. if execution_state > 0 {
  3413. if cost_type > 0 {
  3414. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3415. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3416. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3417. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3418. 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).
  3419. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3420. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3421. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3422. Where("status = 1 AND user_org_id = ?", orgID)
  3423. if scheduleDate != 0 {
  3424. db = db.Where("schedule_date = ?", scheduleDate)
  3425. }
  3426. err = db.Find(&vms).Error
  3427. } else {
  3428. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3429. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3430. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3431. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3432. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3433. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3434. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3435. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3436. Where("status = 1 AND user_org_id = ?", orgID)
  3437. if scheduleDate != 0 {
  3438. db = db.Where("schedule_date = ?", scheduleDate)
  3439. }
  3440. err = db.Find(&vms).Error
  3441. }
  3442. } else {
  3443. if cost_type > 0 {
  3444. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3445. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3446. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3447. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3448. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3449. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3450. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3451. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3452. Where("status = 1 AND user_org_id = ?", orgID)
  3453. if scheduleDate != 0 {
  3454. db = db.Where("schedule_date = ?", scheduleDate)
  3455. }
  3456. err = db.Find(&vms).Error
  3457. } else {
  3458. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3459. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3460. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3461. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3462. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3463. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3464. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3465. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3466. Where("status = 1 AND user_org_id = ?", orgID)
  3467. if scheduleDate != 0 {
  3468. db = db.Where("schedule_date = ?", scheduleDate)
  3469. }
  3470. err = db.Find(&vms).Error
  3471. }
  3472. }
  3473. }
  3474. } else {
  3475. db := readDb.Table("xt_schedule")
  3476. if scheduleType > 0 {
  3477. db = db.Where("schedule_type = ?", scheduleType)
  3478. }
  3479. if partitionType > 0 {
  3480. db = db.Where("partition_id = ?", partitionType)
  3481. }
  3482. if patient_id > 0 {
  3483. if execution_state > 0 {
  3484. if cost_type > 0 {
  3485. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3486. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3487. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3488. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3489. 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).
  3490. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3491. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3492. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3493. Where("status = 1 AND user_org_id = ?", orgID)
  3494. if scheduleDate != 0 {
  3495. db = db.Where("schedule_date = ?", scheduleDate)
  3496. }
  3497. err = db.Find(&vms).Error
  3498. } else {
  3499. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3500. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3501. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3502. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3503. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3504. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3505. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3506. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3507. Where("status = 1 AND user_org_id = ?", orgID)
  3508. if scheduleDate != 0 {
  3509. db = db.Where("schedule_date = ?", scheduleDate)
  3510. }
  3511. err = db.Find(&vms).Error
  3512. }
  3513. } else {
  3514. if cost_type > 0 {
  3515. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3516. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3517. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3518. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3519. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3520. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3521. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3522. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3523. Where("status = 1 AND user_org_id = ?", orgID)
  3524. if scheduleDate != 0 {
  3525. db = db.Where("schedule_date = ?", scheduleDate)
  3526. }
  3527. err = db.Find(&vms).Error
  3528. } else {
  3529. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3530. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3532. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3533. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3534. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3535. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3536. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3537. Where("status = 1 AND user_org_id = ?", orgID)
  3538. if scheduleDate != 0 {
  3539. db = db.Where("schedule_date = ?", scheduleDate)
  3540. }
  3541. err = db.Find(&vms).Error
  3542. }
  3543. }
  3544. } else {
  3545. if execution_state > 0 {
  3546. if cost_type > 0 {
  3547. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3548. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3549. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3550. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3551. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3552. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3553. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3554. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3555. Where("status = 1 AND user_org_id = ?", orgID)
  3556. if scheduleDate != 0 {
  3557. db = db.Where("schedule_date = ?", scheduleDate)
  3558. }
  3559. err = db.Find(&vms).Error
  3560. } else {
  3561. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3562. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3563. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3564. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3565. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3566. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3567. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3568. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3569. Where("status = 1 AND user_org_id = ?", orgID)
  3570. if scheduleDate != 0 {
  3571. db = db.Where("schedule_date = ?", scheduleDate)
  3572. }
  3573. err = db.Find(&vms).Error
  3574. }
  3575. } else {
  3576. if cost_type > 0 {
  3577. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3578. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3579. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3580. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3581. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3582. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3583. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3584. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3585. Where("status = 1 AND user_org_id = ?", orgID)
  3586. if scheduleDate != 0 {
  3587. db = db.Where("schedule_date = ?", scheduleDate)
  3588. }
  3589. err = db.Find(&vms).Error
  3590. } else {
  3591. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3592. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3593. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3594. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3595. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3596. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3597. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3598. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3599. Where("status = 1 AND user_org_id = ?", orgID)
  3600. if scheduleDate != 0 {
  3601. db = db.Where("schedule_date = ?", scheduleDate)
  3602. }
  3603. err = db.Find(&vms).Error
  3604. }
  3605. }
  3606. }
  3607. }
  3608. return vms, err
  3609. }
  3610. func BatchDeleteMonitor(ids []string) (err error) {
  3611. if len(ids) == 1 {
  3612. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3613. } else {
  3614. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3615. }
  3616. return
  3617. }
  3618. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3619. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3620. //table := XTReadDB().Table("xt_schedule as s")
  3621. //fmt.Println(table)
  3622. if patientid > 0 {
  3623. db = db.Where("x.patient_id = ?", patientid)
  3624. }
  3625. if startime > 0 {
  3626. db = db.Where("x.dialysis_date>=?", startime)
  3627. }
  3628. if endtime > 0 {
  3629. db = db.Where("x.dialysis_date <= ?", endtime)
  3630. }
  3631. 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
  3632. return order, err
  3633. }
  3634. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3635. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3636. //table := XTReadDB().Table("xt_schedule as s")
  3637. //fmt.Println(table)
  3638. if patientid > 0 {
  3639. db = db.Where("x.patient_id = ?", patientid)
  3640. }
  3641. if startime > 0 {
  3642. db = db.Where("x.schedule_date>=?", startime)
  3643. }
  3644. if endtime > 0 {
  3645. db = db.Where("x.schedule_date <= ?", endtime)
  3646. }
  3647. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3648. return order, err
  3649. }
  3650. func BatchDeleteAdvice(ids []string) (err error) {
  3651. if len(ids) == 1 {
  3652. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3653. } else {
  3654. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3655. }
  3656. return
  3657. }
  3658. func BatchDeleteHisAdvice(ids []string) (err error) {
  3659. if len(ids) == 1 {
  3660. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3661. } else {
  3662. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3663. }
  3664. return
  3665. }
  3666. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3667. detail := models.AutomaticReduceDetail{}
  3668. 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
  3669. return detail, err
  3670. }
  3671. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3672. detail := models.AutomaticReduceDetail{}
  3673. 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
  3674. return err
  3675. }
  3676. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3677. detail := models.DialysisBeforePrepare{}
  3678. 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
  3679. return err
  3680. }
  3681. func BatchAdviceCheck(ids []string, creator int64) error {
  3682. advice := models.XtDoctorAdvice{}
  3683. 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
  3684. return err
  3685. }
  3686. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3687. advice := models.HisDoctorAdviceInfo{}
  3688. 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
  3689. return err
  3690. }
  3691. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3692. advice := models.XtDoctorAdvice{}
  3693. 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
  3694. return err
  3695. }
  3696. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3697. advice := models.HisDoctorAdviceInfo{}
  3698. 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
  3699. return err
  3700. }
  3701. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3702. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3703. return doctor, err
  3704. }
  3705. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3706. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3707. return doctor, err
  3708. }
  3709. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3710. config := models.XtHisProjectConfig{}
  3711. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3712. return config, err
  3713. }
  3714. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3715. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3716. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3717. }).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
  3718. return
  3719. }
  3720. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3721. var vms []*HisMScheduleProjectVM
  3722. if patientType == 0 {
  3723. if patient_id > 0 {
  3724. if execution_state == 1 {
  3725. db := readDb.
  3726. Table("xt_schedule").
  3727. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3728. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3729. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3730. }).
  3731. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3732. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3733. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3734. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3735. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3736. }).
  3737. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3738. 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")
  3739. }).Where("status = 1 AND user_org_id = ?", orgID)
  3740. if scheduleDate != 0 {
  3741. db = db.Where("schedule_date = ?", scheduleDate)
  3742. }
  3743. err = db.Find(&vms).Error
  3744. } else if execution_state == 2 {
  3745. db := readDb.
  3746. Table("xt_schedule").
  3747. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3748. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3749. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3750. }).
  3751. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3752. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3753. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3754. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3755. 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")
  3756. }).
  3757. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3758. 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")
  3759. }).Where("status = 1 AND user_org_id = ?", orgID)
  3760. if scheduleDate != 0 {
  3761. db = db.Where("schedule_date = ?", scheduleDate)
  3762. }
  3763. err = db.Find(&vms).Error
  3764. } else if execution_state == 0 {
  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", orgID, scheduleDate).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", orgID, scheduleDate).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. }
  3785. } else {
  3786. if patient_id > 0 {
  3787. if execution_state == 1 {
  3788. db := readDb.
  3789. Table("xt_schedule").
  3790. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3791. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3792. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3793. }).
  3794. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3795. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3796. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3797. Preload("HisPrescriptionProject", 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 = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3799. }).
  3800. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3801. 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")
  3802. }).Where("status = 1 AND user_org_id = ?", orgID)
  3803. if scheduleDate != 0 {
  3804. db = db.Where("schedule_date = ?", scheduleDate)
  3805. }
  3806. err = db.Find(&vms).Error
  3807. } else if execution_state == 2 {
  3808. db := readDb.
  3809. Table("xt_schedule").
  3810. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3811. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3812. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3813. }).
  3814. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3815. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3816. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3817. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3818. 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")
  3819. }).
  3820. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3821. 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")
  3822. }).Where("status = 1 AND user_org_id = ?", orgID)
  3823. if scheduleDate != 0 {
  3824. db = db.Where("schedule_date = ?", scheduleDate)
  3825. }
  3826. err = db.Find(&vms).Error
  3827. } else if execution_state == 0 {
  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", orgID, scheduleDate).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", orgID, scheduleDate).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. }
  3848. } else {
  3849. if execution_state == 1 {
  3850. db := readDb.
  3851. Table("xt_schedule").
  3852. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3853. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3854. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3855. }).
  3856. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3857. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3858. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3859. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3860. 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")
  3861. }).
  3862. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3863. 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")
  3864. }).Where("status = 1 AND user_org_id = ?", orgID)
  3865. if scheduleDate != 0 {
  3866. db = db.Where("schedule_date = ?", scheduleDate)
  3867. }
  3868. err = db.Find(&vms).Error
  3869. } else if execution_state == 2 {
  3870. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3871. db := readDb.
  3872. Table("xt_schedule").
  3873. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3874. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3875. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3876. }).
  3877. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3878. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3879. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3880. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3881. 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")
  3882. }).
  3883. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3884. 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")
  3885. }).Where("status = 1 AND user_org_id = ?", orgID)
  3886. if scheduleDate != 0 {
  3887. db = db.Where("schedule_date = ?", scheduleDate)
  3888. }
  3889. err = db.Find(&vms).Error
  3890. } else if execution_state == 0 {
  3891. db := readDb.
  3892. Table("xt_schedule").
  3893. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3894. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3895. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3896. }).
  3897. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3898. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3899. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3900. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3901. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3902. }).
  3903. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3904. 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")
  3905. }).Where("status = 1 AND user_org_id = ?", orgID)
  3906. if scheduleDate != 0 {
  3907. db = db.Where("schedule_date = ?", scheduleDate)
  3908. }
  3909. err = db.Find(&vms).Error
  3910. }
  3911. }
  3912. }
  3913. }
  3914. if patientType > 0 {
  3915. if execution_state == 1 {
  3916. db := readDb.
  3917. Table("xt_schedule").
  3918. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3919. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3920. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3921. }).
  3922. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3923. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3924. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3925. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3926. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3927. 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")
  3928. }).
  3929. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3930. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3931. }).Where("status = 1 AND user_org_id = ?", orgID)
  3932. if scheduleDate != 0 {
  3933. db = db.Where("schedule_date = ?", scheduleDate)
  3934. }
  3935. err = db.Find(&vms).Error
  3936. } else if execution_state == 2 {
  3937. db := readDb.
  3938. Table("xt_schedule").
  3939. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3940. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3941. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3942. }).
  3943. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3944. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3945. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3946. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3947. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3948. 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")
  3949. }).
  3950. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3951. 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")
  3952. }).Where("status = 1 AND user_org_id = ?", orgID)
  3953. if scheduleDate != 0 {
  3954. db = db.Where("schedule_date = ?", scheduleDate)
  3955. }
  3956. err = db.Find(&vms).Error
  3957. } else if execution_state == 0 {
  3958. db := readDb.
  3959. Table("xt_schedule").
  3960. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3961. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3962. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3963. }).
  3964. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3965. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3966. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3967. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3968. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3969. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3970. }).
  3971. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3972. 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")
  3973. }).Where("status = 1 AND user_org_id = ?", orgID)
  3974. if scheduleDate != 0 {
  3975. db = db.Where("schedule_date = ?", scheduleDate)
  3976. }
  3977. err = db.Find(&vms).Error
  3978. }
  3979. }
  3980. return vms, err
  3981. }
  3982. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3983. prepare := models.DialysisBeforePrepare{}
  3984. var err error
  3985. if count > 0 {
  3986. 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
  3987. }
  3988. if count <= 0 {
  3989. 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
  3990. }
  3991. return err
  3992. }
  3993. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3994. detail := models.AutomaticReduceDetail{}
  3995. 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
  3996. return err
  3997. }
  3998. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3999. var record models.DialysisSolution
  4000. 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
  4001. if err != nil {
  4002. if err == gorm.ErrRecordNotFound {
  4003. return nil, nil
  4004. } else {
  4005. return nil, err
  4006. }
  4007. }
  4008. return &record, nil
  4009. }
  4010. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4011. var record models.DialysisPrescription
  4012. 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
  4013. if err != nil {
  4014. if err == gorm.ErrRecordNotFound {
  4015. return nil, nil
  4016. } else {
  4017. return nil, err
  4018. }
  4019. }
  4020. return &record, nil
  4021. }
  4022. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4023. prescription := models.DialysisPrescriptionThrity{}
  4024. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4025. return prescription, err
  4026. }
  4027. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4028. var record models.SystemPrescription
  4029. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4030. if err != nil {
  4031. if err == gorm.ErrRecordNotFound {
  4032. return nil, nil
  4033. } else {
  4034. return nil, err
  4035. }
  4036. }
  4037. return &record, nil
  4038. }
  4039. // 透前评估
  4040. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4041. var record models.PredialysisEvaluation
  4042. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4043. if err != nil {
  4044. if err == gorm.ErrRecordNotFound {
  4045. return nil, nil
  4046. } else {
  4047. return nil, err
  4048. }
  4049. }
  4050. return &record, nil
  4051. }
  4052. //
  4053. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4054. //
  4055. // 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
  4056. // return prepare, err
  4057. //}
  4058. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4059. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4060. return auto, err
  4061. }
  4062. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4063. role := models.SgjUserAdminRole{}
  4064. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4065. return role, err
  4066. }
  4067. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4068. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4069. return auto, err
  4070. }
  4071. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4072. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4073. return outifno, err
  4074. }
  4075. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4076. order := models.DialysisOrder{}
  4077. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4078. return order, err
  4079. }
  4080. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4081. record := models.MonitoringRecord{}
  4082. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4083. return record, err
  4084. }
  4085. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4086. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4087. return record, err
  4088. }
  4089. 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) {
  4090. var vms []*MScheduleDoctorAdviceVM
  4091. keyword = "%" + keyword + "%"
  4092. adviceWhere := ""
  4093. adviceCondition := []interface{}{}
  4094. if adviceType == 0 {
  4095. if patientType == 0 {
  4096. if patient_id > 0 {
  4097. if execution_state > 0 {
  4098. if cost_type > 0 {
  4099. if len(execution_frequency) > 0 {
  4100. if len(keyword) > 0 {
  4101. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4103. } else {
  4104. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4106. }
  4107. } else {
  4108. if len(keyword) > 0 {
  4109. 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 ?"
  4110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4111. } else {
  4112. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ?"
  4113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4114. }
  4115. }
  4116. } else {
  4117. if len(execution_frequency) > 0 {
  4118. if len(keyword) > 0 {
  4119. 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 ?"
  4120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4121. } else {
  4122. 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 = ?"
  4123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4124. }
  4125. } else {
  4126. if len(keyword) > 0 {
  4127. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4129. } else {
  4130. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4132. }
  4133. }
  4134. }
  4135. } else {
  4136. if cost_type > 0 {
  4137. if len(execution_frequency) > 0 {
  4138. 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 = ?"
  4139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4140. } else {
  4141. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4143. }
  4144. } else {
  4145. if len(execution_frequency) > 0 {
  4146. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4148. } else {
  4149. if len(keyword) > 0 {
  4150. 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 ?"
  4151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4152. } else {
  4153. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4155. }
  4156. }
  4157. }
  4158. }
  4159. } else {
  4160. if execution_state > 0 {
  4161. if cost_type > 0 {
  4162. if len(execution_frequency) > 0 {
  4163. if len(keyword) > 0 {
  4164. 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 ?"
  4165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4166. } else {
  4167. 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 = ?"
  4168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4169. }
  4170. } else {
  4171. if len(keyword) > 0 {
  4172. 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 ?"
  4173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4174. } else {
  4175. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4177. }
  4178. }
  4179. } else {
  4180. if len(execution_frequency) > 0 {
  4181. if len(keyword) > 0 {
  4182. 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 ?"
  4183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4184. } else {
  4185. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4187. }
  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 execution_state= ? and advice_name like ?"
  4191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4192. } else {
  4193. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4195. }
  4196. }
  4197. }
  4198. } else {
  4199. if cost_type > 0 {
  4200. if len(execution_frequency) > 0 {
  4201. if len(keyword) > 0 {
  4202. 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 ?"
  4203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4204. } else {
  4205. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4207. }
  4208. } else {
  4209. if len(keyword) > 0 {
  4210. 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 ?"
  4211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4212. } else {
  4213. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4215. }
  4216. }
  4217. } else {
  4218. if len(execution_frequency) > 0 {
  4219. if len(keyword) > 0 {
  4220. 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 ?"
  4221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4222. } else {
  4223. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4225. }
  4226. } else {
  4227. if len(keyword) > 0 {
  4228. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4230. } else {
  4231. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4233. }
  4234. }
  4235. }
  4236. }
  4237. }
  4238. } else if patientType == 1 {
  4239. if patient_id > 0 {
  4240. if execution_state > 0 {
  4241. if cost_type > 0 {
  4242. if len(execution_frequency) > 0 {
  4243. if len(keyword) > 0 {
  4244. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4246. } else {
  4247. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4249. }
  4250. } else {
  4251. if len(keyword) > 0 {
  4252. 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 ?"
  4253. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4254. } else {
  4255. 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 = ?"
  4256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4257. }
  4258. }
  4259. } else {
  4260. if len(execution_frequency) > 0 {
  4261. if len(keyword) > 0 {
  4262. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4264. } else {
  4265. 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 = ?"
  4266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4267. }
  4268. } else {
  4269. if len(keyword) > 0 {
  4270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4272. } else {
  4273. 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= ?"
  4274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4275. }
  4276. }
  4277. }
  4278. } else {
  4279. if cost_type > 0 {
  4280. if len(execution_frequency) > 0 {
  4281. if len(keyword) > 0 {
  4282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4284. } else {
  4285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ?"
  4286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4287. }
  4288. } else {
  4289. if len(keyword) > 0 {
  4290. 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 ?"
  4291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4292. } else {
  4293. 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=?"
  4294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4295. }
  4296. }
  4297. } else {
  4298. if len(execution_frequency) > 0 {
  4299. if len(keyword) > 0 {
  4300. 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 ?"
  4301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4302. } else {
  4303. 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 = ?"
  4304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4305. }
  4306. } else {
  4307. if len(keyword) > 0 {
  4308. 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 ?"
  4309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4310. } else {
  4311. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4313. }
  4314. }
  4315. }
  4316. }
  4317. } else {
  4318. if execution_state > 0 {
  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 execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state = ? and is_settle=? and execution_frequency = ?"
  4326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state = ? and is_settle=? and advice_name like ?"
  4331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state = ? and is_settle=?"
  4334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state = ? and execution_frequency = ? and advice_name like ?"
  4341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state = ? and execution_frequency = ?"
  4344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state = ? and advice_name like ?"
  4349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state = ?"
  4352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4353. }
  4354. }
  4355. }
  4356. } else {
  4357. if cost_type > 0 {
  4358. if len(execution_frequency) > 0 {
  4359. if len(keyword) > 0 {
  4360. 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 ?"
  4361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4362. } else {
  4363. 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 = ?"
  4364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4365. }
  4366. } else {
  4367. if len(keyword) > 0 {
  4368. 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 ?"
  4369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4370. } else {
  4371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4373. }
  4374. }
  4375. } else {
  4376. if len(execution_frequency) > 0 {
  4377. if len(keyword) > 0 {
  4378. 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 ?"
  4379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4380. } else {
  4381. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4383. }
  4384. } else {
  4385. if len(keyword) > 0 {
  4386. 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 ?"
  4387. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4388. } else {
  4389. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4391. }
  4392. }
  4393. }
  4394. }
  4395. }
  4396. } else if patientType == 2 {
  4397. if patient_id > 0 {
  4398. if execution_state > 0 {
  4399. if cost_type > 0 {
  4400. if len(execution_frequency) > 0 {
  4401. if len(keyword) > 0 {
  4402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4404. } else {
  4405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and is_settle=? and execution_frequency = ?"
  4406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4407. }
  4408. } else {
  4409. if len(keyword) > 0 {
  4410. 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 ?"
  4411. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4412. } else {
  4413. 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=?"
  4414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4415. }
  4416. }
  4417. } else {
  4418. if len(execution_frequency) > 0 {
  4419. if len(keyword) > 0 {
  4420. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?and execution_frequency = ? and advice_name like ?"
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4422. } else {
  4423. 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 = ?"
  4424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4425. }
  4426. } else {
  4427. if len(keyword) > 0 {
  4428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and advice_name like ?"
  4429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4430. } else {
  4431. 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 = ?"
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4433. }
  4434. }
  4435. }
  4436. } else {
  4437. if cost_type > 0 {
  4438. if len(execution_frequency) > 0 {
  4439. if len(keyword) > 0 {
  4440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4442. } else {
  4443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and execution_frequency = ?"
  4444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4445. }
  4446. } else {
  4447. if len(keyword) > 0 {
  4448. 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 ?"
  4449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4450. } else {
  4451. 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=?"
  4452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4453. }
  4454. }
  4455. } else {
  4456. if len(execution_frequency) > 0 {
  4457. if len(keyword) > 0 {
  4458. 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 ?"
  4459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4460. } else {
  4461. 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 = ?"
  4462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4463. }
  4464. } else {
  4465. if len(keyword) > 0 {
  4466. 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 ?"
  4467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4468. } else {
  4469. 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 = ?)"
  4470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4471. }
  4472. }
  4473. }
  4474. }
  4475. } else {
  4476. if execution_state > 0 {
  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 execution_state = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and is_settle=? and execution_frequency = ?"
  4484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and is_settle=? and advice_name like ?"
  4489. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and is_settle=?"
  4492. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and execution_frequency = ? and advice_name like ?"
  4499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and execution_frequency = ?"
  4502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and advice_name like ?"
  4507. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ?"
  4510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4511. }
  4512. }
  4513. }
  4514. } else {
  4515. if cost_type > 0 {
  4516. if len(execution_frequency) > 0 {
  4517. if len(keyword) > 0 {
  4518. 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 ?"
  4519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4520. } else {
  4521. 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 = ?"
  4522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4523. }
  4524. } else {
  4525. if len(keyword) > 0 {
  4526. 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 ?"
  4527. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4528. } else {
  4529. 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 = ?"
  4530. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4531. }
  4532. }
  4533. } else {
  4534. if len(execution_frequency) > 0 {
  4535. if len(keyword) > 0 {
  4536. 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 ?"
  4537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4538. } else {
  4539. 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 = ?"
  4540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4541. }
  4542. } else {
  4543. if len(keyword) > 0 {
  4544. 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 ?"
  4545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4546. } else {
  4547. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4549. }
  4550. }
  4551. }
  4552. }
  4553. }
  4554. }
  4555. } else if adviceType == 1 {
  4556. if patientType == 0 {
  4557. if patient_id > 0 {
  4558. if execution_state > 0 {
  4559. if cost_type > 0 {
  4560. if len(execution_frequency) > 0 {
  4561. if len(keyword) > 0 {
  4562. 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 ?"
  4563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4564. } else {
  4565. 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 = ?"
  4566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4567. }
  4568. } else {
  4569. if len(keyword) > 0 {
  4570. 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 ?"
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4572. } else {
  4573. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4575. }
  4576. }
  4577. } else {
  4578. if len(execution_frequency) > 0 {
  4579. if len(keyword) > 0 {
  4580. 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 ?"
  4581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4582. } else {
  4583. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4585. }
  4586. } else {
  4587. if len(keyword) > 0 {
  4588. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4590. } else {
  4591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4593. }
  4594. }
  4595. }
  4596. } else {
  4597. if cost_type > 0 {
  4598. if len(execution_frequency) > 0 {
  4599. if len(keyword) > 0 {
  4600. 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 ?"
  4601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4602. } else {
  4603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4605. }
  4606. } else {
  4607. if len(keyword) > 0 {
  4608. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4610. } else {
  4611. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4613. }
  4614. }
  4615. } else {
  4616. if len(execution_frequency) > 0 {
  4617. if len(keyword) > 0 {
  4618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4620. } else {
  4621. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4623. }
  4624. }
  4625. }
  4626. }
  4627. } else {
  4628. if execution_state > 0 {
  4629. if cost_type > 0 {
  4630. if len(execution_frequency) > 0 {
  4631. if len(keyword) > 0 {
  4632. 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 ?"
  4633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4634. } else {
  4635. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4637. }
  4638. } else {
  4639. if len(keyword) > 0 {
  4640. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4642. } else {
  4643. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4645. }
  4646. }
  4647. } else {
  4648. if len(execution_frequency) > 0 {
  4649. if len(keyword) > 0 {
  4650. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4652. } else {
  4653. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4655. }
  4656. } else {
  4657. if len(keyword) > 0 {
  4658. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4660. } else {
  4661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4663. }
  4664. }
  4665. }
  4666. } else {
  4667. if cost_type > 0 {
  4668. if len(keyword) > 0 {
  4669. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4671. } else {
  4672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4674. }
  4675. } else {
  4676. if len(keyword) > 0 {
  4677. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4679. } else {
  4680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4682. }
  4683. }
  4684. }
  4685. }
  4686. } else if patientType == 1 {
  4687. if patient_id > 0 {
  4688. if execution_state > 0 {
  4689. if cost_type > 0 {
  4690. if len(execution_frequency) > 0 {
  4691. if len(keyword) > 0 {
  4692. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4694. } else {
  4695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4697. }
  4698. } else {
  4699. if len(keyword) > 0 {
  4700. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4702. } else {
  4703. 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 = ?"
  4704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4705. }
  4706. }
  4707. } else {
  4708. if len(execution_frequency) > 0 {
  4709. if len(keyword) > 0 {
  4710. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4712. } else {
  4713. 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 = ?"
  4714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4715. }
  4716. } else {
  4717. if len(keyword) > 0 {
  4718. 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 ?"
  4719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4720. } else {
  4721. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4723. }
  4724. }
  4725. }
  4726. } else {
  4727. if cost_type > 0 {
  4728. if len(execution_frequency) > 0 {
  4729. if len(keyword) > 0 {
  4730. 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 ?"
  4731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4732. } else {
  4733. 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 = ?"
  4734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4735. }
  4736. } else {
  4737. if len(keyword) > 0 {
  4738. 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 ?"
  4739. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4740. } else {
  4741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4742. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4743. }
  4744. }
  4745. } else {
  4746. if len(execution_frequency) > 0 {
  4747. if len(keyword) > 0 {
  4748. 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 ?"
  4749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4750. } else {
  4751. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4753. }
  4754. } else {
  4755. if len(keyword) > 0 {
  4756. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4758. } else {
  4759. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4761. }
  4762. }
  4763. }
  4764. }
  4765. } else {
  4766. if execution_state > 0 {
  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 execution_state=? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state=? and is_settle = ?and execution_frequency = ?"
  4774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state=? and is_settle = ? and advice_name like ?"
  4779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4780. } else {
  4781. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state=?and execution_frequency = ? and advice_name like ?"
  4789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4790. } else {
  4791. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state=? and advice_name like ?"
  4797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4798. } else {
  4799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4801. }
  4802. }
  4803. }
  4804. } else {
  4805. if cost_type > 0 {
  4806. if len(execution_frequency) > 0 {
  4807. if len(keyword) > 0 {
  4808. 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 ?"
  4809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4810. } else {
  4811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4813. }
  4814. } else {
  4815. if len(keyword) > 0 {
  4816. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4818. } else {
  4819. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4821. }
  4822. }
  4823. } else {
  4824. if len(execution_frequency) > 0 {
  4825. if len(keyword) > 0 {
  4826. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4828. } else {
  4829. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4830. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4831. }
  4832. } else {
  4833. if len(keyword) > 0 {
  4834. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4836. } else {
  4837. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4839. }
  4840. }
  4841. }
  4842. }
  4843. }
  4844. } else if patientType == 2 {
  4845. if patient_id > 0 {
  4846. if execution_state > 0 {
  4847. if cost_type > 0 {
  4848. if len(execution_frequency) > 0 {
  4849. if len(keyword) > 0 {
  4850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ? and advice_name like ?"
  4851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4852. } else {
  4853. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ?"
  4854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4855. }
  4856. } else {
  4857. if len(keyword) > 0 {
  4858. 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 ?"
  4859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4860. } else {
  4861. 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 = ?"
  4862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4863. }
  4864. }
  4865. } else {
  4866. if len(execution_frequency) > 0 {
  4867. if len(keyword) > 0 {
  4868. 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 ?"
  4869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4870. } else {
  4871. 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 = ?"
  4872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4873. }
  4874. } else {
  4875. if len(keyword) > 0 {
  4876. 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 ?"
  4877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4878. } else {
  4879. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4881. }
  4882. }
  4883. }
  4884. } else {
  4885. if cost_type > 0 {
  4886. if len(execution_frequency) > 0 {
  4887. if len(keyword) > 0 {
  4888. 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 ?"
  4889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4890. } else {
  4891. 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 = ?"
  4892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4893. }
  4894. } else {
  4895. if len(keyword) > 0 {
  4896. 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 ?"
  4897. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4898. } else {
  4899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4900. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4901. }
  4902. }
  4903. } else {
  4904. if len(execution_frequency) > 0 {
  4905. if len(keyword) > 0 {
  4906. 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 ?"
  4907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4908. } else {
  4909. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4911. }
  4912. } else {
  4913. if len(keyword) > 0 {
  4914. 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 ?"
  4915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4916. } else {
  4917. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4918. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4919. }
  4920. }
  4921. }
  4922. }
  4923. } else {
  4924. if execution_state > 0 {
  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 execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and is_settle = ? and execution_frequency = ?"
  4932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and is_settle = ? and advice_name like ?"
  4937. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and is_settle = ?"
  4940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and execution_frequency = ? and advice_name like ?"
  4947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and execution_frequency = ?"
  4950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state = ? and advice_name like ?"
  4955. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4956. } else {
  4957. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4959. }
  4960. }
  4961. }
  4962. } else {
  4963. if cost_type > 0 {
  4964. if len(execution_frequency) > 0 {
  4965. if len(keyword) > 0 {
  4966. 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 ?"
  4967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4968. } else {
  4969. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4971. }
  4972. } else {
  4973. if len(keyword) > 0 {
  4974. 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 ?"
  4975. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4976. } else {
  4977. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4979. }
  4980. }
  4981. } else {
  4982. if len(execution_frequency) > 0 {
  4983. if len(keyword) > 0 {
  4984. 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 ?"
  4985. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4986. } else {
  4987. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4989. }
  4990. } else {
  4991. if len(keyword) > 0 {
  4992. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  4993. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4994. } else {
  4995. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4996. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4997. }
  4998. }
  4999. }
  5000. }
  5001. }
  5002. }
  5003. } else if adviceType == 3 {
  5004. if patientType == 0 {
  5005. if patient_id > 0 {
  5006. if execution_state > 0 {
  5007. if cost_type > 0 {
  5008. if len(execution_frequency) > 0 {
  5009. if len(keyword) > 0 {
  5010. 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 ?"
  5011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5012. } else {
  5013. 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 =?"
  5014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5015. }
  5016. } else {
  5017. if len(keyword) > 0 {
  5018. 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 ?"
  5019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5020. } else {
  5021. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5023. }
  5024. }
  5025. } else {
  5026. if len(execution_frequency) > 0 {
  5027. if len(keyword) > 0 {
  5028. 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 ?"
  5029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5030. } else {
  5031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5033. }
  5034. } else {
  5035. if len(keyword) > 0 {
  5036. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5037. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5038. } else {
  5039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5041. }
  5042. }
  5043. }
  5044. } else {
  5045. if cost_type > 0 {
  5046. if len(execution_frequency) > 0 {
  5047. if len(keyword) > 0 {
  5048. 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 ?"
  5049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5050. } else {
  5051. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5053. }
  5054. } else {
  5055. if len(keyword) > 0 {
  5056. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5058. } else {
  5059. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5061. }
  5062. }
  5063. } else {
  5064. if len(execution_frequency) > 0 {
  5065. if len(keyword) > 0 {
  5066. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5068. } else {
  5069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5071. }
  5072. } else {
  5073. if len(keyword) > 0 {
  5074. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5076. } else {
  5077. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5079. }
  5080. }
  5081. }
  5082. }
  5083. } else {
  5084. if execution_state > 0 {
  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 execution_state =? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5090. } else {
  5091. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state =? and is_settle = ? and advice_name like ?"
  5097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5098. } else {
  5099. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state =? and execution_frequency =? and advice_name like ?"
  5107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5108. } else {
  5109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state =? and advice_name like ?"
  5115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5116. } else {
  5117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5119. }
  5120. }
  5121. }
  5122. } else {
  5123. if cost_type > 0 {
  5124. if len(execution_frequency) > 0 {
  5125. if len(keyword) > 0 {
  5126. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5128. } else {
  5129. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5131. }
  5132. } else {
  5133. if len(keyword) > 0 {
  5134. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5136. } else {
  5137. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5139. }
  5140. }
  5141. } else {
  5142. if len(execution_frequency) > 0 {
  5143. if len(keyword) > 0 {
  5144. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5146. } else {
  5147. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5149. }
  5150. } else {
  5151. if len(keyword) > 0 {
  5152. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5154. } else {
  5155. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5157. }
  5158. }
  5159. }
  5160. }
  5161. }
  5162. } else if patientType == 1 {
  5163. if patient_id > 0 {
  5164. if execution_state > 0 {
  5165. if cost_type > 0 {
  5166. if len(execution_frequency) > 0 {
  5167. if len(keyword) > 0 {
  5168. 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 ?"
  5169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5170. } else {
  5171. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5173. }
  5174. } else {
  5175. if len(keyword) > 0 {
  5176. 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 ?"
  5177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5178. } else {
  5179. 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 = ?"
  5180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5181. }
  5182. }
  5183. } else {
  5184. if len(execution_frequency) > 0 {
  5185. if len(keyword) > 0 {
  5186. 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 ?"
  5187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5188. } else {
  5189. 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 = ?"
  5190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5191. }
  5192. } else {
  5193. if len(keyword) > 0 {
  5194. 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 ?"
  5195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5196. } else {
  5197. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5199. }
  5200. }
  5201. }
  5202. } else {
  5203. if cost_type > 0 {
  5204. if len(execution_frequency) > 0 {
  5205. if len(keyword) > 0 {
  5206. 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 ?"
  5207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5208. } else {
  5209. 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 = ?"
  5210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5211. }
  5212. } else {
  5213. if len(keyword) > 0 {
  5214. 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 ?"
  5215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5216. } else {
  5217. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5219. }
  5220. }
  5221. } else {
  5222. if len(execution_frequency) > 0 {
  5223. if len(keyword) > 0 {
  5224. 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 ?"
  5225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5226. } else {
  5227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5229. }
  5230. } else {
  5231. if len(keyword) > 0 {
  5232. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5234. } else {
  5235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5237. }
  5238. }
  5239. }
  5240. }
  5241. } else {
  5242. if execution_state > 0 {
  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 execution_state =? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state =? and is_settle = ? and execution_frequency = ?"
  5250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state =? and is_settle = ? and advice_name like ?"
  5255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5256. } else {
  5257. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state =?and execution_frequency = ? and avice_name like ? "
  5265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5266. } else {
  5267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 execution_state =? and advice_name like ?"
  5273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5274. } else {
  5275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5277. }
  5278. }
  5279. }
  5280. } else {
  5281. if cost_type > 0 {
  5282. if len(execution_frequency) > 0 {
  5283. if len(keyword) > 0 {
  5284. 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 ?"
  5285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5286. } else {
  5287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5289. }
  5290. } else {
  5291. if len(keyword) > 0 {
  5292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5294. } else {
  5295. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5297. }
  5298. }
  5299. } else {
  5300. if len(execution_frequency) > 0 {
  5301. if len(keyword) > 0 {
  5302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5304. } else {
  5305. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5307. }
  5308. } else {
  5309. if len(keyword) > 0 {
  5310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5312. } else {
  5313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5315. }
  5316. }
  5317. }
  5318. }
  5319. }
  5320. } else if patientType == 2 {
  5321. if patient_id > 0 {
  5322. if execution_state > 0 {
  5323. if cost_type > 0 {
  5324. if len(execution_frequency) > 0 {
  5325. if len(keyword) > 0 {
  5326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5328. } else {
  5329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5331. }
  5332. } else {
  5333. if len(keyword) > 0 {
  5334. 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 ?"
  5335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5336. } else {
  5337. 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 = ?"
  5338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5339. }
  5340. }
  5341. } else {
  5342. if len(execution_frequency) > 0 {
  5343. if len(keyword) > 0 {
  5344. 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 ?"
  5345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5346. } else {
  5347. 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 = ?"
  5348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5349. }
  5350. } else {
  5351. if len(keyword) > 0 {
  5352. 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 ?"
  5353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5354. } else {
  5355. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5357. }
  5358. }
  5359. }
  5360. } else {
  5361. if cost_type > 0 {
  5362. if len(execution_frequency) > 0 {
  5363. if len(keyword) > 0 {
  5364. 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 ?"
  5365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5366. } else {
  5367. 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 = ?"
  5368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5369. }
  5370. } else {
  5371. if len(keyword) > 0 {
  5372. 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 ?"
  5373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5374. } else {
  5375. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5377. }
  5378. }
  5379. } else {
  5380. if len(execution_frequency) > 0 {
  5381. if len(keyword) > 0 {
  5382. 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 ?"
  5383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5384. } else {
  5385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5387. }
  5388. } else {
  5389. if len(keyword) > 0 {
  5390. 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 ?"
  5391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5392. } else {
  5393. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5395. }
  5396. }
  5397. }
  5398. }
  5399. } else {
  5400. if execution_state > 0 {
  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 execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state= ? and is_settle = ? and execution_frequency = ?"
  5408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state= ? and is_settle = ? and advice_name like ?"
  5413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state= ? and is_settle = ?"
  5416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state= ? and execution_frequency = ? and advice_name like ?"
  5423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state= ? and execution_frequency = ?"
  5426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 execution_state= ? and advice_name like ?"
  5431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5432. } else {
  5433. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5435. }
  5436. }
  5437. }
  5438. } else {
  5439. if cost_type > 0 {
  5440. if len(execution_frequency) > 0 {
  5441. if len(keyword) > 0 {
  5442. 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 ?"
  5443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5444. } else {
  5445. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5447. }
  5448. } else {
  5449. if len(keyword) > 0 {
  5450. 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 ?"
  5451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5452. } else {
  5453. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5455. }
  5456. }
  5457. } else {
  5458. if len(execution_frequency) > 0 {
  5459. if len(keyword) > 0 {
  5460. 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 ?"
  5461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5462. } else {
  5463. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5465. }
  5466. } else {
  5467. if len(keyword) > 0 {
  5468. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5470. } else {
  5471. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5473. }
  5474. }
  5475. }
  5476. }
  5477. }
  5478. }
  5479. } else if adviceType == 2 && len(deliverWay) > 0 {
  5480. if patientType == 0 {
  5481. if patient_id > 0 {
  5482. if execution_state > 0 {
  5483. if cost_type > 0 {
  5484. if len(execution_frequency) > 0 {
  5485. if len(keyword) > 0 {
  5486. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5488. } else {
  5489. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5491. }
  5492. } else {
  5493. if len(keyword) > 0 {
  5494. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5496. } else {
  5497. 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 = ?"
  5498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5499. }
  5500. }
  5501. } else {
  5502. if len(execution_frequency) > 0 {
  5503. if len(keyword) > 0 {
  5504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5506. } else {
  5507. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5509. }
  5510. } else {
  5511. if len(keyword) > 0 {
  5512. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5514. } else {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5517. }
  5518. }
  5519. }
  5520. } else {
  5521. if cost_type > 0 {
  5522. if len(execution_frequency) > 0 {
  5523. if len(keyword) > 0 {
  5524. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5526. } else {
  5527. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5529. }
  5530. } else {
  5531. if len(keyword) > 0 {
  5532. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5534. } else {
  5535. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5537. }
  5538. }
  5539. } else {
  5540. if len(execution_frequency) > 0 {
  5541. if len(keyword) > 0 {
  5542. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5544. } else {
  5545. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5547. }
  5548. } else {
  5549. if len(keyword) > 0 {
  5550. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5552. } else {
  5553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5555. }
  5556. }
  5557. }
  5558. }
  5559. } else {
  5560. if execution_state > 0 {
  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 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5566. } else {
  5567. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5569. }
  5570. } else {
  5571. if len(keyword) > 0 {
  5572. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5574. } else {
  5575. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, 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 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5584. } else {
  5585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5587. }
  5588. } else {
  5589. if len(keyword) > 0 {
  5590. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5592. } else {
  5593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5595. }
  5596. }
  5597. }
  5598. } else {
  5599. if cost_type > 0 {
  5600. if len(execution_frequency) > 0 {
  5601. if len(keyword) > 0 {
  5602. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5604. } else {
  5605. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5607. }
  5608. } else {
  5609. if len(keyword) > 0 {
  5610. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5612. } else {
  5613. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5615. }
  5616. }
  5617. } else {
  5618. if len(execution_frequency) > 0 {
  5619. if len(keyword) > 0 {
  5620. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5622. } else {
  5623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5625. }
  5626. } else {
  5627. if len(keyword) > 0 {
  5628. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and advice_name like ?"
  5629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5630. } else {
  5631. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5633. }
  5634. }
  5635. }
  5636. }
  5637. }
  5638. } else if patientType == 1 {
  5639. if patient_id > 0 {
  5640. if execution_state > 0 {
  5641. if cost_type > 0 {
  5642. if len(execution_frequency) > 0 {
  5643. if len(keyword) > 0 {
  5644. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5645. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5646. } else {
  5647. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5648. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5649. }
  5650. } else {
  5651. if len(keyword) > 0 {
  5652. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5654. } else {
  5655. 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 = ?"
  5656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5657. }
  5658. }
  5659. } else {
  5660. if len(execution_frequency) > 0 {
  5661. if len(keyword) > 0 {
  5662. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5664. } else {
  5665. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5667. }
  5668. } else {
  5669. if len(keyword) > 0 {
  5670. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5672. } else {
  5673. 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 = ?"
  5674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5675. }
  5676. }
  5677. }
  5678. } else {
  5679. if cost_type > 0 {
  5680. if len(execution_frequency) > 0 {
  5681. if len(keyword) > 0 {
  5682. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5684. } else {
  5685. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5686. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5687. }
  5688. } else {
  5689. if len(keyword) > 0 {
  5690. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5692. } else {
  5693. 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 = ?"
  5694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5695. }
  5696. }
  5697. } else {
  5698. if len(execution_frequency) > 0 {
  5699. if len(keyword) > 0 {
  5700. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5702. } else {
  5703. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5705. }
  5706. } else {
  5707. if len(keyword) > 0 {
  5708. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5710. } else {
  5711. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5713. }
  5714. }
  5715. }
  5716. }
  5717. } else {
  5718. if execution_state > 0 {
  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 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5724. } else {
  5725. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, 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 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5732. } else {
  5733. 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 = ?"
  5734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, 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 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5742. } else {
  5743. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, 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 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5750. } else {
  5751. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5753. }
  5754. }
  5755. }
  5756. } else {
  5757. if cost_type > 0 {
  5758. if len(execution_frequency) > 0 {
  5759. if len(keyword) > 0 {
  5760. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5762. } else {
  5763. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5765. }
  5766. } else {
  5767. if len(keyword) > 0 {
  5768. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5770. } else {
  5771. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5773. }
  5774. }
  5775. } else {
  5776. if len(execution_frequency) > 0 {
  5777. if len(keyword) > 0 {
  5778. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5780. } else {
  5781. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5783. }
  5784. } else {
  5785. if len(keyword) > 0 {
  5786. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5788. } else {
  5789. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5790. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5791. }
  5792. }
  5793. }
  5794. }
  5795. }
  5796. } else if patientType == 2 {
  5797. if patient_id > 0 {
  5798. if execution_state > 0 {
  5799. if cost_type > 0 {
  5800. if len(execution_frequency) > 0 {
  5801. if len(keyword) > 0 {
  5802. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5804. } else {
  5805. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5807. }
  5808. } else {
  5809. if len(keyword) > 0 {
  5810. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5812. } else {
  5813. 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 = ?"
  5814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5815. }
  5816. }
  5817. } else {
  5818. if len(execution_frequency) > 0 {
  5819. if len(keyword) > 0 {
  5820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5822. } else {
  5823. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5825. }
  5826. } else {
  5827. if len(keyword) > 0 {
  5828. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5830. } else {
  5831. 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 = ?"
  5832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5833. }
  5834. }
  5835. }
  5836. } else {
  5837. if cost_type > 0 {
  5838. if len(execution_frequency) > 0 {
  5839. if len(keyword) > 0 {
  5840. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5842. } else {
  5843. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5845. }
  5846. } else {
  5847. if len(keyword) > 0 {
  5848. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5849. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5850. } else {
  5851. 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 = ?"
  5852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5853. }
  5854. }
  5855. } else {
  5856. if len(execution_frequency) > 0 {
  5857. if len(keyword) > 0 {
  5858. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5860. } else {
  5861. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5863. }
  5864. } else {
  5865. if len(keyword) > 0 {
  5866. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and advice_name like ?"
  5867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5868. } else {
  5869. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5870. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5871. }
  5872. }
  5873. }
  5874. }
  5875. } else {
  5876. if execution_state > 0 {
  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 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5881. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5882. } else {
  5883. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5884. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, 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 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5890. } else {
  5891. 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 = ?"
  5892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, 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 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5900. } else {
  5901. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, 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 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and advice_name like ?"
  5907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5908. } else {
  5909. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5911. }
  5912. }
  5913. }
  5914. } else {
  5915. if cost_type > 0 {
  5916. if len(execution_frequency) > 0 {
  5917. if len(keyword) > 0 {
  5918. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5920. } else {
  5921. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5923. }
  5924. } else {
  5925. if len(keyword) > 0 {
  5926. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5927. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5928. } else {
  5929. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5931. }
  5932. }
  5933. } else {
  5934. if len(keyword) > 0 {
  5935. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  5936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5937. } else {
  5938. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5940. }
  5941. }
  5942. }
  5943. }
  5944. }
  5945. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5946. if patientType == 0 {
  5947. if patient_id > 0 {
  5948. if execution_state > 0 {
  5949. if cost_type > 0 {
  5950. if len(execution_frequency) > 0 {
  5951. if len(keyword) > 0 {
  5952. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5954. } else {
  5955. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5956. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5957. }
  5958. } else {
  5959. if len(keyword) > 0 {
  5960. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5962. } else {
  5963. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5965. }
  5966. }
  5967. } else {
  5968. if len(execution_frequency) > 0 {
  5969. if len(keyword) > 0 {
  5970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5972. } else {
  5973. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5974. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5975. }
  5976. } else {
  5977. if len(keyword) > 0 {
  5978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5980. } else {
  5981. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5983. }
  5984. }
  5985. }
  5986. } else {
  5987. if cost_type > 0 {
  5988. if len(execution_frequency) > 0 {
  5989. if len(keyword) > 0 {
  5990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5992. } else {
  5993. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5995. }
  5996. } else {
  5997. if len(keyword) > 0 {
  5998. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6000. } else {
  6001. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6003. }
  6004. }
  6005. } else {
  6006. if len(execution_frequency) > 0 {
  6007. if len(keyword) > 0 {
  6008. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6010. } else {
  6011. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6012. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6013. }
  6014. } else {
  6015. if len(keyword) > 0 {
  6016. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and advice_name like ?"
  6017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6018. } else {
  6019. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6021. }
  6022. }
  6023. }
  6024. }
  6025. } else {
  6026. if execution_state > 0 {
  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 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6032. } else {
  6033. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6035. }
  6036. } else {
  6037. if len(keyword) > 0 {
  6038. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6040. } else {
  6041. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6050. } else {
  6051. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6053. }
  6054. } else {
  6055. if len(keyword) > 0 {
  6056. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and advice_name like ?"
  6057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6058. } else {
  6059. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6061. }
  6062. }
  6063. }
  6064. } else {
  6065. if cost_type > 0 {
  6066. if len(execution_frequency) > 0 {
  6067. if len(keyword) > 0 {
  6068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6070. } else {
  6071. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6073. }
  6074. }
  6075. } else {
  6076. if len(execution_frequency) > 0 {
  6077. if len(keyword) > 0 {
  6078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6080. } else {
  6081. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  6082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6083. }
  6084. } else {
  6085. if len(keyword) > 0 {
  6086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and advice_name like ?"
  6087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6088. } else {
  6089. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6091. }
  6092. }
  6093. }
  6094. }
  6095. }
  6096. } else if patientType == 1 {
  6097. if patient_id > 0 {
  6098. if execution_state > 0 {
  6099. if cost_type > 0 {
  6100. if len(execution_frequency) > 0 {
  6101. if len(keyword) > 0 {
  6102. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6104. } else {
  6105. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6107. }
  6108. } else {
  6109. if len(keyword) > 0 {
  6110. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6112. } else {
  6113. 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 = ?"
  6114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6115. }
  6116. }
  6117. } else {
  6118. if len(execution_frequency) > 0 {
  6119. if len(keyword) > 0 {
  6120. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6122. } else {
  6123. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6125. }
  6126. } else {
  6127. if len(keyword) > 0 {
  6128. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6130. } else {
  6131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6133. }
  6134. }
  6135. }
  6136. } else {
  6137. if cost_type > 0 {
  6138. if len(execution_frequency) > 0 {
  6139. if len(keyword) > 0 {
  6140. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6142. } else {
  6143. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6145. }
  6146. } else {
  6147. if len(keyword) > 0 {
  6148. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6149. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6150. } else {
  6151. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6153. }
  6154. }
  6155. } else {
  6156. if len(execution_frequency) > 0 {
  6157. if len(keyword) > 0 {
  6158. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6160. } else {
  6161. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6163. }
  6164. } else {
  6165. if len(keyword) > 0 {
  6166. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6168. } else {
  6169. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6171. }
  6172. }
  6173. }
  6174. }
  6175. } else {
  6176. if execution_state > 0 {
  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 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6182. } else {
  6183. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6184. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6190. } else {
  6191. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6200. } else {
  6201. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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 AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6208. } else {
  6209. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6211. }
  6212. }
  6213. }
  6214. } else {
  6215. if cost_type > 0 {
  6216. if len(execution_frequency) > 0 {
  6217. if len(keyword) > 0 {
  6218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6220. } else {
  6221. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6223. }
  6224. } else {
  6225. if len(keyword) > 0 {
  6226. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6228. } else {
  6229. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6231. }
  6232. }
  6233. } else {
  6234. if len(execution_frequency) > 0 {
  6235. if len(keyword) > 0 {
  6236. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6238. } else {
  6239. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  6240. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6241. }
  6242. } else {
  6243. if len(keyword) > 0 {
  6244. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and advice_name like ?"
  6245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6246. } else {
  6247. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6249. }
  6250. }
  6251. }
  6252. }
  6253. }
  6254. } else if patientType == 2 {
  6255. if patient_id > 0 {
  6256. if execution_state > 0 {
  6257. if cost_type > 0 {
  6258. if len(execution_frequency) > 0 {
  6259. if len(keyword) > 0 {
  6260. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6261. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6262. } else {
  6263. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6264. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6265. }
  6266. } else {
  6267. if len(keyword) > 0 {
  6268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6270. } else {
  6271. 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 = ?"
  6272. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6273. }
  6274. }
  6275. } else {
  6276. if len(execution_frequency) > 0 {
  6277. if len(keyword) > 0 {
  6278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6280. } else {
  6281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6283. }
  6284. } else {
  6285. if len(keyword) > 0 {
  6286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  6287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6288. } else {
  6289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6291. }
  6292. }
  6293. }
  6294. } else {
  6295. if cost_type > 0 {
  6296. if len(execution_frequency) > 0 {
  6297. if len(keyword) > 0 {
  6298. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6299. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6300. } else {
  6301. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6302. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6303. }
  6304. } else {
  6305. if len(keyword) > 0 {
  6306. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6307. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6308. } else {
  6309. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6311. }
  6312. }
  6313. } else {
  6314. if len(execution_frequency) > 0 {
  6315. if len(keyword) > 0 {
  6316. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6318. } else {
  6319. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6321. }
  6322. } else {
  6323. if len(keyword) > 0 {
  6324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6326. } else {
  6327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6329. }
  6330. }
  6331. }
  6332. }
  6333. } else {
  6334. if execution_state > 0 {
  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 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6340. } else {
  6341. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6348. } else {
  6349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6358. } else {
  6359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6366. } else {
  6367. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6369. }
  6370. }
  6371. }
  6372. } else {
  6373. if cost_type > 0 {
  6374. if len(execution_frequency) > 0 {
  6375. if len(keyword) > 0 {
  6376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6378. } else {
  6379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6381. }
  6382. } else {
  6383. if len(keyword) > 0 {
  6384. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6385. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6386. } else {
  6387. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6389. }
  6390. }
  6391. } else {
  6392. if len(execution_frequency) > 0 {
  6393. if len(keyword) > 0 {
  6394. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6396. } else {
  6397. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  6398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6399. }
  6400. } else {
  6401. if len(keyword) > 0 {
  6402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and advice_name like ?"
  6403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6404. } else {
  6405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6407. }
  6408. }
  6409. }
  6410. }
  6411. }
  6412. }
  6413. }
  6414. db := readDb.Table("xt_schedule")
  6415. if scheduleType > 0 {
  6416. db = db.Where("schedule_type = ?", scheduleType)
  6417. }
  6418. if partitonType > 0 {
  6419. db = db.Where("partition_id = ?", partitonType)
  6420. }
  6421. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6422. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6423. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6424. }).
  6425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6426. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6427. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6428. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6429. Preload("DoctorAdvices", adviceCondition...).
  6430. Where("status = 1 AND user_org_id = ?", orgID)
  6431. if scheduleDate != 0 {
  6432. db = db.Where("schedule_date = ?", scheduleDate)
  6433. }
  6434. err := db.Find(&vms).Error
  6435. return vms, err
  6436. }
  6437. 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) {
  6438. var vms []*MScheduleDoctorAdviceVM
  6439. adviceWhere := ""
  6440. adviceCondition := []interface{}{}
  6441. if adviceType == 0 {
  6442. if patientType == 0 {
  6443. if patient_id > 0 {
  6444. if execution_state > 0 {
  6445. if cost_type > 0 {
  6446. 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 = ?"
  6447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6448. } else {
  6449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6451. }
  6452. } else {
  6453. if cost_type > 0 {
  6454. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6456. } else {
  6457. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6459. }
  6460. }
  6461. } else {
  6462. if execution_state > 0 {
  6463. if cost_type > 0 {
  6464. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6466. } else {
  6467. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6469. }
  6470. } else {
  6471. if cost_type > 0 {
  6472. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6474. } else {
  6475. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6477. }
  6478. }
  6479. }
  6480. } else if patientType == 1 {
  6481. if patient_id > 0 {
  6482. if execution_state > 0 {
  6483. if cost_type > 0 {
  6484. 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 = ?"
  6485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6486. } else {
  6487. 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= ?"
  6488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6489. }
  6490. } else {
  6491. if cost_type > 0 {
  6492. 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=?"
  6493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6494. } else {
  6495. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6497. }
  6498. }
  6499. } else {
  6500. if execution_state > 0 {
  6501. if cost_type > 0 {
  6502. 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=?"
  6503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6504. } else {
  6505. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6507. }
  6508. } else {
  6509. if cost_type > 0 {
  6510. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6512. } else {
  6513. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6515. }
  6516. }
  6517. }
  6518. } else if patientType == 2 {
  6519. if patient_id > 0 {
  6520. if execution_state > 0 {
  6521. if cost_type > 0 {
  6522. 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=?"
  6523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6524. } else {
  6525. 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 = ?"
  6526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6527. }
  6528. } else {
  6529. if cost_type > 0 {
  6530. 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=?"
  6531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6532. } else {
  6533. 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 = ?)"
  6534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6535. }
  6536. }
  6537. } else {
  6538. if execution_state > 0 {
  6539. if cost_type > 0 {
  6540. 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=?"
  6541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6542. } else {
  6543. 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 = ?"
  6544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6545. }
  6546. } else {
  6547. if cost_type > 0 {
  6548. 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 = ?"
  6549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6550. } else {
  6551. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6553. }
  6554. }
  6555. }
  6556. }
  6557. } else if adviceType == 1 {
  6558. if patientType == 0 {
  6559. if patient_id > 0 {
  6560. if execution_state > 0 {
  6561. if cost_type > 0 {
  6562. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? 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 advice_type = 1 AND record_date = ? 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 advice_type = 1 AND record_date = ? 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 advice_type = 1 AND record_date = ? 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 advice_type = 1 AND record_date = ? 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 advice_type = 1 AND record_date = ? 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 advice_type = 1 AND record_date = ? and is_settle = ? "
  6589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6590. } else {
  6591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6593. }
  6594. }
  6595. }
  6596. } else if patientType == 1 {
  6597. if patient_id > 0 {
  6598. if execution_state > 0 {
  6599. if cost_type > 0 {
  6600. 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 = ?"
  6601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6602. } else {
  6603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6605. }
  6606. } else {
  6607. if cost_type > 0 {
  6608. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6610. } else {
  6611. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6613. }
  6614. }
  6615. } else {
  6616. if execution_state > 0 {
  6617. if cost_type > 0 {
  6618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6620. } else {
  6621. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6623. }
  6624. } else {
  6625. if cost_type > 0 {
  6626. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6628. } else {
  6629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6631. }
  6632. }
  6633. }
  6634. } else if patientType == 2 {
  6635. if patient_id > 0 {
  6636. if execution_state > 0 {
  6637. if cost_type > 0 {
  6638. 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 = ?"
  6639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6640. } else {
  6641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6643. }
  6644. } else {
  6645. if cost_type > 0 {
  6646. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6647. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6648. } else {
  6649. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6650. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6651. }
  6652. }
  6653. } else {
  6654. if execution_state > 0 {
  6655. if cost_type > 0 {
  6656. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6658. } else {
  6659. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6661. }
  6662. } else {
  6663. if cost_type > 0 {
  6664. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6666. } else {
  6667. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6668. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6669. }
  6670. }
  6671. }
  6672. }
  6673. } else if adviceType == 3 {
  6674. if patientType == 0 {
  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 = 3 AND record_date = ? 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 = 3 AND record_date = ? 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 = 3 AND record_date = ? 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 = 3 AND record_date = ? 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 = 3 AND record_date = ? 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 = 3 AND record_date = ? 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 = 3 AND record_date = ? 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 = 3 AND record_date = ? "
  6708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6709. }
  6710. }
  6711. }
  6712. } else if patientType == 1 {
  6713. if patient_id > 0 {
  6714. if execution_state > 0 {
  6715. if cost_type > 0 {
  6716. 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 = ?"
  6717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6718. } else {
  6719. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6720. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6721. }
  6722. } else {
  6723. if cost_type > 0 {
  6724. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6725. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6726. } else {
  6727. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6728. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6729. }
  6730. }
  6731. } else {
  6732. if execution_state > 0 {
  6733. if cost_type > 0 {
  6734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6736. } else {
  6737. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6739. }
  6740. } else {
  6741. if cost_type > 0 {
  6742. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6744. } else {
  6745. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6747. }
  6748. }
  6749. }
  6750. } else if patientType == 2 {
  6751. if patient_id > 0 {
  6752. if execution_state > 0 {
  6753. if cost_type > 0 {
  6754. 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 = ?"
  6755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6756. } else {
  6757. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6759. }
  6760. } else {
  6761. if cost_type > 0 {
  6762. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6763. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6764. } else {
  6765. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6766. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6767. }
  6768. }
  6769. } else {
  6770. if execution_state > 0 {
  6771. if cost_type > 0 {
  6772. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6774. } else {
  6775. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6776. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6777. }
  6778. } else {
  6779. if cost_type > 0 {
  6780. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6782. } else {
  6783. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6785. }
  6786. }
  6787. }
  6788. }
  6789. } else if adviceType == 2 && len(deliverWay) > 0 {
  6790. if patientType == 0 {
  6791. if patient_id > 0 {
  6792. if execution_state > 0 {
  6793. if cost_type > 0 {
  6794. 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 = ?"
  6795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6796. } else {
  6797. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6798. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6799. }
  6800. } else {
  6801. if cost_type > 0 {
  6802. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6804. } else {
  6805. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6806. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, 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 advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6814. } else {
  6815. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6816. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6817. }
  6818. } else {
  6819. if cost_type > 0 {
  6820. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6822. } else {
  6823. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6825. }
  6826. }
  6827. }
  6828. } else if patientType == 1 {
  6829. if patient_id > 0 {
  6830. if execution_state > 0 {
  6831. if cost_type > 0 {
  6832. 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 = ?"
  6833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6834. } else {
  6835. 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 = ?"
  6836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6837. }
  6838. } else {
  6839. if cost_type > 0 {
  6840. 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 = ?"
  6841. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6842. } else {
  6843. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6844. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6845. }
  6846. }
  6847. } else {
  6848. if execution_state > 0 {
  6849. if cost_type > 0 {
  6850. 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 = ?"
  6851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6852. } else {
  6853. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6855. }
  6856. } else {
  6857. if cost_type > 0 {
  6858. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6860. } else {
  6861. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6863. }
  6864. }
  6865. }
  6866. } else if patientType == 2 {
  6867. if patient_id > 0 {
  6868. if execution_state > 0 {
  6869. if cost_type > 0 {
  6870. 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 = ?"
  6871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6872. } else {
  6873. 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 = ?"
  6874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6875. }
  6876. } else {
  6877. if cost_type > 0 {
  6878. 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 = ?"
  6879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6880. } else {
  6881. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6883. }
  6884. }
  6885. } else {
  6886. if execution_state > 0 {
  6887. if cost_type > 0 {
  6888. 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 = ?"
  6889. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6890. } else {
  6891. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6892. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6893. }
  6894. } else {
  6895. if cost_type > 0 {
  6896. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6897. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6898. } else {
  6899. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6900. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6901. }
  6902. }
  6903. }
  6904. }
  6905. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6906. if patientType == 0 {
  6907. if patient_id > 0 {
  6908. if execution_state > 0 {
  6909. if cost_type > 0 {
  6910. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6912. } else {
  6913. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  6914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6915. }
  6916. } else {
  6917. if cost_type > 0 {
  6918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6920. } else {
  6921. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, 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 advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6929. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6930. } else {
  6931. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6933. }
  6934. } else {
  6935. if cost_type > 0 {
  6936. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  6937. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6938. } else {
  6939. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6941. }
  6942. }
  6943. }
  6944. } else if patientType == 1 {
  6945. if patient_id > 0 {
  6946. if execution_state > 0 {
  6947. if cost_type > 0 {
  6948. 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 = ?"
  6949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6950. } else {
  6951. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6952. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6953. }
  6954. } else {
  6955. if cost_type > 0 {
  6956. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6958. } else {
  6959. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6961. }
  6962. }
  6963. } else {
  6964. if execution_state > 0 {
  6965. if cost_type > 0 {
  6966. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6968. } else {
  6969. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6971. }
  6972. } else {
  6973. if cost_type > 0 {
  6974. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6975. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6976. } else {
  6977. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6979. }
  6980. }
  6981. }
  6982. } else if patientType == 2 {
  6983. if patient_id > 0 {
  6984. if execution_state > 0 {
  6985. if cost_type > 0 {
  6986. 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 = ?"
  6987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6988. } else {
  6989. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6991. }
  6992. } else {
  6993. if cost_type > 0 {
  6994. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6996. } else {
  6997. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6999. }
  7000. }
  7001. } else {
  7002. if execution_state > 0 {
  7003. if cost_type > 0 {
  7004. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7006. } else {
  7007. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7009. }
  7010. } else {
  7011. if cost_type > 0 {
  7012. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7013. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7014. } else {
  7015. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7016. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7017. }
  7018. }
  7019. }
  7020. }
  7021. }
  7022. db := readDb.Table("xt_schedule")
  7023. if scheduleType > 0 {
  7024. db = db.Where("schedule_type = ?", scheduleType)
  7025. }
  7026. if partitonType > 0 {
  7027. db = db.Where("partition_id = ?", partitonType)
  7028. }
  7029. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7030. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7031. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7032. }).
  7033. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7034. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7035. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7036. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7037. Preload("DoctorAdvices", adviceCondition...).
  7038. Where("status = 1 AND user_org_id = ?", orgID)
  7039. if scheduleDate != 0 {
  7040. db = db.Where("schedule_date = ?", scheduleDate)
  7041. }
  7042. err := db.Find(&vms).Error
  7043. return vms, err
  7044. }
  7045. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7046. order := models.XtDialysisOrder{}
  7047. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7048. return order, err
  7049. }
  7050. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7051. order := models.XtPatients{}
  7052. 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
  7053. 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
  7054. return err
  7055. }
  7056. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7057. order := models.BloodDialysisOrderCount{}
  7058. db := XTReadDB().Table("xt_dialysis_order as o")
  7059. 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
  7060. return order, err
  7061. }
  7062. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7063. order := models.BloodDialysisOrderCount{}
  7064. db := XTReadDB().Table("xt_dialysis_order as o")
  7065. 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
  7066. return order, err
  7067. }
  7068. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7069. order := models.DialysisOrder{}
  7070. 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
  7071. return order, err
  7072. }
  7073. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7074. information := models.DeviceInformation{}
  7075. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7076. return err
  7077. }
  7078. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7079. var record models.DoubleCheck
  7080. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7081. return record, err
  7082. }
  7083. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7084. record := models.MonitoringRecord{}
  7085. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7086. return record, err
  7087. }
  7088. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7089. record := models.MonitoringRecord{}
  7090. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7091. return record, err
  7092. }
  7093. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7094. record := models.MonitoringRecord{}
  7095. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7096. return record, err
  7097. }
  7098. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7099. record := models.MonitoringRecord{}
  7100. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7101. return record, err
  7102. }
  7103. 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) {
  7104. var vms []*HisMScheduleDoctorAdviceVM
  7105. if len(deliverWay) > 0 {
  7106. db := readDb.Table("xt_schedule")
  7107. if scheduleType > 0 {
  7108. db = db.Where("schedule_type = ?", scheduleType)
  7109. }
  7110. if partitionType > 0 {
  7111. db = db.Where("partition_id = ?", partitionType)
  7112. }
  7113. if patient_id > 0 {
  7114. if execution_state > 0 {
  7115. if cost_type > 0 {
  7116. if len(execution_frequency) > 0 {
  7117. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7118. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7119. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7120. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7121. 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).
  7122. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7123. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7124. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7125. Where("status = 1 AND user_org_id = ?", orgID)
  7126. if scheduleDate != 0 {
  7127. db = db.Where("schedule_date = ?", scheduleDate)
  7128. }
  7129. err = db.Find(&vms).Error
  7130. } else {
  7131. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7132. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7133. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7134. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7135. 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).
  7136. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7137. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7138. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7139. Where("status = 1 AND user_org_id = ?", orgID)
  7140. if scheduleDate != 0 {
  7141. db = db.Where("schedule_date = ?", scheduleDate)
  7142. }
  7143. err = db.Find(&vms).Error
  7144. }
  7145. } else {
  7146. if len(execution_frequency) > 0 {
  7147. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7148. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7149. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7150. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7151. 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).
  7152. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7153. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7154. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7155. Where("status = 1 AND user_org_id = ?", orgID)
  7156. if scheduleDate != 0 {
  7157. db = db.Where("schedule_date = ?", scheduleDate)
  7158. }
  7159. err = db.Find(&vms).Error
  7160. } else {
  7161. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7162. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7163. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7164. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7165. 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).
  7166. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7167. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7168. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7169. Where("status = 1 AND user_org_id = ?", orgID)
  7170. if scheduleDate != 0 {
  7171. db = db.Where("schedule_date = ?", scheduleDate)
  7172. }
  7173. err = db.Find(&vms).Error
  7174. }
  7175. }
  7176. } else {
  7177. if cost_type > 0 {
  7178. if len(execution_frequency) > 0 {
  7179. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7180. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7181. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7182. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7183. 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).
  7184. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7185. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7186. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7187. Where("status = 1 AND user_org_id = ?", orgID)
  7188. if scheduleDate != 0 {
  7189. db = db.Where("schedule_date = ?", scheduleDate)
  7190. }
  7191. err = db.Find(&vms).Error
  7192. } else {
  7193. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7194. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7195. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7196. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7197. 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).
  7198. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7199. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7200. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7201. Where("status = 1 AND user_org_id = ?", orgID)
  7202. if scheduleDate != 0 {
  7203. db = db.Where("schedule_date = ?", scheduleDate)
  7204. }
  7205. err = db.Find(&vms).Error
  7206. }
  7207. } else {
  7208. if len(execution_frequency) > 0 {
  7209. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7210. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7211. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7212. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7213. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, patient_id, execution_frequency).
  7214. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7215. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7216. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7217. Where("status = 1 AND user_org_id = ?", orgID)
  7218. if scheduleDate != 0 {
  7219. db = db.Where("schedule_date = ?", scheduleDate)
  7220. }
  7221. err = db.Find(&vms).Error
  7222. } else {
  7223. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7224. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7225. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7226. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7227. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7228. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7229. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7230. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7231. Where("status = 1 AND user_org_id = ?", orgID)
  7232. if scheduleDate != 0 {
  7233. db = db.Where("schedule_date = ?", scheduleDate)
  7234. }
  7235. err = db.Find(&vms).Error
  7236. }
  7237. }
  7238. }
  7239. } else {
  7240. if execution_state > 0 {
  7241. if cost_type > 0 {
  7242. if len(execution_frequency) > 0 {
  7243. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7244. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7245. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7246. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7247. 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).
  7248. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7249. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7250. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7251. Where("status = 1 AND user_org_id = ?", orgID)
  7252. if scheduleDate != 0 {
  7253. db = db.Where("schedule_date = ?", scheduleDate)
  7254. }
  7255. err = db.Find(&vms).Error
  7256. } else {
  7257. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7258. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7259. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7260. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7261. 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).
  7262. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7263. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7264. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7265. Where("status = 1 AND user_org_id = ?", orgID)
  7266. if scheduleDate != 0 {
  7267. db = db.Where("schedule_date = ?", scheduleDate)
  7268. }
  7269. err = db.Find(&vms).Error
  7270. }
  7271. } else {
  7272. if len(execution_frequency) > 0 {
  7273. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7274. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7275. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7276. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7277. 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).
  7278. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7279. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7280. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7281. Where("status = 1 AND user_org_id = ?", orgID)
  7282. if scheduleDate != 0 {
  7283. db = db.Where("schedule_date = ?", scheduleDate)
  7284. }
  7285. err = db.Find(&vms).Error
  7286. } else {
  7287. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7288. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7289. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7290. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7291. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7292. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7293. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7294. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7295. Where("status = 1 AND user_org_id = ?", orgID)
  7296. if scheduleDate != 0 {
  7297. db = db.Where("schedule_date = ?", scheduleDate)
  7298. }
  7299. err = db.Find(&vms).Error
  7300. }
  7301. }
  7302. } else {
  7303. if cost_type > 0 {
  7304. if len(execution_frequency) > 0 {
  7305. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7306. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7307. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7308. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7309. 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).
  7310. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7311. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7312. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7313. Where("status = 1 AND user_org_id = ?", orgID)
  7314. if scheduleDate != 0 {
  7315. db = db.Where("schedule_date = ?", scheduleDate)
  7316. }
  7317. err = db.Find(&vms).Error
  7318. } else {
  7319. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7320. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7321. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7322. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7323. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7324. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7325. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7326. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7327. Where("status = 1 AND user_org_id = ?", orgID)
  7328. if scheduleDate != 0 {
  7329. db = db.Where("schedule_date = ?", scheduleDate)
  7330. }
  7331. err = db.Find(&vms).Error
  7332. }
  7333. } else {
  7334. if len(execution_frequency) > 0 {
  7335. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7336. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7337. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7338. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7339. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7340. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7341. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7342. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7343. Where("status = 1 AND user_org_id = ?", orgID)
  7344. if scheduleDate != 0 {
  7345. db = db.Where("schedule_date = ?", scheduleDate)
  7346. }
  7347. err = db.Find(&vms).Error
  7348. } else {
  7349. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7350. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7351. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7352. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7353. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7354. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7355. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7356. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7357. Where("status = 1 AND user_org_id = ?", orgID)
  7358. if scheduleDate != 0 {
  7359. db = db.Where("schedule_date = ?", scheduleDate)
  7360. }
  7361. err = db.Find(&vms).Error
  7362. }
  7363. }
  7364. }
  7365. }
  7366. } else {
  7367. db := readDb.Table("xt_schedule")
  7368. if scheduleType > 0 {
  7369. db = db.Where("schedule_type = ?", scheduleType)
  7370. }
  7371. if partitionType > 0 {
  7372. db = db.Where("partition_id = ?", partitionType)
  7373. }
  7374. if patient_id > 0 {
  7375. if execution_state > 0 {
  7376. fmt.Println("execution_state---------------------", execution_state)
  7377. if cost_type > 0 {
  7378. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7379. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7380. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7381. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7382. 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).
  7383. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7384. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7385. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7386. Where("status = 1 AND user_org_id = ?", orgID)
  7387. if scheduleDate != 0 {
  7388. db = db.Where("schedule_date = ?", scheduleDate)
  7389. }
  7390. err = db.Find(&vms).Error
  7391. } else {
  7392. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7393. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7394. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7395. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7396. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7397. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7398. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7399. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7400. Where("status = 1 AND user_org_id = ?", orgID)
  7401. if scheduleDate != 0 {
  7402. db = db.Where("schedule_date = ?", scheduleDate)
  7403. }
  7404. err = db.Find(&vms).Error
  7405. }
  7406. } else {
  7407. if cost_type > 0 {
  7408. if len(execution_frequency) > 0 {
  7409. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7410. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7411. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7412. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7413. 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).
  7414. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7415. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7416. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7417. Where("status = 1 AND user_org_id = ?", orgID)
  7418. if scheduleDate != 0 {
  7419. db = db.Where("schedule_date = ?", scheduleDate)
  7420. }
  7421. err = db.Find(&vms).Error
  7422. } else {
  7423. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7424. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7425. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7426. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7427. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7428. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7429. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7430. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7431. Where("status = 1 AND user_org_id = ?", orgID)
  7432. if scheduleDate != 0 {
  7433. db = db.Where("schedule_date = ?", scheduleDate)
  7434. }
  7435. err = db.Find(&vms).Error
  7436. }
  7437. } else {
  7438. if len(execution_frequency) > 0 {
  7439. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7440. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7441. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7442. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7443. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7444. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7445. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7446. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7447. Where("status = 1 AND user_org_id = ?", orgID)
  7448. if scheduleDate != 0 {
  7449. db = db.Where("schedule_date = ?", scheduleDate)
  7450. }
  7451. err = db.Find(&vms).Error
  7452. } else {
  7453. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7454. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7455. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7456. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7457. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7458. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7459. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7460. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7461. Where("status = 1 AND user_org_id = ?", orgID)
  7462. if scheduleDate != 0 {
  7463. db = db.Where("schedule_date = ?", scheduleDate)
  7464. }
  7465. err = db.Find(&vms).Error
  7466. }
  7467. }
  7468. }
  7469. } else {
  7470. if execution_state > 0 {
  7471. if cost_type > 0 {
  7472. if len(execution_frequency) > 0 {
  7473. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7474. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7475. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7476. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7477. 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).
  7478. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7479. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7480. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7481. Where("status = 1 AND user_org_id = ?", orgID)
  7482. if scheduleDate != 0 {
  7483. db = db.Where("schedule_date = ?", scheduleDate)
  7484. }
  7485. err = db.Find(&vms).Error
  7486. } else {
  7487. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7488. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7489. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7490. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7491. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7492. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7493. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7494. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7495. Where("status = 1 AND user_org_id = ?", orgID)
  7496. if scheduleDate != 0 {
  7497. db = db.Where("schedule_date = ?", scheduleDate)
  7498. }
  7499. err = db.Find(&vms).Error
  7500. }
  7501. } else {
  7502. if len(execution_frequency) > 0 {
  7503. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7504. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7505. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7506. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7507. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7508. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7509. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7510. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7511. Where("status = 1 AND user_org_id = ?", orgID)
  7512. if scheduleDate != 0 {
  7513. db = db.Where("schedule_date = ?", scheduleDate)
  7514. }
  7515. err = db.Find(&vms).Error
  7516. } else {
  7517. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7518. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7519. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7520. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7521. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7522. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7523. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7524. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7525. Where("status = 1 AND user_org_id = ?", orgID)
  7526. if scheduleDate != 0 {
  7527. db = db.Where("schedule_date = ?", scheduleDate)
  7528. }
  7529. err = db.Find(&vms).Error
  7530. }
  7531. }
  7532. } else {
  7533. if cost_type > 0 {
  7534. if len(execution_frequency) > 0 {
  7535. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7536. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7537. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7538. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7539. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7540. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7541. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7542. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7543. Where("status = 1 AND user_org_id = ?", orgID)
  7544. if scheduleDate != 0 {
  7545. db = db.Where("schedule_date = ?", scheduleDate)
  7546. }
  7547. err = db.Find(&vms).Error
  7548. } else {
  7549. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7550. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7551. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7552. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7553. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7554. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7555. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7556. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7557. Where("status = 1 AND user_org_id = ?", orgID)
  7558. if scheduleDate != 0 {
  7559. db = db.Where("schedule_date = ?", scheduleDate)
  7560. }
  7561. err = db.Find(&vms).Error
  7562. }
  7563. } else {
  7564. if len(execution_frequency) > 0 {
  7565. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7566. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7567. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7568. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7569. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7570. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7571. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7572. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7573. Where("status = 1 AND user_org_id = ?", orgID)
  7574. if scheduleDate != 0 {
  7575. db = db.Where("schedule_date = ?", scheduleDate)
  7576. }
  7577. err = db.Find(&vms).Error
  7578. } else {
  7579. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7580. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7581. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7582. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7583. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7584. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7585. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7586. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7587. Where("status = 1 AND user_org_id = ?", orgID)
  7588. if scheduleDate != 0 {
  7589. db = db.Where("schedule_date = ?", scheduleDate)
  7590. }
  7591. err = db.Find(&vms).Error
  7592. }
  7593. }
  7594. }
  7595. }
  7596. }
  7597. return vms, err
  7598. }
  7599. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7600. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7601. return weight, err
  7602. }
  7603. 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) {
  7604. fmt.Println("deliverWay-----------------", deliverWay)
  7605. fmt.Println("execution_frequency------------------", execution_frequency)
  7606. fmt.Println("adviceType-----------------", adviceType)
  7607. fmt.Println("patientType----------------", patientType)
  7608. fmt.Println("patient_id----------------", patient_id)
  7609. fmt.Println("execution_state----------------", execution_state)
  7610. fmt.Println("cost_type---------------------", cost_type)
  7611. fmt.Println("execution_frequency", execution_frequency)
  7612. var vms []*MScheduleDoctorAdviceVM
  7613. adviceWhere := ""
  7614. keyword = "%" + keyword + "%"
  7615. adviceCondition := []interface{}{}
  7616. if adviceType == 1 {
  7617. if patientType == 0 {
  7618. if patient_id > 0 {
  7619. if execution_state > 0 {
  7620. if cost_type > 0 {
  7621. if len(execution_frequency) > 0 {
  7622. if len(keyword) > 0 {
  7623. if len(deliverWay) > 0 {
  7624. 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 ?"
  7625. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7626. } else {
  7627. 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 ?"
  7628. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7629. }
  7630. } else {
  7631. if len(deliverWay) > 0 {
  7632. 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 =?"
  7633. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7634. } else {
  7635. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7636. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7637. }
  7638. }
  7639. } else {
  7640. if len(keyword) > 0 {
  7641. if len(deliverWay) > 0 {
  7642. 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 =?"
  7643. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7644. } else {
  7645. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7646. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7647. }
  7648. } else {
  7649. if len(deliverWay) > 0 {
  7650. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7651. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7652. } else {
  7653. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7654. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7655. }
  7656. }
  7657. }
  7658. } else {
  7659. if len(execution_frequency) > 0 {
  7660. if len(keyword) > 0 {
  7661. if len(deliverWay) > 0 {
  7662. 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 =?"
  7663. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7664. } else {
  7665. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7666. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7667. }
  7668. } else {
  7669. if len(deliverWay) > 0 {
  7670. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7671. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7672. } else {
  7673. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7674. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7675. }
  7676. }
  7677. } else {
  7678. if len(keyword) > 0 {
  7679. if len(deliverWay) > 0 {
  7680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7681. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7682. } else {
  7683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7684. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7685. }
  7686. } else {
  7687. if len(deliverWay) > 0 {
  7688. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7689. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7690. } else {
  7691. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7692. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7693. }
  7694. }
  7695. }
  7696. }
  7697. } else {
  7698. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7703. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7704. } else {
  7705. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7706. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and execution_frequency = ? and delivery_way =?"
  7711. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7712. } else {
  7713. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7714. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and advice_name like ? and delivery_way =?"
  7721. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7722. } else {
  7723. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7724. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and delivery_way =?"
  7729. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7730. } else {
  7731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7732. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7733. }
  7734. }
  7735. }
  7736. } else {
  7737. if len(execution_frequency) > 0 {
  7738. if len(keyword) > 0 {
  7739. if len(deliverWay) > 0 {
  7740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7741. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7742. } else {
  7743. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7744. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7745. }
  7746. } else {
  7747. if len(deliverWay) > 0 {
  7748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7749. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7750. } else {
  7751. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7752. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7753. }
  7754. }
  7755. } else {
  7756. if len(keyword) > 0 {
  7757. if len(deliverWay) > 0 {
  7758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7759. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7760. } else {
  7761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7762. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7763. }
  7764. } else {
  7765. if len(deliverWay) > 0 {
  7766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7767. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7768. } else {
  7769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7770. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7771. }
  7772. }
  7773. }
  7774. }
  7775. }
  7776. } else {
  7777. if execution_state > 0 {
  7778. if cost_type > 0 {
  7779. if len(execution_frequency) > 0 {
  7780. if len(keyword) > 0 {
  7781. if len(deliverWay) > 0 {
  7782. 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 =?"
  7783. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7784. } else {
  7785. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7786. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7787. }
  7788. } else {
  7789. if len(deliverWay) > 0 {
  7790. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7791. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7792. } else {
  7793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7794. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7795. }
  7796. }
  7797. } else {
  7798. if len(keyword) > 0 {
  7799. if len(deliverWay) > 0 {
  7800. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7801. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7802. } else {
  7803. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7804. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7805. }
  7806. } else {
  7807. if len(deliverWay) > 0 {
  7808. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7809. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7810. } else {
  7811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7812. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7813. }
  7814. }
  7815. }
  7816. } else {
  7817. if len(execution_frequency) > 0 {
  7818. if len(keyword) > 0 {
  7819. if len(deliverWay) > 0 {
  7820. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7821. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7822. } else {
  7823. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7824. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7825. }
  7826. } else {
  7827. if len(deliverWay) > 0 {
  7828. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7829. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7830. } else {
  7831. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7832. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7833. }
  7834. }
  7835. } else {
  7836. if len(keyword) > 0 {
  7837. if len(deliverWay) > 0 {
  7838. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7839. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7840. } else {
  7841. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7842. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7843. }
  7844. } else {
  7845. if len(deliverWay) > 0 {
  7846. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7847. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7848. } else {
  7849. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7850. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7851. }
  7852. }
  7853. }
  7854. }
  7855. } else {
  7856. if cost_type > 0 {
  7857. if len(keyword) > 0 {
  7858. if len(deliverWay) > 0 {
  7859. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7860. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7861. } else {
  7862. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7863. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7864. }
  7865. } else {
  7866. if len(deliverWay) > 0 {
  7867. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7868. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7869. } else {
  7870. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7871. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7872. }
  7873. }
  7874. } else {
  7875. if len(keyword) > 0 {
  7876. if len(deliverWay) > 0 {
  7877. if len(execution_frequency) > 0 {
  7878. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7879. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7880. } else {
  7881. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7882. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7883. }
  7884. } else {
  7885. if len(execution_frequency) > 0 {
  7886. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7887. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7888. } else {
  7889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7890. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7891. }
  7892. }
  7893. } else {
  7894. if len(deliverWay) > 0 {
  7895. if len(execution_frequency) > 0 {
  7896. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7897. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7898. } else {
  7899. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7900. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7901. }
  7902. } else {
  7903. if len(execution_frequency) > 0 {
  7904. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7905. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7906. } else {
  7907. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7908. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7909. }
  7910. }
  7911. }
  7912. }
  7913. }
  7914. }
  7915. } else if patientType == 1 {
  7916. if patient_id > 0 {
  7917. if execution_state > 0 {
  7918. if cost_type > 0 {
  7919. if len(execution_frequency) > 0 {
  7920. if len(keyword) > 0 {
  7921. if len(deliverWay) > 0 {
  7922. 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 =?"
  7923. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7924. } else {
  7925. 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 ?"
  7926. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7927. }
  7928. } else {
  7929. if len(keyword) > 0 {
  7930. if len(deliverWay) > 0 {
  7931. 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 =?"
  7932. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7933. }
  7934. } else {
  7935. if len(deliverWay) > 0 {
  7936. 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 =?"
  7937. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7938. } else {
  7939. 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 = ?"
  7940. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  7941. }
  7942. }
  7943. }
  7944. } else {
  7945. if len(keyword) > 0 {
  7946. if len(deliverWay) > 0 {
  7947. 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 =?"
  7948. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  7949. } else {
  7950. 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 ?"
  7951. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  7952. }
  7953. } else {
  7954. if len(deliverWay) > 0 {
  7955. 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 =?"
  7956. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  7957. } else {
  7958. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7959. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  7960. }
  7961. }
  7962. }
  7963. } else {
  7964. if len(execution_frequency) > 0 {
  7965. if len(keyword) > 0 {
  7966. if len(deliverWay) > 0 {
  7967. 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 =?"
  7968. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7969. } else {
  7970. 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 ?"
  7971. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  7972. }
  7973. } else {
  7974. if len(deliverWay) > 0 {
  7975. 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 =?"
  7976. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  7977. } else {
  7978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7979. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  7980. }
  7981. }
  7982. } else {
  7983. if len(keyword) > 0 {
  7984. if len(deliverWay) > 0 {
  7985. 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 =?"
  7986. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  7987. } else {
  7988. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  7989. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  7990. }
  7991. } else {
  7992. if len(deliverWay) > 0 {
  7993. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  7994. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  7995. } else {
  7996. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7997. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  7998. }
  7999. }
  8000. }
  8001. }
  8002. } else {
  8003. if cost_type > 0 {
  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 is_settle = ?and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8008. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, 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 is_settle = ?and execution_frequency = ? and advice_name like ?"
  8011. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, 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 is_settle = ?and execution_frequency = ? and delivery_way =?"
  8016. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8017. } else {
  8018. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8019. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, 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 is_settle = ? and advice_name like ? and delivery_way =?"
  8026. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8027. } else {
  8028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8029. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, 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 is_settle = ? and delivery_way =? "
  8034. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8035. } else {
  8036. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8037. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8038. }
  8039. }
  8040. }
  8041. } else {
  8042. if len(execution_frequency) > 0 {
  8043. if len(keyword) > 0 {
  8044. if len(deliverWay) > 0 {
  8045. 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 =? "
  8046. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8047. } else {
  8048. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8049. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8050. }
  8051. } else {
  8052. if len(deliverWay) > 0 {
  8053. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8054. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8055. } else {
  8056. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8057. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8058. }
  8059. }
  8060. } else {
  8061. if len(keyword) > 0 {
  8062. if len(deliverWay) > 0 {
  8063. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8064. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8065. } else {
  8066. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8067. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8068. }
  8069. } else {
  8070. if len(deliverWay) > 0 {
  8071. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8072. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8073. } else {
  8074. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8075. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8076. }
  8077. }
  8078. }
  8079. }
  8080. }
  8081. } else {
  8082. if execution_state > 0 {
  8083. if cost_type > 0 {
  8084. if len(execution_frequency) > 0 {
  8085. if len(keyword) > 0 {
  8086. if len(deliverWay) > 0 {
  8087. 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 =?"
  8088. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8089. } else {
  8090. 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 ?"
  8091. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8092. }
  8093. } else {
  8094. if len(deliverWay) > 0 {
  8095. 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 =?"
  8096. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8097. } else {
  8098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8099. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8100. }
  8101. }
  8102. } else {
  8103. if len(keyword) > 0 {
  8104. if len(deliverWay) > 0 {
  8105. 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 =?"
  8106. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8107. } else {
  8108. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8109. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8110. }
  8111. } else {
  8112. if len(deliverWay) > 0 {
  8113. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8114. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8115. } else {
  8116. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8117. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8118. }
  8119. }
  8120. }
  8121. } else {
  8122. if len(execution_frequency) > 0 {
  8123. if len(keyword) > 0 {
  8124. if len(deliverWay) > 0 {
  8125. 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 =?"
  8126. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8127. } else {
  8128. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8129. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8130. }
  8131. } else {
  8132. if len(deliverWay) > 0 {
  8133. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8134. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8135. } else {
  8136. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8137. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8138. }
  8139. }
  8140. } else {
  8141. if len(keyword) > 0 {
  8142. if len(deliverWay) > 0 {
  8143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8144. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8145. } else {
  8146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8147. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8148. }
  8149. } else {
  8150. if len(deliverWay) > 0 {
  8151. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8152. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8153. } else {
  8154. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8155. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8156. }
  8157. }
  8158. }
  8159. }
  8160. } else {
  8161. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8166. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8167. } else {
  8168. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8169. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, 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 is_settle = ? and execution_frequency = ? and delivery_way =?"
  8174. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8175. } else {
  8176. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8177. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, 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 is_settle = ? and advice_name like ? and delivery_way =?"
  8184. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8185. } else {
  8186. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8187. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, 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 is_settle = ? and delivery_way =?"
  8192. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8193. } else {
  8194. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8195. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8196. }
  8197. }
  8198. }
  8199. } else {
  8200. if len(execution_frequency) > 0 {
  8201. if len(keyword) > 0 {
  8202. if len(deliverWay) > 0 {
  8203. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8204. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8205. } else {
  8206. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8207. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8208. }
  8209. } else {
  8210. if len(deliverWay) > 0 {
  8211. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8212. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8213. } else {
  8214. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8215. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8216. }
  8217. }
  8218. } else {
  8219. if len(keyword) > 0 {
  8220. if len(deliverWay) > 0 {
  8221. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8222. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8223. } else {
  8224. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8225. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8226. }
  8227. } else {
  8228. if len(deliverWay) > 0 {
  8229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8230. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8231. } else {
  8232. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8233. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8234. }
  8235. }
  8236. }
  8237. }
  8238. }
  8239. }
  8240. } else if patientType == 2 {
  8241. if patient_id > 0 {
  8242. if execution_state > 0 {
  8243. if cost_type > 0 {
  8244. if len(execution_frequency) > 0 {
  8245. if len(keyword) > 0 {
  8246. if len(deliverWay) > 0 {
  8247. 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 =?"
  8248. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8249. } else {
  8250. 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 ?"
  8251. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8252. }
  8253. } else {
  8254. if len(deliverWay) > 0 {
  8255. 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 =?"
  8256. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8257. } else {
  8258. 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 = ?"
  8259. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8260. }
  8261. }
  8262. } else {
  8263. if len(keyword) > 0 {
  8264. if len(deliverWay) > 0 {
  8265. 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 =?"
  8266. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8267. } else {
  8268. 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 ?"
  8269. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8270. }
  8271. } else {
  8272. if len(deliverWay) > 0 {
  8273. 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 =?"
  8274. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8275. } else {
  8276. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8277. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8278. }
  8279. }
  8280. }
  8281. } else {
  8282. if len(execution_frequency) > 0 {
  8283. if len(keyword) > 0 {
  8284. if len(deliverWay) > 0 {
  8285. 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 =?"
  8286. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8287. } else {
  8288. 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 ?"
  8289. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8290. }
  8291. } else {
  8292. if len(deliverWay) > 0 {
  8293. 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 =?"
  8294. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8295. } else {
  8296. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8297. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8298. }
  8299. }
  8300. } else {
  8301. if len(keyword) > 0 {
  8302. if len(deliverWay) > 0 {
  8303. 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 =?"
  8304. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8305. } else {
  8306. 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 ?"
  8307. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8308. }
  8309. } else {
  8310. if len(deliverWay) > 0 {
  8311. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8312. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8313. } else {
  8314. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8315. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8316. }
  8317. }
  8318. }
  8319. }
  8320. } else {
  8321. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8326. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and execution_frequency = ? and advice_name like ?"
  8329. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and execution_frequency = ? and delivery_way =?"
  8334. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and execution_frequency = ?"
  8337. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and advice_name like ? and delivery_way =?"
  8344. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8345. } else {
  8346. 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 ?"
  8347. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, 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 is_settle = ? and delivery_way =?"
  8352. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8353. } else {
  8354. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8355. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8356. }
  8357. }
  8358. }
  8359. } else {
  8360. if len(execution_frequency) > 0 {
  8361. if len(keyword) > 0 {
  8362. if len(deliverWay) > 0 {
  8363. 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 =?"
  8364. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8365. } else {
  8366. 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 ?"
  8367. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8368. }
  8369. } else {
  8370. if len(deliverWay) > 0 {
  8371. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8372. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8373. } else {
  8374. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8375. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8376. }
  8377. }
  8378. } else {
  8379. if len(keyword) > 0 {
  8380. if len(deliverWay) > 0 {
  8381. 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 =?"
  8382. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8383. } else {
  8384. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8385. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8386. }
  8387. } else {
  8388. if len(deliverWay) > 0 {
  8389. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8390. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8391. } else {
  8392. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8393. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8394. }
  8395. }
  8396. }
  8397. }
  8398. }
  8399. } else {
  8400. if execution_state > 0 {
  8401. if cost_type > 0 {
  8402. if len(execution_frequency) > 0 {
  8403. if len(keyword) > 0 {
  8404. if len(deliverWay) > 0 {
  8405. 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 =?"
  8406. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8407. } else {
  8408. 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 ?"
  8409. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8410. }
  8411. } else {
  8412. if len(deliverWay) > 0 {
  8413. 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 =?"
  8414. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8415. } else {
  8416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8417. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8418. }
  8419. }
  8420. } else {
  8421. if len(keyword) > 0 {
  8422. if len(deliverWay) > 0 {
  8423. 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 =?"
  8424. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8425. } else {
  8426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8427. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8428. }
  8429. } else {
  8430. if len(deliverWay) > 0 {
  8431. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8432. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8433. } else {
  8434. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8435. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8436. }
  8437. }
  8438. }
  8439. } else {
  8440. if len(execution_frequency) > 0 {
  8441. if len(keyword) > 0 {
  8442. if len(deliverWay) > 0 {
  8443. 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 =?"
  8444. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8445. } else {
  8446. 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 ?"
  8447. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8448. }
  8449. } else {
  8450. if len(deliverWay) > 0 {
  8451. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8452. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8453. } else {
  8454. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8455. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8456. }
  8457. }
  8458. } else {
  8459. if len(keyword) > 0 {
  8460. if len(deliverWay) > 0 {
  8461. 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 =?"
  8462. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8463. } else {
  8464. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8465. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8466. }
  8467. } else {
  8468. if len(deliverWay) > 0 {
  8469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8470. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8471. } else {
  8472. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8473. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8474. }
  8475. }
  8476. }
  8477. }
  8478. } else {
  8479. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8484. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8485. } else {
  8486. 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 ?"
  8487. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, 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 is_settle = ? and execution_frequency = ? and delivery_way =?"
  8492. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8493. } else {
  8494. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8495. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, 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 is_settle = ? and advice_name like ? and delivery_way =?"
  8502. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8503. } else {
  8504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8505. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, 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 is_settle = ? and delivery_way =?"
  8510. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8511. } else {
  8512. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8513. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8514. }
  8515. }
  8516. }
  8517. } else {
  8518. if len(execution_frequency) > 0 {
  8519. if len(keyword) > 0 {
  8520. if len(deliverWay) > 0 {
  8521. 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 =?"
  8522. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8523. } else {
  8524. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8525. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8526. }
  8527. } else {
  8528. if len(deliverWay) > 0 {
  8529. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8530. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8531. } else {
  8532. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8533. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8534. }
  8535. }
  8536. } else {
  8537. if len(keyword) > 0 {
  8538. if len(deliverWay) > 0 {
  8539. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8540. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8541. } else {
  8542. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8543. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8544. }
  8545. } else {
  8546. if len(deliverWay) > 0 {
  8547. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8548. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8549. } else {
  8550. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8551. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8552. }
  8553. }
  8554. }
  8555. }
  8556. }
  8557. }
  8558. }
  8559. }
  8560. db := readDb.Table("xt_schedule")
  8561. if scheduleType > 0 {
  8562. db = db.Where("schedule_type = ?", scheduleType)
  8563. }
  8564. if partitonType > 0 {
  8565. db = db.Where("partition_id = ?", partitonType)
  8566. }
  8567. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8568. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8569. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8570. }).
  8571. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8572. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8573. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8574. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8575. Preload("DoctorAdvices", adviceCondition...).
  8576. Where("status = 1 AND user_org_id = ?", orgID)
  8577. if scheduleDate != 0 {
  8578. db = db.Where("schedule_date = ?", scheduleDate)
  8579. }
  8580. err := db.Find(&vms).Error
  8581. return vms, err
  8582. }
  8583. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8584. treatmentAsses := models.ReceiveTreatmentAsses{}
  8585. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8586. return treatmentAsses, err
  8587. }