mobile_dialysis_service.go 540KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "XT_New/models"
  8. "github.com/jinzhu/gorm"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. //err := db.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  38. // return db.Order("dialysis_date desc").Where(" status = 1 AND user_org_id = ? and dialysis_date>=1672502400 && dialysis_date < ?", orgID, scheduleDate)
  39. //}).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  40. return vms, err
  41. }
  42. func GetMonitDialysisOrder(user_org_id int64, patient_id int64, scheduleDate int64) (*models.MDialysisOrderForList, error) {
  43. order := models.MDialysisOrderForList{}
  44. err := XTReadDB().Where("user_org_id = ? and status =1 and patient_id = ?", user_org_id, patient_id).Order("id desc").Last(&order).Error
  45. return &order, err
  46. }
  47. func GetMonitDialysisSolution(user_org_id int64, patient_id int64, mode_id int64) (*models.DialysisSolution, error) {
  48. solution := models.DialysisSolution{}
  49. err := XTReadDB().Where("user_org_id = ? and patient_id =? and solution_status = 1 and mode_id = ? and status=1", user_org_id, patient_id, mode_id).Find(&solution).Error
  50. return &solution, err
  51. }
  52. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  53. var vms []*MDialysisScheduleVM
  54. db := readDb.
  55. Table("xt_schedule as sch").
  56. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  60. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  61. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  62. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  63. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  64. Preload("TreatmentMode", "status = 1").
  65. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  66. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  67. if scheduleDate != 0 {
  68. db = db.Where("schedule_date = ?", scheduleDate)
  69. }
  70. err := db.Find(&vms).Error
  71. return vms, err
  72. }
  73. type VMTreatmentSummary struct {
  74. ID int64 `gorm:"column:id" json:"id"`
  75. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  77. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  78. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  79. }
  80. func (VMTreatmentSummary) TableName() string {
  81. return "xt_treatment_summary"
  82. }
  83. type AssessmentAfterDislysis struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  88. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  89. Status int64 `gorm:"column:status" json:"status"`
  90. }
  91. func (AssessmentAfterDislysis) TableName() string {
  92. return "xt_assessment_after_dislysis"
  93. }
  94. type MDialysisScheduleVM struct {
  95. ID int64 `gorm:"column:id" json:"id"`
  96. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  97. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  98. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  99. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  100. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  101. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  102. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  103. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  104. Status int64 `gorm:"column:status" json:"status"`
  105. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  106. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  107. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  108. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  109. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  110. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  111. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  112. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  113. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  114. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  115. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  116. }
  117. func (MDialysisScheduleVM) TableName() string {
  118. return "xt_schedule"
  119. }
  120. type MDialysisScheduleVMForList struct {
  121. ID int64 `gorm:"column:id" json:"id"`
  122. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  123. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  124. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  125. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  126. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  127. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  128. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  129. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  130. Status int64 `gorm:"column:status" json:"status"`
  131. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  132. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  133. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  134. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  135. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  136. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  137. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  138. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  139. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  140. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  141. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  142. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  143. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  144. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  145. }
  146. func (MDialysisScheduleVMForList) TableName() string {
  147. return "xt_schedule"
  148. }
  149. type MDeviceNumberVM struct {
  150. models.DeviceNumber
  151. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  152. }
  153. func (MDeviceNumberVM) TableName() string {
  154. return "xt_device_number"
  155. }
  156. type MSchedualPatientVMList struct {
  157. ID int64 `gorm:"column:id" json:"id" form:"id"`
  158. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  159. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  160. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  161. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  162. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  163. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  164. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  165. Age int64 `gorm:"column:age" json:"age"`
  166. Name string `gorm:"column:name" json:"name" form:"name"`
  167. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  168. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  169. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  170. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  171. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  172. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  173. }
  174. func (MSchedualPatientVMList) TableName() string {
  175. return "xt_patients"
  176. }
  177. type MSchedualPatientVM struct {
  178. ID int64 `gorm:"column:id" json:"id" form:"id"`
  179. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  180. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  181. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  182. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  183. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  184. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  185. Source int64 `gorm:"column:source" json:"source" form:"source"`
  186. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  187. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  188. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  189. Name string `gorm:"column:name" json:"name" form:"name"`
  190. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  191. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  192. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  193. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  194. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  195. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  196. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  197. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  198. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  199. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  200. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  201. Height int64 `gorm:"column:height" json:"height" form:"height"`
  202. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  203. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  204. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  205. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  206. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  207. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  208. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  209. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  210. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  211. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  212. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  213. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  214. Children int64 `gorm:"column:children" json:"children" form:"children"`
  215. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  216. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  217. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  218. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  219. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  220. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  221. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  222. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  223. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  224. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  225. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  226. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  227. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  228. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  229. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  230. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  231. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  232. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  233. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  234. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  235. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  236. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  237. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  238. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  239. Status int64 `gorm:"column:status" json:"status" form:"status"`
  240. Age int64 `gorm:"column:age" json:"age"`
  241. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  242. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  243. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  244. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  245. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  246. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  247. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  248. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  249. }
  250. func (MSchedualPatientVM) TableName() string {
  251. return "xt_patients"
  252. }
  253. type MDialysisOrderVM struct {
  254. ID int64 `gorm:"column:id" json:"id"`
  255. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  256. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  257. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  258. Stage int64 `gorm:"column:stage" json:"stage"`
  259. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  260. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  261. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  262. Status int64 `gorm:"column:status" json:"status"`
  263. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  264. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  265. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  266. Creator int64 `gorm:"column:creator" json:"creator"`
  267. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  268. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  269. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  270. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  271. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  272. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  273. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  274. }
  275. func (MDialysisOrderVM) TableName() string {
  276. return "xt_dialysis_order"
  277. }
  278. type MDialysisOrderVMList struct {
  279. ID int64 `gorm:"column:id" json:"id"`
  280. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  281. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  282. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  283. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  284. Stage int64 `gorm:"column:stage" json:"stage"`
  285. // Remark string `gorm:"column:remark" json:"remark"`
  286. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  287. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  288. Status int64 `gorm:"column:status" json:"status"`
  289. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  290. Creator int64 `gorm:"column:creator" json:"creator"`
  291. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  292. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  293. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  294. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  295. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  296. }
  297. func (MDialysisOrderVMList) TableName() string {
  298. return "xt_dialysis_order"
  299. }
  300. type VMDoctorAdvice struct {
  301. ID int64 `gorm:"column:id" json:"id" form:"id"`
  302. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  303. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  304. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  305. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  306. Status int64 `gorm:"column:status" json:"status" form:"status"`
  307. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  308. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  309. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  310. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  311. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  312. }
  313. func (VMDoctorAdvice) TableName() string {
  314. return "xt_doctor_advice"
  315. }
  316. type VMHisDoctorAdviceInfo struct {
  317. ID int64 `gorm:"column:id" json:"id" form:"id"`
  318. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  319. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  320. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  321. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  322. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  323. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  324. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  325. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  326. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  327. }
  328. func (VMHisDoctorAdviceInfo) TableName() string {
  329. return "his_doctor_advice_info"
  330. }
  331. type VMAssessmentAfterDislysis struct {
  332. ID int64 `gorm:"column:id" json:"id"`
  333. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  334. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  335. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  336. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  337. Status int64 `gorm:"column:status" json:"status"`
  338. }
  339. func (VMAssessmentAfterDislysis) TableName() string {
  340. return "xt_assessment_after_dislysis"
  341. }
  342. type NewDeviceInformation struct {
  343. ID int64 `gorm:"column:id" json:"id" form:"id"`
  344. Date int64 `gorm:"column:date" json:"date" form:"date"`
  345. Class int64 `gorm:"column:class" json:"class" form:"class"`
  346. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  347. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  348. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  349. Status int64 `gorm:"column:status" json:"status" form:"status"`
  350. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  351. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  352. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  353. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  354. }
  355. func (NewDeviceInformation) TableName() string {
  356. return "xt_device_information"
  357. }
  358. // 获取透析记录
  359. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  360. var record models.DialysisOrder
  361. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  362. if err != nil {
  363. if err == gorm.ErrRecordNotFound {
  364. return nil, nil
  365. } else {
  366. return nil, err
  367. }
  368. }
  369. return &record, nil
  370. }
  371. // 用户基本信息
  372. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  373. var patient MPatient
  374. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  375. //if err != nil {
  376. // if err == gorm.ErrRecordNotFound {
  377. // return nil, nil
  378. // } else {
  379. // return nil, err
  380. // }
  381. //}
  382. //return &patient, nil
  383. redis := RedisClient()
  384. defer redis.Close()
  385. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  386. patient_info_str, _ := redis.Get(key).Result()
  387. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  388. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  389. if err != nil {
  390. if err == gorm.ErrRecordNotFound {
  391. return &patient, nil
  392. } else {
  393. return &patient, err
  394. }
  395. } else {
  396. if patient.ID > 0 {
  397. //缓存数据
  398. patient_info_json, err := json.Marshal(&patient)
  399. if err == nil {
  400. redis.Set(key, patient_info_json, time.Second*60*60*18)
  401. }
  402. }
  403. return &patient, nil
  404. }
  405. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  406. json.Unmarshal([]byte(patient_info_str), &patient)
  407. return &patient, nil
  408. }
  409. }
  410. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  411. var vm MDialysisScheduleVM
  412. err := readDb.
  413. Table("xt_schedule").
  414. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  415. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  416. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  417. First(&vm).Error
  418. return &vm, err
  419. }
  420. // 用户排班信息
  421. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  422. var vm MDialysisScheduleVM
  423. err := readDb.
  424. Table("xt_schedule").
  425. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  426. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  427. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  428. First(&vm).Error
  429. if err != nil {
  430. if err == gorm.ErrRecordNotFound {
  431. return nil, nil
  432. } else {
  433. return nil, err
  434. }
  435. }
  436. return &vm, err
  437. }
  438. // 用户排班信息
  439. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  440. redis := RedisClient()
  441. defer redis.Close()
  442. var vm MDialysisScheduleVM
  443. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  444. redis.Set(key, "", time.Second)
  445. schedual_detail_str, _ := redis.Get(key).Result()
  446. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  447. err := readDb.
  448. Table("xt_schedule").
  449. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  450. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  451. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  452. First(&vm).Error
  453. if err != nil {
  454. if err == gorm.ErrRecordNotFound {
  455. return nil, nil
  456. } else {
  457. return nil, err
  458. }
  459. } else {
  460. if vm.ID > 0 {
  461. //缓存数据
  462. schedual_detail_str, err := json.Marshal(vm)
  463. if err == nil {
  464. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  465. }
  466. } else {
  467. redis.Set(key, "null", time.Second*60*60*18)
  468. }
  469. return &vm, nil
  470. }
  471. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  472. if schedual_detail_str == "null" {
  473. return &vm, nil
  474. }
  475. json.Unmarshal([]byte(schedual_detail_str), &vm)
  476. return &vm, nil
  477. }
  478. }
  479. // 用户排班信息
  480. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  481. var schedule models.Schedule
  482. err := readDb.
  483. Table("xt_schedule").
  484. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  485. First(&schedule).Error
  486. if err != nil {
  487. if err == gorm.ErrRecordNotFound {
  488. return nil, nil
  489. } else {
  490. return nil, err
  491. }
  492. }
  493. return &schedule, nil
  494. }
  495. type MPatient struct {
  496. ID int64 `gorm:"column:id" json:"id" form:"id"`
  497. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  498. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  499. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  500. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  501. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  502. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  503. Source int64 `gorm:"column:source" json:"source" form:"source"`
  504. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  505. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  506. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  507. Name string `gorm:"column:name" json:"name" form:"name"`
  508. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  509. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  510. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  511. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  512. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  513. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  514. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  515. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  516. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  517. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  518. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  519. Height int64 `gorm:"column:height" json:"height" form:"height"`
  520. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  521. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  522. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  523. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  524. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  525. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  526. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  527. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  528. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  529. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  530. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  531. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  532. Children int64 `gorm:"column:children" json:"children" form:"children"`
  533. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  534. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  535. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  536. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  537. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  538. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  539. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  540. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  541. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  542. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  543. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  544. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  545. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  546. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  547. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  548. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  549. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  550. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  551. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  552. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  553. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  554. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  555. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  556. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  557. Status int64 `gorm:"column:status" json:"status" form:"status"`
  558. Age int64 `gorm:"column:age" json:"age"`
  559. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  560. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  561. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  562. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  563. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  564. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  565. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  566. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  567. }
  568. func (MPatient) TableName() string {
  569. return "xt_patients"
  570. }
  571. // 接诊评估
  572. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  573. var record models.ReceiveTreatmentAsses
  574. redis := RedisClient()
  575. defer redis.Close()
  576. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  577. receive_treatment_asses_str, _ := redis.Get(key).Result()
  578. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  579. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  580. if err != nil {
  581. if err == gorm.ErrRecordNotFound {
  582. if record.ID <= 0 {
  583. redis.Set(key, "", time.Second*60*60*18)
  584. }
  585. return nil, nil
  586. } else {
  587. return nil, err
  588. }
  589. } else {
  590. if record.ID > 0 {
  591. //缓存数据
  592. receive_treatment_asses_str, err := json.Marshal(record)
  593. if err == nil {
  594. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  595. }
  596. } else {
  597. redis.Set(key, "null", time.Second*60*60*18)
  598. }
  599. return &record, nil
  600. }
  601. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  602. if receive_treatment_asses_str == "null" {
  603. return &record, nil
  604. }
  605. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  606. return &record, nil
  607. }
  608. }
  609. // 透前评估
  610. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  611. var record models.PredialysisEvaluation
  612. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  613. if err != nil {
  614. if err == gorm.ErrRecordNotFound {
  615. return nil, nil
  616. } else {
  617. return nil, err
  618. }
  619. }
  620. return &record, nil
  621. }
  622. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  623. var record models.PredialysisEvaluation
  624. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  625. return record, err
  626. }
  627. // 透前评估
  628. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  629. var record models.PredialysisEvaluation
  630. redis := RedisClient()
  631. defer redis.Close()
  632. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  633. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  634. redis.Set(key, "", time.Second)
  635. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  636. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  637. if err != nil {
  638. if err == gorm.ErrRecordNotFound {
  639. if record.ID <= 0 {
  640. redis.Set(key, "", time.Second*60*60*18)
  641. }
  642. return nil, nil
  643. } else {
  644. return nil, err
  645. }
  646. } else {
  647. if record.ID > 0 {
  648. //缓存数据
  649. assessment_before_dislysis_str, err := json.Marshal(record)
  650. if err == nil {
  651. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  652. }
  653. } else {
  654. redis.Set(key, "null", time.Second*60*60*18)
  655. }
  656. return &record, nil
  657. }
  658. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  659. if assessment_before_dislysis_str == "null" {
  660. return &record, nil
  661. } else {
  662. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  663. return &record, nil
  664. }
  665. }
  666. }
  667. // 获取 maxDate 之前一次的透前评估记录
  668. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  669. var record models.PredialysisEvaluation
  670. 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
  671. if err != nil {
  672. if err == gorm.ErrRecordNotFound {
  673. return nil, nil
  674. } else {
  675. return nil, err
  676. }
  677. }
  678. return &record, nil
  679. }
  680. // 获取 maxDate 之前一次的透前评估记录
  681. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  682. var record models.PredialysisEvaluation
  683. redis := RedisClient()
  684. defer redis.Close()
  685. // cur_date := time.Now().Format("2006-01-02")
  686. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  687. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  688. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  689. 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
  690. if err != nil {
  691. if err == gorm.ErrRecordNotFound {
  692. if record.ID <= 0 {
  693. redis.Set(key, "", time.Second*60*60*18)
  694. }
  695. return nil, nil
  696. } else {
  697. return nil, err
  698. }
  699. } else {
  700. if record.ID > 0 {
  701. //缓存数据
  702. assessment_before_dislysis_last_str, err := json.Marshal(record)
  703. if err == nil {
  704. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  705. }
  706. } else {
  707. redis.Set(key, "null", time.Second*60*60*18)
  708. }
  709. return &record, nil
  710. }
  711. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  712. if assessment_before_dislysis_last_str == "null" {
  713. return &record, nil
  714. } else {
  715. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  716. return &record, nil
  717. }
  718. }
  719. }
  720. // 临时医嘱
  721. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  722. var records []*models.DoctorAdvice
  723. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  724. err := readDb.
  725. Model(&models.DoctorAdvice{}).
  726. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  727. 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").
  728. Order("start_time asc, groupno desc, advice_order desc, id").
  729. Scan(&records).Error
  730. if err != nil {
  731. return nil, err
  732. }
  733. return records, nil
  734. }
  735. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  736. var records []*models.DoctorAdvice
  737. redis := RedisClient()
  738. defer redis.Close()
  739. // cur_date := time.Now().Format("2006-01-02")
  740. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  741. //fmt.Println("key23233232323323wi", key)
  742. redis.Set(key, "", time.Second)
  743. doctor_advices_str, _ := redis.Get(key).Result()
  744. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  745. err := readDb.Model(&models.DoctorAdvice{}).
  746. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  747. 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").
  748. Order("start_time asc, groupno desc, advice_order desc, id asc").
  749. Scan(&records).Error
  750. if err != nil {
  751. if err == gorm.ErrRecordNotFound {
  752. if len(records) <= 0 {
  753. redis.Set(key, "", time.Second*60*60*18)
  754. }
  755. return nil, nil
  756. } else {
  757. return nil, err
  758. }
  759. } else {
  760. if len(records) > 0 {
  761. //缓存数据
  762. doctor_advices_str, err := json.Marshal(records)
  763. if err == nil {
  764. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  765. return records, nil
  766. }
  767. } else {
  768. redis.Set(key, "null", time.Second*60*60*18)
  769. return records, nil
  770. }
  771. return records, nil
  772. }
  773. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  774. if doctor_advices_str == "null" {
  775. return records, nil
  776. } else {
  777. json.Unmarshal([]byte(doctor_advices_str), &records)
  778. return records, nil
  779. }
  780. }
  781. }
  782. // 透析记录
  783. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  784. var record models.DialysisOrder
  785. 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
  786. if err != nil {
  787. if err == gorm.ErrRecordNotFound {
  788. return nil, nil
  789. } else {
  790. return nil, err
  791. }
  792. }
  793. return &record, nil
  794. }
  795. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  796. // var record models.DialysisOrder
  797. //
  798. // 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
  799. //
  800. //
  801. // return &record,err
  802. //}
  803. // 透析记录
  804. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  805. var record models.DialysisOrder
  806. redis := RedisClient()
  807. defer redis.Close()
  808. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  809. dialysis_order_str, _ := redis.Get(key).Result()
  810. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  811. 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
  812. if err != nil {
  813. if err == gorm.ErrRecordNotFound {
  814. return nil, nil
  815. } else {
  816. return nil, err
  817. }
  818. } else {
  819. if record.ID > 0 {
  820. //缓存数据
  821. dialysis_order_str, err := json.Marshal(record)
  822. if err == nil {
  823. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  824. }
  825. } else {
  826. redis.Set(key, "null", time.Second*60*60*18)
  827. }
  828. return &record, nil
  829. }
  830. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  831. if dialysis_order_str == "null" {
  832. 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
  833. return &record, nil
  834. } else {
  835. json.Unmarshal([]byte(dialysis_order_str), &record)
  836. return &record, nil
  837. }
  838. }
  839. }
  840. // 双人核对
  841. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  842. var record models.DoubleCheck
  843. redis := RedisClient()
  844. defer redis.Close()
  845. // cur_date := time.Now().Format("2006-01-02")
  846. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  847. double_check_str, _ := redis.Get(key).Result()
  848. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  849. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  850. if err != nil {
  851. if err == gorm.ErrRecordNotFound {
  852. if record.ID <= 0 {
  853. redis.Set(key, "null", time.Second*60*60*18)
  854. }
  855. return nil, nil
  856. } else {
  857. return nil, err
  858. }
  859. } else {
  860. if record.ID > 0 {
  861. //缓存数据
  862. double_check_str, err := json.Marshal(record)
  863. if err == nil {
  864. redis.Set(key, double_check_str, time.Second*60*60*18)
  865. }
  866. } else {
  867. redis.Set(key, "null", time.Second*60*60*18)
  868. }
  869. return &record, nil
  870. }
  871. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  872. if double_check_str == "null" {
  873. return &record, nil
  874. } else {
  875. json.Unmarshal([]byte(double_check_str), &record)
  876. return &record, nil
  877. }
  878. }
  879. }
  880. // 透析监测记录
  881. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  882. var records []*models.MonitoringRecord
  883. redis := RedisClient()
  884. defer redis.Close()
  885. // cur_date := time.Now().Format("2006-01-02")
  886. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  887. redis.Set(key, "", time.Second)
  888. monitor_records_str, _ := redis.Get(key).Result()
  889. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  890. 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
  891. if err != nil {
  892. if err == gorm.ErrRecordNotFound {
  893. //if len(records) <= 0 {
  894. // redis.Set(key, "null", time.Second*60*60*18)
  895. //}
  896. return nil, nil
  897. } else {
  898. return nil, err
  899. }
  900. } else {
  901. if len(records) > 0 {
  902. //缓存数据
  903. monitor_records_str, err := json.Marshal(records)
  904. if err == nil {
  905. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  906. }
  907. } else {
  908. redis.Set(key, "null", time.Second*60*60*18)
  909. }
  910. return records, nil
  911. }
  912. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  913. if monitor_records_str == "null" {
  914. return records, nil
  915. } else {
  916. json.Unmarshal([]byte(monitor_records_str), &records)
  917. return records, nil
  918. }
  919. }
  920. }
  921. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  922. var records models.MonitoringRecord
  923. 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
  924. if err != nil {
  925. return nil, err
  926. }
  927. return &records, nil
  928. }
  929. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  930. var record models.MonitoringRecord
  931. 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
  932. if err != nil {
  933. if err == gorm.ErrRecordNotFound {
  934. return nil, nil
  935. } else {
  936. return nil, err
  937. }
  938. }
  939. return &record, nil
  940. }
  941. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  942. var record models.MonitoringRecord
  943. redis := RedisClient()
  944. defer redis.Close()
  945. // cur_date := time.Now().Format("2006-01-02")
  946. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  947. monitor_record_last_str, _ := redis.Get(key).Result()
  948. redis.Set(key, "", time.Second)
  949. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  950. 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
  951. if err != nil {
  952. if err == gorm.ErrRecordNotFound {
  953. if record.ID <= 0 {
  954. redis.Set(key, "null", time.Second*60*60*18)
  955. }
  956. return nil, nil
  957. } else {
  958. return nil, err
  959. }
  960. } else {
  961. if record.ID > 0 {
  962. //缓存数据
  963. monitor_record_last_str, err := json.Marshal(record)
  964. if err == nil {
  965. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  966. }
  967. } else {
  968. redis.Set(key, "null", time.Second*60*60*18)
  969. }
  970. return &record, nil
  971. }
  972. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  973. if monitor_record_last_str == "null" {
  974. return &record, nil
  975. } else {
  976. json.Unmarshal([]byte(monitor_record_last_str), &record)
  977. return &record, nil
  978. }
  979. }
  980. }
  981. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  982. var record models.AssessmentAfterDislysis
  983. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  984. if err != nil {
  985. if err == gorm.ErrRecordNotFound {
  986. return nil, nil
  987. } else {
  988. return nil, err
  989. }
  990. }
  991. return &record, nil
  992. }
  993. // 透后评估
  994. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  995. var record models.AssessmentAfterDislysis
  996. redis := RedisClient()
  997. defer redis.Close()
  998. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  999. redis.Set(key, "", time.Second)
  1000. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  1001. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1002. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1003. if err != nil {
  1004. if err == gorm.ErrRecordNotFound {
  1005. if record.ID <= 0 {
  1006. redis.Set(key, "null", time.Second*60*60*18)
  1007. }
  1008. return nil, nil
  1009. } else {
  1010. return nil, err
  1011. }
  1012. } else {
  1013. if record.ID > 0 {
  1014. //缓存数据
  1015. assessment_after_dislysis_str, err := json.Marshal(record)
  1016. if err == nil {
  1017. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1018. }
  1019. } else {
  1020. redis.Set(key, "null", time.Second*60*60*18)
  1021. }
  1022. return &record, nil
  1023. }
  1024. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1025. if assessment_after_dislysis_str == "null" {
  1026. return &record, nil
  1027. } else {
  1028. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1029. return &record, nil
  1030. }
  1031. }
  1032. }
  1033. // 获取 maxDate 之前一次的透后评估记录
  1034. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1035. var record models.AssessmentAfterDislysis
  1036. redis := RedisClient()
  1037. defer redis.Close()
  1038. // cur_date := time.Now().Format("2006-01-02")
  1039. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1040. redis.Set(key, "", time.Second)
  1041. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1042. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1043. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where(" patient_id = ? and user_org_id = ? and status = 1 and assessment_date>=1725120000 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1044. if err != nil {
  1045. if err == gorm.ErrRecordNotFound {
  1046. if record.ID <= 0 {
  1047. redis.Set(key, "null", time.Second*60*60*18)
  1048. }
  1049. return nil, nil
  1050. } else {
  1051. return nil, err
  1052. }
  1053. } else {
  1054. if record.ID > 0 {
  1055. //缓存数据
  1056. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1057. if err == nil {
  1058. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1059. }
  1060. } else {
  1061. redis.Set(key, "null", time.Second*60*60*18)
  1062. }
  1063. return &record, nil
  1064. }
  1065. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1066. if assessment_after_dislysis_last_str == "null" {
  1067. return &record, nil
  1068. } else {
  1069. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1070. return &record, nil
  1071. }
  1072. }
  1073. }
  1074. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1075. var record models.AssessmentAfterDislysis
  1076. 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
  1077. if err != nil {
  1078. if err == gorm.ErrRecordNotFound {
  1079. return nil, nil
  1080. } else {
  1081. return nil, err
  1082. }
  1083. }
  1084. return &record, nil
  1085. }
  1086. func MobileGetLastTimeAssessmentAfterDislysisTwo(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1087. var record models.AssessmentAfterDislysis
  1088. 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
  1089. return &record, nil
  1090. }
  1091. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1092. dislysis := models.AssessmentAfterDislysis{}
  1093. 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
  1094. return dislysis, err
  1095. }
  1096. // 治疗小结
  1097. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1098. var record models.TreatmentSummary
  1099. redis := RedisClient()
  1100. defer redis.Close()
  1101. // cur_date := time.Now().Format("2006-01-02")
  1102. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1103. treatment_summary_str, _ := redis.Get(key).Result()
  1104. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1105. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1106. if err != nil {
  1107. if err == gorm.ErrRecordNotFound {
  1108. if record.ID <= 0 {
  1109. redis.Set(key, "null", time.Second*60*60*18)
  1110. }
  1111. return nil, nil
  1112. } else {
  1113. return nil, err
  1114. }
  1115. } else {
  1116. if record.ID > 0 {
  1117. //缓存数据
  1118. treatment_summary_str, err := json.Marshal(record)
  1119. if err == nil {
  1120. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1121. }
  1122. } else {
  1123. redis.Set(key, "null", time.Second*60*60*18)
  1124. }
  1125. return &record, nil
  1126. }
  1127. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1128. if treatment_summary_str == "null" {
  1129. return &record, nil
  1130. } else {
  1131. json.Unmarshal([]byte(treatment_summary_str), &record)
  1132. return &record, nil
  1133. }
  1134. }
  1135. }
  1136. // 透析处方
  1137. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1138. var record models.DialysisPrescription
  1139. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1140. if err != nil {
  1141. if err == gorm.ErrRecordNotFound {
  1142. return nil, nil
  1143. } else {
  1144. return nil, err
  1145. }
  1146. }
  1147. return &record, nil
  1148. }
  1149. func MobileGetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  1150. var record models.DialysisPrescription
  1151. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1152. return record, nil
  1153. }
  1154. func UpdateMobileGetDialysisPrescribe(id int64, dewater_amount float64) error {
  1155. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount, "prescription_water": dewater_amount}).Error
  1156. return err
  1157. }
  1158. func UpdateMobileGetDialysisPrescribeOne(id int64, dewater_amount float64) error {
  1159. err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id=? and status=1", id).Updates(map[string]interface{}{"target_ultrafiltration": dewater_amount}).Error
  1160. return err
  1161. }
  1162. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1163. var schedule models.XtSchedule
  1164. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1165. if err != nil {
  1166. if err == gorm.ErrRecordNotFound {
  1167. return nil, nil
  1168. } else {
  1169. return nil, err
  1170. }
  1171. }
  1172. return &schedule, nil
  1173. }
  1174. // 透析方案
  1175. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1176. var record models.DialysisSolution
  1177. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1178. if err != nil {
  1179. if err == gorm.ErrRecordNotFound {
  1180. return nil, nil
  1181. } else {
  1182. return nil, err
  1183. }
  1184. }
  1185. return &record, nil
  1186. }
  1187. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1188. var patient models.Patients
  1189. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1190. if err != nil {
  1191. if err == gorm.ErrRecordNotFound {
  1192. return nil, nil
  1193. } else {
  1194. return nil, err
  1195. }
  1196. }
  1197. return &patient, nil
  1198. }
  1199. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1200. fmt.Println()
  1201. tx := writeDb.Begin()
  1202. updateTime := time.Now().Unix()
  1203. 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
  1204. if err != nil {
  1205. tx.Rollback()
  1206. return err
  1207. }
  1208. tx.Commit()
  1209. return nil
  1210. }
  1211. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1212. record := models.MonitoringRecord{}
  1213. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1214. return record, err
  1215. }
  1216. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1217. var monitor models.MonitoringRecord
  1218. var err error
  1219. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1220. if err == gorm.ErrRecordNotFound {
  1221. return nil, nil
  1222. }
  1223. if err != nil {
  1224. return nil, err
  1225. }
  1226. return &monitor, nil
  1227. }
  1228. type MScheduleDoctorAdviceVM struct {
  1229. ID int64 `gorm:"column:id" json:"id"`
  1230. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1231. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1232. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1233. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1234. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1235. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1236. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1237. Status int64 `gorm:"column:status" json:"status"`
  1238. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1239. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1240. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1241. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1242. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1243. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1244. }
  1245. func (MScheduleDoctorAdviceVM) TableName() string {
  1246. return "xt_schedule"
  1247. }
  1248. type MScheduleDoctorAdviceVMOne struct {
  1249. ID int64 `gorm:"column:id" json:"id"`
  1250. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1251. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1252. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1253. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1254. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1255. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1256. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1257. Status int64 `gorm:"column:status" json:"status"`
  1258. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1259. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1260. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1261. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1262. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1263. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1264. }
  1265. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1266. return "xt_schedule"
  1267. }
  1268. type MDoctorAdviceVM struct {
  1269. ID int64 `gorm:"column:id" json:"id"`
  1270. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1271. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1272. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1273. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1274. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1275. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1276. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1277. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1278. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1279. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1280. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1281. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1282. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1283. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1284. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1285. Status int64 `gorm:"column:status" json:"status"`
  1286. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1287. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1288. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1289. Remark string `gorm:"column:remark" json:"remark"`
  1290. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1291. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1292. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1293. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1294. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1295. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1296. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1297. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1298. Checker int64 `gorm:"column:checker" json:"checker"`
  1299. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1300. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1301. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1302. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1303. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1304. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1305. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1306. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1307. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1308. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1309. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1310. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1311. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1312. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1313. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1314. }
  1315. func (MDoctorAdviceVM) TableName() string {
  1316. return "xt_doctor_advice"
  1317. }
  1318. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1319. var vms []*MScheduleDoctorAdviceVM
  1320. adviceWhere := ""
  1321. adviceCondition := []interface{}{}
  1322. if adviceType == 0 {
  1323. if patientType == 0 {
  1324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1326. } else if patientType == 1 {
  1327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1329. } else if patientType == 2 {
  1330. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1332. }
  1333. } else if adviceType == 1 {
  1334. if patientType == 0 {
  1335. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1337. } else if patientType == 1 {
  1338. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1340. } else if patientType == 2 {
  1341. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1343. }
  1344. } else if adviceType == 3 {
  1345. if patientType == 0 {
  1346. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1348. } else if patientType == 1 {
  1349. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1350. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1351. } else if patientType == 2 {
  1352. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1354. }
  1355. } else if adviceType == 2 && len(deliverWay) > 0 {
  1356. if patientType == 0 {
  1357. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1359. } else if patientType == 1 {
  1360. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1362. } else if patientType == 2 {
  1363. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1365. }
  1366. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1367. if patientType == 0 {
  1368. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1370. } else if patientType == 1 {
  1371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1373. } else if patientType == 2 {
  1374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1376. }
  1377. }
  1378. db := readDb.
  1379. Table("xt_schedule").
  1380. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1381. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1382. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1383. }).
  1384. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1385. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1386. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1387. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1388. Preload("DoctorAdvices", adviceCondition...).
  1389. Where("status = 1 AND user_org_id = ?", orgID)
  1390. if scheduleDate != 0 {
  1391. db = db.Where("schedule_date = ?", scheduleDate)
  1392. }
  1393. err := db.Find(&vms).Error
  1394. return vms, err
  1395. }
  1396. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1397. var vms []*MScheduleDoctorAdviceVMOne
  1398. adviceWhere := ""
  1399. adviceCondition := []interface{}{}
  1400. if adviceType == 0 {
  1401. if patientType == 0 {
  1402. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1404. } else if patientType == 1 {
  1405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1407. } else if patientType == 2 {
  1408. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1410. } else if patientType == 3 {
  1411. 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"
  1412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1413. } else if patientType == 4 {
  1414. 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)"
  1415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1416. }
  1417. } else if adviceType == 1 {
  1418. if patientType == 0 {
  1419. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1421. } else if patientType == 1 {
  1422. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1424. } else if patientType == 2 {
  1425. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1427. } else if patientType == 3 {
  1428. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1430. } else if patientType == 4 {
  1431. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1433. }
  1434. } else if adviceType == 3 {
  1435. if patientType == 0 {
  1436. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1438. } else if patientType == 1 {
  1439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1441. } else if patientType == 2 {
  1442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1444. } else if patientType == 3 {
  1445. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1447. } else if patientType == 4 {
  1448. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1450. }
  1451. } else if adviceType == 2 && len(deliverWay) > 0 {
  1452. if patientType == 0 {
  1453. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1455. } else if patientType == 1 {
  1456. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1458. } else if patientType == 2 {
  1459. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1461. } else if patientType == 3 {
  1462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1464. } else if patientType == 4 {
  1465. 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)"
  1466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1467. }
  1468. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1469. if patientType == 0 {
  1470. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1472. } else if patientType == 1 {
  1473. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1475. } else if patientType == 2 {
  1476. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1478. } else if patientType == 3 {
  1479. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1481. } else if patientType == 4 {
  1482. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1484. }
  1485. }
  1486. db := readDb.
  1487. Table("xt_schedule").
  1488. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1489. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1490. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1491. //}).
  1492. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1494. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1495. Preload("DoctorAdvices", adviceCondition...).
  1496. Where("status = 1 AND user_org_id = ?", orgID)
  1497. if scheduleDate != 0 {
  1498. db = db.Where("schedule_date = ?", scheduleDate)
  1499. }
  1500. err := db.Find(&vms).Error
  1501. return vms, err
  1502. }
  1503. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1504. var vms []*HisMScheduleDoctorAdviceVM
  1505. if len(deliverWay) > 0 {
  1506. if patientType == 0 {
  1507. db := readDb.
  1508. Table("xt_schedule").
  1509. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1510. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1511. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1512. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1514. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1515. }).
  1516. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1517. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1518. Where("status = 1 AND user_org_id = ?", orgID)
  1519. if scheduleDate != 0 {
  1520. db = db.Where("schedule_date = ?", scheduleDate)
  1521. }
  1522. err = db.Find(&vms).Error
  1523. }
  1524. if patientType > 0 {
  1525. db := readDb.
  1526. Table("xt_schedule").
  1527. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1528. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1529. 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).
  1530. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1531. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1532. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  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. }).Where("status = 1 AND user_org_id = ?", orgID)
  1536. if scheduleDate != 0 {
  1537. db = db.Where("schedule_date = ?", scheduleDate)
  1538. }
  1539. err = db.Find(&vms).Error
  1540. }
  1541. } else {
  1542. if patientType == 0 {
  1543. db := readDb.
  1544. Table("xt_schedule").
  1545. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1546. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1547. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1548. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1549. }).
  1550. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1551. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1552. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1553. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1554. Where("status = 1 AND user_org_id = ?", orgID)
  1555. if scheduleDate != 0 {
  1556. db = db.Where("schedule_date = ?", scheduleDate)
  1557. }
  1558. err = db.Find(&vms).Error
  1559. }
  1560. if patientType > 0 {
  1561. db := readDb.
  1562. Table("xt_schedule").
  1563. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1564. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1565. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1566. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1567. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1568. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1569. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1570. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1571. Where("status = 1 AND user_org_id = ?", orgID)
  1572. if scheduleDate != 0 {
  1573. db = db.Where("schedule_date = ?", scheduleDate)
  1574. }
  1575. err = db.Find(&vms).Error
  1576. }
  1577. }
  1578. return vms, err
  1579. }
  1580. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1581. var vms []*HisMScheduleDoctorAdviceVMOne
  1582. if len(deliverWay) > 0 {
  1583. if patientType == 0 {
  1584. db := readDb.
  1585. Table("xt_schedule").
  1586. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1587. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1588. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1589. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1590. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1591. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1592. }).
  1593. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1594. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1595. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1596. Where("status = 1 AND user_org_id = ?", orgID)
  1597. if scheduleDate != 0 {
  1598. db = db.Where("schedule_date = ?", scheduleDate)
  1599. }
  1600. err = db.Find(&vms).Error
  1601. }
  1602. if patientType > 0 {
  1603. if patientType == 1 {
  1604. db := readDb.
  1605. Table("xt_schedule").
  1606. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1607. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1608. 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).
  1609. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1610. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1611. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1612. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1613. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1614. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1615. Where("status = 1 AND user_org_id = ?", orgID)
  1616. if scheduleDate != 0 {
  1617. db = db.Where("schedule_date = ?", scheduleDate)
  1618. }
  1619. err = db.Find(&vms).Error
  1620. }
  1621. if patientType == 2 {
  1622. db := readDb.
  1623. Table("xt_schedule").
  1624. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1625. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1626. 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).
  1627. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1628. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1629. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1630. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1631. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1632. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1633. if scheduleDate != 0 {
  1634. db = db.Where("schedule_date = ?", scheduleDate)
  1635. }
  1636. err = db.Find(&vms).Error
  1637. }
  1638. if patientType == 3 {
  1639. db := readDb.
  1640. Table("xt_schedule").
  1641. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1642. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1643. 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).
  1644. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1645. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1646. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1647. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1648. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1649. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1650. if scheduleDate != 0 {
  1651. db = db.Where("schedule_date = ?", scheduleDate)
  1652. }
  1653. err = db.Find(&vms).Error
  1654. }
  1655. if patientType == 4 {
  1656. db := readDb.
  1657. Table("xt_schedule").
  1658. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1659. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1660. 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).
  1661. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1662. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1663. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1664. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1665. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1666. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1667. if scheduleDate != 0 {
  1668. db = db.Where("schedule_date = ?", scheduleDate)
  1669. }
  1670. err = db.Find(&vms).Error
  1671. }
  1672. }
  1673. } else {
  1674. if patientType == 0 {
  1675. db := readDb.
  1676. Table("xt_schedule").
  1677. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1678. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1679. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1680. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1681. }).
  1682. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1683. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1684. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1685. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1686. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1687. Where("status = 1 AND user_org_id = ?", orgID)
  1688. if scheduleDate != 0 {
  1689. db = db.Where("schedule_date = ?", scheduleDate)
  1690. }
  1691. err = db.Find(&vms).Error
  1692. }
  1693. if patientType > 0 {
  1694. if patientType == 1 {
  1695. db := readDb.
  1696. Table("xt_schedule").
  1697. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1698. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1699. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1700. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1701. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1702. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1703. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1704. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1705. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1706. Where("status = 1 AND user_org_id = ?", orgID)
  1707. if scheduleDate != 0 {
  1708. db = db.Where("schedule_date = ?", scheduleDate)
  1709. }
  1710. err = db.Find(&vms).Error
  1711. }
  1712. if patientType == 2 {
  1713. db := readDb.
  1714. Table("xt_schedule").
  1715. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1716. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1717. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1718. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1719. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1720. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1721. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1722. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1723. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1724. Where("status = 1 AND user_org_id = ?", orgID)
  1725. if scheduleDate != 0 {
  1726. db = db.Where("schedule_date = ?", scheduleDate)
  1727. }
  1728. err = db.Find(&vms).Error
  1729. }
  1730. if patientType == 3 {
  1731. db := readDb.
  1732. Table("xt_schedule").
  1733. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1734. 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).
  1735. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1736. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1737. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1738. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1739. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1740. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1741. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1742. Where("status = 1 AND user_org_id = ?", orgID)
  1743. if scheduleDate != 0 {
  1744. db = db.Where("schedule_date = ?", scheduleDate)
  1745. }
  1746. err = db.Find(&vms).Error
  1747. }
  1748. if patientType == 4 {
  1749. db := readDb.
  1750. Table("xt_schedule").
  1751. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1752. 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).
  1753. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1754. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1755. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1756. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1757. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1758. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1759. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1760. Where("status = 1 AND user_org_id = ?", orgID)
  1761. if scheduleDate != 0 {
  1762. db = db.Where("schedule_date = ?", scheduleDate)
  1763. }
  1764. err = db.Find(&vms).Error
  1765. }
  1766. }
  1767. }
  1768. return vms, err
  1769. }
  1770. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1771. var vms []*HisMScheduleProjectVM
  1772. //if patientType == 0 {
  1773. // db := readDb.
  1774. // Table("xt_schedule").
  1775. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1776. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1777. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1778. // }).
  1779. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1780. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1781. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1782. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1783. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1784. // }).
  1785. // Where("status = 1 AND user_org_id = ?", orgID)
  1786. // if scheduleDate != 0 {
  1787. // db = db.Where("schedule_date = ?", scheduleDate)
  1788. // }
  1789. // err = db.Find(&vms).Error
  1790. //}
  1791. //if patientType > 0 {
  1792. // db := readDb.
  1793. // Table("xt_schedule").
  1794. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1795. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1796. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1797. // }).
  1798. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1799. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1800. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1801. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1802. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1803. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1804. // }).
  1805. // Where("status = 1 AND user_org_id = ?", orgID)
  1806. // if scheduleDate != 0 {
  1807. // db = db.Where("schedule_date = ?", scheduleDate)
  1808. // }
  1809. // err = db.Find(&vms).Error
  1810. //}
  1811. db := readDb.Table("xt_schedule").Where("status = 1")
  1812. if orgID > 0 {
  1813. db = db.Where("user_org_id = ?", orgID)
  1814. }
  1815. if scheduleDate > 0 {
  1816. db = db.Where("schedule_date =?", scheduleDate)
  1817. }
  1818. err = db.Find(&vms).Error
  1819. if patientType == 0 {
  1820. db := readDb.
  1821. Table("xt_schedule").
  1822. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1823. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1824. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1825. }).
  1826. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1827. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1828. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1829. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1830. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1831. }).
  1832. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1833. 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")
  1834. }).
  1835. Where("status = 1 AND user_org_id = ?", orgID)
  1836. if scheduleDate != 0 {
  1837. db = db.Where("schedule_date = ?", scheduleDate)
  1838. }
  1839. err = db.Find(&vms).Error
  1840. }
  1841. if patientType > 0 {
  1842. db := readDb.
  1843. Table("xt_schedule").
  1844. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1845. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1846. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1847. }).
  1848. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1849. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1850. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1851. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1852. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1853. }).
  1854. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1855. 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")
  1856. }).
  1857. Where("status = 1 AND user_org_id = ?", orgID)
  1858. if scheduleDate != 0 {
  1859. db = db.Where("schedule_date = ?", scheduleDate)
  1860. }
  1861. err = db.Find(&vms).Error
  1862. }
  1863. return vms, err
  1864. }
  1865. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1866. now := time.Now()
  1867. tx := writeDb.Begin()
  1868. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1869. tx.Rollback()
  1870. return createOrderErr
  1871. }
  1872. // 更新透析记录 ID
  1873. // 透析处方
  1874. 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 {
  1875. tx.Rollback()
  1876. return err
  1877. }
  1878. // 接诊评估
  1879. 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 {
  1880. tx.Rollback()
  1881. return err
  1882. }
  1883. // 透前评估
  1884. 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 {
  1885. tx.Rollback()
  1886. return err
  1887. }
  1888. // 临时医嘱
  1889. 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 {
  1890. tx.Rollback()
  1891. return err
  1892. }
  1893. // 双人核对
  1894. 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 {
  1895. tx.Rollback()
  1896. return err
  1897. }
  1898. // 透后评估
  1899. 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 {
  1900. tx.Rollback()
  1901. return err
  1902. }
  1903. // 治疗小结
  1904. 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 {
  1905. tx.Rollback()
  1906. return err
  1907. }
  1908. // 透析监测
  1909. 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 {
  1910. tx.Rollback()
  1911. return err
  1912. }
  1913. tx.Commit()
  1914. return nil
  1915. }
  1916. type MobileUrgentSchedulePatientVM struct {
  1917. ID int64 `gorm:"column:id" json:"id"`
  1918. Name string `gorm:"column:name" json:"name"`
  1919. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1920. }
  1921. func (MobileUrgentSchedulePatientVM) TableName() string {
  1922. return "xt_patients"
  1923. }
  1924. type MobileUrgentScheduleTreatmentModeVM struct {
  1925. ID int64 `gorm:"column:id" json:"id"`
  1926. Name string `gorm:"column:name" json:"name"`
  1927. }
  1928. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1929. return "xt_treatment_mode"
  1930. }
  1931. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1932. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1933. 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()
  1934. defer rows.Close()
  1935. if err != nil {
  1936. return nil, err
  1937. }
  1938. for rows.Next() {
  1939. var vm MobileUrgentSchedulePatientVM
  1940. readDb.ScanRows(rows, &vm)
  1941. vms = append(vms, &vm)
  1942. }
  1943. return vms, nil
  1944. }
  1945. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1946. var modes []*MobileUrgentScheduleTreatmentModeVM
  1947. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1948. if err != nil {
  1949. return nil, err
  1950. }
  1951. return modes, nil
  1952. }
  1953. type MobileUrgentScheduleScheduleListVM struct {
  1954. ID int64 `gorm:"column:id" json:"id"`
  1955. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1956. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1957. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1958. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1959. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1960. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1961. }
  1962. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1963. return "xt_schedule"
  1964. }
  1965. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1966. db := readDb.
  1967. Model(&MobileUrgentScheduleScheduleListVM{}).
  1968. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1969. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1970. err = db.Find(&schedules).Error
  1971. if err != nil {
  1972. return nil, err
  1973. }
  1974. return schedules, nil
  1975. }
  1976. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1977. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1978. 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()
  1979. defer rows.Close()
  1980. if err != nil {
  1981. return nil, err
  1982. }
  1983. for rows.Next() {
  1984. var vm MobileUrgentScheduleScheduleListVM
  1985. readDb.ScanRows(rows, &vm)
  1986. vms = append(vms, &vm)
  1987. }
  1988. return vms, nil
  1989. }
  1990. type MobileUrgentScheduleDeviceNumberVM struct {
  1991. ID int64 `gorm:"column:id" json:"id"`
  1992. Number string `gorm:"column:number" json:"number"`
  1993. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1994. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1995. }
  1996. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1997. return "xt_device_number"
  1998. }
  1999. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2000. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2001. 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()
  2002. defer rows.Close()
  2003. if err != nil {
  2004. return nil, err
  2005. }
  2006. for rows.Next() {
  2007. var vm DeviceNumberViewModel
  2008. readDb.ScanRows(rows, &vm)
  2009. vms = append(vms, &vm)
  2010. }
  2011. return vms, nil
  2012. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  2013. //db := readDb.
  2014. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  2015. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  2016. // Where("status = 1 AND org_id = ?", orgID)
  2017. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  2018. //if err != nil {
  2019. // return nil, err
  2020. //}
  2021. //return deviceNumbers, nil
  2022. }
  2023. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2024. var total int64
  2025. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2026. return total, err
  2027. }
  2028. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2029. var monitors []*models.MonitoringRecord
  2030. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2031. if err != nil {
  2032. return nil, err
  2033. }
  2034. return monitors, nil
  2035. }
  2036. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2037. tx := writeDb.Begin()
  2038. for index := 0; index < len(monitors); index++ {
  2039. tx.Save(monitors[index])
  2040. }
  2041. return tx.Commit().Error
  2042. }
  2043. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2044. tx := writeDb.Begin()
  2045. updateTime := time.Now().Unix()
  2046. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType, "washpipe_nurse": order.WashpipeNurse, "change_nurse": order.ChangeNurse, "difficult_puncture_nurse": order.DifficultPunctureNurse, "new_fistula_nurse": order.NewFistulaNurse, "quality_nurse_id": order.QualityNurseId, "puncture_needle": order.PunctureNeedle, "puncture_way": order.PunctureWay, "dialysis_dialyszers": order.DialysisDialyszers, "dialysis_irrigation": order.DialysisIrrigation, "blood_access_id": order.BloodAccessId, "nuclein_date": order.NucleinDate, "schedule_remark": order.ScheduleRemark, "order_remark": order.OrderRemark, "catheter_operation": order.CatheterOperation, "blood_flow_volume": order.BloodFlowVolume, "blood_drawing": order.BloodDrawing, "dialysis_strainer": order.DialysisStrainer}).Error
  2047. if err != nil {
  2048. tx.Rollback()
  2049. return err
  2050. }
  2051. tx.Commit()
  2052. return err
  2053. }
  2054. func UpdateScheduleByBedId(patient_id int64, schedule_date int64, bed_id int64, schedule_type int64, zone_id int64) error {
  2055. 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
  2056. return err
  2057. }
  2058. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2059. tx := writeDb.Begin()
  2060. updateTime := time.Now().Unix()
  2061. 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
  2062. if err != nil {
  2063. tx.Rollback()
  2064. return err
  2065. }
  2066. tx.Commit()
  2067. return err
  2068. }
  2069. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2070. var record models.SgjPatientDryweight
  2071. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2072. if err != nil {
  2073. if err == gorm.ErrRecordNotFound {
  2074. return nil, nil
  2075. } else {
  2076. return nil, err
  2077. }
  2078. }
  2079. return &record, nil
  2080. }
  2081. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2082. // var record models.SgjPatientDryweight
  2083. // redis := RedisClient()
  2084. // defer redis.Close()
  2085. //
  2086. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2087. // last_dry_weight_str, _ := redis.Get(key).Result()
  2088. //
  2089. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2090. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2091. // if err != nil {
  2092. // if err == gorm.ErrRecordNotFound {
  2093. // if record.ID <= 0 {
  2094. // redis.Set(key, "null", time.Second*60*60*18)
  2095. // }
  2096. // return nil, nil
  2097. // } else {
  2098. // return nil, err
  2099. // }
  2100. // } else {
  2101. // if record.ID > 0 {
  2102. // //缓存数据
  2103. // last_dry_weight_str, err := json.Marshal(record)
  2104. // if err == nil {
  2105. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2106. // return nil, err
  2107. // }
  2108. // } else {
  2109. // redis.Set(key, "null", time.Second*60*60*18)
  2110. // return nil, err
  2111. // }
  2112. // return &record, nil
  2113. // }
  2114. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2115. // if last_dry_weight_str == "null" {
  2116. // return &record, nil
  2117. // } else {
  2118. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2119. // return &record, nil
  2120. // }
  2121. //
  2122. // }
  2123. //}
  2124. // 透析方案
  2125. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2126. var record models.DialysisSolution
  2127. 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
  2128. if err != nil {
  2129. if err == gorm.ErrRecordNotFound {
  2130. return nil, nil
  2131. } else {
  2132. return nil, err
  2133. }
  2134. }
  2135. return &record, nil
  2136. }
  2137. // 透析方案
  2138. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2139. var record models.DialysisSolution
  2140. 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
  2141. return record, nil
  2142. }
  2143. // 透析方案
  2144. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2145. var record models.DialysisSolution
  2146. redis := RedisClient()
  2147. defer redis.Close()
  2148. // cur_date := time.Now().Format("2006-01-02")
  2149. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2150. dialysis_solution_str, _ := redis.Get(key).Result()
  2151. redis.Set(key, "", time.Second*60)
  2152. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2153. 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
  2154. if err != nil {
  2155. if err == gorm.ErrRecordNotFound {
  2156. if record.ID <= 0 {
  2157. redis.Set(key, "null", time.Second*60*60*18)
  2158. }
  2159. return nil, nil
  2160. } else {
  2161. return nil, err
  2162. }
  2163. } else {
  2164. if record.ID > 0 {
  2165. //缓存数据
  2166. dialysis_solution_str, err := json.Marshal(record)
  2167. if err == nil {
  2168. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2169. }
  2170. } else {
  2171. redis.Set(key, "null", time.Second*60*60*18)
  2172. }
  2173. return &record, nil
  2174. }
  2175. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2176. if dialysis_solution_str == "null" {
  2177. return &record, nil
  2178. } else {
  2179. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2180. return &record, nil
  2181. }
  2182. }
  2183. }
  2184. // 透析处方
  2185. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2186. var record models.DialysisPrescription
  2187. redis := RedisClient()
  2188. defer redis.Close()
  2189. // cur_date := time.Now().Format("2006-01-02")
  2190. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2191. redis.Set(key, "", time.Second)
  2192. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2193. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2194. 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
  2195. if err != nil {
  2196. if err == gorm.ErrRecordNotFound {
  2197. if record.ID <= 0 {
  2198. redis.Set(key, "null", time.Second*60*60*18)
  2199. }
  2200. return nil, nil
  2201. } else {
  2202. return nil, err
  2203. }
  2204. } else {
  2205. if record.ID > 0 {
  2206. //缓存数据
  2207. dialysis_prescribe_str, err := json.Marshal(record)
  2208. if err == nil {
  2209. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2210. }
  2211. } else {
  2212. redis.Set(key, "null", time.Second*60*60*18)
  2213. }
  2214. return &record, nil
  2215. }
  2216. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2217. if dialysis_prescribe_str == "null" {
  2218. return &record, nil
  2219. } else {
  2220. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2221. return &record, nil
  2222. }
  2223. }
  2224. }
  2225. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2226. var record models.DialysisPrescription
  2227. 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
  2228. if err != nil {
  2229. if err == gorm.ErrRecordNotFound {
  2230. return nil, nil
  2231. } else {
  2232. return nil, err
  2233. }
  2234. }
  2235. return &record, nil
  2236. }
  2237. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2238. var record models.DialysisPrescription
  2239. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2240. if err != nil {
  2241. if err == gorm.ErrRecordNotFound {
  2242. return nil, nil
  2243. } else {
  2244. return nil, err
  2245. }
  2246. }
  2247. return &record, nil
  2248. }
  2249. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2250. // var record models.DialysisPrescription
  2251. // redis := RedisClient()
  2252. // defer redis.Close()
  2253. //
  2254. // // cur_date := time.Now().Format("2006-01-02")
  2255. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2256. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2257. //
  2258. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2259. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2260. // if err != nil {
  2261. // if err == gorm.ErrRecordNotFound {
  2262. // if record.ID <= 0 {
  2263. // redis.Set(key, "null", time.Second*60*60*18)
  2264. // }
  2265. // return nil, nil
  2266. // } else {
  2267. // return nil, err
  2268. // }
  2269. // } else {
  2270. //
  2271. // if record.ID > 0 {
  2272. // //缓存数据
  2273. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2274. //
  2275. // if err == nil {
  2276. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2277. // return nil, err
  2278. // }
  2279. // } else {
  2280. // redis.Set(key, "null", time.Second*60*60*18)
  2281. // return nil, err
  2282. // }
  2283. // return &record, nil
  2284. // }
  2285. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2286. // if dialysis_prescribe_by_mode_str == "null" {
  2287. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2288. // return &record, nil
  2289. // } else {
  2290. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2291. // return &record, nil
  2292. // }
  2293. //
  2294. // }
  2295. //}
  2296. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2297. var record models.DialysisPrescription
  2298. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2299. if err != nil {
  2300. if err == gorm.ErrRecordNotFound {
  2301. return nil, nil
  2302. } else {
  2303. return nil, err
  2304. }
  2305. }
  2306. return &record, nil
  2307. }
  2308. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2309. var record models.DialysisPrescription
  2310. 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
  2311. //if err != nil {
  2312. // if err == gorm.ErrRecordNotFound {
  2313. // return nil, nil
  2314. // } else {
  2315. // return nil, err
  2316. // }
  2317. //}
  2318. return &record, err
  2319. }
  2320. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2321. var record models.DialysisPrescription
  2322. 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
  2323. if err != nil {
  2324. if err == gorm.ErrRecordNotFound {
  2325. return nil, nil
  2326. } else {
  2327. return nil, err
  2328. }
  2329. }
  2330. return &record, err
  2331. }
  2332. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2333. var record models.DialysisPrescription
  2334. redis := RedisClient()
  2335. defer redis.Close()
  2336. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2337. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2338. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2339. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2340. if err != nil {
  2341. if err == gorm.ErrRecordNotFound {
  2342. if record.ID <= 0 {
  2343. redis.Set(key, "null", time.Second*60*60*18)
  2344. }
  2345. return nil, nil
  2346. } else {
  2347. return nil, err
  2348. }
  2349. } else {
  2350. if record.ID > 0 {
  2351. //缓存数据
  2352. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2353. if err == nil {
  2354. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2355. return nil, err
  2356. }
  2357. } else {
  2358. redis.Set(key, "null", time.Second*60*60*18)
  2359. return nil, err
  2360. }
  2361. return &record, nil
  2362. }
  2363. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2364. if dialysis_prescribe_by_mode_id == "null" {
  2365. return &record, nil
  2366. } else {
  2367. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2368. return &record, nil
  2369. }
  2370. }
  2371. }
  2372. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2373. var record models.DialysisPrescription
  2374. 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
  2375. return record, err
  2376. }
  2377. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2378. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2379. 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()
  2380. defer rows.Close()
  2381. if err != nil {
  2382. return nil, err
  2383. }
  2384. for rows.Next() {
  2385. var vm DeviceNumberViewModel
  2386. readDb.ScanRows(rows, &vm)
  2387. vms = append(vms, &vm)
  2388. }
  2389. return vms, nil
  2390. }
  2391. // 获取 maxDate 之前一次的透前评估记录
  2392. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2393. var record models.PredialysisEvaluation
  2394. 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
  2395. if err != nil {
  2396. if err == gorm.ErrRecordNotFound {
  2397. return nil, nil
  2398. } else {
  2399. return nil, err
  2400. }
  2401. }
  2402. return &record, nil
  2403. }
  2404. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2405. var record models.DialysisOrder
  2406. 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
  2407. if err != nil {
  2408. if err == gorm.ErrRecordNotFound {
  2409. return nil, nil
  2410. } else {
  2411. return nil, err
  2412. }
  2413. }
  2414. return &record, nil
  2415. }
  2416. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2417. var record models.MonitoringRecord
  2418. 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
  2419. if err != nil {
  2420. if err == gorm.ErrRecordNotFound {
  2421. return nil, nil
  2422. } else {
  2423. return nil, err
  2424. }
  2425. }
  2426. return &record, nil
  2427. }
  2428. func GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2429. var record models.MonitoringRecord
  2430. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and ultrafiltration_volume_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2431. return record, nil
  2432. }
  2433. func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2434. var record models.MonitoringRecord
  2435. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_systolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2436. return record, nil
  2437. }
  2438. func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2439. var record models.MonitoringRecord
  2440. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_diastolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2441. return record, nil
  2442. }
  2443. func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2444. var record models.MonitoringRecord
  2445. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and pulse_frequency_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2446. return record, nil
  2447. }
  2448. func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
  2449. var record models.MonitoringRecord
  2450. err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and displacement_quantity_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2451. return record, nil
  2452. }
  2453. // 获取 maxDate 之前一次的透后评估记录
  2454. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2455. var record models.AssessmentAfterDislysis
  2456. 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
  2457. if err != nil {
  2458. if err == gorm.ErrRecordNotFound {
  2459. return nil, nil
  2460. } else {
  2461. return nil, err
  2462. }
  2463. }
  2464. return &record, nil
  2465. }
  2466. // 透析处方
  2467. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2468. var record models.DialysisPrescription
  2469. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2470. if err != nil {
  2471. if err == gorm.ErrRecordNotFound {
  2472. return nil, nil
  2473. } else {
  2474. return nil, err
  2475. }
  2476. }
  2477. return &record, nil
  2478. }
  2479. func GetDialysisPrescribeOne(orgID int64, patientID int64, recordDate int64) (models.DialysisPrescription, error) {
  2480. var record models.DialysisPrescription
  2481. err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2482. return record, err
  2483. }
  2484. // 透析方案
  2485. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2486. var record models.DialysisSolution
  2487. 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
  2488. return record, err
  2489. }
  2490. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2491. var record models.DialysisSolution
  2492. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2493. if err != nil {
  2494. if err == gorm.ErrRecordNotFound {
  2495. return nil, nil
  2496. } else {
  2497. return nil, err
  2498. }
  2499. }
  2500. return &record, nil
  2501. }
  2502. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2503. var record models.DialysisPrescription
  2504. 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
  2505. if err != nil {
  2506. if err == gorm.ErrRecordNotFound {
  2507. return nil, nil
  2508. } else {
  2509. return nil, err
  2510. }
  2511. }
  2512. return &record, nil
  2513. }
  2514. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2515. var record models.SgjPatientDryweight
  2516. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2517. if err != nil {
  2518. if err == gorm.ErrRecordNotFound {
  2519. return nil, nil
  2520. } else {
  2521. return nil, err
  2522. }
  2523. }
  2524. return &record, nil
  2525. }
  2526. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2527. var record models.SystemPrescription
  2528. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2529. if err != nil {
  2530. if err == gorm.ErrRecordNotFound {
  2531. return nil, nil
  2532. } else {
  2533. return nil, err
  2534. }
  2535. }
  2536. return &record, nil
  2537. }
  2538. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2539. var record models.SystemPrescription
  2540. redis := RedisClient()
  2541. defer redis.Close()
  2542. // cur_date := time.Now().Format("2006-01-02")
  2543. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2544. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2545. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2546. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2547. if err != nil {
  2548. if err == gorm.ErrRecordNotFound {
  2549. if record.ID <= 0 {
  2550. redis.Set(key, "null", time.Second*60*60*18)
  2551. }
  2552. return nil, nil
  2553. } else {
  2554. return nil, err
  2555. }
  2556. } else {
  2557. if record.ID > 0 {
  2558. //缓存数据
  2559. system_dialysis_prescribe_str, err := json.Marshal(record)
  2560. if err == nil {
  2561. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2562. }
  2563. } else {
  2564. redis.Set(key, "null", time.Second*60*60*18)
  2565. }
  2566. return &record, nil
  2567. }
  2568. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2569. if system_dialysis_prescribe_str == "null" {
  2570. return &record, nil
  2571. } else {
  2572. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2573. return &record, nil
  2574. }
  2575. }
  2576. }
  2577. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2578. var record models.SystemPrescription
  2579. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2580. return record, err
  2581. }
  2582. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2583. var record models.SystemPrescription
  2584. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2585. if err != nil {
  2586. if err == gorm.ErrRecordNotFound {
  2587. return nil, nil
  2588. } else {
  2589. return nil, err
  2590. }
  2591. }
  2592. return &record, nil
  2593. }
  2594. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2595. 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
  2596. return
  2597. }
  2598. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2599. 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
  2600. return
  2601. }
  2602. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2603. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1735660800 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2604. return
  2605. }
  2606. func GetFirstDateOfMonth(d time.Time) time.Time {
  2607. d = d.AddDate(0, 0, -d.Day()+1)
  2608. return GetZeroTime(d)
  2609. }
  2610. func GetZeroTime(d time.Time) time.Time {
  2611. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2612. }
  2613. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2614. db := XTReadDB().Table("xt_dialysis_order as o")
  2615. 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
  2616. return order, err
  2617. }
  2618. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2619. 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
  2620. return
  2621. }
  2622. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2623. 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
  2624. return
  2625. }
  2626. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2627. 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
  2628. return
  2629. }
  2630. func FindHisPrescription(orgID int64, patient_id int64, recordDate int64) (project []*models.HisPrescriptionProject, err error) {
  2631. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 and type =3", orgID, patient_id, recordDate).Find(&project).Error
  2632. return
  2633. }
  2634. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2635. // 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
  2636. // return
  2637. //}
  2638. //
  2639. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2640. 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
  2641. return
  2642. }
  2643. type GoodsType struct {
  2644. ID int64 `gorm:"column:id" json:"id"`
  2645. TypeName string `gorm:"column:type_name" json:"type_name"`
  2646. Remark string `gorm:"column:remark" json:"remark"`
  2647. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2648. Status int64 `gorm:"column:status" json:"status"`
  2649. Type int64 `gorm:"column:type" json:"type"`
  2650. }
  2651. func (GoodsType) TableName() string {
  2652. return "xt_goods_type"
  2653. }
  2654. type VMGoodInfo struct {
  2655. ID int64 `gorm:"column:id" json:"id"`
  2656. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2657. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2658. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2659. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2660. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2661. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2662. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2663. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2664. }
  2665. func (VMGoodInfo) TableName() string {
  2666. return "xt_good_information"
  2667. }
  2668. type AutomaticReduceDetail struct {
  2669. ID int64 `gorm:"column:id" json:"id"`
  2670. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2671. Status int64 `gorm:"column:status" json:"status"`
  2672. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2673. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2674. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2675. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2676. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2677. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2678. Count int64 `gorm:"column:count" json:"count"`
  2679. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2680. }
  2681. func (AutomaticReduceDetail) TableName() string {
  2682. return "xt_automatic_reduce_detail"
  2683. }
  2684. type DialysisBeforePrepare struct {
  2685. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2686. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2687. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2688. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2689. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2690. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2691. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2692. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2693. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2694. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2695. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2696. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2697. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2698. }
  2699. func (DialysisBeforePrepare) TableName() string {
  2700. return "dialysis_before_prepare"
  2701. }
  2702. type MDialysisGoodsVM struct {
  2703. ID int64 `gorm:"column:id" json:"id"`
  2704. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2705. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2706. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2707. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2708. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2709. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2710. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2711. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2712. Status int64 `gorm:"column:status" json:"status"`
  2713. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2714. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2715. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2716. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2717. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2718. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2719. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2720. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2721. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2722. }
  2723. func (MDialysisGoodsVM) TableName() string {
  2724. return "xt_schedule"
  2725. }
  2726. type VMWarehouseOutInfo struct {
  2727. ID int64 `gorm:"column:id" json:"id"`
  2728. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2729. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2730. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2731. Count int64 `gorm:"column:count" json:"count"`
  2732. Price float64 `gorm:"column:price" json:"price"`
  2733. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2734. Status int64 `gorm:"column:status" json:"status"`
  2735. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2736. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2737. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2738. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2739. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2740. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2741. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2742. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2743. }
  2744. func (VMWarehouseOutInfo) TableName() string {
  2745. return "xt_warehouse_out_info"
  2746. }
  2747. type DialysisGoodsDate struct {
  2748. RecordDate int64
  2749. }
  2750. type DialysisGoodsDetailDate struct {
  2751. RecordTime int64
  2752. }
  2753. 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) {
  2754. var vms []*MDialysisGoodsVM
  2755. var total int64
  2756. db := readDb.
  2757. Table("xt_schedule as sch").
  2758. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2759. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2760. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2761. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2762. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2763. 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)
  2764. }).
  2765. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2766. 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")
  2767. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2768. if scheduleDate != 0 {
  2769. db = db.Where("schedule_date = ?", scheduleDate)
  2770. }
  2771. if schedule_type != 0 {
  2772. db = db.Where("schedule_type = ?", schedule_type)
  2773. }
  2774. if partition_id != 0 {
  2775. db = db.Where("partition_id = ?", partition_id)
  2776. }
  2777. if patient_id != 0 {
  2778. db = db.Where("patient_id = ?", patient_id)
  2779. }
  2780. err := db.Find(&vms).Error
  2781. return vms, err, total
  2782. }
  2783. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2784. var Id []*DialysisGoodsDetailDate
  2785. 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
  2786. if len(Id) > 0 {
  2787. 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
  2788. }
  2789. return
  2790. }
  2791. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2792. var Id []*DialysisGoodsDate
  2793. 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
  2794. if len(Id) > 0 {
  2795. 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
  2796. }
  2797. return
  2798. }
  2799. func GetPatientAutoMatic(patient_id int64, orgID int64, record_time int64, good_id int64) (auto []*models.AutomaticReduceDetail, err error) {
  2800. err = XTReadDB().Where("patient_id = ? and org_id = ? and record_time = ? and good_id =? and status=1", patient_id, orgID, record_time, good_id).Find(&auto).Error
  2801. return auto, err
  2802. }
  2803. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2804. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Preload("GoodInfo", "status=1 and org_id = ?", orgID).Find(&info).Error
  2805. return info, err
  2806. }
  2807. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2808. db := readDb.Model(&models.StockInfo{})
  2809. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2810. 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")
  2811. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2812. 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)
  2813. })
  2814. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2815. err = db.Order("ctime desc").Find(&list).Error
  2816. return
  2817. }
  2818. 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) {
  2819. var vms []*MDialysisGoodsVM
  2820. var total int64
  2821. db := readDb.
  2822. Model(&models.Schedule{}).
  2823. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2824. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2825. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2826. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2827. 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)
  2828. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2829. 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)
  2830. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2831. if scheduleDate != 0 {
  2832. db = db.Where("schedule_date = ?", scheduleDate)
  2833. }
  2834. if patient_id != 0 {
  2835. db = db.Where("patient_id = ?", patient_id)
  2836. }
  2837. if len(keywords) != 0 {
  2838. keywords = "%" + keywords + "%"
  2839. 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)
  2840. if schedule_type != 0 {
  2841. db = db.Where("schedule_type = ?", schedule_type)
  2842. }
  2843. if partition_id != 0 {
  2844. db = db.Where("partition_id = ?", partition_id)
  2845. }
  2846. if good_type == 1 {
  2847. db = db.Where("patient_id in(?)", ids)
  2848. }
  2849. if good_type == 2 {
  2850. if len(ids) > 0 {
  2851. db = db.Where("patient_id not in(?)", ids)
  2852. }
  2853. }
  2854. } else {
  2855. if schedule_type != 0 {
  2856. db = db.Where("schedule_type = ?", schedule_type)
  2857. }
  2858. if partition_id != 0 {
  2859. db = db.Where("partition_id = ?", partition_id)
  2860. }
  2861. if good_type == 1 {
  2862. db = db.Where("patient_id in(?)", ids)
  2863. }
  2864. if good_type == 2 {
  2865. if len(ids) > 0 {
  2866. db = db.Where("patient_id not in(?)", ids)
  2867. }
  2868. }
  2869. db = db.Count(&total)
  2870. offset := (page - 1) * limit
  2871. db = db.Offset(offset).Limit(limit)
  2872. }
  2873. err := db.Find(&vms).Error
  2874. return vms, err, total
  2875. }
  2876. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2877. var Id []*DialysisGoodsDetailDate
  2878. 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
  2879. if len(Id) > 0 {
  2880. 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
  2881. }
  2882. return
  2883. }
  2884. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2885. var Id []*DialysisGoodsDate
  2886. 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
  2887. if len(Id) > 0 {
  2888. 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
  2889. }
  2890. return
  2891. }
  2892. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2893. evaluation := models.PredialysisEvaluation{}
  2894. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2895. if err == gorm.ErrRecordNotFound {
  2896. return nil, err
  2897. }
  2898. if err != nil {
  2899. return nil, err
  2900. }
  2901. return &evaluation, nil
  2902. }
  2903. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2904. evaluation := models.PredialysisEvaluation{}
  2905. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2906. return evaluation, err
  2907. }
  2908. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2909. evaluation := models.XtAssessmentBeforeDislysis{}
  2910. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2911. return evaluation, err
  2912. }
  2913. func GetHisPrescriptionTemplateList(user_org_id int64, patient_id int64, mode_id int64) (models.HisPrescriptionTemplateSix, error) {
  2914. templateSix := models.HisPrescriptionTemplateSix{}
  2915. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode = ? and status =1", user_org_id, patient_id, mode_id).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  2916. return db.Where("status = 1 AND user_org_id = ? and type =2", user_org_id).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  2917. return db.Where("status = 1 AND user_org_id = ? and type =3", user_org_id).Preload("GoodInfo", "org_id = ? and status=1 ", user_org_id)
  2918. })
  2919. }).Find(&templateSix).Error
  2920. return templateSix, err
  2921. }
  2922. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2923. redis := RedisClient()
  2924. defer redis.Close()
  2925. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2926. his_doctor_advice_str, _ := redis.Get(key).Result()
  2927. redis.Set(key, "", time.Second)
  2928. if orgid != 10721 {
  2929. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2930. 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
  2931. if err != nil {
  2932. if err == gorm.ErrRecordNotFound {
  2933. if len(his) <= 0 {
  2934. redis.Set(key, "null", time.Second*60*60*18)
  2935. }
  2936. return his, nil
  2937. } else {
  2938. return his, err
  2939. }
  2940. } else {
  2941. if len(his) > 0 {
  2942. //缓存数据
  2943. his_doctor_advice_str, err := json.Marshal(his)
  2944. if err == nil {
  2945. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2946. }
  2947. } else {
  2948. redis.Set(key, "null", time.Second*60*60*18)
  2949. }
  2950. return his, nil
  2951. }
  2952. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2953. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2954. return his, nil
  2955. }
  2956. }
  2957. if orgid == 10721 {
  2958. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2959. var keyword = "胰岛素"
  2960. keyword = "%" + keyword + "%"
  2961. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? and execution_frequency!='上机前' and delivery_way!='口服' and advice_name not like ?", patientid, orgid, recorddate, keyword).Order("created_time asc").Find(&his).Error
  2962. if err != nil {
  2963. if err == gorm.ErrRecordNotFound {
  2964. if len(his) <= 0 {
  2965. redis.Set(key, "null", time.Second*60*60*18)
  2966. }
  2967. return his, nil
  2968. } else {
  2969. return his, err
  2970. }
  2971. } else {
  2972. if len(his) > 0 {
  2973. //缓存数据
  2974. his_doctor_advice_str, err := json.Marshal(his)
  2975. if err == nil {
  2976. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2977. }
  2978. } else {
  2979. redis.Set(key, "null", time.Second*60*60*18)
  2980. }
  2981. return his, nil
  2982. }
  2983. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2984. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2985. return his, nil
  2986. }
  2987. }
  2988. return his, nil
  2989. }
  2990. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2991. prescription := models.DialysisPrescription{}
  2992. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2993. if err == gorm.ErrRecordNotFound {
  2994. return nil, err
  2995. }
  2996. if err != nil {
  2997. return nil, err
  2998. }
  2999. return &prescription, nil
  3000. }
  3001. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  3002. prescription := models.DialysisPrescription{}
  3003. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  3004. return prescription, err
  3005. }
  3006. type HisMScheduleDoctorAdviceVM struct {
  3007. ID int64 `gorm:"column:id" json:"id"`
  3008. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3009. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3010. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3011. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3012. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3013. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3014. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3015. Status int64 `gorm:"column:status" json:"status"`
  3016. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3017. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3018. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3019. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3020. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3021. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3022. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3023. }
  3024. func (HisMScheduleDoctorAdviceVM) TableName() string {
  3025. return "xt_schedule"
  3026. }
  3027. type HisMScheduleDoctorAdviceVMOne struct {
  3028. ID int64 `gorm:"column:id" json:"id"`
  3029. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3030. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3031. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3032. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3033. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3034. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3035. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3036. Status int64 `gorm:"column:status" json:"status"`
  3037. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3038. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3039. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3040. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3041. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  3042. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3043. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  3044. }
  3045. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  3046. return "xt_schedule"
  3047. }
  3048. type HisMScheduleProjectVM struct {
  3049. ID int64 `gorm:"column:id" json:"id"`
  3050. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  3051. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  3052. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  3053. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  3054. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  3055. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  3056. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  3057. Status int64 `gorm:"column:status" json:"status"`
  3058. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  3059. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  3060. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  3061. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  3062. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  3063. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  3064. }
  3065. func (HisMScheduleProjectVM) TableName() string {
  3066. return "xt_schedule"
  3067. }
  3068. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  3069. config := models.XtHisConfig{}
  3070. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3071. return config, err
  3072. }
  3073. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  3074. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  3075. if orgid > 0 {
  3076. db = db.Where("x.user_org_id = ?", orgid)
  3077. }
  3078. if patientid > 0 {
  3079. db = db.Where("x.patient_id =?", patientid)
  3080. }
  3081. if recordtime > 0 {
  3082. db = db.Where("x.advice_date = ?", recordtime)
  3083. }
  3084. 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
  3085. return advice, err
  3086. }
  3087. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3088. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  3089. if startime > 0 {
  3090. db = db.Where("x.advice_date >= ?", startime)
  3091. }
  3092. if endtime > 0 {
  3093. db = db.Where("x.advice_date<=?", endtime)
  3094. }
  3095. if orgid > 0 {
  3096. db = db.Where("x.user_org_id = ?", orgid)
  3097. }
  3098. if len(deliveway) > 0 {
  3099. db = db.Where("x.delivery_way = ?", deliveway)
  3100. }
  3101. 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
  3102. return advice, err
  3103. }
  3104. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  3105. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  3106. if startime > 0 {
  3107. db = db.Where("x.advice_date >= ?", startime)
  3108. }
  3109. if endtime > 0 {
  3110. db = db.Where("x.advice_date<=?", endtime)
  3111. }
  3112. if orgid > 0 {
  3113. db = db.Where("x.user_org_id = ?", orgid)
  3114. }
  3115. if len(deliveway) > 0 {
  3116. db = db.Where("x.delivery_way = ?", deliveway)
  3117. }
  3118. 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
  3119. return advice, err
  3120. }
  3121. 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) {
  3122. var vms []*MScheduleDoctorAdviceVM
  3123. adviceWhere := ""
  3124. adviceCondition := []interface{}{}
  3125. if adviceType == 0 {
  3126. if patientType == 0 {
  3127. if patient_id > 0 {
  3128. if execution_state > 0 {
  3129. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3131. } else {
  3132. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3133. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3134. }
  3135. } else {
  3136. if execution_state > 0 {
  3137. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3139. } else {
  3140. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3141. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3142. }
  3143. }
  3144. } else if patientType == 1 {
  3145. if patient_id > 0 {
  3146. if execution_state > 0 {
  3147. 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= ?"
  3148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3149. } else {
  3150. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3152. }
  3153. } else {
  3154. if execution_state > 0 {
  3155. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3157. } else {
  3158. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3160. }
  3161. }
  3162. } else if patientType == 2 {
  3163. if patient_id > 0 {
  3164. if execution_state > 0 {
  3165. 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 = ?"
  3166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3167. } else {
  3168. 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 = ?)"
  3169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3170. }
  3171. } else {
  3172. if execution_state > 0 {
  3173. 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 = ?"
  3174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3175. } else {
  3176. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3178. }
  3179. }
  3180. }
  3181. } else if adviceType == 1 {
  3182. if patientType == 0 {
  3183. if patient_id > 0 {
  3184. if execution_state > 0 {
  3185. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3187. } else {
  3188. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3190. }
  3191. } else {
  3192. if execution_state > 0 {
  3193. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3195. } else {
  3196. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3198. }
  3199. }
  3200. } else if patientType == 1 {
  3201. if patient_id > 0 {
  3202. if execution_state > 0 {
  3203. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3205. } else {
  3206. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3208. }
  3209. } else {
  3210. if execution_state > 0 {
  3211. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3213. } else {
  3214. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3216. }
  3217. }
  3218. } else if patientType == 2 {
  3219. if patient_id > 0 {
  3220. if execution_state > 0 {
  3221. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3223. } else {
  3224. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3226. }
  3227. } else {
  3228. if execution_state > 0 {
  3229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3231. } else {
  3232. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3234. }
  3235. }
  3236. }
  3237. } else if adviceType == 3 {
  3238. if patientType == 0 {
  3239. if patient_id > 0 {
  3240. if execution_state > 0 {
  3241. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3243. } else {
  3244. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3245. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3246. }
  3247. } else {
  3248. if execution_state > 0 {
  3249. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3251. } else {
  3252. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3253. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3254. }
  3255. }
  3256. } else if patientType == 1 {
  3257. if patient_id > 0 {
  3258. if execution_state > 0 {
  3259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3261. } else {
  3262. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3264. }
  3265. } else {
  3266. if execution_state > 0 {
  3267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3269. } else {
  3270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3272. }
  3273. }
  3274. } else if patientType == 2 {
  3275. if patient_id > 0 {
  3276. if execution_state > 0 {
  3277. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3279. } else {
  3280. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3282. }
  3283. } else {
  3284. if execution_state > 0 {
  3285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3287. } else {
  3288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3290. }
  3291. }
  3292. }
  3293. } else if adviceType == 2 && len(deliverWay) > 0 {
  3294. if patientType == 0 {
  3295. if patient_id > 0 {
  3296. if execution_state > 0 {
  3297. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3298. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3299. } else {
  3300. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3302. }
  3303. } else {
  3304. if execution_state > 0 {
  3305. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3307. } else {
  3308. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3310. }
  3311. }
  3312. } else if patientType == 1 {
  3313. if patient_id > 0 {
  3314. if execution_state > 0 {
  3315. 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 = ?"
  3316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3317. } else {
  3318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3320. }
  3321. } else {
  3322. if execution_state > 0 {
  3323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3325. } else {
  3326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3328. }
  3329. }
  3330. } else if patientType == 2 {
  3331. if patient_id > 0 {
  3332. if execution_state > 0 {
  3333. 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 = ?"
  3334. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3335. } else {
  3336. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3338. }
  3339. } else {
  3340. if execution_state > 0 {
  3341. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3342. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3343. } else {
  3344. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3346. }
  3347. }
  3348. }
  3349. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3350. if patientType == 0 {
  3351. if patient_id > 0 {
  3352. if execution_state > 0 {
  3353. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3355. } else {
  3356. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3358. }
  3359. } else {
  3360. if execution_state > 0 {
  3361. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3363. } else {
  3364. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3366. }
  3367. }
  3368. } else if patientType == 1 {
  3369. if patient_id > 0 {
  3370. if execution_state > 0 {
  3371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3373. } else {
  3374. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3376. }
  3377. } else {
  3378. if execution_state > 0 {
  3379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3381. } else {
  3382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3384. }
  3385. }
  3386. } else if patientType == 2 {
  3387. if patient_id > 0 {
  3388. if execution_state > 0 {
  3389. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3391. } else {
  3392. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3394. }
  3395. } else {
  3396. if execution_state > 0 {
  3397. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3399. } else {
  3400. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3402. }
  3403. }
  3404. }
  3405. }
  3406. db := readDb.Table("xt_schedule")
  3407. if scheduleType > 0 {
  3408. db = db.Where("schedule_type = ?", scheduleType)
  3409. }
  3410. if partitonType > 0 {
  3411. db = db.Where("partition_id = ?", partitonType)
  3412. }
  3413. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3414. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3415. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3416. }).
  3417. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3418. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3419. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3420. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3421. Preload("DoctorAdvices", adviceCondition...).
  3422. Where("status = 1 AND user_org_id = ?", orgID)
  3423. if scheduleDate != 0 {
  3424. db = db.Where("schedule_date = ?", scheduleDate)
  3425. }
  3426. err := db.Find(&vms).Error
  3427. return vms, err
  3428. }
  3429. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3430. var vms []*HisMScheduleDoctorAdviceVM
  3431. if len(deliverWay) > 0 {
  3432. db := readDb.Table("xt_schedule")
  3433. if scheduleType > 0 {
  3434. db = db.Where("schedule_type = ?", scheduleType)
  3435. }
  3436. if partitionType > 0 {
  3437. db = db.Where("partition_id = ?", partitionType)
  3438. }
  3439. if patient_id > 0 {
  3440. if execution_state > 0 {
  3441. if cost_type > 0 {
  3442. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3443. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3444. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3445. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3446. 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).
  3447. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3448. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3449. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3450. Where("status = 1 AND user_org_id = ?", orgID)
  3451. if scheduleDate != 0 {
  3452. db = db.Where("schedule_date = ?", scheduleDate)
  3453. }
  3454. err = db.Find(&vms).Error
  3455. } else {
  3456. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3457. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3458. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3459. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3460. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state).
  3461. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3462. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3463. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3464. Where("status = 1 AND user_org_id = ?", orgID)
  3465. if scheduleDate != 0 {
  3466. db = db.Where("schedule_date = ?", scheduleDate)
  3467. }
  3468. err = db.Find(&vms).Error
  3469. }
  3470. } else {
  3471. if cost_type > 0 {
  3472. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3473. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3474. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3475. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3476. 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).
  3477. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3478. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3479. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3480. Where("status = 1 AND user_org_id = ?", orgID)
  3481. if scheduleDate != 0 {
  3482. db = db.Where("schedule_date = ?", scheduleDate)
  3483. }
  3484. err = db.Find(&vms).Error
  3485. } else {
  3486. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3487. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3488. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3489. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3490. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3491. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3492. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3493. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3494. Where("status = 1 AND user_org_id = ?", orgID)
  3495. if scheduleDate != 0 {
  3496. db = db.Where("schedule_date = ?", scheduleDate)
  3497. }
  3498. err = db.Find(&vms).Error
  3499. }
  3500. }
  3501. } else {
  3502. if execution_state > 0 {
  3503. if cost_type > 0 {
  3504. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3505. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3506. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3507. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3508. 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).
  3509. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3510. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3511. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3512. Where("status = 1 AND user_org_id = ?", orgID)
  3513. if scheduleDate != 0 {
  3514. db = db.Where("schedule_date = ?", scheduleDate)
  3515. }
  3516. err = db.Find(&vms).Error
  3517. } else {
  3518. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3519. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3520. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3521. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3522. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3523. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3524. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3525. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3526. Where("status = 1 AND user_org_id = ?", orgID)
  3527. if scheduleDate != 0 {
  3528. db = db.Where("schedule_date = ?", scheduleDate)
  3529. }
  3530. err = db.Find(&vms).Error
  3531. }
  3532. } else {
  3533. if cost_type > 0 {
  3534. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3535. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3536. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3537. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3538. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3539. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3540. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3541. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3542. Where("status = 1 AND user_org_id = ?", orgID)
  3543. if scheduleDate != 0 {
  3544. db = db.Where("schedule_date = ?", scheduleDate)
  3545. }
  3546. err = db.Find(&vms).Error
  3547. } else {
  3548. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3549. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3550. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3551. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3552. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3553. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3554. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3555. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3556. Where("status = 1 AND user_org_id = ?", orgID)
  3557. if scheduleDate != 0 {
  3558. db = db.Where("schedule_date = ?", scheduleDate)
  3559. }
  3560. err = db.Find(&vms).Error
  3561. }
  3562. }
  3563. }
  3564. } else {
  3565. db := readDb.Table("xt_schedule")
  3566. if scheduleType > 0 {
  3567. db = db.Where("schedule_type = ?", scheduleType)
  3568. }
  3569. if partitionType > 0 {
  3570. db = db.Where("partition_id = ?", partitionType)
  3571. }
  3572. if patient_id > 0 {
  3573. if execution_state > 0 {
  3574. if cost_type > 0 {
  3575. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3576. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3577. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3578. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3579. 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).
  3580. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3581. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3582. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3583. Where("status = 1 AND user_org_id = ?", orgID)
  3584. if scheduleDate != 0 {
  3585. db = db.Where("schedule_date = ?", scheduleDate)
  3586. }
  3587. err = db.Find(&vms).Error
  3588. } else {
  3589. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3590. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3591. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3592. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3593. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3594. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3595. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3596. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3597. Where("status = 1 AND user_org_id = ?", orgID)
  3598. if scheduleDate != 0 {
  3599. db = db.Where("schedule_date = ?", scheduleDate)
  3600. }
  3601. err = db.Find(&vms).Error
  3602. }
  3603. } else {
  3604. if cost_type > 0 {
  3605. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3606. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3607. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3608. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3609. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3610. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3611. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3612. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3613. Where("status = 1 AND user_org_id = ?", orgID)
  3614. if scheduleDate != 0 {
  3615. db = db.Where("schedule_date = ?", scheduleDate)
  3616. }
  3617. err = db.Find(&vms).Error
  3618. } else {
  3619. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3620. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3621. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3622. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3623. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3624. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3625. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3626. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3627. Where("status = 1 AND user_org_id = ?", orgID)
  3628. if scheduleDate != 0 {
  3629. db = db.Where("schedule_date = ?", scheduleDate)
  3630. }
  3631. err = db.Find(&vms).Error
  3632. }
  3633. }
  3634. } else {
  3635. if execution_state > 0 {
  3636. if cost_type > 0 {
  3637. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3638. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3639. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3640. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3641. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3642. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3643. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3644. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3645. Where("status = 1 AND user_org_id = ?", orgID)
  3646. if scheduleDate != 0 {
  3647. db = db.Where("schedule_date = ?", scheduleDate)
  3648. }
  3649. err = db.Find(&vms).Error
  3650. } else {
  3651. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3652. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3653. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3654. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3655. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3656. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3657. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3658. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3659. Where("status = 1 AND user_org_id = ?", orgID)
  3660. if scheduleDate != 0 {
  3661. db = db.Where("schedule_date = ?", scheduleDate)
  3662. }
  3663. err = db.Find(&vms).Error
  3664. }
  3665. } else {
  3666. if cost_type > 0 {
  3667. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3668. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3669. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3670. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3671. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3672. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3673. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3674. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3675. Where("status = 1 AND user_org_id = ?", orgID)
  3676. if scheduleDate != 0 {
  3677. db = db.Where("schedule_date = ?", scheduleDate)
  3678. }
  3679. err = db.Find(&vms).Error
  3680. } else {
  3681. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3682. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3683. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3684. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3685. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3686. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3687. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3688. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3689. Where("status = 1 AND user_org_id = ?", orgID)
  3690. if scheduleDate != 0 {
  3691. db = db.Where("schedule_date = ?", scheduleDate)
  3692. }
  3693. err = db.Find(&vms).Error
  3694. }
  3695. }
  3696. }
  3697. }
  3698. return vms, err
  3699. }
  3700. func BatchDeleteMonitor(ids []string) (err error) {
  3701. if len(ids) == 1 {
  3702. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3703. } else {
  3704. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3705. }
  3706. return
  3707. }
  3708. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3709. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3710. //table := XTReadDB().Table("xt_schedule as s")
  3711. //fmt.Println(table)
  3712. if patientid > 0 {
  3713. db = db.Where("x.patient_id = ?", patientid)
  3714. }
  3715. if startime > 0 {
  3716. db = db.Where("x.dialysis_date>=?", startime)
  3717. }
  3718. if endtime > 0 {
  3719. db = db.Where("x.dialysis_date <= ?", endtime)
  3720. }
  3721. 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
  3722. return order, err
  3723. }
  3724. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3725. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3726. //table := XTReadDB().Table("xt_schedule as s")
  3727. //fmt.Println(table)
  3728. if patientid > 0 {
  3729. db = db.Where("x.patient_id = ?", patientid)
  3730. }
  3731. if startime > 0 {
  3732. db = db.Where("x.schedule_date>=?", startime)
  3733. }
  3734. if endtime > 0 {
  3735. db = db.Where("x.schedule_date <= ?", endtime)
  3736. }
  3737. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3738. return order, err
  3739. }
  3740. func BatchDeleteAdvice(ids []string) (err error) {
  3741. if len(ids) == 1 {
  3742. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3743. } else {
  3744. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3745. }
  3746. return
  3747. }
  3748. func BatchDeleteHisAdvice(ids []string) (err error) {
  3749. if len(ids) == 1 {
  3750. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3751. } else {
  3752. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3753. }
  3754. return
  3755. }
  3756. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3757. detail := models.AutomaticReduceDetail{}
  3758. 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
  3759. return detail, err
  3760. }
  3761. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3762. detail := models.AutomaticReduceDetail{}
  3763. 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
  3764. return err
  3765. }
  3766. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3767. detail := models.DialysisBeforePrepare{}
  3768. 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
  3769. return err
  3770. }
  3771. func BatchAdviceCheck(ids []string, creator int64) error {
  3772. advice := models.XtDoctorAdvice{}
  3773. 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
  3774. return err
  3775. }
  3776. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3777. advice := models.HisDoctorAdviceInfo{}
  3778. 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
  3779. return err
  3780. }
  3781. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3782. advice := models.XtDoctorAdvice{}
  3783. 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
  3784. return err
  3785. }
  3786. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3787. advice := models.HisDoctorAdviceInfo{}
  3788. 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
  3789. return err
  3790. }
  3791. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3792. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3793. return doctor, err
  3794. }
  3795. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3796. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3797. return doctor, err
  3798. }
  3799. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3800. config := models.XtHisProjectConfig{}
  3801. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3802. return config, err
  3803. }
  3804. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3805. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3806. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3807. }).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
  3808. return
  3809. }
  3810. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3811. var vms []*HisMScheduleProjectVM
  3812. if patientType == 0 {
  3813. if patient_id > 0 {
  3814. if execution_state == 1 {
  3815. db := readDb.
  3816. Table("xt_schedule").
  3817. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3818. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3819. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3820. }).
  3821. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3822. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3823. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3824. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3825. 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")
  3826. }).
  3827. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3828. 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")
  3829. }).Where("status = 1 AND user_org_id = ?", orgID)
  3830. if scheduleDate != 0 {
  3831. db = db.Where("schedule_date = ?", scheduleDate)
  3832. }
  3833. err = db.Find(&vms).Error
  3834. } else if execution_state == 2 {
  3835. db := readDb.
  3836. Table("xt_schedule").
  3837. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3838. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3839. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3840. }).
  3841. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3842. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3843. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3844. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3845. 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")
  3846. }).
  3847. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3848. 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")
  3849. }).Where("status = 1 AND user_org_id = ?", orgID)
  3850. if scheduleDate != 0 {
  3851. db = db.Where("schedule_date = ?", scheduleDate)
  3852. }
  3853. err = db.Find(&vms).Error
  3854. } else if execution_state == 0 {
  3855. db := readDb.
  3856. Table("xt_schedule").
  3857. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3858. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3859. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3860. }).
  3861. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3862. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3863. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3864. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3865. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3866. }).
  3867. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3868. 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")
  3869. }).Where("status = 1 AND user_org_id = ?", orgID)
  3870. if scheduleDate != 0 {
  3871. db = db.Where("schedule_date = ?", scheduleDate)
  3872. }
  3873. err = db.Find(&vms).Error
  3874. }
  3875. } else {
  3876. if patient_id > 0 {
  3877. if execution_state == 1 {
  3878. db := readDb.
  3879. Table("xt_schedule").
  3880. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3881. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3882. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3883. }).
  3884. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3885. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3886. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3887. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3888. 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")
  3889. }).
  3890. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3891. 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")
  3892. }).Where("status = 1 AND user_org_id = ?", orgID)
  3893. if scheduleDate != 0 {
  3894. db = db.Where("schedule_date = ?", scheduleDate)
  3895. }
  3896. err = db.Find(&vms).Error
  3897. } else if execution_state == 2 {
  3898. db := readDb.
  3899. Table("xt_schedule").
  3900. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3901. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3902. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3903. }).
  3904. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3905. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3906. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3907. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3908. 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")
  3909. }).
  3910. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3911. 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")
  3912. }).Where("status = 1 AND user_org_id = ?", orgID)
  3913. if scheduleDate != 0 {
  3914. db = db.Where("schedule_date = ?", scheduleDate)
  3915. }
  3916. err = db.Find(&vms).Error
  3917. } else if execution_state == 0 {
  3918. db := readDb.
  3919. Table("xt_schedule").
  3920. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3921. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3922. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3923. }).
  3924. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3925. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3926. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3927. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3928. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3929. }).
  3930. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3931. 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")
  3932. }).Where("status = 1 AND user_org_id = ?", orgID)
  3933. if scheduleDate != 0 {
  3934. db = db.Where("schedule_date = ?", scheduleDate)
  3935. }
  3936. err = db.Find(&vms).Error
  3937. }
  3938. } else {
  3939. if execution_state == 1 {
  3940. db := readDb.
  3941. Table("xt_schedule").
  3942. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3943. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3944. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3945. }).
  3946. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3947. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3948. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3949. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3950. 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")
  3951. }).
  3952. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3953. 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")
  3954. }).Where("status = 1 AND user_org_id = ?", orgID)
  3955. if scheduleDate != 0 {
  3956. db = db.Where("schedule_date = ?", scheduleDate)
  3957. }
  3958. err = db.Find(&vms).Error
  3959. } else if execution_state == 2 {
  3960. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3961. db := readDb.
  3962. Table("xt_schedule").
  3963. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3964. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3965. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3966. }).
  3967. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3968. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3969. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3970. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3971. 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")
  3972. }).
  3973. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3974. 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")
  3975. }).Where("status = 1 AND user_org_id = ?", orgID)
  3976. if scheduleDate != 0 {
  3977. db = db.Where("schedule_date = ?", scheduleDate)
  3978. }
  3979. err = db.Find(&vms).Error
  3980. } else if execution_state == 0 {
  3981. db := readDb.
  3982. Table("xt_schedule").
  3983. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3984. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3985. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3986. }).
  3987. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3988. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3989. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3990. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3991. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3992. }).
  3993. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3994. 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")
  3995. }).Where("status = 1 AND user_org_id = ?", orgID)
  3996. if scheduleDate != 0 {
  3997. db = db.Where("schedule_date = ?", scheduleDate)
  3998. }
  3999. err = db.Find(&vms).Error
  4000. }
  4001. }
  4002. }
  4003. }
  4004. if patientType > 0 {
  4005. if execution_state == 1 {
  4006. db := readDb.
  4007. Table("xt_schedule").
  4008. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4009. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4010. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4011. }).
  4012. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4013. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4014. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4015. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4016. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4017. 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")
  4018. }).
  4019. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4020. 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")
  4021. }).Where("status = 1 AND user_org_id = ?", orgID)
  4022. if scheduleDate != 0 {
  4023. db = db.Where("schedule_date = ?", scheduleDate)
  4024. }
  4025. err = db.Find(&vms).Error
  4026. } else if execution_state == 2 {
  4027. db := readDb.
  4028. Table("xt_schedule").
  4029. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4030. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4031. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4032. }).
  4033. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4034. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4035. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4036. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4037. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4038. 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")
  4039. }).
  4040. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4041. 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")
  4042. }).Where("status = 1 AND user_org_id = ?", orgID)
  4043. if scheduleDate != 0 {
  4044. db = db.Where("schedule_date = ?", scheduleDate)
  4045. }
  4046. err = db.Find(&vms).Error
  4047. } else if execution_state == 0 {
  4048. db := readDb.
  4049. Table("xt_schedule").
  4050. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  4051. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  4052. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  4053. }).
  4054. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  4055. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  4056. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  4057. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  4058. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  4059. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  4060. }).
  4061. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  4062. 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")
  4063. }).Where("status = 1 AND user_org_id = ?", orgID)
  4064. if scheduleDate != 0 {
  4065. db = db.Where("schedule_date = ?", scheduleDate)
  4066. }
  4067. err = db.Find(&vms).Error
  4068. }
  4069. }
  4070. return vms, err
  4071. }
  4072. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4073. prepare := models.DialysisBeforePrepare{}
  4074. var err error
  4075. if count > 0 {
  4076. 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
  4077. }
  4078. if count <= 0 {
  4079. 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
  4080. }
  4081. return err
  4082. }
  4083. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  4084. detail := models.AutomaticReduceDetail{}
  4085. 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
  4086. return err
  4087. }
  4088. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  4089. var record models.DialysisSolution
  4090. 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
  4091. if err != nil {
  4092. if err == gorm.ErrRecordNotFound {
  4093. return nil, nil
  4094. } else {
  4095. return nil, err
  4096. }
  4097. }
  4098. return &record, nil
  4099. }
  4100. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  4101. var record models.DialysisPrescription
  4102. 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
  4103. if err != nil {
  4104. if err == gorm.ErrRecordNotFound {
  4105. return nil, nil
  4106. } else {
  4107. return nil, err
  4108. }
  4109. }
  4110. return &record, nil
  4111. }
  4112. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4113. prescription := models.DialysisPrescriptionThrity{}
  4114. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4115. return prescription, err
  4116. }
  4117. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4118. var record models.SystemPrescription
  4119. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4120. if err != nil {
  4121. if err == gorm.ErrRecordNotFound {
  4122. return nil, nil
  4123. } else {
  4124. return nil, err
  4125. }
  4126. }
  4127. return &record, nil
  4128. }
  4129. // 透前评估
  4130. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4131. var record models.PredialysisEvaluation
  4132. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4133. if err != nil {
  4134. if err == gorm.ErrRecordNotFound {
  4135. return nil, nil
  4136. } else {
  4137. return nil, err
  4138. }
  4139. }
  4140. return &record, nil
  4141. }
  4142. //
  4143. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4144. //
  4145. // 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
  4146. // return prepare, err
  4147. //}
  4148. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4149. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4150. return auto, err
  4151. }
  4152. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4153. role := models.SgjUserAdminRole{}
  4154. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4155. return role, err
  4156. }
  4157. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4158. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4159. return auto, err
  4160. }
  4161. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4162. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4163. return outifno, err
  4164. }
  4165. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4166. order := models.DialysisOrder{}
  4167. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4168. return order, err
  4169. }
  4170. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4171. record := models.MonitoringRecord{}
  4172. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4173. return record, err
  4174. }
  4175. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4176. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4177. return record, err
  4178. }
  4179. 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) {
  4180. var vms []*MScheduleDoctorAdviceVM
  4181. keyword = "%" + keyword + "%"
  4182. adviceWhere := ""
  4183. adviceCondition := []interface{}{}
  4184. if adviceType == 0 {
  4185. if patientType == 0 {
  4186. if patient_id > 0 {
  4187. if execution_state > 0 {
  4188. if cost_type > 0 {
  4189. if len(execution_frequency) > 0 {
  4190. if len(keyword) > 0 {
  4191. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4192. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4193. } else {
  4194. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and execution_frequency = ?"
  4195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4196. }
  4197. } else {
  4198. if len(keyword) > 0 {
  4199. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and is_settle = ? and advice_name like ?"
  4200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4201. } else {
  4202. 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 = ?"
  4203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4204. }
  4205. }
  4206. } else {
  4207. if len(execution_frequency) > 0 {
  4208. if len(keyword) > 0 {
  4209. 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 ?"
  4210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4211. } else {
  4212. 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 = ?"
  4213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4214. }
  4215. } else {
  4216. if len(keyword) > 0 {
  4217. 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 ?"
  4218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4219. } else {
  4220. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4222. }
  4223. }
  4224. }
  4225. } else {
  4226. if cost_type > 0 {
  4227. if len(execution_frequency) > 0 {
  4228. 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 = ?"
  4229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4230. } else {
  4231. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4233. }
  4234. } else {
  4235. if len(execution_frequency) > 0 {
  4236. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4237. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4238. } else {
  4239. if len(keyword) > 0 {
  4240. 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 ?"
  4241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4242. } else {
  4243. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4245. }
  4246. }
  4247. }
  4248. }
  4249. } else {
  4250. if execution_state > 0 {
  4251. if cost_type > 0 {
  4252. if len(execution_frequency) > 0 {
  4253. if len(keyword) > 0 {
  4254. 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 ?"
  4255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4256. } else {
  4257. 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 = ?"
  4258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4259. }
  4260. } else {
  4261. if len(keyword) > 0 {
  4262. 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 ?"
  4263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4264. } else {
  4265. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4267. }
  4268. }
  4269. } else {
  4270. if len(execution_frequency) > 0 {
  4271. if len(keyword) > 0 {
  4272. 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 ?"
  4273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4274. } else {
  4275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4277. }
  4278. } else {
  4279. if len(keyword) > 0 {
  4280. 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 ?"
  4281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4282. } else {
  4283. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4285. }
  4286. }
  4287. }
  4288. } else {
  4289. if cost_type > 0 {
  4290. if len(execution_frequency) > 0 {
  4291. if len(keyword) > 0 {
  4292. 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 ?"
  4293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4294. } else {
  4295. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4297. }
  4298. } else {
  4299. if len(keyword) > 0 {
  4300. 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 ?"
  4301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4302. } else {
  4303. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4305. }
  4306. }
  4307. } else {
  4308. if len(execution_frequency) > 0 {
  4309. if len(keyword) > 0 {
  4310. 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 ?"
  4311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4312. } else {
  4313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4315. }
  4316. } else {
  4317. if len(keyword) > 0 {
  4318. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4320. } else {
  4321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4323. }
  4324. }
  4325. }
  4326. }
  4327. }
  4328. } else if patientType == 1 {
  4329. if patient_id > 0 {
  4330. if execution_state > 0 {
  4331. if cost_type > 0 {
  4332. if len(execution_frequency) > 0 {
  4333. if len(keyword) > 0 {
  4334. 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 ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4336. } else {
  4337. 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 = ?"
  4338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4339. }
  4340. } else {
  4341. if len(keyword) > 0 {
  4342. 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 ?"
  4343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4344. } else {
  4345. 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 = ?"
  4346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4347. }
  4348. }
  4349. } else {
  4350. if len(execution_frequency) > 0 {
  4351. if len(keyword) > 0 {
  4352. 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 ?"
  4353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4354. } else {
  4355. 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 = ?"
  4356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4357. }
  4358. } else {
  4359. if len(keyword) > 0 {
  4360. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and advice_name like ?"
  4361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4362. } else {
  4363. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4365. }
  4366. }
  4367. }
  4368. } else {
  4369. if cost_type > 0 {
  4370. if len(execution_frequency) > 0 {
  4371. if len(keyword) > 0 {
  4372. 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 ?"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4374. } else {
  4375. 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 = ?"
  4376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4377. }
  4378. } else {
  4379. if len(keyword) > 0 {
  4380. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and advice_name like ?"
  4381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4382. } else {
  4383. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=?"
  4384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4385. }
  4386. }
  4387. } else {
  4388. if len(execution_frequency) > 0 {
  4389. if len(keyword) > 0 {
  4390. 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 ?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4392. } else {
  4393. 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 = ?"
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4395. }
  4396. } else {
  4397. if len(keyword) > 0 {
  4398. 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 ?"
  4399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4400. } else {
  4401. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4403. }
  4404. }
  4405. }
  4406. }
  4407. } else {
  4408. if execution_state > 0 {
  4409. if cost_type > 0 {
  4410. if len(execution_frequency) > 0 {
  4411. if len(keyword) > 0 {
  4412. 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 ?"
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4414. } else {
  4415. 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 = ?"
  4416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4417. }
  4418. } else {
  4419. if len(keyword) > 0 {
  4420. 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 ?"
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4422. } else {
  4423. 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=?"
  4424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4425. }
  4426. }
  4427. } else {
  4428. if len(execution_frequency) > 0 {
  4429. if len(keyword) > 0 {
  4430. 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 ?"
  4431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4432. } else {
  4433. 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 = ?"
  4434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4435. }
  4436. } else {
  4437. if len(keyword) > 0 {
  4438. 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 ?"
  4439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4440. } else {
  4441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4443. }
  4444. }
  4445. }
  4446. } else {
  4447. if cost_type > 0 {
  4448. if len(execution_frequency) > 0 {
  4449. if len(keyword) > 0 {
  4450. 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 ?"
  4451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4452. } else {
  4453. 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 = ?"
  4454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4455. }
  4456. } else {
  4457. if len(keyword) > 0 {
  4458. 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 ?"
  4459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4460. } else {
  4461. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4463. }
  4464. }
  4465. } else {
  4466. if len(execution_frequency) > 0 {
  4467. if len(keyword) > 0 {
  4468. 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 ?"
  4469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4470. } else {
  4471. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4473. }
  4474. } else {
  4475. if len(keyword) > 0 {
  4476. 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 ?"
  4477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4478. } else {
  4479. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4481. }
  4482. }
  4483. }
  4484. }
  4485. }
  4486. } else if patientType == 2 {
  4487. if patient_id > 0 {
  4488. if execution_state > 0 {
  4489. if cost_type > 0 {
  4490. if len(execution_frequency) > 0 {
  4491. if len(keyword) > 0 {
  4492. 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 ?"
  4493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4494. } else {
  4495. 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 = ?"
  4496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4497. }
  4498. } else {
  4499. if len(keyword) > 0 {
  4500. 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 ?"
  4501. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4502. } else {
  4503. 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=?"
  4504. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4505. }
  4506. }
  4507. } else {
  4508. if len(execution_frequency) > 0 {
  4509. if len(keyword) > 0 {
  4510. 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 ?"
  4511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4512. } else {
  4513. 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 = ?"
  4514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4515. }
  4516. } else {
  4517. if len(keyword) > 0 {
  4518. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ? and advice_name like ?"
  4519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4520. } else {
  4521. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
  4522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4523. }
  4524. }
  4525. }
  4526. } else {
  4527. if cost_type > 0 {
  4528. if len(execution_frequency) > 0 {
  4529. if len(keyword) > 0 {
  4530. 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 ?"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4532. } else {
  4533. 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 = ?"
  4534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4535. }
  4536. } else {
  4537. if len(keyword) > 0 {
  4538. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and advice_name like ?"
  4539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4540. } else {
  4541. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=?"
  4542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4543. }
  4544. }
  4545. } else {
  4546. if len(execution_frequency) > 0 {
  4547. if len(keyword) > 0 {
  4548. 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 ?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4550. } else {
  4551. 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 = ?"
  4552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4553. }
  4554. } else {
  4555. if len(keyword) > 0 {
  4556. 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 ?"
  4557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4558. } else {
  4559. 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 = ?)"
  4560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4561. }
  4562. }
  4563. }
  4564. }
  4565. } else {
  4566. if execution_state > 0 {
  4567. if cost_type > 0 {
  4568. if len(execution_frequency) > 0 {
  4569. if len(keyword) > 0 {
  4570. 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 ?"
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4572. } else {
  4573. 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 = ?"
  4574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4575. }
  4576. } else {
  4577. if len(keyword) > 0 {
  4578. 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 ?"
  4579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4580. } else {
  4581. 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=?"
  4582. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4583. }
  4584. }
  4585. } else {
  4586. if len(execution_frequency) > 0 {
  4587. if len(keyword) > 0 {
  4588. 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 ?"
  4589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4590. } else {
  4591. 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 = ?"
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4593. }
  4594. } else {
  4595. if len(keyword) > 0 {
  4596. 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 ?"
  4597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4598. } else {
  4599. 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 = ?"
  4600. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4601. }
  4602. }
  4603. }
  4604. } else {
  4605. if cost_type > 0 {
  4606. if len(execution_frequency) > 0 {
  4607. if len(keyword) > 0 {
  4608. 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 ?"
  4609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4610. } else {
  4611. 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 = ?"
  4612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4613. }
  4614. } else {
  4615. if len(keyword) > 0 {
  4616. 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 ?"
  4617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4618. } else {
  4619. 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 = ?"
  4620. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4621. }
  4622. }
  4623. } else {
  4624. if len(execution_frequency) > 0 {
  4625. if len(keyword) > 0 {
  4626. 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 ?"
  4627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4628. } else {
  4629. 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 = ?"
  4630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4631. }
  4632. } else {
  4633. if len(keyword) > 0 {
  4634. 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 ?"
  4635. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4636. } else {
  4637. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4639. }
  4640. }
  4641. }
  4642. }
  4643. }
  4644. }
  4645. } else if adviceType == 1 {
  4646. if patientType == 0 {
  4647. if patient_id > 0 {
  4648. if execution_state > 0 {
  4649. if cost_type > 0 {
  4650. if len(execution_frequency) > 0 {
  4651. if len(keyword) > 0 {
  4652. 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 ?"
  4653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4654. } else {
  4655. 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 = ?"
  4656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4657. }
  4658. } else {
  4659. if len(keyword) > 0 {
  4660. 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 ?"
  4661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4662. } else {
  4663. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4665. }
  4666. }
  4667. } else {
  4668. if len(execution_frequency) > 0 {
  4669. if len(keyword) > 0 {
  4670. 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 ?"
  4671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4672. } else {
  4673. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4675. }
  4676. } else {
  4677. if len(keyword) > 0 {
  4678. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4680. } else {
  4681. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4683. }
  4684. }
  4685. }
  4686. } else {
  4687. if cost_type > 0 {
  4688. if len(execution_frequency) > 0 {
  4689. if len(keyword) > 0 {
  4690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  4691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4692. } else {
  4693. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4695. }
  4696. } else {
  4697. if len(keyword) > 0 {
  4698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4700. } else {
  4701. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4703. }
  4704. }
  4705. } else {
  4706. if len(execution_frequency) > 0 {
  4707. if len(keyword) > 0 {
  4708. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4710. } else {
  4711. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4713. }
  4714. }
  4715. }
  4716. }
  4717. } else {
  4718. if execution_state > 0 {
  4719. if cost_type > 0 {
  4720. if len(execution_frequency) > 0 {
  4721. if len(keyword) > 0 {
  4722. 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 ?"
  4723. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4724. } else {
  4725. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4727. }
  4728. } else {
  4729. if len(keyword) > 0 {
  4730. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4731. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4732. } else {
  4733. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4734. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4735. }
  4736. }
  4737. } else {
  4738. if len(execution_frequency) > 0 {
  4739. if len(keyword) > 0 {
  4740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4742. } else {
  4743. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4745. }
  4746. } else {
  4747. if len(keyword) > 0 {
  4748. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4750. } else {
  4751. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4753. }
  4754. }
  4755. }
  4756. } else {
  4757. if cost_type > 0 {
  4758. if len(keyword) > 0 {
  4759. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4761. } else {
  4762. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4763. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4764. }
  4765. } else {
  4766. if len(keyword) > 0 {
  4767. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4769. } else {
  4770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4772. }
  4773. }
  4774. }
  4775. }
  4776. } else if patientType == 1 {
  4777. if patient_id > 0 {
  4778. if execution_state > 0 {
  4779. if cost_type > 0 {
  4780. if len(execution_frequency) > 0 {
  4781. if len(keyword) > 0 {
  4782. 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 ?"
  4783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4784. } else {
  4785. 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 = ?"
  4786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4787. }
  4788. } else {
  4789. if len(keyword) > 0 {
  4790. 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 ?"
  4791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4792. } else {
  4793. 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 = ?"
  4794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4795. }
  4796. }
  4797. } else {
  4798. if len(execution_frequency) > 0 {
  4799. if len(keyword) > 0 {
  4800. 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 ?"
  4801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4802. } else {
  4803. 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 = ?"
  4804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4805. }
  4806. } else {
  4807. if len(keyword) > 0 {
  4808. 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 ?"
  4809. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4810. } else {
  4811. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4813. }
  4814. }
  4815. }
  4816. } else {
  4817. if cost_type > 0 {
  4818. if len(execution_frequency) > 0 {
  4819. if len(keyword) > 0 {
  4820. 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 ?"
  4821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4822. } else {
  4823. 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 = ?"
  4824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4825. }
  4826. } else {
  4827. if len(keyword) > 0 {
  4828. 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 ?"
  4829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4830. } else {
  4831. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4833. }
  4834. }
  4835. } else {
  4836. if len(execution_frequency) > 0 {
  4837. if len(keyword) > 0 {
  4838. 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 ?"
  4839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4840. } else {
  4841. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4843. }
  4844. } else {
  4845. if len(keyword) > 0 {
  4846. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4847. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4848. } else {
  4849. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4851. }
  4852. }
  4853. }
  4854. }
  4855. } else {
  4856. if execution_state > 0 {
  4857. if cost_type > 0 {
  4858. if len(execution_frequency) > 0 {
  4859. if len(keyword) > 0 {
  4860. 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 ?"
  4861. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4862. } else {
  4863. 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 = ?"
  4864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4865. }
  4866. } else {
  4867. if len(keyword) > 0 {
  4868. 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 ?"
  4869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4870. } else {
  4871. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4873. }
  4874. }
  4875. } else {
  4876. if len(execution_frequency) > 0 {
  4877. if len(keyword) > 0 {
  4878. 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 ?"
  4879. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4880. } else {
  4881. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4883. }
  4884. } else {
  4885. if len(keyword) > 0 {
  4886. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4887. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4888. } else {
  4889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4891. }
  4892. }
  4893. }
  4894. } else {
  4895. if cost_type > 0 {
  4896. if len(execution_frequency) > 0 {
  4897. if len(keyword) > 0 {
  4898. 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 ?"
  4899. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4900. } else {
  4901. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4903. }
  4904. } else {
  4905. if len(keyword) > 0 {
  4906. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4907. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4908. } else {
  4909. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4911. }
  4912. }
  4913. } else {
  4914. if len(execution_frequency) > 0 {
  4915. if len(keyword) > 0 {
  4916. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4917. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4918. } else {
  4919. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4921. }
  4922. } else {
  4923. if len(keyword) > 0 {
  4924. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4925. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4926. } else {
  4927. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4928. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4929. }
  4930. }
  4931. }
  4932. }
  4933. }
  4934. } else if patientType == 2 {
  4935. if patient_id > 0 {
  4936. if execution_state > 0 {
  4937. if cost_type > 0 {
  4938. if len(execution_frequency) > 0 {
  4939. if len(keyword) > 0 {
  4940. 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 ?"
  4941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4942. } else {
  4943. 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 = ?"
  4944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4945. }
  4946. } else {
  4947. if len(keyword) > 0 {
  4948. 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 ?"
  4949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4950. } else {
  4951. 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 = ?"
  4952. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4953. }
  4954. }
  4955. } else {
  4956. if len(execution_frequency) > 0 {
  4957. if len(keyword) > 0 {
  4958. 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 ?"
  4959. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4960. } else {
  4961. 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 = ?"
  4962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4963. }
  4964. } else {
  4965. if len(keyword) > 0 {
  4966. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  4967. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4968. } else {
  4969. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4971. }
  4972. }
  4973. }
  4974. } else {
  4975. if cost_type > 0 {
  4976. if len(execution_frequency) > 0 {
  4977. if len(keyword) > 0 {
  4978. 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 ?"
  4979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4980. } else {
  4981. 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 = ?"
  4982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4983. }
  4984. } else {
  4985. if len(keyword) > 0 {
  4986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  4987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4988. } else {
  4989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4991. }
  4992. }
  4993. } else {
  4994. if len(execution_frequency) > 0 {
  4995. if len(keyword) > 0 {
  4996. 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 ?"
  4997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4998. } else {
  4999. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5001. }
  5002. } else {
  5003. if len(keyword) > 0 {
  5004. 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 ?"
  5005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5006. } else {
  5007. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5009. }
  5010. }
  5011. }
  5012. }
  5013. } else {
  5014. if execution_state > 0 {
  5015. if cost_type > 0 {
  5016. if len(execution_frequency) > 0 {
  5017. if len(keyword) > 0 {
  5018. 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 ?"
  5019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5020. } else {
  5021. 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 = ?"
  5022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5023. }
  5024. } else {
  5025. if len(keyword) > 0 {
  5026. 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 ?"
  5027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5028. } else {
  5029. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5031. }
  5032. }
  5033. } else {
  5034. if len(execution_frequency) > 0 {
  5035. if len(keyword) > 0 {
  5036. 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 ?"
  5037. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5038. } else {
  5039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5041. }
  5042. } else {
  5043. if len(keyword) > 0 {
  5044. 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 ?"
  5045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5046. } else {
  5047. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5049. }
  5050. }
  5051. }
  5052. } else {
  5053. if cost_type > 0 {
  5054. if len(execution_frequency) > 0 {
  5055. if len(keyword) > 0 {
  5056. 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 ?"
  5057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5058. } else {
  5059. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5061. }
  5062. } else {
  5063. if len(keyword) > 0 {
  5064. 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 ?"
  5065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5066. } else {
  5067. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5068. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5069. }
  5070. }
  5071. } else {
  5072. if len(execution_frequency) > 0 {
  5073. if len(keyword) > 0 {
  5074. 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 ?"
  5075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5076. } else {
  5077. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  5078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5079. }
  5080. } else {
  5081. if len(keyword) > 0 {
  5082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  5083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5084. } else {
  5085. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5087. }
  5088. }
  5089. }
  5090. }
  5091. }
  5092. }
  5093. } else if adviceType == 3 {
  5094. if patientType == 0 {
  5095. if patient_id > 0 {
  5096. if execution_state > 0 {
  5097. if cost_type > 0 {
  5098. if len(execution_frequency) > 0 {
  5099. if len(keyword) > 0 {
  5100. 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 ?"
  5101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5102. } else {
  5103. 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 =?"
  5104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5105. }
  5106. } else {
  5107. if len(keyword) > 0 {
  5108. 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 ?"
  5109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5110. } else {
  5111. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5113. }
  5114. }
  5115. } else {
  5116. if len(execution_frequency) > 0 {
  5117. if len(keyword) > 0 {
  5118. 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 ?"
  5119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5120. } else {
  5121. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5123. }
  5124. } else {
  5125. if len(keyword) > 0 {
  5126. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5128. } else {
  5129. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5131. }
  5132. }
  5133. }
  5134. } else {
  5135. if cost_type > 0 {
  5136. if len(execution_frequency) > 0 {
  5137. if len(keyword) > 0 {
  5138. 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 ?"
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5140. } else {
  5141. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5143. }
  5144. } else {
  5145. if len(keyword) > 0 {
  5146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5148. } else {
  5149. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5151. }
  5152. }
  5153. } else {
  5154. if len(execution_frequency) > 0 {
  5155. if len(keyword) > 0 {
  5156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5158. } else {
  5159. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5161. }
  5162. } else {
  5163. if len(keyword) > 0 {
  5164. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5166. } else {
  5167. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5169. }
  5170. }
  5171. }
  5172. }
  5173. } else {
  5174. if execution_state > 0 {
  5175. if cost_type > 0 {
  5176. if len(execution_frequency) > 0 {
  5177. if len(keyword) > 0 {
  5178. 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 ?"
  5179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5180. } else {
  5181. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5183. }
  5184. } else {
  5185. if len(keyword) > 0 {
  5186. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5188. } else {
  5189. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5191. }
  5192. }
  5193. } else {
  5194. if len(execution_frequency) > 0 {
  5195. if len(keyword) > 0 {
  5196. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5198. } else {
  5199. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5201. }
  5202. } else {
  5203. if len(keyword) > 0 {
  5204. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5206. } else {
  5207. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5209. }
  5210. }
  5211. }
  5212. } else {
  5213. if cost_type > 0 {
  5214. if len(execution_frequency) > 0 {
  5215. if len(keyword) > 0 {
  5216. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5218. } else {
  5219. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5221. }
  5222. } else {
  5223. if len(keyword) > 0 {
  5224. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5226. } else {
  5227. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5229. }
  5230. }
  5231. } else {
  5232. if len(execution_frequency) > 0 {
  5233. if len(keyword) > 0 {
  5234. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5236. } else {
  5237. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5239. }
  5240. } else {
  5241. if len(keyword) > 0 {
  5242. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5244. } else {
  5245. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5247. }
  5248. }
  5249. }
  5250. }
  5251. }
  5252. } else if patientType == 1 {
  5253. if patient_id > 0 {
  5254. if execution_state > 0 {
  5255. if cost_type > 0 {
  5256. if len(execution_frequency) > 0 {
  5257. if len(keyword) > 0 {
  5258. 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 ?"
  5259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5260. } else {
  5261. 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 = ?"
  5262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5263. }
  5264. } else {
  5265. if len(keyword) > 0 {
  5266. 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 ?"
  5267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5268. } else {
  5269. 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 = ?"
  5270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5271. }
  5272. }
  5273. } else {
  5274. if len(execution_frequency) > 0 {
  5275. if len(keyword) > 0 {
  5276. 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 ?"
  5277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5278. } else {
  5279. 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 = ?"
  5280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5281. }
  5282. } else {
  5283. if len(keyword) > 0 {
  5284. 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 ?"
  5285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5286. } else {
  5287. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5289. }
  5290. }
  5291. }
  5292. } else {
  5293. if cost_type > 0 {
  5294. if len(execution_frequency) > 0 {
  5295. if len(keyword) > 0 {
  5296. 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 ?"
  5297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5298. } else {
  5299. 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 = ?"
  5300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5301. }
  5302. } else {
  5303. if len(keyword) > 0 {
  5304. 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 ?"
  5305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5306. } else {
  5307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5309. }
  5310. }
  5311. } else {
  5312. if len(execution_frequency) > 0 {
  5313. if len(keyword) > 0 {
  5314. 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 ?"
  5315. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5316. } else {
  5317. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5319. }
  5320. } else {
  5321. if len(keyword) > 0 {
  5322. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5323. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5324. } else {
  5325. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5326. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5327. }
  5328. }
  5329. }
  5330. }
  5331. } else {
  5332. if execution_state > 0 {
  5333. if cost_type > 0 {
  5334. if len(execution_frequency) > 0 {
  5335. if len(keyword) > 0 {
  5336. 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 ?"
  5337. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5338. } else {
  5339. 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 = ?"
  5340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5341. }
  5342. } else {
  5343. if len(keyword) > 0 {
  5344. 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 ?"
  5345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5346. } else {
  5347. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5349. }
  5350. }
  5351. } else {
  5352. if len(execution_frequency) > 0 {
  5353. if len(keyword) > 0 {
  5354. 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 ? "
  5355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5356. } else {
  5357. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5358. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5359. }
  5360. } else {
  5361. if len(keyword) > 0 {
  5362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5364. } else {
  5365. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5367. }
  5368. }
  5369. }
  5370. } else {
  5371. if cost_type > 0 {
  5372. if len(execution_frequency) > 0 {
  5373. if len(keyword) > 0 {
  5374. 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 ?"
  5375. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5376. } else {
  5377. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5379. }
  5380. } else {
  5381. if len(keyword) > 0 {
  5382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5384. } else {
  5385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5387. }
  5388. }
  5389. } else {
  5390. if len(execution_frequency) > 0 {
  5391. if len(keyword) > 0 {
  5392. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5394. } else {
  5395. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5397. }
  5398. } else {
  5399. if len(keyword) > 0 {
  5400. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5402. } else {
  5403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5405. }
  5406. }
  5407. }
  5408. }
  5409. }
  5410. } else if patientType == 2 {
  5411. if patient_id > 0 {
  5412. if execution_state > 0 {
  5413. if cost_type > 0 {
  5414. if len(execution_frequency) > 0 {
  5415. if len(keyword) > 0 {
  5416. 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 ?"
  5417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5418. } else {
  5419. 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 = ?"
  5420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5421. }
  5422. } else {
  5423. if len(keyword) > 0 {
  5424. 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 ?"
  5425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5426. } else {
  5427. 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 = ?"
  5428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5429. }
  5430. }
  5431. } else {
  5432. if len(execution_frequency) > 0 {
  5433. if len(keyword) > 0 {
  5434. 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 ?"
  5435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5436. } else {
  5437. 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 = ?"
  5438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5439. }
  5440. } else {
  5441. if len(keyword) > 0 {
  5442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  5443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5444. } else {
  5445. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5447. }
  5448. }
  5449. }
  5450. } else {
  5451. if cost_type > 0 {
  5452. if len(execution_frequency) > 0 {
  5453. if len(keyword) > 0 {
  5454. 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 ?"
  5455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5456. } else {
  5457. 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 = ?"
  5458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5459. }
  5460. } else {
  5461. if len(keyword) > 0 {
  5462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  5463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5464. } else {
  5465. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5467. }
  5468. }
  5469. } else {
  5470. if len(execution_frequency) > 0 {
  5471. if len(keyword) > 0 {
  5472. 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 ?"
  5473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5474. } else {
  5475. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5477. }
  5478. } else {
  5479. if len(keyword) > 0 {
  5480. 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 ?"
  5481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5482. } else {
  5483. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5484. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5485. }
  5486. }
  5487. }
  5488. }
  5489. } else {
  5490. if execution_state > 0 {
  5491. if cost_type > 0 {
  5492. if len(execution_frequency) > 0 {
  5493. if len(keyword) > 0 {
  5494. 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 ?"
  5495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5496. } else {
  5497. 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 = ?"
  5498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5499. }
  5500. } else {
  5501. if len(keyword) > 0 {
  5502. 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 ?"
  5503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5504. } else {
  5505. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5507. }
  5508. }
  5509. } else {
  5510. if len(execution_frequency) > 0 {
  5511. if len(keyword) > 0 {
  5512. 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 ?"
  5513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5514. } else {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5517. }
  5518. } else {
  5519. if len(keyword) > 0 {
  5520. 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 ?"
  5521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5522. } else {
  5523. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5525. }
  5526. }
  5527. }
  5528. } else {
  5529. if cost_type > 0 {
  5530. if len(execution_frequency) > 0 {
  5531. if len(keyword) > 0 {
  5532. 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 ?"
  5533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5534. } else {
  5535. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5537. }
  5538. } else {
  5539. if len(keyword) > 0 {
  5540. 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 ?"
  5541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5542. } else {
  5543. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5545. }
  5546. }
  5547. } else {
  5548. if len(execution_frequency) > 0 {
  5549. if len(keyword) > 0 {
  5550. 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 ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5552. } else {
  5553. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5555. }
  5556. } else {
  5557. if len(keyword) > 0 {
  5558. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5560. } else {
  5561. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5562. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5563. }
  5564. }
  5565. }
  5566. }
  5567. }
  5568. }
  5569. } else if adviceType == 2 && len(deliverWay) > 0 {
  5570. if patientType == 0 {
  5571. if patient_id > 0 {
  5572. if execution_state > 0 {
  5573. if cost_type > 0 {
  5574. if len(execution_frequency) > 0 {
  5575. if len(keyword) > 0 {
  5576. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5578. } else {
  5579. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5580. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5581. }
  5582. } else {
  5583. if len(keyword) > 0 {
  5584. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5585. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5586. } else {
  5587. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5588. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5589. }
  5590. }
  5591. } else {
  5592. if len(execution_frequency) > 0 {
  5593. if len(keyword) > 0 {
  5594. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5596. } else {
  5597. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5598. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5599. }
  5600. } else {
  5601. if len(keyword) > 0 {
  5602. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5604. } else {
  5605. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5607. }
  5608. }
  5609. }
  5610. } else {
  5611. if cost_type > 0 {
  5612. if len(execution_frequency) > 0 {
  5613. if len(keyword) > 0 {
  5614. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5616. } else {
  5617. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5618. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5619. }
  5620. } else {
  5621. if len(keyword) > 0 {
  5622. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5623. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5624. } else {
  5625. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5626. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5627. }
  5628. }
  5629. } else {
  5630. if len(execution_frequency) > 0 {
  5631. if len(keyword) > 0 {
  5632. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5634. } else {
  5635. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5637. }
  5638. } else {
  5639. if len(keyword) > 0 {
  5640. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5642. } else {
  5643. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and patient_id = ?"
  5644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5645. }
  5646. }
  5647. }
  5648. }
  5649. } else {
  5650. if execution_state > 0 {
  5651. if cost_type > 0 {
  5652. if len(execution_frequency) > 0 {
  5653. if len(keyword) > 0 {
  5654. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5655. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5656. } else {
  5657. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5658. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5659. }
  5660. } else {
  5661. if len(keyword) > 0 {
  5662. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5663. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5664. } else {
  5665. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5667. }
  5668. }
  5669. } else {
  5670. if len(execution_frequency) > 0 {
  5671. if len(keyword) > 0 {
  5672. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5674. } else {
  5675. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5677. }
  5678. } else {
  5679. if len(keyword) > 0 {
  5680. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5682. } else {
  5683. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_state = ?"
  5684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5685. }
  5686. }
  5687. }
  5688. } else {
  5689. if cost_type > 0 {
  5690. if len(execution_frequency) > 0 {
  5691. if len(keyword) > 0 {
  5692. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5693. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5694. } else {
  5695. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5696. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5697. }
  5698. } else {
  5699. if len(keyword) > 0 {
  5700. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3)2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5701. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5702. } else {
  5703. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and is_settle = ?"
  5704. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5705. }
  5706. }
  5707. } else {
  5708. if len(execution_frequency) > 0 {
  5709. if len(keyword) > 0 {
  5710. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5712. } else {
  5713. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5715. }
  5716. } else {
  5717. if len(keyword) > 0 {
  5718. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ? and advice_name like ?"
  5719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5720. } else {
  5721. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and delivery_way = ?"
  5722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5723. }
  5724. }
  5725. }
  5726. }
  5727. }
  5728. } else if patientType == 1 {
  5729. if patient_id > 0 {
  5730. if execution_state > 0 {
  5731. if cost_type > 0 {
  5732. if len(execution_frequency) > 0 {
  5733. if len(keyword) > 0 {
  5734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5736. } else {
  5737. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5739. }
  5740. } else {
  5741. if len(keyword) > 0 {
  5742. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5744. } else {
  5745. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5747. }
  5748. }
  5749. } else {
  5750. if len(execution_frequency) > 0 {
  5751. if len(keyword) > 0 {
  5752. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5753. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5754. } else {
  5755. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5757. }
  5758. } else {
  5759. if len(keyword) > 0 {
  5760. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5762. } else {
  5763. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5765. }
  5766. }
  5767. }
  5768. } else {
  5769. if cost_type > 0 {
  5770. if len(execution_frequency) > 0 {
  5771. if len(keyword) > 0 {
  5772. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5774. } else {
  5775. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5776. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5777. }
  5778. } else {
  5779. if len(keyword) > 0 {
  5780. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5782. } else {
  5783. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5784. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5785. }
  5786. }
  5787. } else {
  5788. if len(execution_frequency) > 0 {
  5789. if len(keyword) > 0 {
  5790. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5792. } else {
  5793. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5795. }
  5796. } else {
  5797. if len(keyword) > 0 {
  5798. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5800. } else {
  5801. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5803. }
  5804. }
  5805. }
  5806. }
  5807. } else {
  5808. if execution_state > 0 {
  5809. if cost_type > 0 {
  5810. if len(execution_frequency) > 0 {
  5811. if len(keyword) > 0 {
  5812. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5814. } else {
  5815. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5816. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5817. }
  5818. } else {
  5819. if len(keyword) > 0 {
  5820. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5822. } else {
  5823. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5825. }
  5826. }
  5827. } else {
  5828. if len(execution_frequency) > 0 {
  5829. if len(keyword) > 0 {
  5830. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5831. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5832. } else {
  5833. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5835. }
  5836. } else {
  5837. if len(keyword) > 0 {
  5838. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5839. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5840. } else {
  5841. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5843. }
  5844. }
  5845. }
  5846. } else {
  5847. if cost_type > 0 {
  5848. if len(execution_frequency) > 0 {
  5849. if len(keyword) > 0 {
  5850. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND(advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5852. } else {
  5853. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5855. }
  5856. } else {
  5857. if len(keyword) > 0 {
  5858. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5859. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5860. } else {
  5861. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5863. }
  5864. }
  5865. } else {
  5866. if len(execution_frequency) > 0 {
  5867. if len(keyword) > 0 {
  5868. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5869. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5870. } else {
  5871. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5873. }
  5874. } else {
  5875. if len(keyword) > 0 {
  5876. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5878. } else {
  5879. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and delivery_way = ? "
  5880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5881. }
  5882. }
  5883. }
  5884. }
  5885. }
  5886. } else if patientType == 2 {
  5887. if patient_id > 0 {
  5888. if execution_state > 0 {
  5889. if cost_type > 0 {
  5890. if len(execution_frequency) > 0 {
  5891. if len(keyword) > 0 {
  5892. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5894. } else {
  5895. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5896. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5897. }
  5898. } else {
  5899. if len(keyword) > 0 {
  5900. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5902. } else {
  5903. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5904. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5905. }
  5906. }
  5907. } else {
  5908. if len(execution_frequency) > 0 {
  5909. if len(keyword) > 0 {
  5910. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5912. } else {
  5913. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5915. }
  5916. } else {
  5917. if len(keyword) > 0 {
  5918. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5920. } else {
  5921. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
  5922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5923. }
  5924. }
  5925. }
  5926. } else {
  5927. if cost_type > 0 {
  5928. if len(execution_frequency) > 0 {
  5929. if len(keyword) > 0 {
  5930. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5931. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5932. } else {
  5933. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5934. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5935. }
  5936. } else {
  5937. if len(keyword) > 0 {
  5938. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5940. } else {
  5941. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ?"
  5942. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5943. }
  5944. }
  5945. } else {
  5946. if len(execution_frequency) > 0 {
  5947. if len(keyword) > 0 {
  5948. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5950. } else {
  5951. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5952. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5953. }
  5954. } else {
  5955. if len(keyword) > 0 {
  5956. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ? and advice_name like ?"
  5957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5958. } else {
  5959. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5961. }
  5962. }
  5963. }
  5964. }
  5965. } else {
  5966. if execution_state > 0 {
  5967. if cost_type > 0 {
  5968. if len(execution_frequency) > 0 {
  5969. if len(keyword) > 0 {
  5970. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5972. } else {
  5973. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5974. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5975. }
  5976. } else {
  5977. if len(keyword) > 0 {
  5978. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5980. } else {
  5981. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  5982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5983. }
  5984. }
  5985. } else {
  5986. if len(execution_frequency) > 0 {
  5987. if len(keyword) > 0 {
  5988. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5990. } else {
  5991. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5993. }
  5994. } else {
  5995. if len(keyword) > 0 {
  5996. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ? and advice_name like ?"
  5997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5998. } else {
  5999. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6001. }
  6002. }
  6003. }
  6004. } else {
  6005. if cost_type > 0 {
  6006. if len(execution_frequency) > 0 {
  6007. if len(keyword) > 0 {
  6008. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  6009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6010. } else {
  6011. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6012. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6013. }
  6014. } else {
  6015. if len(keyword) > 0 {
  6016. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  6017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  6018. } else {
  6019. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6021. }
  6022. }
  6023. } else {
  6024. if len(keyword) > 0 {
  6025. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  6026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  6027. } else {
  6028. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and delivery_way = ?"
  6029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6030. }
  6031. }
  6032. }
  6033. }
  6034. }
  6035. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6036. if patientType == 0 {
  6037. if patient_id > 0 {
  6038. if execution_state > 0 {
  6039. if cost_type > 0 {
  6040. if len(execution_frequency) > 0 {
  6041. if len(keyword) > 0 {
  6042. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6044. } else {
  6045. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6047. }
  6048. } else {
  6049. if len(keyword) > 0 {
  6050. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6052. } else {
  6053. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6054. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6055. }
  6056. }
  6057. } else {
  6058. if len(execution_frequency) > 0 {
  6059. if len(keyword) > 0 {
  6060. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6062. } else {
  6063. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6065. }
  6066. } else {
  6067. if len(keyword) > 0 {
  6068. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6070. } else {
  6071. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_state = ?"
  6072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6073. }
  6074. }
  6075. }
  6076. } else {
  6077. if cost_type > 0 {
  6078. if len(execution_frequency) > 0 {
  6079. if len(keyword) > 0 {
  6080. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6082. } else {
  6083. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6084. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6085. }
  6086. } else {
  6087. if len(keyword) > 0 {
  6088. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6090. } else {
  6091. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and is_settle = ?"
  6092. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6093. }
  6094. }
  6095. } else {
  6096. if len(execution_frequency) > 0 {
  6097. if len(keyword) > 0 {
  6098. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6100. } else {
  6101. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and execution_frequency = ?"
  6102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6103. }
  6104. } else {
  6105. if len(keyword) > 0 {
  6106. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ? and advice_name like ?"
  6107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6108. } else {
  6109. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and patient_id = ?"
  6110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6111. }
  6112. }
  6113. }
  6114. }
  6115. } else {
  6116. if execution_state > 0 {
  6117. if cost_type > 0 {
  6118. if len(execution_frequency) > 0 {
  6119. if len(keyword) > 0 {
  6120. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6122. } else {
  6123. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6125. }
  6126. } else {
  6127. if len(keyword) > 0 {
  6128. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6130. } else {
  6131. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and is_settle = ?"
  6132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6133. }
  6134. }
  6135. } else {
  6136. if len(execution_frequency) > 0 {
  6137. if len(keyword) > 0 {
  6138. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6140. } else {
  6141. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6143. }
  6144. } else {
  6145. if len(keyword) > 0 {
  6146. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ? and advice_name like ?"
  6147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6148. } else {
  6149. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_state = ?"
  6150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6151. }
  6152. }
  6153. }
  6154. } else {
  6155. if cost_type > 0 {
  6156. if len(execution_frequency) > 0 {
  6157. if len(keyword) > 0 {
  6158. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6160. } else {
  6161. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6163. }
  6164. }
  6165. } else {
  6166. if len(execution_frequency) > 0 {
  6167. if len(keyword) > 0 {
  6168. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6170. } else {
  6171. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and execution_frequency = ?"
  6172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6173. }
  6174. } else {
  6175. if len(keyword) > 0 {
  6176. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ? and advice_name like ?"
  6177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6178. } else {
  6179. adviceWhere = "status = 1 AND user_org_id = ? AND (advice_type = 2 or advice_type =3) AND record_date = ?"
  6180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6181. }
  6182. }
  6183. }
  6184. }
  6185. }
  6186. } else if patientType == 1 {
  6187. if patient_id > 0 {
  6188. if execution_state > 0 {
  6189. if cost_type > 0 {
  6190. if len(execution_frequency) > 0 {
  6191. if len(keyword) > 0 {
  6192. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6194. } else {
  6195. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6196. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6197. }
  6198. } else {
  6199. if len(keyword) > 0 {
  6200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6202. } else {
  6203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6205. }
  6206. }
  6207. } else {
  6208. if len(execution_frequency) > 0 {
  6209. if len(keyword) > 0 {
  6210. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6212. } else {
  6213. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6215. }
  6216. } else {
  6217. if len(keyword) > 0 {
  6218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6220. } else {
  6221. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6223. }
  6224. }
  6225. }
  6226. } else {
  6227. if cost_type > 0 {
  6228. if len(execution_frequency) > 0 {
  6229. if len(keyword) > 0 {
  6230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6232. } else {
  6233. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6234. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6235. }
  6236. } else {
  6237. if len(keyword) > 0 {
  6238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6240. } else {
  6241. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6243. }
  6244. }
  6245. } else {
  6246. if len(execution_frequency) > 0 {
  6247. if len(keyword) > 0 {
  6248. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6250. } else {
  6251. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6253. }
  6254. } else {
  6255. if len(keyword) > 0 {
  6256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6258. } else {
  6259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and patient_id = ?"
  6260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6261. }
  6262. }
  6263. }
  6264. }
  6265. } else {
  6266. if execution_state > 0 {
  6267. if cost_type > 0 {
  6268. if len(execution_frequency) > 0 {
  6269. if len(keyword) > 0 {
  6270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6272. } else {
  6273. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6275. }
  6276. } else {
  6277. if len(keyword) > 0 {
  6278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6280. } else {
  6281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6283. }
  6284. }
  6285. } else {
  6286. if len(execution_frequency) > 0 {
  6287. if len(keyword) > 0 {
  6288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6290. } else {
  6291. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6293. }
  6294. } else {
  6295. if len(keyword) > 0 {
  6296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6298. } else {
  6299. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_state = ?"
  6300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6301. }
  6302. }
  6303. }
  6304. } else {
  6305. if cost_type > 0 {
  6306. if len(execution_frequency) > 0 {
  6307. if len(keyword) > 0 {
  6308. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6310. } else {
  6311. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6313. }
  6314. } else {
  6315. if len(keyword) > 0 {
  6316. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6318. } else {
  6319. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and is_settle = ?"
  6320. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6321. }
  6322. }
  6323. } else {
  6324. if len(execution_frequency) > 0 {
  6325. if len(keyword) > 0 {
  6326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6328. } else {
  6329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and execution_frequency = ?"
  6330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6331. }
  6332. } else {
  6333. if len(keyword) > 0 {
  6334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ? and advice_name like ?"
  6335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6336. } else {
  6337. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND advice_doctor = ?"
  6338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6339. }
  6340. }
  6341. }
  6342. }
  6343. }
  6344. } else if patientType == 2 {
  6345. if patient_id > 0 {
  6346. if execution_state > 0 {
  6347. if cost_type > 0 {
  6348. if len(execution_frequency) > 0 {
  6349. if len(keyword) > 0 {
  6350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6352. } else {
  6353. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6355. }
  6356. } else {
  6357. if len(keyword) > 0 {
  6358. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6360. } else {
  6361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3)2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6363. }
  6364. }
  6365. } else {
  6366. if len(execution_frequency) > 0 {
  6367. if len(keyword) > 0 {
  6368. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6370. } else {
  6371. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6372. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6373. }
  6374. } else {
  6375. if len(keyword) > 0 {
  6376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  6377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6378. } else {
  6379. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6380. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6381. }
  6382. }
  6383. }
  6384. } else {
  6385. if cost_type > 0 {
  6386. if len(execution_frequency) > 0 {
  6387. if len(keyword) > 0 {
  6388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6390. } else {
  6391. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6393. }
  6394. } else {
  6395. if len(keyword) > 0 {
  6396. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6398. } else {
  6399. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6401. }
  6402. }
  6403. } else {
  6404. if len(execution_frequency) > 0 {
  6405. if len(keyword) > 0 {
  6406. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6408. } else {
  6409. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6411. }
  6412. } else {
  6413. if len(keyword) > 0 {
  6414. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6416. } else {
  6417. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and patient_id = ?"
  6418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6419. }
  6420. }
  6421. }
  6422. }
  6423. } else {
  6424. if execution_state > 0 {
  6425. if cost_type > 0 {
  6426. if len(execution_frequency) > 0 {
  6427. if len(keyword) > 0 {
  6428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6430. } else {
  6431. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6433. }
  6434. } else {
  6435. if len(keyword) > 0 {
  6436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6438. } else {
  6439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6441. }
  6442. }
  6443. } else {
  6444. if len(execution_frequency) > 0 {
  6445. if len(keyword) > 0 {
  6446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6448. } else {
  6449. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6451. }
  6452. } else {
  6453. if len(keyword) > 0 {
  6454. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6456. } else {
  6457. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND a(advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_state = ?"
  6458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6459. }
  6460. }
  6461. }
  6462. } else {
  6463. if cost_type > 0 {
  6464. if len(execution_frequency) > 0 {
  6465. if len(keyword) > 0 {
  6466. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6468. } else {
  6469. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6471. }
  6472. } else {
  6473. if len(keyword) > 0 {
  6474. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6476. } else {
  6477. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and is_settle = ?"
  6478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6479. }
  6480. }
  6481. } else {
  6482. if len(execution_frequency) > 0 {
  6483. if len(keyword) > 0 {
  6484. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6486. } else {
  6487. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and execution_frequency = ?"
  6488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6489. }
  6490. } else {
  6491. if len(keyword) > 0 {
  6492. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0 and advice_name like ?"
  6493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6494. } else {
  6495. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 2 or advice_type =3) AND execution_staff = 0"
  6496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6497. }
  6498. }
  6499. }
  6500. }
  6501. }
  6502. }
  6503. }
  6504. db := readDb.Table("xt_schedule")
  6505. if scheduleType > 0 {
  6506. db = db.Where("schedule_type = ?", scheduleType)
  6507. }
  6508. if partitonType > 0 {
  6509. db = db.Where("partition_id = ?", partitonType)
  6510. }
  6511. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6512. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6513. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6514. }).
  6515. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6516. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6517. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6518. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6519. Preload("DoctorAdvices", adviceCondition...).
  6520. Where("status = 1 AND user_org_id = ?", orgID)
  6521. if scheduleDate != 0 {
  6522. db = db.Where("schedule_date = ?", scheduleDate)
  6523. }
  6524. err := db.Find(&vms).Error
  6525. return vms, err
  6526. }
  6527. 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) {
  6528. var vms []*MScheduleDoctorAdviceVM
  6529. adviceWhere := ""
  6530. adviceCondition := []interface{}{}
  6531. if adviceType == 0 {
  6532. if patientType == 0 {
  6533. if patient_id > 0 {
  6534. if execution_state > 0 {
  6535. if cost_type > 0 {
  6536. 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 = ?"
  6537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6538. } else {
  6539. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6540. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6541. }
  6542. } else {
  6543. if cost_type > 0 {
  6544. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6545. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6546. } else {
  6547. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6549. }
  6550. }
  6551. } else {
  6552. if execution_state > 0 {
  6553. if cost_type > 0 {
  6554. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6555. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6556. } else {
  6557. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6558. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6559. }
  6560. } else {
  6561. if cost_type > 0 {
  6562. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6564. } else {
  6565. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6567. }
  6568. }
  6569. }
  6570. } else if patientType == 1 {
  6571. if patient_id > 0 {
  6572. if execution_state > 0 {
  6573. if cost_type > 0 {
  6574. 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 = ?"
  6575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6576. } else {
  6577. 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= ?"
  6578. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6579. }
  6580. } else {
  6581. if cost_type > 0 {
  6582. 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=?"
  6583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6584. } else {
  6585. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6587. }
  6588. }
  6589. } else {
  6590. if execution_state > 0 {
  6591. if cost_type > 0 {
  6592. 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=?"
  6593. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6594. } else {
  6595. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6596. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6597. }
  6598. } else {
  6599. if cost_type > 0 {
  6600. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6602. } else {
  6603. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6605. }
  6606. }
  6607. }
  6608. } else if patientType == 2 {
  6609. if patient_id > 0 {
  6610. if execution_state > 0 {
  6611. if cost_type > 0 {
  6612. 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=?"
  6613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6614. } else {
  6615. 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 = ?"
  6616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6617. }
  6618. } else {
  6619. if cost_type > 0 {
  6620. 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=?"
  6621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6622. } else {
  6623. 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 = ?)"
  6624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6625. }
  6626. }
  6627. } else {
  6628. if execution_state > 0 {
  6629. if cost_type > 0 {
  6630. 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=?"
  6631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6632. } else {
  6633. 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 = ?"
  6634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6635. }
  6636. } else {
  6637. if cost_type > 0 {
  6638. 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 = ?"
  6639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6640. } else {
  6641. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6643. }
  6644. }
  6645. }
  6646. }
  6647. } else if adviceType == 1 {
  6648. if patientType == 0 {
  6649. if patient_id > 0 {
  6650. if execution_state > 0 {
  6651. if cost_type > 0 {
  6652. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6654. } else {
  6655. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6657. }
  6658. } else {
  6659. if cost_type > 0 {
  6660. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6662. } else {
  6663. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6665. }
  6666. }
  6667. } else {
  6668. if execution_state > 0 {
  6669. if cost_type > 0 {
  6670. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6671. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6672. } else {
  6673. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6675. }
  6676. } else {
  6677. if cost_type > 0 {
  6678. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6680. } else {
  6681. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6683. }
  6684. }
  6685. }
  6686. } else if patientType == 1 {
  6687. if patient_id > 0 {
  6688. if execution_state > 0 {
  6689. if cost_type > 0 {
  6690. 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 = ?"
  6691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6692. } else {
  6693. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6695. }
  6696. } else {
  6697. if cost_type > 0 {
  6698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6700. } else {
  6701. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6703. }
  6704. }
  6705. } else {
  6706. if execution_state > 0 {
  6707. if cost_type > 0 {
  6708. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6710. } else {
  6711. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6712. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6713. }
  6714. } else {
  6715. if cost_type > 0 {
  6716. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6718. } else {
  6719. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6720. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6721. }
  6722. }
  6723. }
  6724. } else if patientType == 2 {
  6725. if patient_id > 0 {
  6726. if execution_state > 0 {
  6727. if cost_type > 0 {
  6728. 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 = ?"
  6729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6730. } else {
  6731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6733. }
  6734. } else {
  6735. if cost_type > 0 {
  6736. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6738. } else {
  6739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6741. }
  6742. }
  6743. } else {
  6744. if execution_state > 0 {
  6745. if cost_type > 0 {
  6746. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6748. } else {
  6749. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6751. }
  6752. } else {
  6753. if cost_type > 0 {
  6754. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6756. } else {
  6757. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6759. }
  6760. }
  6761. }
  6762. }
  6763. } else if adviceType == 3 {
  6764. if patientType == 0 {
  6765. if patient_id > 0 {
  6766. if execution_state > 0 {
  6767. if cost_type > 0 {
  6768. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6769. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6770. } else {
  6771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6773. }
  6774. } else {
  6775. if cost_type > 0 {
  6776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6778. } else {
  6779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6781. }
  6782. }
  6783. } else {
  6784. if execution_state > 0 {
  6785. if cost_type > 0 {
  6786. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6788. } else {
  6789. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6790. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6791. }
  6792. } else {
  6793. if cost_type > 0 {
  6794. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6796. } else {
  6797. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6798. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6799. }
  6800. }
  6801. }
  6802. } else if patientType == 1 {
  6803. if patient_id > 0 {
  6804. if execution_state > 0 {
  6805. if cost_type > 0 {
  6806. 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 = ?"
  6807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6808. } else {
  6809. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6811. }
  6812. } else {
  6813. if cost_type > 0 {
  6814. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6816. } else {
  6817. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6819. }
  6820. }
  6821. } else {
  6822. if execution_state > 0 {
  6823. if cost_type > 0 {
  6824. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6826. } else {
  6827. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6829. }
  6830. } else {
  6831. if cost_type > 0 {
  6832. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6834. } else {
  6835. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6837. }
  6838. }
  6839. }
  6840. } else if patientType == 2 {
  6841. if patient_id > 0 {
  6842. if execution_state > 0 {
  6843. if cost_type > 0 {
  6844. 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 = ?"
  6845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6846. } else {
  6847. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6849. }
  6850. } else {
  6851. if cost_type > 0 {
  6852. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6854. } else {
  6855. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6857. }
  6858. }
  6859. } else {
  6860. if execution_state > 0 {
  6861. if cost_type > 0 {
  6862. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6864. } else {
  6865. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6867. }
  6868. } else {
  6869. if cost_type > 0 {
  6870. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6872. } else {
  6873. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6875. }
  6876. }
  6877. }
  6878. }
  6879. } else if adviceType == 2 && len(deliverWay) > 0 {
  6880. if patientType == 0 {
  6881. if patient_id > 0 {
  6882. if execution_state > 0 {
  6883. if cost_type > 0 {
  6884. 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 = ?"
  6885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6886. } else {
  6887. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6889. }
  6890. } else {
  6891. if cost_type > 0 {
  6892. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6894. } else {
  6895. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6896. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6897. }
  6898. }
  6899. } else {
  6900. if execution_state > 0 {
  6901. if cost_type > 0 {
  6902. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6904. } else {
  6905. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6907. }
  6908. } else {
  6909. if cost_type > 0 {
  6910. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6912. } else {
  6913. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6915. }
  6916. }
  6917. }
  6918. } else if patientType == 1 {
  6919. if patient_id > 0 {
  6920. if execution_state > 0 {
  6921. if cost_type > 0 {
  6922. 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 = ?"
  6923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6924. } else {
  6925. 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 = ?"
  6926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6927. }
  6928. } else {
  6929. if cost_type > 0 {
  6930. 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 = ?"
  6931. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6932. } else {
  6933. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6934. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6935. }
  6936. }
  6937. } else {
  6938. if execution_state > 0 {
  6939. if cost_type > 0 {
  6940. 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 = ?"
  6941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6942. } else {
  6943. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6945. }
  6946. } else {
  6947. if cost_type > 0 {
  6948. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6949. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6950. } else {
  6951. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6952. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6953. }
  6954. }
  6955. }
  6956. } else if patientType == 2 {
  6957. if patient_id > 0 {
  6958. if execution_state > 0 {
  6959. if cost_type > 0 {
  6960. 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 = ?"
  6961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6962. } else {
  6963. 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 = ?"
  6964. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6965. }
  6966. } else {
  6967. if cost_type > 0 {
  6968. 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 = ?"
  6969. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6970. } else {
  6971. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6972. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6973. }
  6974. }
  6975. } else {
  6976. if execution_state > 0 {
  6977. if cost_type > 0 {
  6978. 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 = ?"
  6979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6980. } else {
  6981. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6983. }
  6984. } else {
  6985. if cost_type > 0 {
  6986. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6988. } else {
  6989. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6991. }
  6992. }
  6993. }
  6994. }
  6995. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6996. if patientType == 0 {
  6997. if patient_id > 0 {
  6998. if execution_state > 0 {
  6999. if cost_type > 0 {
  7000. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7001. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7002. } else {
  7003. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  7004. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7005. }
  7006. } else {
  7007. if cost_type > 0 {
  7008. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  7009. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7010. } else {
  7011. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  7012. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7013. }
  7014. }
  7015. } else {
  7016. if execution_state > 0 {
  7017. if cost_type > 0 {
  7018. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  7019. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7020. } else {
  7021. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  7022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7023. }
  7024. } else {
  7025. if cost_type > 0 {
  7026. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  7027. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7028. } else {
  7029. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  7030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7031. }
  7032. }
  7033. }
  7034. } else if patientType == 1 {
  7035. if patient_id > 0 {
  7036. if execution_state > 0 {
  7037. if cost_type > 0 {
  7038. 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 = ?"
  7039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  7040. } else {
  7041. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  7043. }
  7044. } else {
  7045. if cost_type > 0 {
  7046. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7047. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  7048. } else {
  7049. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  7050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  7051. }
  7052. }
  7053. } else {
  7054. if execution_state > 0 {
  7055. if cost_type > 0 {
  7056. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  7057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  7058. } else {
  7059. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  7060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  7061. }
  7062. } else {
  7063. if cost_type > 0 {
  7064. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  7065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  7066. } else {
  7067. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  7068. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  7069. }
  7070. }
  7071. }
  7072. } else if patientType == 2 {
  7073. if patient_id > 0 {
  7074. if execution_state > 0 {
  7075. if cost_type > 0 {
  7076. 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 = ?"
  7077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  7078. } else {
  7079. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  7081. }
  7082. } else {
  7083. if cost_type > 0 {
  7084. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  7086. } else {
  7087. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  7088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  7089. }
  7090. }
  7091. } else {
  7092. if execution_state > 0 {
  7093. if cost_type > 0 {
  7094. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7095. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  7096. } else {
  7097. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  7098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  7099. }
  7100. } else {
  7101. if cost_type > 0 {
  7102. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  7103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  7104. } else {
  7105. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  7106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7107. }
  7108. }
  7109. }
  7110. }
  7111. }
  7112. db := readDb.Table("xt_schedule")
  7113. if scheduleType > 0 {
  7114. db = db.Where("schedule_type = ?", scheduleType)
  7115. }
  7116. if partitonType > 0 {
  7117. db = db.Where("partition_id = ?", partitonType)
  7118. }
  7119. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7120. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7121. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7122. }).
  7123. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7124. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7125. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7126. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7127. Preload("DoctorAdvices", adviceCondition...).
  7128. Where("status = 1 AND user_org_id = ?", orgID)
  7129. if scheduleDate != 0 {
  7130. db = db.Where("schedule_date = ?", scheduleDate)
  7131. }
  7132. err := db.Find(&vms).Error
  7133. return vms, err
  7134. }
  7135. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7136. order := models.XtDialysisOrder{}
  7137. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7138. return order, err
  7139. }
  7140. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7141. order := models.XtPatients{}
  7142. 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
  7143. 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
  7144. return err
  7145. }
  7146. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7147. order := models.BloodDialysisOrderCount{}
  7148. db := XTReadDB().Table("xt_dialysis_order as o")
  7149. 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
  7150. return order, err
  7151. }
  7152. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7153. order := models.BloodDialysisOrderCount{}
  7154. db := XTReadDB().Table("xt_dialysis_order as o")
  7155. 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>=1735660800 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7156. return order, err
  7157. }
  7158. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7159. order := models.DialysisOrder{}
  7160. 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
  7161. return order, err
  7162. }
  7163. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7164. information := models.DeviceInformation{}
  7165. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7166. return err
  7167. }
  7168. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7169. var record models.DoubleCheck
  7170. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7171. return record, err
  7172. }
  7173. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7174. record := models.MonitoringRecord{}
  7175. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7176. return record, err
  7177. }
  7178. func GetFirstMonitorOne(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7179. record := models.MonitoringRecord{}
  7180. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id=?", patient_id, monit_date, org_id).First(&record).Error
  7181. return record, err
  7182. }
  7183. func GetLastMonitor(patient_id int64, monit_date int64, org_id int64) (models.MonitoringRecord, error) {
  7184. record := models.MonitoringRecord{}
  7185. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1 and user_org_id = ?", patient_id, monit_date, org_id).Last(&record).Error
  7186. return record, err
  7187. }
  7188. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7189. record := models.MonitoringRecord{}
  7190. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7191. return record, err
  7192. }
  7193. 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) {
  7194. var vms []*HisMScheduleDoctorAdviceVM
  7195. if len(deliverWay) > 0 {
  7196. db := readDb.Table("xt_schedule")
  7197. if scheduleType > 0 {
  7198. db = db.Where("schedule_type = ?", scheduleType)
  7199. }
  7200. if partitionType > 0 {
  7201. db = db.Where("partition_id = ?", partitionType)
  7202. }
  7203. if patient_id > 0 {
  7204. if execution_state > 0 {
  7205. if cost_type > 0 {
  7206. if len(execution_frequency) > 0 {
  7207. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7208. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7209. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7210. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7211. 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).
  7212. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7213. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7214. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7215. Where("status = 1 AND user_org_id = ?", orgID)
  7216. if scheduleDate != 0 {
  7217. db = db.Where("schedule_date = ?", scheduleDate)
  7218. }
  7219. err = db.Find(&vms).Error
  7220. } else {
  7221. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7222. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7223. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7224. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7225. 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).
  7226. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7227. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7228. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7229. Where("status = 1 AND user_org_id = ?", orgID)
  7230. if scheduleDate != 0 {
  7231. db = db.Where("schedule_date = ?", scheduleDate)
  7232. }
  7233. err = db.Find(&vms).Error
  7234. }
  7235. } else {
  7236. if len(execution_frequency) > 0 {
  7237. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7238. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7239. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7240. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7241. 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).
  7242. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7243. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7244. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7245. Where("status = 1 AND user_org_id = ?", orgID)
  7246. if scheduleDate != 0 {
  7247. db = db.Where("schedule_date = ?", scheduleDate)
  7248. }
  7249. err = db.Find(&vms).Error
  7250. } else {
  7251. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7252. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7253. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7254. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7255. 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).
  7256. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7257. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7258. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7259. Where("status = 1 AND user_org_id = ?", orgID)
  7260. if scheduleDate != 0 {
  7261. db = db.Where("schedule_date = ?", scheduleDate)
  7262. }
  7263. err = db.Find(&vms).Error
  7264. }
  7265. }
  7266. } else {
  7267. if cost_type > 0 {
  7268. if len(execution_frequency) > 0 {
  7269. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7270. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7271. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7272. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7273. 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).
  7274. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7275. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7276. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7277. Where("status = 1 AND user_org_id = ?", orgID)
  7278. if scheduleDate != 0 {
  7279. db = db.Where("schedule_date = ?", scheduleDate)
  7280. }
  7281. err = db.Find(&vms).Error
  7282. } else {
  7283. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7284. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7285. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7286. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7287. 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).
  7288. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7289. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7290. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7291. Where("status = 1 AND user_org_id = ?", orgID)
  7292. if scheduleDate != 0 {
  7293. db = db.Where("schedule_date = ?", scheduleDate)
  7294. }
  7295. err = db.Find(&vms).Error
  7296. }
  7297. } else {
  7298. if len(execution_frequency) > 0 {
  7299. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7300. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7301. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7302. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7303. 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).
  7304. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7305. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7306. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7307. Where("status = 1 AND user_org_id = ?", orgID)
  7308. if scheduleDate != 0 {
  7309. db = db.Where("schedule_date = ?", scheduleDate)
  7310. }
  7311. err = db.Find(&vms).Error
  7312. } else {
  7313. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7314. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7315. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7316. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7317. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7318. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7319. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7320. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7321. Where("status = 1 AND user_org_id = ?", orgID)
  7322. if scheduleDate != 0 {
  7323. db = db.Where("schedule_date = ?", scheduleDate)
  7324. }
  7325. err = db.Find(&vms).Error
  7326. }
  7327. }
  7328. }
  7329. } else {
  7330. if execution_state > 0 {
  7331. if cost_type > 0 {
  7332. if len(execution_frequency) > 0 {
  7333. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7334. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7335. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7336. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7337. 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).
  7338. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7339. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7340. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7341. Where("status = 1 AND user_org_id = ?", orgID)
  7342. if scheduleDate != 0 {
  7343. db = db.Where("schedule_date = ?", scheduleDate)
  7344. }
  7345. err = db.Find(&vms).Error
  7346. } else {
  7347. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7348. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7349. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7350. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7351. 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).
  7352. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7353. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7354. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7355. Where("status = 1 AND user_org_id = ?", orgID)
  7356. if scheduleDate != 0 {
  7357. db = db.Where("schedule_date = ?", scheduleDate)
  7358. }
  7359. err = db.Find(&vms).Error
  7360. }
  7361. } else {
  7362. if len(execution_frequency) > 0 {
  7363. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7364. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7365. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7366. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7367. 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).
  7368. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7369. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7370. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7371. Where("status = 1 AND user_org_id = ?", orgID)
  7372. if scheduleDate != 0 {
  7373. db = db.Where("schedule_date = ?", scheduleDate)
  7374. }
  7375. err = db.Find(&vms).Error
  7376. } else {
  7377. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7378. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7379. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7380. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7381. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7382. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7383. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7384. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7385. Where("status = 1 AND user_org_id = ?", orgID)
  7386. if scheduleDate != 0 {
  7387. db = db.Where("schedule_date = ?", scheduleDate)
  7388. }
  7389. err = db.Find(&vms).Error
  7390. }
  7391. }
  7392. } else {
  7393. if cost_type > 0 {
  7394. if len(execution_frequency) > 0 {
  7395. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7396. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7397. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7398. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7399. 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).
  7400. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7401. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7402. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7403. Where("status = 1 AND user_org_id = ?", orgID)
  7404. if scheduleDate != 0 {
  7405. db = db.Where("schedule_date = ?", scheduleDate)
  7406. }
  7407. err = db.Find(&vms).Error
  7408. } else {
  7409. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7410. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7411. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7412. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7413. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7414. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7415. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7416. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7417. Where("status = 1 AND user_org_id = ?", orgID)
  7418. if scheduleDate != 0 {
  7419. db = db.Where("schedule_date = ?", scheduleDate)
  7420. }
  7421. err = db.Find(&vms).Error
  7422. }
  7423. } else {
  7424. if len(execution_frequency) > 0 {
  7425. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7426. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7427. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7428. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7429. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7430. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7431. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7432. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7433. Where("status = 1 AND user_org_id = ?", orgID)
  7434. if scheduleDate != 0 {
  7435. db = db.Where("schedule_date = ?", scheduleDate)
  7436. }
  7437. err = db.Find(&vms).Error
  7438. } else {
  7439. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7440. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7441. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7442. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7443. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7444. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7445. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7446. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7447. Where("status = 1 AND user_org_id = ?", orgID)
  7448. if scheduleDate != 0 {
  7449. db = db.Where("schedule_date = ?", scheduleDate)
  7450. }
  7451. err = db.Find(&vms).Error
  7452. }
  7453. }
  7454. }
  7455. }
  7456. } else {
  7457. db := readDb.Table("xt_schedule")
  7458. if scheduleType > 0 {
  7459. db = db.Where("schedule_type = ?", scheduleType)
  7460. }
  7461. if partitionType > 0 {
  7462. db = db.Where("partition_id = ?", partitionType)
  7463. }
  7464. if patient_id > 0 {
  7465. if execution_state > 0 {
  7466. fmt.Println("execution_state---------------------", execution_state)
  7467. if cost_type > 0 {
  7468. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7469. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7470. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7471. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7472. 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).
  7473. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7474. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7475. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7476. Where("status = 1 AND user_org_id = ?", orgID)
  7477. if scheduleDate != 0 {
  7478. db = db.Where("schedule_date = ?", scheduleDate)
  7479. }
  7480. err = db.Find(&vms).Error
  7481. } else {
  7482. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7483. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7484. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7485. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7486. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7487. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7488. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7489. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7490. Where("status = 1 AND user_org_id = ?", orgID)
  7491. if scheduleDate != 0 {
  7492. db = db.Where("schedule_date = ?", scheduleDate)
  7493. }
  7494. err = db.Find(&vms).Error
  7495. }
  7496. } else {
  7497. if cost_type > 0 {
  7498. if len(execution_frequency) > 0 {
  7499. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7500. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7501. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7502. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7503. 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).
  7504. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7505. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7506. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7507. Where("status = 1 AND user_org_id = ?", orgID)
  7508. if scheduleDate != 0 {
  7509. db = db.Where("schedule_date = ?", scheduleDate)
  7510. }
  7511. err = db.Find(&vms).Error
  7512. } else {
  7513. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7514. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7515. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7516. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7517. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7518. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7519. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7520. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7521. Where("status = 1 AND user_org_id = ?", orgID)
  7522. if scheduleDate != 0 {
  7523. db = db.Where("schedule_date = ?", scheduleDate)
  7524. }
  7525. err = db.Find(&vms).Error
  7526. }
  7527. } else {
  7528. if len(execution_frequency) > 0 {
  7529. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7530. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7532. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7533. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7534. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7535. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7536. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7537. Where("status = 1 AND user_org_id = ?", orgID)
  7538. if scheduleDate != 0 {
  7539. db = db.Where("schedule_date = ?", scheduleDate)
  7540. }
  7541. err = db.Find(&vms).Error
  7542. } else {
  7543. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7544. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7545. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7546. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7547. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7548. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7549. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7550. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7551. Where("status = 1 AND user_org_id = ?", orgID)
  7552. if scheduleDate != 0 {
  7553. db = db.Where("schedule_date = ?", scheduleDate)
  7554. }
  7555. err = db.Find(&vms).Error
  7556. }
  7557. }
  7558. }
  7559. } else {
  7560. if execution_state > 0 {
  7561. if cost_type > 0 {
  7562. if len(execution_frequency) > 0 {
  7563. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7564. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7565. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7566. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7567. 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).
  7568. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7569. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7570. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7571. Where("status = 1 AND user_org_id = ?", orgID)
  7572. if scheduleDate != 0 {
  7573. db = db.Where("schedule_date = ?", scheduleDate)
  7574. }
  7575. err = db.Find(&vms).Error
  7576. } else {
  7577. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7578. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7579. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7580. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7581. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7582. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7583. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7584. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7585. Where("status = 1 AND user_org_id = ?", orgID)
  7586. if scheduleDate != 0 {
  7587. db = db.Where("schedule_date = ?", scheduleDate)
  7588. }
  7589. err = db.Find(&vms).Error
  7590. }
  7591. } else {
  7592. if len(execution_frequency) > 0 {
  7593. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7594. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7595. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7596. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7597. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7598. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7599. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7600. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7601. Where("status = 1 AND user_org_id = ?", orgID)
  7602. if scheduleDate != 0 {
  7603. db = db.Where("schedule_date = ?", scheduleDate)
  7604. }
  7605. err = db.Find(&vms).Error
  7606. } else {
  7607. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7608. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7609. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7610. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7611. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7612. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7613. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7614. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7615. Where("status = 1 AND user_org_id = ?", orgID)
  7616. if scheduleDate != 0 {
  7617. db = db.Where("schedule_date = ?", scheduleDate)
  7618. }
  7619. err = db.Find(&vms).Error
  7620. }
  7621. }
  7622. } else {
  7623. if cost_type > 0 {
  7624. if len(execution_frequency) > 0 {
  7625. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7626. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7627. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7628. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7629. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7630. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7631. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7632. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7633. Where("status = 1 AND user_org_id = ?", orgID)
  7634. if scheduleDate != 0 {
  7635. db = db.Where("schedule_date = ?", scheduleDate)
  7636. }
  7637. err = db.Find(&vms).Error
  7638. } else {
  7639. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7640. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7641. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7642. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7643. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7644. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7645. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7646. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7647. Where("status = 1 AND user_org_id = ?", orgID)
  7648. if scheduleDate != 0 {
  7649. db = db.Where("schedule_date = ?", scheduleDate)
  7650. }
  7651. err = db.Find(&vms).Error
  7652. }
  7653. } else {
  7654. if len(execution_frequency) > 0 {
  7655. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7656. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7657. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7658. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7659. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7660. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7661. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7662. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7663. Where("status = 1 AND user_org_id = ?", orgID)
  7664. if scheduleDate != 0 {
  7665. db = db.Where("schedule_date = ?", scheduleDate)
  7666. }
  7667. err = db.Find(&vms).Error
  7668. } else {
  7669. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7670. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7671. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7672. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7673. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7674. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7675. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7676. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7677. Where("status = 1 AND user_org_id = ?", orgID)
  7678. if scheduleDate != 0 {
  7679. db = db.Where("schedule_date = ?", scheduleDate)
  7680. }
  7681. err = db.Find(&vms).Error
  7682. }
  7683. }
  7684. }
  7685. }
  7686. }
  7687. return vms, err
  7688. }
  7689. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7690. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7691. return weight, err
  7692. }
  7693. 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) {
  7694. fmt.Println("deliverWay-----------------", deliverWay)
  7695. fmt.Println("execution_frequency------------------", execution_frequency)
  7696. fmt.Println("adviceType-----------------", adviceType)
  7697. fmt.Println("patientType----------------", patientType)
  7698. fmt.Println("patient_id----------------", patient_id)
  7699. fmt.Println("execution_state----------------", execution_state)
  7700. fmt.Println("cost_type---------------------", cost_type)
  7701. fmt.Println("execution_frequency", execution_frequency)
  7702. var vms []*MScheduleDoctorAdviceVM
  7703. adviceWhere := ""
  7704. keyword = "%" + keyword + "%"
  7705. adviceCondition := []interface{}{}
  7706. if adviceType == 1 {
  7707. if patientType == 0 {
  7708. if patient_id > 0 {
  7709. if execution_state > 0 {
  7710. if cost_type > 0 {
  7711. if len(execution_frequency) > 0 {
  7712. if len(keyword) > 0 {
  7713. if len(deliverWay) > 0 {
  7714. 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 ?"
  7715. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay, keyword)
  7716. } else {
  7717. 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 ?"
  7718. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7719. }
  7720. } else {
  7721. if len(deliverWay) > 0 {
  7722. 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 =?"
  7723. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  7724. } else {
  7725. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7726. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7727. }
  7728. }
  7729. } else {
  7730. if len(keyword) > 0 {
  7731. if len(deliverWay) > 0 {
  7732. 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 =?"
  7733. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  7734. } else {
  7735. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7736. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7737. }
  7738. } else {
  7739. if len(deliverWay) > 0 {
  7740. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  7741. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  7742. } else {
  7743. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7744. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7745. }
  7746. }
  7747. }
  7748. } else {
  7749. if len(execution_frequency) > 0 {
  7750. if len(keyword) > 0 {
  7751. if len(deliverWay) > 0 {
  7752. 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 =?"
  7753. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  7754. } else {
  7755. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7756. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7757. }
  7758. } else {
  7759. if len(deliverWay) > 0 {
  7760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7761. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  7762. } else {
  7763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7764. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7765. }
  7766. }
  7767. } else {
  7768. if len(keyword) > 0 {
  7769. if len(deliverWay) > 0 {
  7770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ? and delivery_way =?"
  7771. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  7772. } else {
  7773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7774. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7775. }
  7776. } else {
  7777. if len(deliverWay) > 0 {
  7778. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and delivery_way =?"
  7779. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  7780. } else {
  7781. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7782. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7783. }
  7784. }
  7785. }
  7786. }
  7787. } else {
  7788. if cost_type > 0 {
  7789. if len(execution_frequency) > 0 {
  7790. if len(keyword) > 0 {
  7791. if len(deliverWay) > 0 {
  7792. 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 =?"
  7793. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  7794. } else {
  7795. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7796. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7797. }
  7798. } else {
  7799. if len(deliverWay) > 0 {
  7800. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7801. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  7802. } else {
  7803. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7804. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7805. }
  7806. }
  7807. } else {
  7808. if len(keyword) > 0 {
  7809. if len(deliverWay) > 0 {
  7810. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7811. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  7812. } else {
  7813. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7814. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7815. }
  7816. } else {
  7817. if len(deliverWay) > 0 {
  7818. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and delivery_way =?"
  7819. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  7820. } else {
  7821. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7822. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7823. }
  7824. }
  7825. }
  7826. } else {
  7827. if len(execution_frequency) > 0 {
  7828. if len(keyword) > 0 {
  7829. if len(deliverWay) > 0 {
  7830. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7831. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  7832. } else {
  7833. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7834. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7835. }
  7836. } else {
  7837. if len(deliverWay) > 0 {
  7838. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  7839. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  7840. } else {
  7841. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7842. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7843. }
  7844. }
  7845. } else {
  7846. if len(keyword) > 0 {
  7847. if len(deliverWay) > 0 {
  7848. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ? and delivery_way =?"
  7849. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  7850. } else {
  7851. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7852. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7853. }
  7854. } else {
  7855. if len(deliverWay) > 0 {
  7856. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and delivery_way =?"
  7857. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  7858. } else {
  7859. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7860. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7861. }
  7862. }
  7863. }
  7864. }
  7865. }
  7866. } else {
  7867. if execution_state > 0 {
  7868. if cost_type > 0 {
  7869. if len(execution_frequency) > 0 {
  7870. if len(keyword) > 0 {
  7871. if len(deliverWay) > 0 {
  7872. 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 =?"
  7873. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  7874. } else {
  7875. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7876. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7877. }
  7878. } else {
  7879. if len(deliverWay) > 0 {
  7880. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  7881. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  7882. } else {
  7883. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7884. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7885. }
  7886. }
  7887. } else {
  7888. if len(keyword) > 0 {
  7889. if len(deliverWay) > 0 {
  7890. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  7891. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  7892. } else {
  7893. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7894. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7895. }
  7896. } else {
  7897. if len(deliverWay) > 0 {
  7898. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and delivery_way =?"
  7899. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  7900. } else {
  7901. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7902. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7903. }
  7904. }
  7905. }
  7906. } else {
  7907. if len(execution_frequency) > 0 {
  7908. if len(keyword) > 0 {
  7909. if len(deliverWay) > 0 {
  7910. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  7911. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  7912. } else {
  7913. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7914. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7915. }
  7916. } else {
  7917. if len(deliverWay) > 0 {
  7918. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  7919. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  7920. } else {
  7921. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7922. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7923. }
  7924. }
  7925. } else {
  7926. if len(keyword) > 0 {
  7927. if len(deliverWay) > 0 {
  7928. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ? and delivery_way =?"
  7929. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  7930. } else {
  7931. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7932. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7933. }
  7934. } else {
  7935. if len(deliverWay) > 0 {
  7936. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and delivery_way =?"
  7937. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  7938. } else {
  7939. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7940. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7941. }
  7942. }
  7943. }
  7944. }
  7945. } else {
  7946. if cost_type > 0 {
  7947. if len(keyword) > 0 {
  7948. if len(deliverWay) > 0 {
  7949. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ? and delivery_way =?"
  7950. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  7951. } else {
  7952. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7953. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7954. }
  7955. } else {
  7956. if len(deliverWay) > 0 {
  7957. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and delivery_way =?"
  7958. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  7959. } else {
  7960. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7961. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7962. }
  7963. }
  7964. } else {
  7965. if len(keyword) > 0 {
  7966. if len(deliverWay) > 0 {
  7967. if len(execution_frequency) > 0 {
  7968. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =? and execution_frequency =? "
  7969. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay, execution_frequency)
  7970. } else {
  7971. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and delivery_way =?"
  7972. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  7973. }
  7974. } else {
  7975. if len(execution_frequency) > 0 {
  7976. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ? and execution_frequency =?"
  7977. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, execution_frequency)
  7978. } else {
  7979. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7980. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7981. }
  7982. }
  7983. } else {
  7984. if len(deliverWay) > 0 {
  7985. if len(execution_frequency) > 0 {
  7986. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =? and execution_frequency =?"
  7987. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay, execution_frequency)
  7988. } else {
  7989. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and delivery_way =?"
  7990. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  7991. }
  7992. } else {
  7993. if len(execution_frequency) > 0 {
  7994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_frequency =?"
  7995. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  7996. } else {
  7997. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7998. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7999. }
  8000. }
  8001. }
  8002. }
  8003. }
  8004. }
  8005. } else if patientType == 1 {
  8006. if patient_id > 0 {
  8007. if execution_state > 0 {
  8008. if cost_type > 0 {
  8009. if len(execution_frequency) > 0 {
  8010. if len(keyword) > 0 {
  8011. if len(deliverWay) > 0 {
  8012. 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 =?"
  8013. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8014. } else {
  8015. 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 ?"
  8016. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8017. }
  8018. } else {
  8019. if len(keyword) > 0 {
  8020. if len(deliverWay) > 0 {
  8021. 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 =?"
  8022. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  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 execution_state = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8027. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8028. } else {
  8029. 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 = ?"
  8030. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  8031. }
  8032. }
  8033. }
  8034. } else {
  8035. if len(keyword) > 0 {
  8036. if len(deliverWay) > 0 {
  8037. 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 =?"
  8038. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword, deliverWay)
  8039. } else {
  8040. 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 ?"
  8041. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  8042. }
  8043. } else {
  8044. if len(deliverWay) > 0 {
  8045. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  8046. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, deliverWay)
  8047. } else {
  8048. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  8049. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  8050. }
  8051. }
  8052. }
  8053. } else {
  8054. if len(execution_frequency) > 0 {
  8055. if len(keyword) > 0 {
  8056. if len(deliverWay) > 0 {
  8057. 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 =?"
  8058. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8059. } else {
  8060. 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 ?"
  8061. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  8062. }
  8063. } else {
  8064. if len(deliverWay) > 0 {
  8065. 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 =?"
  8066. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, deliverWay)
  8067. } else {
  8068. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8069. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  8070. }
  8071. }
  8072. } else {
  8073. if len(keyword) > 0 {
  8074. if len(deliverWay) > 0 {
  8075. 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 =?"
  8076. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword, deliverWay)
  8077. } else {
  8078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  8079. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  8080. }
  8081. } else {
  8082. if len(deliverWay) > 0 {
  8083. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and delivery_way =?"
  8084. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, deliverWay)
  8085. } else {
  8086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  8087. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  8088. }
  8089. }
  8090. }
  8091. }
  8092. } else {
  8093. if cost_type > 0 {
  8094. if len(execution_frequency) > 0 {
  8095. if len(keyword) > 0 {
  8096. if len(deliverWay) > 0 {
  8097. 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 =?"
  8098. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8099. } else {
  8100. 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 ?"
  8101. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  8102. }
  8103. } else {
  8104. if len(deliverWay) > 0 {
  8105. 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 =?"
  8106. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, deliverWay)
  8107. } else {
  8108. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  8109. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  8110. }
  8111. }
  8112. } else {
  8113. if len(keyword) > 0 {
  8114. if len(deliverWay) > 0 {
  8115. 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 =?"
  8116. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword, deliverWay)
  8117. } else {
  8118. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  8119. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  8120. }
  8121. } else {
  8122. if len(deliverWay) > 0 {
  8123. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and delivery_way =? "
  8124. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, deliverWay)
  8125. } else {
  8126. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  8127. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  8128. }
  8129. }
  8130. }
  8131. } else {
  8132. if len(execution_frequency) > 0 {
  8133. if len(keyword) > 0 {
  8134. if len(deliverWay) > 0 {
  8135. 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 =? "
  8136. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword, deliverWay)
  8137. } else {
  8138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  8139. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  8140. }
  8141. } else {
  8142. if len(deliverWay) > 0 {
  8143. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and delivery_way =? "
  8144. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, deliverWay)
  8145. } else {
  8146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  8147. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  8148. }
  8149. }
  8150. } else {
  8151. if len(keyword) > 0 {
  8152. if len(deliverWay) > 0 {
  8153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ? and delivery_way =?"
  8154. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword, deliverWay)
  8155. } else {
  8156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  8157. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  8158. }
  8159. } else {
  8160. if len(deliverWay) > 0 {
  8161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and delivery_way =?"
  8162. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, deliverWay)
  8163. } else {
  8164. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  8165. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  8166. }
  8167. }
  8168. }
  8169. }
  8170. }
  8171. } else {
  8172. if execution_state > 0 {
  8173. if cost_type > 0 {
  8174. if len(execution_frequency) > 0 {
  8175. if len(keyword) > 0 {
  8176. if len(deliverWay) > 0 {
  8177. 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 =?"
  8178. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8179. } else {
  8180. 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 ?"
  8181. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  8182. }
  8183. } else {
  8184. if len(deliverWay) > 0 {
  8185. 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 =?"
  8186. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, deliverWay)
  8187. } else {
  8188. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  8189. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  8190. }
  8191. }
  8192. } else {
  8193. if len(keyword) > 0 {
  8194. if len(deliverWay) > 0 {
  8195. 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 =?"
  8196. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword, deliverWay)
  8197. } else {
  8198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  8199. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  8200. }
  8201. } else {
  8202. if len(deliverWay) > 0 {
  8203. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and delivery_way =?"
  8204. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, deliverWay)
  8205. } else {
  8206. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  8207. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  8208. }
  8209. }
  8210. }
  8211. } else {
  8212. if len(execution_frequency) > 0 {
  8213. if len(keyword) > 0 {
  8214. if len(deliverWay) > 0 {
  8215. 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 =?"
  8216. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword, deliverWay)
  8217. } else {
  8218. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  8219. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  8220. }
  8221. } else {
  8222. if len(deliverWay) > 0 {
  8223. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and delivery_way =?"
  8224. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, deliverWay)
  8225. } else {
  8226. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  8227. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  8228. }
  8229. }
  8230. } else {
  8231. if len(keyword) > 0 {
  8232. if len(deliverWay) > 0 {
  8233. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ? and delivery_way =?"
  8234. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword, deliverWay)
  8235. } else {
  8236. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  8237. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  8238. }
  8239. } else {
  8240. if len(deliverWay) > 0 {
  8241. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and delivery_way =?"
  8242. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, deliverWay)
  8243. } else {
  8244. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  8245. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  8246. }
  8247. }
  8248. }
  8249. }
  8250. } else {
  8251. if cost_type > 0 {
  8252. if len(execution_frequency) > 0 {
  8253. if len(keyword) > 0 {
  8254. if len(deliverWay) > 0 {
  8255. 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 =?"
  8256. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword, deliverWay)
  8257. } else {
  8258. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  8259. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  8260. }
  8261. } else {
  8262. if len(deliverWay) > 0 {
  8263. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8264. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, deliverWay)
  8265. } else {
  8266. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  8267. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  8268. }
  8269. }
  8270. } else {
  8271. if len(keyword) > 0 {
  8272. if len(deliverWay) > 0 {
  8273. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ? and delivery_way =?"
  8274. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword, deliverWay)
  8275. } else {
  8276. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  8277. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  8278. }
  8279. } else {
  8280. if len(deliverWay) > 0 {
  8281. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and delivery_way =?"
  8282. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, deliverWay)
  8283. } else {
  8284. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  8285. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  8286. }
  8287. }
  8288. }
  8289. } else {
  8290. if len(execution_frequency) > 0 {
  8291. if len(keyword) > 0 {
  8292. if len(deliverWay) > 0 {
  8293. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ? and delivery_way =?"
  8294. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword, deliverWay)
  8295. } else {
  8296. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  8297. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  8298. }
  8299. } else {
  8300. if len(deliverWay) > 0 {
  8301. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and delivery_way =?"
  8302. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, deliverWay)
  8303. } else {
  8304. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  8305. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  8306. }
  8307. }
  8308. } else {
  8309. if len(keyword) > 0 {
  8310. if len(deliverWay) > 0 {
  8311. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ? and delivery_way =?"
  8312. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword, deliverWay)
  8313. } else {
  8314. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  8315. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  8316. }
  8317. } else {
  8318. if len(deliverWay) > 0 {
  8319. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and delivery_way =?"
  8320. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, deliverWay)
  8321. } else {
  8322. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  8323. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  8324. }
  8325. }
  8326. }
  8327. }
  8328. }
  8329. }
  8330. } else if patientType == 2 {
  8331. if patient_id > 0 {
  8332. if execution_state > 0 {
  8333. if cost_type > 0 {
  8334. if len(execution_frequency) > 0 {
  8335. if len(keyword) > 0 {
  8336. if len(deliverWay) > 0 {
  8337. 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 =?"
  8338. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8339. } else {
  8340. 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 ?"
  8341. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  8342. }
  8343. } else {
  8344. if len(deliverWay) > 0 {
  8345. 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 =?"
  8346. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, deliverWay)
  8347. } else {
  8348. 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 = ?"
  8349. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  8350. }
  8351. }
  8352. } else {
  8353. if len(keyword) > 0 {
  8354. if len(deliverWay) > 0 {
  8355. 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 =?"
  8356. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword, deliverWay)
  8357. } else {
  8358. 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 ?"
  8359. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  8360. }
  8361. } else {
  8362. if len(deliverWay) > 0 {
  8363. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and delivery_way =?"
  8364. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, deliverWay)
  8365. } else {
  8366. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  8367. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  8368. }
  8369. }
  8370. }
  8371. } else {
  8372. if len(execution_frequency) > 0 {
  8373. if len(keyword) > 0 {
  8374. if len(deliverWay) > 0 {
  8375. 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 =?"
  8376. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword, deliverWay)
  8377. } else {
  8378. 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 ?"
  8379. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  8380. }
  8381. } else {
  8382. if len(deliverWay) > 0 {
  8383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8384. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, deliverWay)
  8385. } else {
  8386. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  8387. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  8388. }
  8389. }
  8390. } else {
  8391. if len(keyword) > 0 {
  8392. if len(deliverWay) > 0 {
  8393. 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 =?"
  8394. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword, deliverWay)
  8395. } else {
  8396. 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 ?"
  8397. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  8398. }
  8399. } else {
  8400. if len(deliverWay) > 0 {
  8401. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and delivery_way =?"
  8402. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, deliverWay)
  8403. } else {
  8404. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  8405. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  8406. }
  8407. }
  8408. }
  8409. }
  8410. } else {
  8411. if cost_type > 0 {
  8412. if len(execution_frequency) > 0 {
  8413. if len(keyword) > 0 {
  8414. if len(deliverWay) > 0 {
  8415. 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 =?"
  8416. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword, deliverWay)
  8417. } else {
  8418. 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 ?"
  8419. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  8420. }
  8421. } else {
  8422. if len(deliverWay) > 0 {
  8423. 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 =?"
  8424. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, deliverWay)
  8425. } else {
  8426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  8427. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  8428. }
  8429. }
  8430. } else {
  8431. if len(keyword) > 0 {
  8432. if len(deliverWay) > 0 {
  8433. 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 =?"
  8434. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword, deliverWay)
  8435. } else {
  8436. 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 ?"
  8437. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  8438. }
  8439. } else {
  8440. if len(deliverWay) > 0 {
  8441. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and delivery_way =?"
  8442. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, deliverWay)
  8443. } else {
  8444. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  8445. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  8446. }
  8447. }
  8448. }
  8449. } else {
  8450. if len(execution_frequency) > 0 {
  8451. if len(keyword) > 0 {
  8452. if len(deliverWay) > 0 {
  8453. 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 =?"
  8454. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword, deliverWay)
  8455. } else {
  8456. 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 ?"
  8457. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  8458. }
  8459. } else {
  8460. if len(deliverWay) > 0 {
  8461. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and delivery_way =?"
  8462. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, deliverWay)
  8463. } else {
  8464. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  8465. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  8466. }
  8467. }
  8468. } else {
  8469. if len(keyword) > 0 {
  8470. if len(deliverWay) > 0 {
  8471. 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 =?"
  8472. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword, deliverWay)
  8473. } else {
  8474. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  8475. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  8476. }
  8477. } else {
  8478. if len(deliverWay) > 0 {
  8479. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and delivery_way =?"
  8480. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, deliverWay)
  8481. } else {
  8482. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  8483. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  8484. }
  8485. }
  8486. }
  8487. }
  8488. }
  8489. } else {
  8490. if execution_state > 0 {
  8491. if cost_type > 0 {
  8492. if len(execution_frequency) > 0 {
  8493. if len(keyword) > 0 {
  8494. if len(deliverWay) > 0 {
  8495. 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 =?"
  8496. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword, deliverWay)
  8497. } else {
  8498. 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 ?"
  8499. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  8500. }
  8501. } else {
  8502. if len(deliverWay) > 0 {
  8503. 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 =?"
  8504. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, deliverWay)
  8505. } else {
  8506. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  8507. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  8508. }
  8509. }
  8510. } else {
  8511. if len(keyword) > 0 {
  8512. if len(deliverWay) > 0 {
  8513. 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 =?"
  8514. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword, deliverWay)
  8515. } else {
  8516. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  8517. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  8518. }
  8519. } else {
  8520. if len(deliverWay) > 0 {
  8521. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and delivery_way =?"
  8522. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, deliverWay)
  8523. } else {
  8524. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  8525. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  8526. }
  8527. }
  8528. }
  8529. } else {
  8530. if len(execution_frequency) > 0 {
  8531. if len(keyword) > 0 {
  8532. if len(deliverWay) > 0 {
  8533. 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 =?"
  8534. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword, deliverWay)
  8535. } else {
  8536. 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 ?"
  8537. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  8538. }
  8539. } else {
  8540. if len(deliverWay) > 0 {
  8541. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and delivery_way =?"
  8542. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, deliverWay)
  8543. } else {
  8544. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  8545. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  8546. }
  8547. }
  8548. } else {
  8549. if len(keyword) > 0 {
  8550. if len(deliverWay) > 0 {
  8551. 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 =?"
  8552. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword, deliverWay)
  8553. } else {
  8554. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  8555. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  8556. }
  8557. } else {
  8558. if len(deliverWay) > 0 {
  8559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and delivery_way =?"
  8560. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, deliverWay)
  8561. } else {
  8562. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  8563. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  8564. }
  8565. }
  8566. }
  8567. }
  8568. } else {
  8569. if cost_type > 0 {
  8570. if len(execution_frequency) > 0 {
  8571. if len(keyword) > 0 {
  8572. if len(deliverWay) > 0 {
  8573. 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 =?"
  8574. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword, deliverWay)
  8575. } else {
  8576. 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 ?"
  8577. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8578. }
  8579. } else {
  8580. if len(deliverWay) > 0 {
  8581. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and delivery_way =?"
  8582. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, deliverWay)
  8583. } else {
  8584. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8585. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8586. }
  8587. }
  8588. } else {
  8589. if len(keyword) > 0 {
  8590. if len(deliverWay) > 0 {
  8591. 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 =?"
  8592. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword, deliverWay)
  8593. } else {
  8594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8595. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8596. }
  8597. } else {
  8598. if len(deliverWay) > 0 {
  8599. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and delivery_way =?"
  8600. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, deliverWay)
  8601. } else {
  8602. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8603. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8604. }
  8605. }
  8606. }
  8607. } else {
  8608. if len(execution_frequency) > 0 {
  8609. if len(keyword) > 0 {
  8610. if len(deliverWay) > 0 {
  8611. 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 =?"
  8612. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword, deliverWay)
  8613. } else {
  8614. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8615. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8616. }
  8617. } else {
  8618. if len(deliverWay) > 0 {
  8619. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and delivery_way =?"
  8620. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, deliverWay)
  8621. } else {
  8622. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8623. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8624. }
  8625. }
  8626. } else {
  8627. if len(keyword) > 0 {
  8628. if len(deliverWay) > 0 {
  8629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ? and delivery_way =?"
  8630. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword, deliverWay)
  8631. } else {
  8632. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8633. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8634. }
  8635. } else {
  8636. if len(deliverWay) > 0 {
  8637. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and delivery_way =?"
  8638. adviceCondition = append(adviceCondition, adviceWhere, orgID, deliverWay)
  8639. } else {
  8640. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8641. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8642. }
  8643. }
  8644. }
  8645. }
  8646. }
  8647. }
  8648. }
  8649. }
  8650. db := readDb.Table("xt_schedule")
  8651. if scheduleType > 0 {
  8652. db = db.Where("schedule_type = ?", scheduleType)
  8653. }
  8654. if partitonType > 0 {
  8655. db = db.Where("partition_id = ?", partitonType)
  8656. }
  8657. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8658. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8659. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8660. }).
  8661. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8662. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8663. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8664. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8665. Preload("DoctorAdvices", adviceCondition...).
  8666. Where("status = 1 AND user_org_id = ?", orgID)
  8667. if scheduleDate != 0 {
  8668. db = db.Where("schedule_date = ?", scheduleDate)
  8669. }
  8670. err := db.Find(&vms).Error
  8671. return vms, err
  8672. }
  8673. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8674. treatmentAsses := models.ReceiveTreatmentAsses{}
  8675. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8676. return treatmentAsses, err
  8677. }
  8678. func GetDrugIsShow(id int64, org_id int64) (models.XtBaseDrug, error) {
  8679. baseDrug := models.XtBaseDrug{}
  8680. err := XTReadDB().Where("id = ? and status =1 and org_id = ?", id, org_id).Find(&baseDrug).Error
  8681. return baseDrug, err
  8682. }