mobile_dialysis_service.go 530KB

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