mobile_dialysis_service.go 495KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "XT_New/models"
  8. "github.com/jinzhu/gorm"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. //err := db.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  38. // return db.Order("dialysis_date desc").Where(" status = 1 AND user_org_id = ? and dialysis_date>=1672502400 && dialysis_date < ?", orgID, scheduleDate)
  39. //}).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  40. return vms, err
  41. }
  42. func GetMonitDialysisOrder(user_org_id int64, patient_id int64, scheduleDate int64) (*models.MDialysisOrderForList, error) {
  43. order := models.MDialysisOrderForList{}
  44. err := XTReadDB().Where("user_org_id = ? and status =1 and patient_id = ?", user_org_id, patient_id).Order("id desc").Last(&order).Error
  45. return &order, err
  46. }
  47. func GetMonitDialysisSolution(user_org_id int64, patient_id int64, mode_id int64) (*models.DialysisSolution, error) {
  48. solution := models.DialysisSolution{}
  49. err := XTReadDB().Where("user_org_id = ? and patient_id =? and solution_status = 1 and mode_id = ?", user_org_id, patient_id, mode_id).Find(&solution).Error
  50. return &solution, err
  51. }
  52. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  53. var vms []*MDialysisScheduleVM
  54. db := readDb.
  55. Table("xt_schedule as sch").
  56. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  60. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  61. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  62. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  63. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  64. Preload("TreatmentMode", "status = 1").
  65. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  66. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  67. if scheduleDate != 0 {
  68. db = db.Where("schedule_date = ?", scheduleDate)
  69. }
  70. err := db.Find(&vms).Error
  71. return vms, err
  72. }
  73. type VMTreatmentSummary struct {
  74. ID int64 `gorm:"column:id" json:"id"`
  75. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  77. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  78. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  79. }
  80. func (VMTreatmentSummary) TableName() string {
  81. return "xt_treatment_summary"
  82. }
  83. type AssessmentAfterDislysis struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  88. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  89. Status int64 `gorm:"column:status" json:"status"`
  90. }
  91. func (AssessmentAfterDislysis) TableName() string {
  92. return "xt_assessment_after_dislysis"
  93. }
  94. type MDialysisScheduleVM struct {
  95. ID int64 `gorm:"column:id" json:"id"`
  96. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  97. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  98. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  99. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  100. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  101. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  102. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  103. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  104. Status int64 `gorm:"column:status" json:"status"`
  105. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  106. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  107. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  108. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  109. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  110. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  111. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  112. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  113. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  114. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  115. }
  116. func (MDialysisScheduleVM) TableName() string {
  117. return "xt_schedule"
  118. }
  119. type MDialysisScheduleVMForList struct {
  120. ID int64 `gorm:"column:id" json:"id"`
  121. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  125. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  126. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  127. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  128. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  129. Status int64 `gorm:"column:status" json:"status"`
  130. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  131. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  132. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  133. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  134. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  135. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  136. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  137. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  138. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  139. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  140. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  141. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  142. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  143. //VMMonitoringRecord []models.VMMonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitor_record"`
  144. }
  145. func (MDialysisScheduleVMForList) TableName() string {
  146. return "xt_schedule"
  147. }
  148. type MDeviceNumberVM struct {
  149. models.DeviceNumber
  150. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  151. }
  152. func (MDeviceNumberVM) TableName() string {
  153. return "xt_device_number"
  154. }
  155. type MSchedualPatientVMList struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  159. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  160. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  161. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  162. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  163. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  164. Age int64 `gorm:"column:age" json:"age"`
  165. Name string `gorm:"column:name" json:"name" form:"name"`
  166. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  167. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  168. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  169. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  170. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  171. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  172. }
  173. func (MSchedualPatientVMList) TableName() string {
  174. return "xt_patients"
  175. }
  176. type MSchedualPatientVM struct {
  177. ID int64 `gorm:"column:id" json:"id" form:"id"`
  178. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  179. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  180. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  181. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  182. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  183. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  184. Source int64 `gorm:"column:source" json:"source" form:"source"`
  185. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  186. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  187. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  188. Name string `gorm:"column:name" json:"name" form:"name"`
  189. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  190. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  191. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  192. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  193. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  194. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  195. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  196. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  197. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  198. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  199. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  200. Height int64 `gorm:"column:height" json:"height" form:"height"`
  201. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  202. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  203. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  204. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  205. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  206. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  207. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  208. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  209. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  210. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  211. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  212. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  213. Children int64 `gorm:"column:children" json:"children" form:"children"`
  214. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  215. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  216. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  217. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  218. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  219. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  220. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  221. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  222. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  223. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  224. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  225. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  226. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  227. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  228. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  229. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  230. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  231. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  232. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  233. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  234. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  235. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  236. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  237. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  238. Status int64 `gorm:"column:status" json:"status" form:"status"`
  239. Age int64 `gorm:"column:age" json:"age"`
  240. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  241. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  242. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  243. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  244. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  245. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  246. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  247. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  248. }
  249. func (MSchedualPatientVM) TableName() string {
  250. return "xt_patients"
  251. }
  252. type MDialysisOrderVM struct {
  253. ID int64 `gorm:"column:id" json:"id"`
  254. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  255. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  256. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  257. Stage int64 `gorm:"column:stage" json:"stage"`
  258. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  259. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  260. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  261. Status int64 `gorm:"column:status" json:"status"`
  262. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  263. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  264. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  265. Creator int64 `gorm:"column:creator" json:"creator"`
  266. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  267. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  268. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  269. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  270. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  271. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  272. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  273. }
  274. func (MDialysisOrderVM) TableName() string {
  275. return "xt_dialysis_order"
  276. }
  277. type MDialysisOrderVMList struct {
  278. ID int64 `gorm:"column:id" json:"id"`
  279. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  280. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  281. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  282. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  283. Stage int64 `gorm:"column:stage" json:"stage"`
  284. // Remark string `gorm:"column:remark" json:"remark"`
  285. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  286. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  287. Status int64 `gorm:"column:status" json:"status"`
  288. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  289. Creator int64 `gorm:"column:creator" json:"creator"`
  290. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  291. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  292. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  293. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  294. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  295. }
  296. func (MDialysisOrderVMList) TableName() string {
  297. return "xt_dialysis_order"
  298. }
  299. type VMDoctorAdvice struct {
  300. ID int64 `gorm:"column:id" json:"id" form:"id"`
  301. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  302. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  303. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  304. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  305. Status int64 `gorm:"column:status" json:"status" form:"status"`
  306. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  307. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  308. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  309. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  310. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  311. }
  312. func (VMDoctorAdvice) TableName() string {
  313. return "xt_doctor_advice"
  314. }
  315. type VMHisDoctorAdviceInfo struct {
  316. ID int64 `gorm:"column:id" json:"id" form:"id"`
  317. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  318. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  319. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  320. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  321. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  322. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  323. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  324. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  325. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  326. }
  327. func (VMHisDoctorAdviceInfo) TableName() string {
  328. return "his_doctor_advice_info"
  329. }
  330. type VMAssessmentAfterDislysis struct {
  331. ID int64 `gorm:"column:id" json:"id"`
  332. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  333. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  334. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  335. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  336. Status int64 `gorm:"column:status" json:"status"`
  337. }
  338. func (VMAssessmentAfterDislysis) TableName() string {
  339. return "xt_assessment_after_dislysis"
  340. }
  341. type NewDeviceInformation struct {
  342. ID int64 `gorm:"column:id" json:"id" form:"id"`
  343. Date int64 `gorm:"column:date" json:"date" form:"date"`
  344. Class int64 `gorm:"column:class" json:"class" form:"class"`
  345. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  346. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  347. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  348. Status int64 `gorm:"column:status" json:"status" form:"status"`
  349. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  350. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  351. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  352. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  353. }
  354. func (NewDeviceInformation) TableName() string {
  355. return "xt_device_information"
  356. }
  357. // 获取透析记录
  358. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  359. var record models.DialysisOrder
  360. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  361. if err != nil {
  362. if err == gorm.ErrRecordNotFound {
  363. return nil, nil
  364. } else {
  365. return nil, err
  366. }
  367. }
  368. return &record, nil
  369. }
  370. // 用户基本信息
  371. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  372. var patient MPatient
  373. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  374. //if err != nil {
  375. // if err == gorm.ErrRecordNotFound {
  376. // return nil, nil
  377. // } else {
  378. // return nil, err
  379. // }
  380. //}
  381. //return &patient, nil
  382. redis := RedisClient()
  383. defer redis.Close()
  384. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  385. patient_info_str, _ := redis.Get(key).Result()
  386. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  387. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  388. if err != nil {
  389. if err == gorm.ErrRecordNotFound {
  390. return &patient, nil
  391. } else {
  392. return &patient, err
  393. }
  394. } else {
  395. if patient.ID > 0 {
  396. //缓存数据
  397. patient_info_json, err := json.Marshal(&patient)
  398. if err == nil {
  399. redis.Set(key, patient_info_json, time.Second*60*60*18)
  400. }
  401. }
  402. return &patient, nil
  403. }
  404. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  405. json.Unmarshal([]byte(patient_info_str), &patient)
  406. return &patient, nil
  407. }
  408. }
  409. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  410. var vm MDialysisScheduleVM
  411. err := readDb.
  412. Table("xt_schedule").
  413. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  414. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  415. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  416. First(&vm).Error
  417. return &vm, err
  418. }
  419. // 用户排班信息
  420. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  421. var vm MDialysisScheduleVM
  422. err := readDb.
  423. Table("xt_schedule").
  424. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  426. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  427. First(&vm).Error
  428. if err != nil {
  429. if err == gorm.ErrRecordNotFound {
  430. return nil, nil
  431. } else {
  432. return nil, err
  433. }
  434. }
  435. return &vm, err
  436. }
  437. // 用户排班信息
  438. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  439. redis := RedisClient()
  440. defer redis.Close()
  441. var vm MDialysisScheduleVM
  442. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  443. redis.Set(key, "", time.Second)
  444. schedual_detail_str, _ := redis.Get(key).Result()
  445. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  446. err := readDb.
  447. Table("xt_schedule").
  448. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  449. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  450. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  451. First(&vm).Error
  452. if err != nil {
  453. if err == gorm.ErrRecordNotFound {
  454. return nil, nil
  455. } else {
  456. return nil, err
  457. }
  458. } else {
  459. if vm.ID > 0 {
  460. //缓存数据
  461. schedual_detail_str, err := json.Marshal(vm)
  462. if err == nil {
  463. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  464. }
  465. } else {
  466. redis.Set(key, "null", time.Second*60*60*18)
  467. }
  468. return &vm, nil
  469. }
  470. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  471. if schedual_detail_str == "null" {
  472. return &vm, nil
  473. }
  474. json.Unmarshal([]byte(schedual_detail_str), &vm)
  475. return &vm, nil
  476. }
  477. }
  478. // 用户排班信息
  479. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  480. var schedule models.Schedule
  481. err := readDb.
  482. Table("xt_schedule").
  483. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  484. First(&schedule).Error
  485. if err != nil {
  486. if err == gorm.ErrRecordNotFound {
  487. return nil, nil
  488. } else {
  489. return nil, err
  490. }
  491. }
  492. return &schedule, nil
  493. }
  494. type MPatient struct {
  495. ID int64 `gorm:"column:id" json:"id" form:"id"`
  496. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  497. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  498. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  499. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  500. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  501. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  502. Source int64 `gorm:"column:source" json:"source" form:"source"`
  503. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  504. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  505. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  506. Name string `gorm:"column:name" json:"name" form:"name"`
  507. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  508. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  509. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  510. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  511. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  512. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  513. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  514. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  515. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  516. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  517. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  518. Height int64 `gorm:"column:height" json:"height" form:"height"`
  519. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  520. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  521. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  522. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  523. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  524. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  525. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  526. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  527. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  528. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  529. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  530. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  531. Children int64 `gorm:"column:children" json:"children" form:"children"`
  532. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  533. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  534. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  535. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  536. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  537. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  538. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  539. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  540. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  541. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  542. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  543. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  544. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  545. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  546. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  547. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  548. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  549. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  550. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  551. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  552. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  553. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  554. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  555. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  556. Status int64 `gorm:"column:status" json:"status" form:"status"`
  557. Age int64 `gorm:"column:age" json:"age"`
  558. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  559. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  560. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  561. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  562. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  563. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  564. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  565. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  566. }
  567. func (MPatient) TableName() string {
  568. return "xt_patients"
  569. }
  570. // 接诊评估
  571. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  572. var record models.ReceiveTreatmentAsses
  573. redis := RedisClient()
  574. defer redis.Close()
  575. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  576. receive_treatment_asses_str, _ := redis.Get(key).Result()
  577. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  578. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  579. if err != nil {
  580. if err == gorm.ErrRecordNotFound {
  581. if record.ID <= 0 {
  582. redis.Set(key, "", time.Second*60*60*18)
  583. }
  584. return nil, nil
  585. } else {
  586. return nil, err
  587. }
  588. } else {
  589. if record.ID > 0 {
  590. //缓存数据
  591. receive_treatment_asses_str, err := json.Marshal(record)
  592. if err == nil {
  593. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  594. }
  595. } else {
  596. redis.Set(key, "null", time.Second*60*60*18)
  597. }
  598. return &record, nil
  599. }
  600. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  601. if receive_treatment_asses_str == "null" {
  602. return &record, nil
  603. }
  604. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  605. return &record, nil
  606. }
  607. }
  608. // 透前评估
  609. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  610. var record models.PredialysisEvaluation
  611. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  612. if err != nil {
  613. if err == gorm.ErrRecordNotFound {
  614. return nil, nil
  615. } else {
  616. return nil, err
  617. }
  618. }
  619. return &record, nil
  620. }
  621. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  622. var record models.PredialysisEvaluation
  623. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  624. return record, err
  625. }
  626. // 透前评估
  627. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  628. var record models.PredialysisEvaluation
  629. redis := RedisClient()
  630. defer redis.Close()
  631. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  632. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  633. redis.Set(key, "", time.Second)
  634. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  635. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  636. if err != nil {
  637. if err == gorm.ErrRecordNotFound {
  638. if record.ID <= 0 {
  639. redis.Set(key, "", time.Second*60*60*18)
  640. }
  641. return nil, nil
  642. } else {
  643. return nil, err
  644. }
  645. } else {
  646. if record.ID > 0 {
  647. //缓存数据
  648. assessment_before_dislysis_str, err := json.Marshal(record)
  649. if err == nil {
  650. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  651. }
  652. } else {
  653. redis.Set(key, "null", time.Second*60*60*18)
  654. }
  655. return &record, nil
  656. }
  657. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  658. if assessment_before_dislysis_str == "null" {
  659. return &record, nil
  660. } else {
  661. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  662. return &record, nil
  663. }
  664. }
  665. }
  666. // 获取 maxDate 之前一次的透前评估记录
  667. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  668. var record models.PredialysisEvaluation
  669. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  670. if err != nil {
  671. if err == gorm.ErrRecordNotFound {
  672. return nil, nil
  673. } else {
  674. return nil, err
  675. }
  676. }
  677. return &record, nil
  678. }
  679. // 获取 maxDate 之前一次的透前评估记录
  680. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  681. var record models.PredialysisEvaluation
  682. redis := RedisClient()
  683. defer redis.Close()
  684. // cur_date := time.Now().Format("2006-01-02")
  685. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  686. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  687. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  688. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  689. if err != nil {
  690. if err == gorm.ErrRecordNotFound {
  691. if record.ID <= 0 {
  692. redis.Set(key, "", time.Second*60*60*18)
  693. }
  694. return nil, nil
  695. } else {
  696. return nil, err
  697. }
  698. } else {
  699. if record.ID > 0 {
  700. //缓存数据
  701. assessment_before_dislysis_last_str, err := json.Marshal(record)
  702. if err == nil {
  703. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  704. }
  705. } else {
  706. redis.Set(key, "null", time.Second*60*60*18)
  707. }
  708. return &record, nil
  709. }
  710. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  711. if assessment_before_dislysis_last_str == "null" {
  712. return &record, nil
  713. } else {
  714. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  715. return &record, nil
  716. }
  717. }
  718. }
  719. // 临时医嘱
  720. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  721. var records []*models.DoctorAdvice
  722. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  723. err := readDb.
  724. Model(&models.DoctorAdvice{}).
  725. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  726. Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno,is_medicine").
  727. Order("start_time asc, groupno desc, advice_order desc, id").
  728. Scan(&records).Error
  729. if err != nil {
  730. return nil, err
  731. }
  732. return records, nil
  733. }
  734. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  735. var records []*models.DoctorAdvice
  736. redis := RedisClient()
  737. defer redis.Close()
  738. // cur_date := time.Now().Format("2006-01-02")
  739. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  740. //fmt.Println("key23233232323323wi", key)
  741. redis.Set(key, "", time.Second)
  742. doctor_advices_str, _ := redis.Get(key).Result()
  743. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  744. err := readDb.Model(&models.DoctorAdvice{}).
  745. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  746. Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,is_medicine,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  747. Order("start_time asc, groupno desc, advice_order desc, id asc").
  748. Scan(&records).Error
  749. if err != nil {
  750. if err == gorm.ErrRecordNotFound {
  751. if len(records) <= 0 {
  752. redis.Set(key, "", time.Second*60*60*18)
  753. }
  754. return nil, nil
  755. } else {
  756. return nil, err
  757. }
  758. } else {
  759. if len(records) > 0 {
  760. //缓存数据
  761. doctor_advices_str, err := json.Marshal(records)
  762. if err == nil {
  763. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  764. return records, nil
  765. }
  766. } else {
  767. redis.Set(key, "null", time.Second*60*60*18)
  768. return records, nil
  769. }
  770. return records, nil
  771. }
  772. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  773. if doctor_advices_str == "null" {
  774. return records, nil
  775. } else {
  776. json.Unmarshal([]byte(doctor_advices_str), &records)
  777. return records, nil
  778. }
  779. }
  780. }
  781. // 透析记录
  782. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  783. var record models.DialysisOrder
  784. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ?", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  785. if err != nil {
  786. if err == gorm.ErrRecordNotFound {
  787. return nil, nil
  788. } else {
  789. return nil, err
  790. }
  791. }
  792. return &record, nil
  793. }
  794. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  795. // var record models.DialysisOrder
  796. //
  797. // err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  798. //
  799. //
  800. // return &record,err
  801. //}
  802. // 透析记录
  803. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  804. var record models.DialysisOrder
  805. redis := RedisClient()
  806. defer redis.Close()
  807. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  808. dialysis_order_str, _ := redis.Get(key).Result()
  809. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  810. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  811. if err != nil {
  812. if err == gorm.ErrRecordNotFound {
  813. return nil, nil
  814. } else {
  815. return nil, err
  816. }
  817. } else {
  818. if record.ID > 0 {
  819. //缓存数据
  820. dialysis_order_str, err := json.Marshal(record)
  821. if err == nil {
  822. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  823. }
  824. } else {
  825. redis.Set(key, "null", time.Second*60*60*18)
  826. }
  827. return &record, nil
  828. }
  829. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  830. if dialysis_order_str == "null" {
  831. err = readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  832. return &record, nil
  833. } else {
  834. json.Unmarshal([]byte(dialysis_order_str), &record)
  835. return &record, nil
  836. }
  837. }
  838. }
  839. // 双人核对
  840. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  841. var record models.DoubleCheck
  842. redis := RedisClient()
  843. defer redis.Close()
  844. // cur_date := time.Now().Format("2006-01-02")
  845. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  846. double_check_str, _ := redis.Get(key).Result()
  847. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  848. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  849. if err != nil {
  850. if err == gorm.ErrRecordNotFound {
  851. if record.ID <= 0 {
  852. redis.Set(key, "null", time.Second*60*60*18)
  853. }
  854. return nil, nil
  855. } else {
  856. return nil, err
  857. }
  858. } else {
  859. if record.ID > 0 {
  860. //缓存数据
  861. double_check_str, err := json.Marshal(record)
  862. if err == nil {
  863. redis.Set(key, double_check_str, time.Second*60*60*18)
  864. }
  865. } else {
  866. redis.Set(key, "null", time.Second*60*60*18)
  867. }
  868. return &record, nil
  869. }
  870. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  871. if double_check_str == "null" {
  872. return &record, nil
  873. } else {
  874. json.Unmarshal([]byte(double_check_str), &record)
  875. return &record, nil
  876. }
  877. }
  878. }
  879. // 透析监测记录
  880. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  881. var records []*models.MonitoringRecord
  882. redis := RedisClient()
  883. defer redis.Close()
  884. // cur_date := time.Now().Format("2006-01-02")
  885. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  886. redis.Set(key, "", time.Second)
  887. monitor_records_str, _ := redis.Get(key).Result()
  888. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  889. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
  890. if err != nil {
  891. if err == gorm.ErrRecordNotFound {
  892. //if len(records) <= 0 {
  893. // redis.Set(key, "null", time.Second*60*60*18)
  894. //}
  895. return nil, nil
  896. } else {
  897. return nil, err
  898. }
  899. } else {
  900. if len(records) > 0 {
  901. //缓存数据
  902. monitor_records_str, err := json.Marshal(records)
  903. if err == nil {
  904. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  905. }
  906. } else {
  907. redis.Set(key, "null", time.Second*60*60*18)
  908. }
  909. return records, nil
  910. }
  911. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  912. if monitor_records_str == "null" {
  913. return records, nil
  914. } else {
  915. json.Unmarshal([]byte(monitor_records_str), &records)
  916. return records, nil
  917. }
  918. }
  919. }
  920. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  921. var records models.MonitoringRecord
  922. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").First(&records).Error
  923. if err != nil {
  924. return nil, err
  925. }
  926. return &records, nil
  927. }
  928. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  929. var record models.MonitoringRecord
  930. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  931. if err != nil {
  932. if err == gorm.ErrRecordNotFound {
  933. return nil, nil
  934. } else {
  935. return nil, err
  936. }
  937. }
  938. return &record, nil
  939. }
  940. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  941. var record models.MonitoringRecord
  942. redis := RedisClient()
  943. defer redis.Close()
  944. // cur_date := time.Now().Format("2006-01-02")
  945. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  946. monitor_record_last_str, _ := redis.Get(key).Result()
  947. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  948. 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
  949. if err != nil {
  950. if err == gorm.ErrRecordNotFound {
  951. if record.ID <= 0 {
  952. redis.Set(key, "null", time.Second*60*60*18)
  953. }
  954. return nil, nil
  955. } else {
  956. return nil, err
  957. }
  958. } else {
  959. if record.ID > 0 {
  960. //缓存数据
  961. monitor_record_last_str, err := json.Marshal(record)
  962. if err == nil {
  963. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  964. }
  965. } else {
  966. redis.Set(key, "null", time.Second*60*60*18)
  967. }
  968. return &record, nil
  969. }
  970. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  971. if monitor_record_last_str == "null" {
  972. return &record, nil
  973. } else {
  974. json.Unmarshal([]byte(monitor_record_last_str), &record)
  975. return &record, nil
  976. }
  977. }
  978. }
  979. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  980. var record models.AssessmentAfterDislysis
  981. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  982. if err != nil {
  983. if err == gorm.ErrRecordNotFound {
  984. return nil, nil
  985. } else {
  986. return nil, err
  987. }
  988. }
  989. return &record, nil
  990. }
  991. // 透后评估
  992. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  993. var record models.AssessmentAfterDislysis
  994. redis := RedisClient()
  995. defer redis.Close()
  996. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  997. redis.Set(key, "", time.Second)
  998. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  999. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1000. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1001. if err != nil {
  1002. if err == gorm.ErrRecordNotFound {
  1003. if record.ID <= 0 {
  1004. redis.Set(key, "null", time.Second*60*60*18)
  1005. }
  1006. return nil, nil
  1007. } else {
  1008. return nil, err
  1009. }
  1010. } else {
  1011. if record.ID > 0 {
  1012. //缓存数据
  1013. assessment_after_dislysis_str, err := json.Marshal(record)
  1014. if err == nil {
  1015. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1016. }
  1017. } else {
  1018. redis.Set(key, "null", time.Second*60*60*18)
  1019. }
  1020. return &record, nil
  1021. }
  1022. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1023. if assessment_after_dislysis_str == "null" {
  1024. return &record, nil
  1025. } else {
  1026. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1027. return &record, nil
  1028. }
  1029. }
  1030. }
  1031. // 获取 maxDate 之前一次的透后评估记录
  1032. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1033. var record models.AssessmentAfterDislysis
  1034. redis := RedisClient()
  1035. defer redis.Close()
  1036. // cur_date := time.Now().Format("2006-01-02")
  1037. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1038. redis.Set(key, "", time.Second)
  1039. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1040. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1041. 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
  1042. if err != nil {
  1043. if err == gorm.ErrRecordNotFound {
  1044. if record.ID <= 0 {
  1045. redis.Set(key, "null", time.Second*60*60*18)
  1046. }
  1047. return nil, nil
  1048. } else {
  1049. return nil, err
  1050. }
  1051. } else {
  1052. if record.ID > 0 {
  1053. //缓存数据
  1054. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1055. if err == nil {
  1056. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1057. }
  1058. } else {
  1059. redis.Set(key, "null", time.Second*60*60*18)
  1060. }
  1061. return &record, nil
  1062. }
  1063. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1064. if assessment_after_dislysis_last_str == "null" {
  1065. return &record, nil
  1066. } else {
  1067. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1068. return &record, nil
  1069. }
  1070. }
  1071. }
  1072. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1073. var record models.AssessmentAfterDislysis
  1074. 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
  1075. if err != nil {
  1076. if err == gorm.ErrRecordNotFound {
  1077. return nil, nil
  1078. } else {
  1079. return nil, err
  1080. }
  1081. }
  1082. return &record, nil
  1083. }
  1084. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1085. dislysis := models.AssessmentAfterDislysis{}
  1086. 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
  1087. return dislysis, err
  1088. }
  1089. // 治疗小结
  1090. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1091. var record models.TreatmentSummary
  1092. redis := RedisClient()
  1093. defer redis.Close()
  1094. // cur_date := time.Now().Format("2006-01-02")
  1095. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1096. treatment_summary_str, _ := redis.Get(key).Result()
  1097. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1098. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1099. if err != nil {
  1100. if err == gorm.ErrRecordNotFound {
  1101. if record.ID <= 0 {
  1102. redis.Set(key, "null", time.Second*60*60*18)
  1103. }
  1104. return nil, nil
  1105. } else {
  1106. return nil, err
  1107. }
  1108. } else {
  1109. if record.ID > 0 {
  1110. //缓存数据
  1111. treatment_summary_str, err := json.Marshal(record)
  1112. if err == nil {
  1113. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1114. }
  1115. } else {
  1116. redis.Set(key, "null", time.Second*60*60*18)
  1117. }
  1118. return &record, nil
  1119. }
  1120. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1121. if treatment_summary_str == "null" {
  1122. return &record, nil
  1123. } else {
  1124. json.Unmarshal([]byte(treatment_summary_str), &record)
  1125. return &record, nil
  1126. }
  1127. }
  1128. }
  1129. // 透析处方
  1130. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1131. var record models.DialysisPrescription
  1132. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1133. if err != nil {
  1134. if err == gorm.ErrRecordNotFound {
  1135. return nil, nil
  1136. } else {
  1137. return nil, err
  1138. }
  1139. }
  1140. return &record, nil
  1141. }
  1142. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1143. var schedule models.XtSchedule
  1144. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1145. if err != nil {
  1146. if err == gorm.ErrRecordNotFound {
  1147. return nil, nil
  1148. } else {
  1149. return nil, err
  1150. }
  1151. }
  1152. return &schedule, nil
  1153. }
  1154. // 透析方案
  1155. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1156. var record models.DialysisSolution
  1157. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1158. if err != nil {
  1159. if err == gorm.ErrRecordNotFound {
  1160. return nil, nil
  1161. } else {
  1162. return nil, err
  1163. }
  1164. }
  1165. return &record, nil
  1166. }
  1167. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1168. var patient models.Patients
  1169. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1170. if err != nil {
  1171. if err == gorm.ErrRecordNotFound {
  1172. return nil, nil
  1173. } else {
  1174. return nil, err
  1175. }
  1176. }
  1177. return &patient, nil
  1178. }
  1179. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1180. fmt.Println()
  1181. tx := writeDb.Begin()
  1182. updateTime := time.Now().Unix()
  1183. 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
  1184. if err != nil {
  1185. tx.Rollback()
  1186. return err
  1187. }
  1188. tx.Commit()
  1189. return nil
  1190. }
  1191. func GetMonitorById(id int64, orgId int64) (models.MonitoringRecord, error) {
  1192. record := models.MonitoringRecord{}
  1193. err := XTReadDB().Where("id = ? and user_org_id =?", id, orgId).Find(&record).Error
  1194. return record, err
  1195. }
  1196. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1197. var monitor models.MonitoringRecord
  1198. var err error
  1199. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1200. if err == gorm.ErrRecordNotFound {
  1201. return nil, nil
  1202. }
  1203. if err != nil {
  1204. return nil, err
  1205. }
  1206. return &monitor, nil
  1207. }
  1208. type MScheduleDoctorAdviceVM struct {
  1209. ID int64 `gorm:"column:id" json:"id"`
  1210. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1211. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1212. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1213. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1214. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1215. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1216. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1217. Status int64 `gorm:"column:status" json:"status"`
  1218. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1219. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1220. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1221. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1222. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1223. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1224. }
  1225. func (MScheduleDoctorAdviceVM) TableName() string {
  1226. return "xt_schedule"
  1227. }
  1228. type MScheduleDoctorAdviceVMOne 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 (MScheduleDoctorAdviceVMOne) TableName() string {
  1246. return "xt_schedule"
  1247. }
  1248. type MDoctorAdviceVM struct {
  1249. ID int64 `gorm:"column:id" json:"id"`
  1250. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1251. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1252. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1253. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1254. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1255. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1256. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1257. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1258. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1259. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1260. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1261. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1262. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1263. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1264. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1265. Status int64 `gorm:"column:status" json:"status"`
  1266. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1267. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1268. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1269. Remark string `gorm:"column:remark" json:"remark"`
  1270. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1271. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1272. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1273. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1274. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1275. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1276. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1277. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1278. Checker int64 `gorm:"column:checker" json:"checker"`
  1279. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1280. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1281. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1282. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1283. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1284. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1285. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1286. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1287. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1288. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1289. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1290. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1291. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1292. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1293. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1294. }
  1295. func (MDoctorAdviceVM) TableName() string {
  1296. return "xt_doctor_advice"
  1297. }
  1298. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1299. var vms []*MScheduleDoctorAdviceVM
  1300. adviceWhere := ""
  1301. adviceCondition := []interface{}{}
  1302. if adviceType == 0 {
  1303. if patientType == 0 {
  1304. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1306. } else if patientType == 1 {
  1307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1309. } else if patientType == 2 {
  1310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1312. }
  1313. } else if adviceType == 1 {
  1314. if patientType == 0 {
  1315. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1317. } else if patientType == 1 {
  1318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1320. } else if patientType == 2 {
  1321. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1323. }
  1324. } else if adviceType == 3 {
  1325. if patientType == 0 {
  1326. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1328. } else if patientType == 1 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1331. } else if patientType == 2 {
  1332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1334. }
  1335. } else if adviceType == 2 && len(deliverWay) > 0 {
  1336. if patientType == 0 {
  1337. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1339. } else if patientType == 1 {
  1340. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1342. } else if patientType == 2 {
  1343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1345. }
  1346. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1347. if patientType == 0 {
  1348. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1350. } else if patientType == 1 {
  1351. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1353. } else if patientType == 2 {
  1354. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1356. }
  1357. }
  1358. db := readDb.
  1359. Table("xt_schedule").
  1360. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1361. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1362. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1363. }).
  1364. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1365. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1366. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1367. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1368. Preload("DoctorAdvices", adviceCondition...).
  1369. Where("status = 1 AND user_org_id = ?", orgID)
  1370. if scheduleDate != 0 {
  1371. db = db.Where("schedule_date = ?", scheduleDate)
  1372. }
  1373. err := db.Find(&vms).Error
  1374. return vms, err
  1375. }
  1376. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1377. var vms []*MScheduleDoctorAdviceVMOne
  1378. adviceWhere := ""
  1379. adviceCondition := []interface{}{}
  1380. if adviceType == 0 {
  1381. if patientType == 0 {
  1382. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1384. } else if patientType == 1 {
  1385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1387. } else if patientType == 2 {
  1388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1390. } else if patientType == 3 {
  1391. 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"
  1392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1393. } else if patientType == 4 {
  1394. 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)"
  1395. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1396. }
  1397. } else if adviceType == 1 {
  1398. if patientType == 0 {
  1399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1401. } else if patientType == 1 {
  1402. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1403. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1404. } else if patientType == 2 {
  1405. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1407. } else if patientType == 3 {
  1408. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1410. } else if patientType == 4 {
  1411. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1413. }
  1414. } else if adviceType == 3 {
  1415. if patientType == 0 {
  1416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1418. } else if patientType == 1 {
  1419. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1421. } else if patientType == 2 {
  1422. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1424. } else if patientType == 3 {
  1425. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1427. } else if patientType == 4 {
  1428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1430. }
  1431. } else if adviceType == 2 && len(deliverWay) > 0 {
  1432. if patientType == 0 {
  1433. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1435. } else if patientType == 1 {
  1436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1438. } else if patientType == 2 {
  1439. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1440. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1441. } else if patientType == 3 {
  1442. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1444. } else if patientType == 4 {
  1445. 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)"
  1446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1447. }
  1448. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1449. if patientType == 0 {
  1450. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1452. } else if patientType == 1 {
  1453. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1455. } else if patientType == 2 {
  1456. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1458. } else if patientType == 3 {
  1459. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1461. } else if patientType == 4 {
  1462. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1464. }
  1465. }
  1466. db := readDb.
  1467. Table("xt_schedule").
  1468. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1469. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1470. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1471. //}).
  1472. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1473. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1474. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1475. Preload("DoctorAdvices", adviceCondition...).
  1476. Where("status = 1 AND user_org_id = ?", orgID)
  1477. if scheduleDate != 0 {
  1478. db = db.Where("schedule_date = ?", scheduleDate)
  1479. }
  1480. err := db.Find(&vms).Error
  1481. return vms, err
  1482. }
  1483. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1484. var vms []*HisMScheduleDoctorAdviceVM
  1485. if len(deliverWay) > 0 {
  1486. if patientType == 0 {
  1487. db := readDb.
  1488. Table("xt_schedule").
  1489. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1490. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1491. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1492. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1493. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1494. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1495. }).
  1496. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1497. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1498. Where("status = 1 AND user_org_id = ?", orgID)
  1499. if scheduleDate != 0 {
  1500. db = db.Where("schedule_date = ?", scheduleDate)
  1501. }
  1502. err = db.Find(&vms).Error
  1503. }
  1504. if patientType > 0 {
  1505. db := readDb.
  1506. Table("xt_schedule").
  1507. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1508. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1509. 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).
  1510. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1511. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1512. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  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. }).Where("status = 1 AND user_org_id = ?", orgID)
  1516. if scheduleDate != 0 {
  1517. db = db.Where("schedule_date = ?", scheduleDate)
  1518. }
  1519. err = db.Find(&vms).Error
  1520. }
  1521. } else {
  1522. if patientType == 0 {
  1523. db := readDb.
  1524. Table("xt_schedule").
  1525. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1526. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1527. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1528. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1529. }).
  1530. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1532. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1533. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1534. Where("status = 1 AND user_org_id = ?", orgID)
  1535. if scheduleDate != 0 {
  1536. db = db.Where("schedule_date = ?", scheduleDate)
  1537. }
  1538. err = db.Find(&vms).Error
  1539. }
  1540. if patientType > 0 {
  1541. db := readDb.
  1542. Table("xt_schedule").
  1543. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1544. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1545. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1546. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  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. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1550. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1551. Where("status = 1 AND user_org_id = ?", orgID)
  1552. if scheduleDate != 0 {
  1553. db = db.Where("schedule_date = ?", scheduleDate)
  1554. }
  1555. err = db.Find(&vms).Error
  1556. }
  1557. }
  1558. return vms, err
  1559. }
  1560. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1561. var vms []*HisMScheduleDoctorAdviceVMOne
  1562. if len(deliverWay) > 0 {
  1563. if patientType == 0 {
  1564. db := readDb.
  1565. Table("xt_schedule").
  1566. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1567. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1568. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1569. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1570. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1571. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1572. }).
  1573. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1574. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1575. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1576. Where("status = 1 AND user_org_id = ?", orgID)
  1577. if scheduleDate != 0 {
  1578. db = db.Where("schedule_date = ?", scheduleDate)
  1579. }
  1580. err = db.Find(&vms).Error
  1581. }
  1582. if patientType > 0 {
  1583. if patientType == 1 {
  1584. db := readDb.
  1585. Table("xt_schedule").
  1586. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1587. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1588. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1589. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1590. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1591. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1592. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1593. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1594. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1595. Where("status = 1 AND user_org_id = ?", orgID)
  1596. if scheduleDate != 0 {
  1597. db = db.Where("schedule_date = ?", scheduleDate)
  1598. }
  1599. err = db.Find(&vms).Error
  1600. }
  1601. if patientType == 2 {
  1602. db := readDb.
  1603. Table("xt_schedule").
  1604. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1605. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1606. 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).
  1607. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1608. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1609. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1610. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1611. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1612. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1613. if scheduleDate != 0 {
  1614. db = db.Where("schedule_date = ?", scheduleDate)
  1615. }
  1616. err = db.Find(&vms).Error
  1617. }
  1618. if patientType == 3 {
  1619. db := readDb.
  1620. Table("xt_schedule").
  1621. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1622. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1623. 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).
  1624. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1625. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1626. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1627. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1628. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1629. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1630. if scheduleDate != 0 {
  1631. db = db.Where("schedule_date = ?", scheduleDate)
  1632. }
  1633. err = db.Find(&vms).Error
  1634. }
  1635. if patientType == 4 {
  1636. db := readDb.
  1637. Table("xt_schedule").
  1638. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1639. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1640. 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).
  1641. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1642. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1643. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1644. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1645. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1646. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1647. if scheduleDate != 0 {
  1648. db = db.Where("schedule_date = ?", scheduleDate)
  1649. }
  1650. err = db.Find(&vms).Error
  1651. }
  1652. }
  1653. } else {
  1654. if patientType == 0 {
  1655. db := readDb.
  1656. Table("xt_schedule").
  1657. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1658. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1659. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1660. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1661. }).
  1662. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1663. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1664. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1665. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1666. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1667. Where("status = 1 AND user_org_id = ?", orgID)
  1668. if scheduleDate != 0 {
  1669. db = db.Where("schedule_date = ?", scheduleDate)
  1670. }
  1671. err = db.Find(&vms).Error
  1672. }
  1673. if patientType > 0 {
  1674. if patientType == 1 {
  1675. db := readDb.
  1676. Table("xt_schedule").
  1677. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1678. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1679. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1680. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1681. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1682. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1683. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1684. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1685. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1686. Where("status = 1 AND user_org_id = ?", orgID)
  1687. if scheduleDate != 0 {
  1688. db = db.Where("schedule_date = ?", scheduleDate)
  1689. }
  1690. err = db.Find(&vms).Error
  1691. }
  1692. if patientType == 2 {
  1693. db := readDb.
  1694. Table("xt_schedule").
  1695. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1696. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1697. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1698. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1699. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1700. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1701. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1702. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1703. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1704. Where("status = 1 AND user_org_id = ?", orgID)
  1705. if scheduleDate != 0 {
  1706. db = db.Where("schedule_date = ?", scheduleDate)
  1707. }
  1708. err = db.Find(&vms).Error
  1709. }
  1710. if patientType == 3 {
  1711. db := readDb.
  1712. Table("xt_schedule").
  1713. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1714. 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).
  1715. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1716. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1717. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1718. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1719. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1720. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1721. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1722. Where("status = 1 AND user_org_id = ?", orgID)
  1723. if scheduleDate != 0 {
  1724. db = db.Where("schedule_date = ?", scheduleDate)
  1725. }
  1726. err = db.Find(&vms).Error
  1727. }
  1728. if patientType == 4 {
  1729. db := readDb.
  1730. Table("xt_schedule").
  1731. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1732. 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).
  1733. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1734. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1735. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1736. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1737. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1738. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1739. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1740. Where("status = 1 AND user_org_id = ?", orgID)
  1741. if scheduleDate != 0 {
  1742. db = db.Where("schedule_date = ?", scheduleDate)
  1743. }
  1744. err = db.Find(&vms).Error
  1745. }
  1746. }
  1747. }
  1748. return vms, err
  1749. }
  1750. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1751. var vms []*HisMScheduleProjectVM
  1752. //if patientType == 0 {
  1753. // db := readDb.
  1754. // Table("xt_schedule").
  1755. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1756. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1757. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1758. // }).
  1759. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1760. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1761. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1762. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1763. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1764. // }).
  1765. // Where("status = 1 AND user_org_id = ?", orgID)
  1766. // if scheduleDate != 0 {
  1767. // db = db.Where("schedule_date = ?", scheduleDate)
  1768. // }
  1769. // err = db.Find(&vms).Error
  1770. //}
  1771. //if patientType > 0 {
  1772. // db := readDb.
  1773. // Table("xt_schedule").
  1774. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1775. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1776. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1777. // }).
  1778. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1779. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1780. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1781. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  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. db := readDb.Table("xt_schedule").Where("status = 1")
  1792. if orgID > 0 {
  1793. db = db.Where("user_org_id = ?", orgID)
  1794. }
  1795. if scheduleDate > 0 {
  1796. db = db.Where("schedule_date =?", scheduleDate)
  1797. }
  1798. err = db.Find(&vms).Error
  1799. if patientType == 0 {
  1800. db := readDb.
  1801. Table("xt_schedule").
  1802. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1803. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1804. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1805. }).
  1806. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1807. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1808. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1809. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1810. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1811. }).
  1812. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1813. 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")
  1814. }).
  1815. Where("status = 1 AND user_org_id = ?", orgID)
  1816. if scheduleDate != 0 {
  1817. db = db.Where("schedule_date = ?", scheduleDate)
  1818. }
  1819. err = db.Find(&vms).Error
  1820. }
  1821. if patientType > 0 {
  1822. db := readDb.
  1823. Table("xt_schedule").
  1824. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1825. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1826. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1827. }).
  1828. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1829. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1830. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1831. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1832. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1833. }).
  1834. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1835. 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")
  1836. }).
  1837. Where("status = 1 AND user_org_id = ?", orgID)
  1838. if scheduleDate != 0 {
  1839. db = db.Where("schedule_date = ?", scheduleDate)
  1840. }
  1841. err = db.Find(&vms).Error
  1842. }
  1843. return vms, err
  1844. }
  1845. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1846. now := time.Now()
  1847. tx := writeDb.Begin()
  1848. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1849. tx.Rollback()
  1850. return createOrderErr
  1851. }
  1852. // 更新透析记录 ID
  1853. // 透析处方
  1854. 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 {
  1855. tx.Rollback()
  1856. return err
  1857. }
  1858. // 接诊评估
  1859. 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 {
  1860. tx.Rollback()
  1861. return err
  1862. }
  1863. // 透前评估
  1864. 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 {
  1865. tx.Rollback()
  1866. return err
  1867. }
  1868. // 临时医嘱
  1869. 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 {
  1870. tx.Rollback()
  1871. return err
  1872. }
  1873. // 双人核对
  1874. 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 {
  1875. tx.Rollback()
  1876. return err
  1877. }
  1878. // 透后评估
  1879. 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 {
  1880. tx.Rollback()
  1881. return err
  1882. }
  1883. // 治疗小结
  1884. 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 {
  1885. tx.Rollback()
  1886. return err
  1887. }
  1888. // 透析监测
  1889. 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 {
  1890. tx.Rollback()
  1891. return err
  1892. }
  1893. tx.Commit()
  1894. return nil
  1895. }
  1896. type MobileUrgentSchedulePatientVM struct {
  1897. ID int64 `gorm:"column:id" json:"id"`
  1898. Name string `gorm:"column:name" json:"name"`
  1899. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1900. }
  1901. func (MobileUrgentSchedulePatientVM) TableName() string {
  1902. return "xt_patients"
  1903. }
  1904. type MobileUrgentScheduleTreatmentModeVM struct {
  1905. ID int64 `gorm:"column:id" json:"id"`
  1906. Name string `gorm:"column:name" json:"name"`
  1907. }
  1908. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1909. return "xt_treatment_mode"
  1910. }
  1911. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1912. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1913. 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()
  1914. defer rows.Close()
  1915. if err != nil {
  1916. return nil, err
  1917. }
  1918. for rows.Next() {
  1919. var vm MobileUrgentSchedulePatientVM
  1920. readDb.ScanRows(rows, &vm)
  1921. vms = append(vms, &vm)
  1922. }
  1923. return vms, nil
  1924. }
  1925. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1926. var modes []*MobileUrgentScheduleTreatmentModeVM
  1927. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1928. if err != nil {
  1929. return nil, err
  1930. }
  1931. return modes, nil
  1932. }
  1933. type MobileUrgentScheduleScheduleListVM struct {
  1934. ID int64 `gorm:"column:id" json:"id"`
  1935. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1936. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1937. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1938. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1939. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1940. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1941. }
  1942. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1943. return "xt_schedule"
  1944. }
  1945. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1946. db := readDb.
  1947. Model(&MobileUrgentScheduleScheduleListVM{}).
  1948. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1949. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1950. err = db.Find(&schedules).Error
  1951. if err != nil {
  1952. return nil, err
  1953. }
  1954. return schedules, nil
  1955. }
  1956. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1957. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1958. 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()
  1959. defer rows.Close()
  1960. if err != nil {
  1961. return nil, err
  1962. }
  1963. for rows.Next() {
  1964. var vm MobileUrgentScheduleScheduleListVM
  1965. readDb.ScanRows(rows, &vm)
  1966. vms = append(vms, &vm)
  1967. }
  1968. return vms, nil
  1969. }
  1970. type MobileUrgentScheduleDeviceNumberVM struct {
  1971. ID int64 `gorm:"column:id" json:"id"`
  1972. Number string `gorm:"column:number" json:"number"`
  1973. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1974. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1975. }
  1976. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1977. return "xt_device_number"
  1978. }
  1979. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1980. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1981. 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()
  1982. defer rows.Close()
  1983. if err != nil {
  1984. return nil, err
  1985. }
  1986. for rows.Next() {
  1987. var vm DeviceNumberViewModel
  1988. readDb.ScanRows(rows, &vm)
  1989. vms = append(vms, &vm)
  1990. }
  1991. return vms, nil
  1992. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1993. //db := readDb.
  1994. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1995. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1996. // Where("status = 1 AND org_id = ?", orgID)
  1997. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1998. //if err != nil {
  1999. // return nil, err
  2000. //}
  2001. //return deviceNumbers, nil
  2002. }
  2003. func GetValidScheduleMonitorRecordCount() (int64, error) {
  2004. var total int64
  2005. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  2006. return total, err
  2007. }
  2008. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  2009. var monitors []*models.MonitoringRecord
  2010. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  2011. if err != nil {
  2012. return nil, err
  2013. }
  2014. return monitors, nil
  2015. }
  2016. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  2017. tx := writeDb.Begin()
  2018. for index := 0; index < len(monitors); index++ {
  2019. tx.Save(monitors[index])
  2020. }
  2021. return tx.Commit().Error
  2022. }
  2023. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2024. tx := writeDb.Begin()
  2025. updateTime := time.Now().Unix()
  2026. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType, "washpipe_nurse": order.WashpipeNurse, "change_nurse": order.ChangeNurse, "difficult_puncture_nurse": order.DifficultPunctureNurse, "new_fistula_nurse": order.NewFistulaNurse, "quality_nurse_id": order.QualityNurseId, "puncture_needle": order.PunctureNeedle, "puncture_way": order.PunctureWay, "dialysis_dialyszers": order.DialysisDialyszers, "dialysis_irrigation": order.DialysisIrrigation, "blood_access_id": order.BloodAccessId, "nuclein_date": order.NucleinDate, "schedule_remark": order.ScheduleRemark, "order_remark": order.OrderRemark, "catheter_operation": order.CatheterOperation, "blood_flow_volume": order.BloodFlowVolume, "blood_drawing": order.BloodDrawing}).Error
  2027. if err != nil {
  2028. tx.Rollback()
  2029. return err
  2030. }
  2031. tx.Commit()
  2032. return err
  2033. }
  2034. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2035. tx := writeDb.Begin()
  2036. updateTime := time.Now().Unix()
  2037. 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
  2038. if err != nil {
  2039. tx.Rollback()
  2040. return err
  2041. }
  2042. tx.Commit()
  2043. return err
  2044. }
  2045. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2046. var record models.SgjPatientDryweight
  2047. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2048. if err != nil {
  2049. if err == gorm.ErrRecordNotFound {
  2050. return nil, nil
  2051. } else {
  2052. return nil, err
  2053. }
  2054. }
  2055. return &record, nil
  2056. }
  2057. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2058. // var record models.SgjPatientDryweight
  2059. // redis := RedisClient()
  2060. // defer redis.Close()
  2061. //
  2062. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2063. // last_dry_weight_str, _ := redis.Get(key).Result()
  2064. //
  2065. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2066. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2067. // if err != nil {
  2068. // if err == gorm.ErrRecordNotFound {
  2069. // if record.ID <= 0 {
  2070. // redis.Set(key, "null", time.Second*60*60*18)
  2071. // }
  2072. // return nil, nil
  2073. // } else {
  2074. // return nil, err
  2075. // }
  2076. // } else {
  2077. // if record.ID > 0 {
  2078. // //缓存数据
  2079. // last_dry_weight_str, err := json.Marshal(record)
  2080. // if err == nil {
  2081. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2082. // return nil, err
  2083. // }
  2084. // } else {
  2085. // redis.Set(key, "null", time.Second*60*60*18)
  2086. // return nil, err
  2087. // }
  2088. // return &record, nil
  2089. // }
  2090. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2091. // if last_dry_weight_str == "null" {
  2092. // return &record, nil
  2093. // } else {
  2094. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2095. // return &record, nil
  2096. // }
  2097. //
  2098. // }
  2099. //}
  2100. // 透析方案
  2101. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2102. var record models.DialysisSolution
  2103. 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
  2104. if err != nil {
  2105. if err == gorm.ErrRecordNotFound {
  2106. return nil, nil
  2107. } else {
  2108. return nil, err
  2109. }
  2110. }
  2111. return &record, nil
  2112. }
  2113. // 透析方案
  2114. func MobileGetDialysisSolutionByModeIdSevenTwety(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2115. var record models.DialysisSolution
  2116. 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
  2117. return record, nil
  2118. }
  2119. // 透析方案
  2120. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2121. var record models.DialysisSolution
  2122. redis := RedisClient()
  2123. defer redis.Close()
  2124. // cur_date := time.Now().Format("2006-01-02")
  2125. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2126. dialysis_solution_str, _ := redis.Get(key).Result()
  2127. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2128. 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
  2129. if err != nil {
  2130. if err == gorm.ErrRecordNotFound {
  2131. if record.ID <= 0 {
  2132. redis.Set(key, "null", time.Second*60*60*18)
  2133. }
  2134. return nil, nil
  2135. } else {
  2136. return nil, err
  2137. }
  2138. } else {
  2139. if record.ID > 0 {
  2140. //缓存数据
  2141. dialysis_solution_str, err := json.Marshal(record)
  2142. if err == nil {
  2143. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2144. }
  2145. } else {
  2146. redis.Set(key, "null", time.Second*60*60*18)
  2147. }
  2148. return &record, nil
  2149. }
  2150. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2151. if dialysis_solution_str == "null" {
  2152. return &record, nil
  2153. } else {
  2154. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2155. return &record, nil
  2156. }
  2157. }
  2158. }
  2159. // 透析处方
  2160. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2161. var record models.DialysisPrescription
  2162. redis := RedisClient()
  2163. defer redis.Close()
  2164. // cur_date := time.Now().Format("2006-01-02")
  2165. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2166. redis.Set(key, "", time.Second)
  2167. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2168. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2169. 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
  2170. if err != nil {
  2171. if err == gorm.ErrRecordNotFound {
  2172. if record.ID <= 0 {
  2173. redis.Set(key, "null", time.Second*60*60*18)
  2174. }
  2175. return nil, nil
  2176. } else {
  2177. return nil, err
  2178. }
  2179. } else {
  2180. if record.ID > 0 {
  2181. //缓存数据
  2182. dialysis_prescribe_str, err := json.Marshal(record)
  2183. if err == nil {
  2184. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2185. }
  2186. } else {
  2187. redis.Set(key, "null", time.Second*60*60*18)
  2188. }
  2189. return &record, nil
  2190. }
  2191. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2192. if dialysis_prescribe_str == "null" {
  2193. return &record, nil
  2194. } else {
  2195. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2196. return &record, nil
  2197. }
  2198. }
  2199. }
  2200. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2201. var record models.DialysisPrescription
  2202. 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
  2203. if err != nil {
  2204. if err == gorm.ErrRecordNotFound {
  2205. return nil, nil
  2206. } else {
  2207. return nil, err
  2208. }
  2209. }
  2210. return &record, nil
  2211. }
  2212. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2213. var record models.DialysisPrescription
  2214. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2215. if err != nil {
  2216. if err == gorm.ErrRecordNotFound {
  2217. return nil, nil
  2218. } else {
  2219. return nil, err
  2220. }
  2221. }
  2222. return &record, nil
  2223. }
  2224. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2225. // var record models.DialysisPrescription
  2226. // redis := RedisClient()
  2227. // defer redis.Close()
  2228. //
  2229. // // cur_date := time.Now().Format("2006-01-02")
  2230. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2231. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2232. //
  2233. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2234. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2235. // if err != nil {
  2236. // if err == gorm.ErrRecordNotFound {
  2237. // if record.ID <= 0 {
  2238. // redis.Set(key, "null", time.Second*60*60*18)
  2239. // }
  2240. // return nil, nil
  2241. // } else {
  2242. // return nil, err
  2243. // }
  2244. // } else {
  2245. //
  2246. // if record.ID > 0 {
  2247. // //缓存数据
  2248. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2249. //
  2250. // if err == nil {
  2251. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2252. // return nil, err
  2253. // }
  2254. // } else {
  2255. // redis.Set(key, "null", time.Second*60*60*18)
  2256. // return nil, err
  2257. // }
  2258. // return &record, nil
  2259. // }
  2260. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2261. // if dialysis_prescribe_by_mode_str == "null" {
  2262. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2263. // return &record, nil
  2264. // } else {
  2265. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2266. // return &record, nil
  2267. // }
  2268. //
  2269. // }
  2270. //}
  2271. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2272. var record models.DialysisPrescription
  2273. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2274. if err != nil {
  2275. if err == gorm.ErrRecordNotFound {
  2276. return nil, nil
  2277. } else {
  2278. return nil, err
  2279. }
  2280. }
  2281. return &record, nil
  2282. }
  2283. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2284. var record models.DialysisPrescription
  2285. 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
  2286. //if err != nil {
  2287. // if err == gorm.ErrRecordNotFound {
  2288. // return nil, nil
  2289. // } else {
  2290. // return nil, err
  2291. // }
  2292. //}
  2293. return &record, err
  2294. }
  2295. func MobileGetLastDialysisPrescribeByModeIdTen(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2296. var record models.DialysisPrescription
  2297. 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
  2298. if err != nil {
  2299. if err == gorm.ErrRecordNotFound {
  2300. return nil, nil
  2301. } else {
  2302. return nil, err
  2303. }
  2304. }
  2305. return &record, err
  2306. }
  2307. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2308. var record models.DialysisPrescription
  2309. redis := RedisClient()
  2310. defer redis.Close()
  2311. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2312. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2313. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2314. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2315. if err != nil {
  2316. if err == gorm.ErrRecordNotFound {
  2317. if record.ID <= 0 {
  2318. redis.Set(key, "null", time.Second*60*60*18)
  2319. }
  2320. return nil, nil
  2321. } else {
  2322. return nil, err
  2323. }
  2324. } else {
  2325. if record.ID > 0 {
  2326. //缓存数据
  2327. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2328. if err == nil {
  2329. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2330. return nil, err
  2331. }
  2332. } else {
  2333. redis.Set(key, "null", time.Second*60*60*18)
  2334. return nil, err
  2335. }
  2336. return &record, nil
  2337. }
  2338. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2339. if dialysis_prescribe_by_mode_id == "null" {
  2340. return &record, nil
  2341. } else {
  2342. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2343. return &record, nil
  2344. }
  2345. }
  2346. }
  2347. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2348. var record models.DialysisPrescription
  2349. 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
  2350. return record, err
  2351. }
  2352. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2353. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2354. 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()
  2355. defer rows.Close()
  2356. if err != nil {
  2357. return nil, err
  2358. }
  2359. for rows.Next() {
  2360. var vm DeviceNumberViewModel
  2361. readDb.ScanRows(rows, &vm)
  2362. vms = append(vms, &vm)
  2363. }
  2364. return vms, nil
  2365. }
  2366. // 获取 maxDate 之前一次的透前评估记录
  2367. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2368. var record models.PredialysisEvaluation
  2369. 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
  2370. if err != nil {
  2371. if err == gorm.ErrRecordNotFound {
  2372. return nil, nil
  2373. } else {
  2374. return nil, err
  2375. }
  2376. }
  2377. return &record, nil
  2378. }
  2379. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2380. var record models.DialysisOrder
  2381. 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
  2382. if err != nil {
  2383. if err == gorm.ErrRecordNotFound {
  2384. return nil, nil
  2385. } else {
  2386. return nil, err
  2387. }
  2388. }
  2389. return &record, nil
  2390. }
  2391. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2392. var record models.MonitoringRecord
  2393. 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
  2394. if err != nil {
  2395. if err == gorm.ErrRecordNotFound {
  2396. return nil, nil
  2397. } else {
  2398. return nil, err
  2399. }
  2400. }
  2401. return &record, nil
  2402. }
  2403. // 获取 maxDate 之前一次的透后评估记录
  2404. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2405. var record models.AssessmentAfterDislysis
  2406. 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
  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. // 透析处方
  2417. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2418. var record models.DialysisPrescription
  2419. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2420. if err != nil {
  2421. if err == gorm.ErrRecordNotFound {
  2422. return nil, nil
  2423. } else {
  2424. return nil, err
  2425. }
  2426. }
  2427. return &record, nil
  2428. }
  2429. // 透析方案
  2430. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2431. var record models.DialysisSolution
  2432. 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
  2433. return record, err
  2434. }
  2435. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2436. var record models.DialysisSolution
  2437. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2438. if err != nil {
  2439. if err == gorm.ErrRecordNotFound {
  2440. return nil, nil
  2441. } else {
  2442. return nil, err
  2443. }
  2444. }
  2445. return &record, nil
  2446. }
  2447. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2448. var record models.DialysisPrescription
  2449. 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
  2450. if err != nil {
  2451. if err == gorm.ErrRecordNotFound {
  2452. return nil, nil
  2453. } else {
  2454. return nil, err
  2455. }
  2456. }
  2457. return &record, nil
  2458. }
  2459. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2460. var record models.SgjPatientDryweight
  2461. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2462. if err != nil {
  2463. if err == gorm.ErrRecordNotFound {
  2464. return nil, nil
  2465. } else {
  2466. return nil, err
  2467. }
  2468. }
  2469. return &record, nil
  2470. }
  2471. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2472. var record models.SystemPrescription
  2473. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2474. if err != nil {
  2475. if err == gorm.ErrRecordNotFound {
  2476. return nil, nil
  2477. } else {
  2478. return nil, err
  2479. }
  2480. }
  2481. return &record, nil
  2482. }
  2483. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2484. var record models.SystemPrescription
  2485. redis := RedisClient()
  2486. defer redis.Close()
  2487. // cur_date := time.Now().Format("2006-01-02")
  2488. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2489. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2490. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2491. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2492. if err != nil {
  2493. if err == gorm.ErrRecordNotFound {
  2494. if record.ID <= 0 {
  2495. redis.Set(key, "null", time.Second*60*60*18)
  2496. }
  2497. return nil, nil
  2498. } else {
  2499. return nil, err
  2500. }
  2501. } else {
  2502. if record.ID > 0 {
  2503. //缓存数据
  2504. system_dialysis_prescribe_str, err := json.Marshal(record)
  2505. if err == nil {
  2506. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2507. }
  2508. } else {
  2509. redis.Set(key, "null", time.Second*60*60*18)
  2510. }
  2511. return &record, nil
  2512. }
  2513. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2514. if system_dialysis_prescribe_str == "null" {
  2515. return &record, nil
  2516. } else {
  2517. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2518. return &record, nil
  2519. }
  2520. }
  2521. }
  2522. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2523. var record models.SystemPrescription
  2524. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2525. return record, err
  2526. }
  2527. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2528. var record models.SystemPrescription
  2529. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2530. if err != nil {
  2531. if err == gorm.ErrRecordNotFound {
  2532. return nil, nil
  2533. } else {
  2534. return nil, err
  2535. }
  2536. }
  2537. return &record, nil
  2538. }
  2539. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2540. 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
  2541. return
  2542. }
  2543. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2544. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1640966400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2545. return
  2546. }
  2547. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2548. 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
  2549. return
  2550. }
  2551. func GetFirstDateOfMonth(d time.Time) time.Time {
  2552. d = d.AddDate(0, 0, -d.Day()+1)
  2553. return GetZeroTime(d)
  2554. }
  2555. func GetZeroTime(d time.Time) time.Time {
  2556. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2557. }
  2558. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2559. db := XTReadDB().Table("xt_dialysis_order as o")
  2560. 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
  2561. return order, err
  2562. }
  2563. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2564. 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
  2565. return
  2566. }
  2567. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2568. 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
  2569. return
  2570. }
  2571. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2572. 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
  2573. return
  2574. }
  2575. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2576. // 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
  2577. // return
  2578. //}
  2579. //
  2580. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2581. 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
  2582. return
  2583. }
  2584. type GoodsType struct {
  2585. ID int64 `gorm:"column:id" json:"id"`
  2586. TypeName string `gorm:"column:type_name" json:"type_name"`
  2587. Remark string `gorm:"column:remark" json:"remark"`
  2588. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2589. Status int64 `gorm:"column:status" json:"status"`
  2590. Type int64 `gorm:"column:type" json:"type"`
  2591. }
  2592. func (GoodsType) TableName() string {
  2593. return "xt_goods_type"
  2594. }
  2595. type VMGoodInfo struct {
  2596. ID int64 `gorm:"column:id" json:"id"`
  2597. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2598. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2599. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2600. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2601. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2602. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2603. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2604. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2605. }
  2606. func (VMGoodInfo) TableName() string {
  2607. return "xt_good_information"
  2608. }
  2609. type AutomaticReduceDetail struct {
  2610. ID int64 `gorm:"column:id" json:"id"`
  2611. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2612. Status int64 `gorm:"column:status" json:"status"`
  2613. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2614. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2615. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2616. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2617. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2618. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2619. Count int64 `gorm:"column:count" json:"count"`
  2620. }
  2621. func (AutomaticReduceDetail) TableName() string {
  2622. return "xt_automatic_reduce_detail"
  2623. }
  2624. type DialysisBeforePrepare struct {
  2625. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2626. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2627. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2628. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2629. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2630. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2631. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2632. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2633. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2634. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2635. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2636. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2637. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2638. }
  2639. func (DialysisBeforePrepare) TableName() string {
  2640. return "dialysis_before_prepare"
  2641. }
  2642. type MDialysisGoodsVM struct {
  2643. ID int64 `gorm:"column:id" json:"id"`
  2644. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2645. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2646. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2647. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2648. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2649. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2650. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2651. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2652. Status int64 `gorm:"column:status" json:"status"`
  2653. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2654. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2655. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2656. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2657. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2658. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2659. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2660. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2661. DialysisPrescription models.DialysisPrescriptionListSix `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"prescription"`
  2662. }
  2663. func (MDialysisGoodsVM) TableName() string {
  2664. return "xt_schedule"
  2665. }
  2666. type VMWarehouseOutInfo struct {
  2667. ID int64 `gorm:"column:id" json:"id"`
  2668. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2669. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2670. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2671. Count int64 `gorm:"column:count" json:"count"`
  2672. Price float64 `gorm:"column:price" json:"price"`
  2673. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2674. Status int64 `gorm:"column:status" json:"status"`
  2675. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2676. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2677. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2678. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2679. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2680. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2681. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2682. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2683. }
  2684. func (VMWarehouseOutInfo) TableName() string {
  2685. return "xt_warehouse_out_info"
  2686. }
  2687. type DialysisGoodsDate struct {
  2688. RecordDate int64
  2689. }
  2690. type DialysisGoodsDetailDate struct {
  2691. RecordTime int64
  2692. }
  2693. 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) {
  2694. var vms []*MDialysisGoodsVM
  2695. var total int64
  2696. db := readDb.
  2697. Table("xt_schedule as sch").
  2698. Preload("DialysisPrescription", "status=1 and user_org_id =? and solution_status = 1", orgID).
  2699. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2700. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2701. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2702. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2703. 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)
  2704. }).
  2705. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2706. 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")
  2707. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2708. if scheduleDate != 0 {
  2709. db = db.Where("schedule_date = ?", scheduleDate)
  2710. }
  2711. if schedule_type != 0 {
  2712. db = db.Where("schedule_type = ?", schedule_type)
  2713. }
  2714. if partition_id != 0 {
  2715. db = db.Where("partition_id = ?", partition_id)
  2716. }
  2717. if patient_id != 0 {
  2718. db = db.Where("patient_id = ?", patient_id)
  2719. }
  2720. err := db.Find(&vms).Error
  2721. return vms, err, total
  2722. }
  2723. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2724. var Id []*DialysisGoodsDetailDate
  2725. 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
  2726. if len(Id) > 0 {
  2727. 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
  2728. }
  2729. return
  2730. }
  2731. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2732. var Id []*DialysisGoodsDate
  2733. 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
  2734. if len(Id) > 0 {
  2735. 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
  2736. }
  2737. return
  2738. }
  2739. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2740. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2741. return info, err
  2742. }
  2743. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2744. db := readDb.Model(&models.StockInfo{})
  2745. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2746. 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")
  2747. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2748. 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)
  2749. })
  2750. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2751. err = db.Order("ctime desc").Find(&list).Error
  2752. return
  2753. }
  2754. 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) {
  2755. var vms []*MDialysisGoodsVM
  2756. var total int64
  2757. db := readDb.
  2758. Model(&models.Schedule{}).
  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 = ? ", 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. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2765. 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)
  2766. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2767. if scheduleDate != 0 {
  2768. db = db.Where("schedule_date = ?", scheduleDate)
  2769. }
  2770. if patient_id != 0 {
  2771. db = db.Where("patient_id = ?", patient_id)
  2772. }
  2773. if len(keywords) != 0 {
  2774. keywords = "%" + keywords + "%"
  2775. 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)
  2776. if schedule_type != 0 {
  2777. db = db.Where("schedule_type = ?", schedule_type)
  2778. }
  2779. if partition_id != 0 {
  2780. db = db.Where("partition_id = ?", partition_id)
  2781. }
  2782. if good_type == 1 {
  2783. db = db.Where("patient_id in(?)", ids)
  2784. }
  2785. if good_type == 2 {
  2786. if len(ids) > 0 {
  2787. db = db.Where("patient_id not in(?)", ids)
  2788. }
  2789. }
  2790. } else {
  2791. if schedule_type != 0 {
  2792. db = db.Where("schedule_type = ?", schedule_type)
  2793. }
  2794. if partition_id != 0 {
  2795. db = db.Where("partition_id = ?", partition_id)
  2796. }
  2797. if good_type == 1 {
  2798. db = db.Where("patient_id in(?)", ids)
  2799. }
  2800. if good_type == 2 {
  2801. if len(ids) > 0 {
  2802. db = db.Where("patient_id not in(?)", ids)
  2803. }
  2804. }
  2805. db = db.Count(&total)
  2806. offset := (page - 1) * limit
  2807. db = db.Offset(offset).Limit(limit)
  2808. }
  2809. err := db.Find(&vms).Error
  2810. return vms, err, total
  2811. }
  2812. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2813. var Id []*DialysisGoodsDetailDate
  2814. 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
  2815. if len(Id) > 0 {
  2816. 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
  2817. }
  2818. return
  2819. }
  2820. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2821. var Id []*DialysisGoodsDate
  2822. 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
  2823. if len(Id) > 0 {
  2824. 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
  2825. }
  2826. return
  2827. }
  2828. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2829. evaluation := models.PredialysisEvaluation{}
  2830. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2831. if err == gorm.ErrRecordNotFound {
  2832. return nil, err
  2833. }
  2834. if err != nil {
  2835. return nil, err
  2836. }
  2837. return &evaluation, nil
  2838. }
  2839. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2840. evaluation := models.PredialysisEvaluation{}
  2841. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2842. return evaluation, err
  2843. }
  2844. func GetAssessmentBeforFourty(orgid int64, patientid int64, recorddate int64) (models.XtAssessmentBeforeDislysis, error) {
  2845. evaluation := models.XtAssessmentBeforeDislysis{}
  2846. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2847. return evaluation, err
  2848. }
  2849. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2850. redis := RedisClient()
  2851. defer redis.Close()
  2852. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2853. his_doctor_advice_str, _ := redis.Get(key).Result()
  2854. redis.Set(key, "", time.Second)
  2855. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2856. 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
  2857. if err != nil {
  2858. if err == gorm.ErrRecordNotFound {
  2859. if len(his) <= 0 {
  2860. redis.Set(key, "null", time.Second*60*60*18)
  2861. }
  2862. return his, nil
  2863. } else {
  2864. return his, err
  2865. }
  2866. } else {
  2867. if len(his) > 0 {
  2868. //缓存数据
  2869. his_doctor_advice_str, err := json.Marshal(his)
  2870. if err == nil {
  2871. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2872. }
  2873. } else {
  2874. redis.Set(key, "null", time.Second*60*60*18)
  2875. }
  2876. return his, nil
  2877. }
  2878. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2879. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2880. return his, nil
  2881. }
  2882. }
  2883. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2884. prescription := models.DialysisPrescription{}
  2885. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2886. if err == gorm.ErrRecordNotFound {
  2887. return nil, err
  2888. }
  2889. if err != nil {
  2890. return nil, err
  2891. }
  2892. return &prescription, nil
  2893. }
  2894. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2895. prescription := models.DialysisPrescription{}
  2896. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2897. return prescription, err
  2898. }
  2899. type HisMScheduleDoctorAdviceVM struct {
  2900. ID int64 `gorm:"column:id" json:"id"`
  2901. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2902. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2903. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2904. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2905. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2906. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2907. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2908. Status int64 `gorm:"column:status" json:"status"`
  2909. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2910. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2911. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2912. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2913. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2914. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2915. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2916. }
  2917. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2918. return "xt_schedule"
  2919. }
  2920. type HisMScheduleDoctorAdviceVMOne struct {
  2921. ID int64 `gorm:"column:id" json:"id"`
  2922. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2923. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2924. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2925. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2926. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2927. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2928. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2929. Status int64 `gorm:"column:status" json:"status"`
  2930. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2931. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2932. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2933. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2934. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2935. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2936. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2937. }
  2938. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2939. return "xt_schedule"
  2940. }
  2941. type HisMScheduleProjectVM struct {
  2942. ID int64 `gorm:"column:id" json:"id"`
  2943. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2944. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2945. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2946. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2947. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2948. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2949. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2950. Status int64 `gorm:"column:status" json:"status"`
  2951. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2952. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2953. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2954. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2955. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2956. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2957. }
  2958. func (HisMScheduleProjectVM) TableName() string {
  2959. return "xt_schedule"
  2960. }
  2961. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2962. config := models.XtHisConfig{}
  2963. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2964. return config, err
  2965. }
  2966. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2967. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2968. if orgid > 0 {
  2969. db = db.Where("x.user_org_id = ?", orgid)
  2970. }
  2971. if patientid > 0 {
  2972. db = db.Where("x.patient_id =?", patientid)
  2973. }
  2974. if recordtime > 0 {
  2975. db = db.Where("x.advice_date = ?", recordtime)
  2976. }
  2977. 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
  2978. return advice, err
  2979. }
  2980. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2981. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2982. if startime > 0 {
  2983. db = db.Where("x.advice_date >= ?", startime)
  2984. }
  2985. if endtime > 0 {
  2986. db = db.Where("x.advice_date<=?", endtime)
  2987. }
  2988. if orgid > 0 {
  2989. db = db.Where("x.user_org_id = ?", orgid)
  2990. }
  2991. if len(deliveway) > 0 {
  2992. db = db.Where("x.delivery_way = ?", deliveway)
  2993. }
  2994. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  2995. return advice, err
  2996. }
  2997. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2998. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2999. if startime > 0 {
  3000. db = db.Where("x.advice_date >= ?", startime)
  3001. }
  3002. if endtime > 0 {
  3003. db = db.Where("x.advice_date<=?", endtime)
  3004. }
  3005. if orgid > 0 {
  3006. db = db.Where("x.user_org_id = ?", orgid)
  3007. }
  3008. if len(deliveway) > 0 {
  3009. db = db.Where("x.delivery_way = ?", deliveway)
  3010. }
  3011. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  3012. return advice, err
  3013. }
  3014. func 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) {
  3015. var vms []*MScheduleDoctorAdviceVM
  3016. adviceWhere := ""
  3017. adviceCondition := []interface{}{}
  3018. if adviceType == 0 {
  3019. if patientType == 0 {
  3020. if patient_id > 0 {
  3021. if execution_state > 0 {
  3022. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  3023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3024. } else {
  3025. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3027. }
  3028. } else {
  3029. if execution_state > 0 {
  3030. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  3031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3032. } else {
  3033. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  3034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3035. }
  3036. }
  3037. } else if patientType == 1 {
  3038. if patient_id > 0 {
  3039. if execution_state > 0 {
  3040. 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= ?"
  3041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3042. } else {
  3043. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3045. }
  3046. } else {
  3047. if execution_state > 0 {
  3048. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3050. } else {
  3051. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3053. }
  3054. }
  3055. } else if patientType == 2 {
  3056. if patient_id > 0 {
  3057. if execution_state > 0 {
  3058. 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 = ?"
  3059. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3060. } else {
  3061. 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 = ?)"
  3062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3063. }
  3064. } else {
  3065. if execution_state > 0 {
  3066. 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 = ?"
  3067. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3068. } else {
  3069. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3071. }
  3072. }
  3073. }
  3074. } else if adviceType == 1 {
  3075. if patientType == 0 {
  3076. if patient_id > 0 {
  3077. if execution_state > 0 {
  3078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3080. } else {
  3081. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3083. }
  3084. } else {
  3085. if execution_state > 0 {
  3086. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3088. } else {
  3089. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3091. }
  3092. }
  3093. } else if patientType == 1 {
  3094. if patient_id > 0 {
  3095. if execution_state > 0 {
  3096. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3098. } else {
  3099. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3100. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3101. }
  3102. } else {
  3103. if execution_state > 0 {
  3104. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3106. } else {
  3107. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3109. }
  3110. }
  3111. } else if patientType == 2 {
  3112. if patient_id > 0 {
  3113. if execution_state > 0 {
  3114. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3116. } else {
  3117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3119. }
  3120. } else {
  3121. if execution_state > 0 {
  3122. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3123. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3124. } else {
  3125. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3127. }
  3128. }
  3129. }
  3130. } else if adviceType == 3 {
  3131. if patientType == 0 {
  3132. if patient_id > 0 {
  3133. if execution_state > 0 {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3136. } else {
  3137. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3139. }
  3140. } else {
  3141. if execution_state > 0 {
  3142. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3143. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3144. } else {
  3145. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3146. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3147. }
  3148. }
  3149. } else if patientType == 1 {
  3150. if patient_id > 0 {
  3151. if execution_state > 0 {
  3152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3154. } else {
  3155. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3157. }
  3158. } else {
  3159. if execution_state > 0 {
  3160. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3162. } else {
  3163. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3165. }
  3166. }
  3167. } else if patientType == 2 {
  3168. if patient_id > 0 {
  3169. if execution_state > 0 {
  3170. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3171. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3172. } else {
  3173. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3175. }
  3176. } else {
  3177. if execution_state > 0 {
  3178. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3180. } else {
  3181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3183. }
  3184. }
  3185. }
  3186. } else if adviceType == 2 && len(deliverWay) > 0 {
  3187. if patientType == 0 {
  3188. if patient_id > 0 {
  3189. if execution_state > 0 {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3192. } else {
  3193. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3195. }
  3196. } else {
  3197. if execution_state > 0 {
  3198. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3199. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3200. } else {
  3201. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3203. }
  3204. }
  3205. } else if patientType == 1 {
  3206. if patient_id > 0 {
  3207. if execution_state > 0 {
  3208. 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 = ?"
  3209. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3210. } else {
  3211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3213. }
  3214. } else {
  3215. if execution_state > 0 {
  3216. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3218. } else {
  3219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3221. }
  3222. }
  3223. } else if patientType == 2 {
  3224. if patient_id > 0 {
  3225. if execution_state > 0 {
  3226. 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 = ?"
  3227. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3228. } else {
  3229. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3231. }
  3232. } else {
  3233. if execution_state > 0 {
  3234. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3236. } else {
  3237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3239. }
  3240. }
  3241. }
  3242. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3243. if patientType == 0 {
  3244. if patient_id > 0 {
  3245. if execution_state > 0 {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3248. } else {
  3249. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3251. }
  3252. } else {
  3253. if execution_state > 0 {
  3254. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3256. } else {
  3257. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3259. }
  3260. }
  3261. } else if patientType == 1 {
  3262. if patient_id > 0 {
  3263. if execution_state > 0 {
  3264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3266. } else {
  3267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3269. }
  3270. } else {
  3271. if execution_state > 0 {
  3272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3274. } else {
  3275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3277. }
  3278. }
  3279. } else if patientType == 2 {
  3280. if patient_id > 0 {
  3281. if execution_state > 0 {
  3282. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3283. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3284. } else {
  3285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3287. }
  3288. } else {
  3289. if execution_state > 0 {
  3290. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3291. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3292. } else {
  3293. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3295. }
  3296. }
  3297. }
  3298. }
  3299. db := readDb.Table("xt_schedule")
  3300. if scheduleType > 0 {
  3301. db = db.Where("schedule_type = ?", scheduleType)
  3302. }
  3303. if partitonType > 0 {
  3304. db = db.Where("partition_id = ?", partitonType)
  3305. }
  3306. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3307. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3308. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3309. }).
  3310. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3311. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3312. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3313. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3314. Preload("DoctorAdvices", adviceCondition...).
  3315. Where("status = 1 AND user_org_id = ?", orgID)
  3316. if scheduleDate != 0 {
  3317. db = db.Where("schedule_date = ?", scheduleDate)
  3318. }
  3319. err := db.Find(&vms).Error
  3320. return vms, err
  3321. }
  3322. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3323. var vms []*HisMScheduleDoctorAdviceVM
  3324. if len(deliverWay) > 0 {
  3325. db := readDb.Table("xt_schedule")
  3326. if scheduleType > 0 {
  3327. db = db.Where("schedule_type = ?", scheduleType)
  3328. }
  3329. if partitionType > 0 {
  3330. db = db.Where("partition_id = ?", partitionType)
  3331. }
  3332. if patient_id > 0 {
  3333. if execution_state > 0 {
  3334. if cost_type > 0 {
  3335. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3336. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3337. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3338. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3339. 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).
  3340. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3341. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3342. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3343. Where("status = 1 AND user_org_id = ?", orgID)
  3344. if scheduleDate != 0 {
  3345. db = db.Where("schedule_date = ?", scheduleDate)
  3346. }
  3347. err = db.Find(&vms).Error
  3348. } else {
  3349. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3350. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3351. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3352. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3353. 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).
  3354. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3355. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3356. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3357. Where("status = 1 AND user_org_id = ?", orgID)
  3358. if scheduleDate != 0 {
  3359. db = db.Where("schedule_date = ?", scheduleDate)
  3360. }
  3361. err = db.Find(&vms).Error
  3362. }
  3363. } else {
  3364. if cost_type > 0 {
  3365. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3369. 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).
  3370. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3371. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3372. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3373. Where("status = 1 AND user_org_id = ?", orgID)
  3374. if scheduleDate != 0 {
  3375. db = db.Where("schedule_date = ?", scheduleDate)
  3376. }
  3377. err = db.Find(&vms).Error
  3378. } else {
  3379. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3380. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3381. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3382. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3383. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3384. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3385. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3386. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3387. Where("status = 1 AND user_org_id = ?", orgID)
  3388. if scheduleDate != 0 {
  3389. db = db.Where("schedule_date = ?", scheduleDate)
  3390. }
  3391. err = db.Find(&vms).Error
  3392. }
  3393. }
  3394. } else {
  3395. if execution_state > 0 {
  3396. if cost_type > 0 {
  3397. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3398. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3399. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3400. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3401. 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).
  3402. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3403. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3404. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3405. Where("status = 1 AND user_org_id = ?", orgID)
  3406. if scheduleDate != 0 {
  3407. db = db.Where("schedule_date = ?", scheduleDate)
  3408. }
  3409. err = db.Find(&vms).Error
  3410. } else {
  3411. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3412. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3413. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3414. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3415. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3416. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3417. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3418. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3419. Where("status = 1 AND user_org_id = ?", orgID)
  3420. if scheduleDate != 0 {
  3421. db = db.Where("schedule_date = ?", scheduleDate)
  3422. }
  3423. err = db.Find(&vms).Error
  3424. }
  3425. } else {
  3426. if cost_type > 0 {
  3427. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3428. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3429. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3430. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3431. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3432. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3433. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3434. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3435. Where("status = 1 AND user_org_id = ?", orgID)
  3436. if scheduleDate != 0 {
  3437. db = db.Where("schedule_date = ?", scheduleDate)
  3438. }
  3439. err = db.Find(&vms).Error
  3440. } else {
  3441. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3442. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3443. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3444. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3445. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3446. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3447. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3448. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3449. Where("status = 1 AND user_org_id = ?", orgID)
  3450. if scheduleDate != 0 {
  3451. db = db.Where("schedule_date = ?", scheduleDate)
  3452. }
  3453. err = db.Find(&vms).Error
  3454. }
  3455. }
  3456. }
  3457. } else {
  3458. db := readDb.Table("xt_schedule")
  3459. if scheduleType > 0 {
  3460. db = db.Where("schedule_type = ?", scheduleType)
  3461. }
  3462. if partitionType > 0 {
  3463. db = db.Where("partition_id = ?", partitionType)
  3464. }
  3465. if patient_id > 0 {
  3466. if execution_state > 0 {
  3467. if cost_type > 0 {
  3468. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3469. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3470. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3471. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3472. 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).
  3473. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3474. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3475. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3476. Where("status = 1 AND user_org_id = ?", orgID)
  3477. if scheduleDate != 0 {
  3478. db = db.Where("schedule_date = ?", scheduleDate)
  3479. }
  3480. err = db.Find(&vms).Error
  3481. } else {
  3482. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3483. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3484. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3485. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3486. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3487. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3488. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3489. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3490. Where("status = 1 AND user_org_id = ?", orgID)
  3491. if scheduleDate != 0 {
  3492. db = db.Where("schedule_date = ?", scheduleDate)
  3493. }
  3494. err = db.Find(&vms).Error
  3495. }
  3496. } else {
  3497. if cost_type > 0 {
  3498. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3499. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3500. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3501. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3502. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3503. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3504. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3505. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3506. Where("status = 1 AND user_org_id = ?", orgID)
  3507. if scheduleDate != 0 {
  3508. db = db.Where("schedule_date = ?", scheduleDate)
  3509. }
  3510. err = db.Find(&vms).Error
  3511. } else {
  3512. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3513. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3514. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3515. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3516. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3517. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3518. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3519. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3520. Where("status = 1 AND user_org_id = ?", orgID)
  3521. if scheduleDate != 0 {
  3522. db = db.Where("schedule_date = ?", scheduleDate)
  3523. }
  3524. err = db.Find(&vms).Error
  3525. }
  3526. }
  3527. } else {
  3528. if execution_state > 0 {
  3529. if cost_type > 0 {
  3530. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3531. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3532. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3533. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3534. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3535. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3536. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3537. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3538. Where("status = 1 AND user_org_id = ?", orgID)
  3539. if scheduleDate != 0 {
  3540. db = db.Where("schedule_date = ?", scheduleDate)
  3541. }
  3542. err = db.Find(&vms).Error
  3543. } else {
  3544. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3545. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3546. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3547. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3548. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3549. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3550. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3551. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3552. Where("status = 1 AND user_org_id = ?", orgID)
  3553. if scheduleDate != 0 {
  3554. db = db.Where("schedule_date = ?", scheduleDate)
  3555. }
  3556. err = db.Find(&vms).Error
  3557. }
  3558. } else {
  3559. if cost_type > 0 {
  3560. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3561. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3562. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3563. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3564. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3565. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3566. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3567. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3568. Where("status = 1 AND user_org_id = ?", orgID)
  3569. if scheduleDate != 0 {
  3570. db = db.Where("schedule_date = ?", scheduleDate)
  3571. }
  3572. err = db.Find(&vms).Error
  3573. } else {
  3574. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3575. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3576. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3577. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3578. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3579. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3580. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3581. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3582. Where("status = 1 AND user_org_id = ?", orgID)
  3583. if scheduleDate != 0 {
  3584. db = db.Where("schedule_date = ?", scheduleDate)
  3585. }
  3586. err = db.Find(&vms).Error
  3587. }
  3588. }
  3589. }
  3590. }
  3591. return vms, err
  3592. }
  3593. func BatchDeleteMonitor(ids []string) (err error) {
  3594. if len(ids) == 1 {
  3595. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3596. } else {
  3597. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3598. }
  3599. return
  3600. }
  3601. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3602. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3603. //table := XTReadDB().Table("xt_schedule as s")
  3604. //fmt.Println(table)
  3605. if patientid > 0 {
  3606. db = db.Where("x.patient_id = ?", patientid)
  3607. }
  3608. if startime > 0 {
  3609. db = db.Where("x.dialysis_date>=?", startime)
  3610. }
  3611. if endtime > 0 {
  3612. db = db.Where("x.dialysis_date <= ?", endtime)
  3613. }
  3614. 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
  3615. return order, err
  3616. }
  3617. func GetPatientDialysisRecordListOne(patientid int64, startime int64, endtime int64) (order []*models.XtScheduleSixTy, err error) {
  3618. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  3619. //table := XTReadDB().Table("xt_schedule as s")
  3620. //fmt.Println(table)
  3621. if patientid > 0 {
  3622. db = db.Where("x.patient_id = ?", patientid)
  3623. }
  3624. if startime > 0 {
  3625. db = db.Where("x.schedule_date>=?", startime)
  3626. }
  3627. if endtime > 0 {
  3628. db = db.Where("x.schedule_date <= ?", endtime)
  3629. }
  3630. err = db.Select("x.id,x.schedule_date,x.schedule_type,x.mode_id").Find(&order).Error
  3631. return order, err
  3632. }
  3633. func BatchDeleteAdvice(ids []string) (err error) {
  3634. if len(ids) == 1 {
  3635. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3636. } else {
  3637. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3638. }
  3639. return
  3640. }
  3641. func BatchDeleteHisAdvice(ids []string) (err error) {
  3642. if len(ids) == 1 {
  3643. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3644. } else {
  3645. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3646. }
  3647. return
  3648. }
  3649. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3650. detail := models.AutomaticReduceDetail{}
  3651. 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
  3652. return detail, err
  3653. }
  3654. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3655. detail := models.AutomaticReduceDetail{}
  3656. 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
  3657. return err
  3658. }
  3659. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3660. detail := models.DialysisBeforePrepare{}
  3661. 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
  3662. return err
  3663. }
  3664. func BatchAdviceCheck(ids []string, creator int64) error {
  3665. advice := models.XtDoctorAdvice{}
  3666. 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
  3667. return err
  3668. }
  3669. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3670. advice := models.HisDoctorAdviceInfo{}
  3671. 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
  3672. return err
  3673. }
  3674. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3675. advice := models.XtDoctorAdvice{}
  3676. 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
  3677. return err
  3678. }
  3679. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3680. advice := models.HisDoctorAdviceInfo{}
  3681. 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
  3682. return err
  3683. }
  3684. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3685. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3686. return doctor, err
  3687. }
  3688. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3689. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3690. return doctor, err
  3691. }
  3692. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3693. config := models.XtHisProjectConfig{}
  3694. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3695. return config, err
  3696. }
  3697. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3698. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3699. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3700. }).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
  3701. return
  3702. }
  3703. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3704. var vms []*HisMScheduleProjectVM
  3705. if patientType == 0 {
  3706. if patient_id > 0 {
  3707. if execution_state == 1 {
  3708. db := readDb.
  3709. Table("xt_schedule").
  3710. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3711. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3712. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3713. }).
  3714. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3715. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3716. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3717. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3718. 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")
  3719. }).
  3720. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3721. 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")
  3722. }).Where("status = 1 AND user_org_id = ?", orgID)
  3723. if scheduleDate != 0 {
  3724. db = db.Where("schedule_date = ?", scheduleDate)
  3725. }
  3726. err = db.Find(&vms).Error
  3727. } else if execution_state == 2 {
  3728. db := readDb.
  3729. Table("xt_schedule").
  3730. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3731. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3732. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3733. }).
  3734. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3735. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3736. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3737. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3738. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3739. }).
  3740. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3741. 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")
  3742. }).Where("status = 1 AND user_org_id = ?", orgID)
  3743. if scheduleDate != 0 {
  3744. db = db.Where("schedule_date = ?", scheduleDate)
  3745. }
  3746. err = db.Find(&vms).Error
  3747. } else if execution_state == 0 {
  3748. db := readDb.
  3749. Table("xt_schedule").
  3750. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3751. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3752. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3753. }).
  3754. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3755. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3756. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3757. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3758. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3759. }).
  3760. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3761. 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")
  3762. }).Where("status = 1 AND user_org_id = ?", orgID)
  3763. if scheduleDate != 0 {
  3764. db = db.Where("schedule_date = ?", scheduleDate)
  3765. }
  3766. err = db.Find(&vms).Error
  3767. }
  3768. } else {
  3769. if patient_id > 0 {
  3770. if execution_state == 1 {
  3771. db := readDb.
  3772. Table("xt_schedule").
  3773. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3774. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3775. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3776. }).
  3777. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3778. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3779. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3780. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3781. 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")
  3782. }).
  3783. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3784. 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")
  3785. }).Where("status = 1 AND user_org_id = ?", orgID)
  3786. if scheduleDate != 0 {
  3787. db = db.Where("schedule_date = ?", scheduleDate)
  3788. }
  3789. err = db.Find(&vms).Error
  3790. } else if execution_state == 2 {
  3791. db := readDb.
  3792. Table("xt_schedule").
  3793. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3794. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3795. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3796. }).
  3797. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3798. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3799. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3800. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3801. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3802. }).
  3803. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3804. 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")
  3805. }).Where("status = 1 AND user_org_id = ?", orgID)
  3806. if scheduleDate != 0 {
  3807. db = db.Where("schedule_date = ?", scheduleDate)
  3808. }
  3809. err = db.Find(&vms).Error
  3810. } else if execution_state == 0 {
  3811. db := readDb.
  3812. Table("xt_schedule").
  3813. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3814. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3815. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3816. }).
  3817. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3818. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3819. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3820. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3821. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3822. }).
  3823. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3824. 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")
  3825. }).Where("status = 1 AND user_org_id = ?", orgID)
  3826. if scheduleDate != 0 {
  3827. db = db.Where("schedule_date = ?", scheduleDate)
  3828. }
  3829. err = db.Find(&vms).Error
  3830. }
  3831. } else {
  3832. if execution_state == 1 {
  3833. db := readDb.
  3834. Table("xt_schedule").
  3835. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3836. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3837. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3838. }).
  3839. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3840. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3841. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3842. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3843. 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")
  3844. }).
  3845. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3846. 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")
  3847. }).Where("status = 1 AND user_org_id = ?", orgID)
  3848. if scheduleDate != 0 {
  3849. db = db.Where("schedule_date = ?", scheduleDate)
  3850. }
  3851. err = db.Find(&vms).Error
  3852. } else if execution_state == 2 {
  3853. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3854. db := readDb.
  3855. Table("xt_schedule").
  3856. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3857. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3858. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3859. }).
  3860. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3861. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3862. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3863. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3864. 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")
  3865. }).
  3866. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3867. 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")
  3868. }).Where("status = 1 AND user_org_id = ?", orgID)
  3869. if scheduleDate != 0 {
  3870. db = db.Where("schedule_date = ?", scheduleDate)
  3871. }
  3872. err = db.Find(&vms).Error
  3873. } else if execution_state == 0 {
  3874. db := readDb.
  3875. Table("xt_schedule").
  3876. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3877. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3878. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3879. }).
  3880. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3881. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3882. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3883. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3884. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3885. }).
  3886. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3887. 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")
  3888. }).Where("status = 1 AND user_org_id = ?", orgID)
  3889. if scheduleDate != 0 {
  3890. db = db.Where("schedule_date = ?", scheduleDate)
  3891. }
  3892. err = db.Find(&vms).Error
  3893. }
  3894. }
  3895. }
  3896. }
  3897. if patientType > 0 {
  3898. if execution_state == 1 {
  3899. db := readDb.
  3900. Table("xt_schedule").
  3901. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3902. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3903. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3904. }).
  3905. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3906. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3907. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3908. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3909. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3910. 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")
  3911. }).
  3912. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3913. 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")
  3914. }).Where("status = 1 AND user_org_id = ?", orgID)
  3915. if scheduleDate != 0 {
  3916. db = db.Where("schedule_date = ?", scheduleDate)
  3917. }
  3918. err = db.Find(&vms).Error
  3919. } else if execution_state == 2 {
  3920. db := readDb.
  3921. Table("xt_schedule").
  3922. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3923. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3924. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3925. }).
  3926. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3927. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3928. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3929. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3930. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3931. 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")
  3932. }).
  3933. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3934. 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")
  3935. }).Where("status = 1 AND user_org_id = ?", orgID)
  3936. if scheduleDate != 0 {
  3937. db = db.Where("schedule_date = ?", scheduleDate)
  3938. }
  3939. err = db.Find(&vms).Error
  3940. } else if execution_state == 0 {
  3941. db := readDb.
  3942. Table("xt_schedule").
  3943. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3944. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3945. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3946. }).
  3947. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3948. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3949. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3950. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3951. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3952. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3953. }).
  3954. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3955. 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")
  3956. }).Where("status = 1 AND user_org_id = ?", orgID)
  3957. if scheduleDate != 0 {
  3958. db = db.Where("schedule_date = ?", scheduleDate)
  3959. }
  3960. err = db.Find(&vms).Error
  3961. }
  3962. }
  3963. return vms, err
  3964. }
  3965. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3966. prepare := models.DialysisBeforePrepare{}
  3967. var err error
  3968. if count > 0 {
  3969. 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
  3970. }
  3971. if count <= 0 {
  3972. 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
  3973. }
  3974. return err
  3975. }
  3976. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3977. detail := models.AutomaticReduceDetail{}
  3978. 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
  3979. return err
  3980. }
  3981. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3982. var record models.DialysisSolution
  3983. 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
  3984. if err != nil {
  3985. if err == gorm.ErrRecordNotFound {
  3986. return nil, nil
  3987. } else {
  3988. return nil, err
  3989. }
  3990. }
  3991. return &record, nil
  3992. }
  3993. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3994. var record models.DialysisPrescription
  3995. 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
  3996. if err != nil {
  3997. if err == gorm.ErrRecordNotFound {
  3998. return nil, nil
  3999. } else {
  4000. return nil, err
  4001. }
  4002. }
  4003. return &record, nil
  4004. }
  4005. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  4006. prescription := models.DialysisPrescriptionThrity{}
  4007. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  4008. return prescription, err
  4009. }
  4010. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  4011. var record models.SystemPrescription
  4012. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  4013. if err != nil {
  4014. if err == gorm.ErrRecordNotFound {
  4015. return nil, nil
  4016. } else {
  4017. return nil, err
  4018. }
  4019. }
  4020. return &record, nil
  4021. }
  4022. // 透前评估
  4023. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  4024. var record models.PredialysisEvaluation
  4025. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  4026. if err != nil {
  4027. if err == gorm.ErrRecordNotFound {
  4028. return nil, nil
  4029. } else {
  4030. return nil, err
  4031. }
  4032. }
  4033. return &record, nil
  4034. }
  4035. //
  4036. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  4037. //
  4038. // 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
  4039. // return prepare, err
  4040. //}
  4041. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4042. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  4043. return auto, err
  4044. }
  4045. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  4046. role := models.SgjUserAdminRole{}
  4047. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  4048. return role, err
  4049. }
  4050. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  4051. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  4052. return auto, err
  4053. }
  4054. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4055. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4056. return outifno, err
  4057. }
  4058. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4059. order := models.DialysisOrder{}
  4060. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4061. return order, err
  4062. }
  4063. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4064. record := models.MonitoringRecord{}
  4065. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4066. return record, err
  4067. }
  4068. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4069. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4070. return record, err
  4071. }
  4072. 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) {
  4073. var vms []*MScheduleDoctorAdviceVM
  4074. keyword = "%" + keyword + "%"
  4075. adviceWhere := ""
  4076. adviceCondition := []interface{}{}
  4077. if adviceType == 0 {
  4078. if patientType == 0 {
  4079. if patient_id > 0 {
  4080. if execution_state > 0 {
  4081. if cost_type > 0 {
  4082. if len(execution_frequency) > 0 {
  4083. if len(keyword) > 0 {
  4084. 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 ?"
  4085. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4086. } else {
  4087. 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 = ?"
  4088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4089. }
  4090. } else {
  4091. if len(keyword) > 0 {
  4092. 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 ?"
  4093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4094. } else {
  4095. 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 = ?"
  4096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4097. }
  4098. }
  4099. } else {
  4100. if len(execution_frequency) > 0 {
  4101. if len(keyword) > 0 {
  4102. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4103. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4104. } else {
  4105. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ?"
  4106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4107. }
  4108. } else {
  4109. if len(keyword) > 0 {
  4110. 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 ?"
  4111. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4112. } else {
  4113. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4114. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4115. }
  4116. }
  4117. }
  4118. } else {
  4119. if cost_type > 0 {
  4120. if len(execution_frequency) > 0 {
  4121. 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 = ?"
  4122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4123. } else {
  4124. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4125. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4126. }
  4127. } else {
  4128. if len(execution_frequency) > 0 {
  4129. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4131. } else {
  4132. if len(keyword) > 0 {
  4133. 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 ?"
  4134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4135. } else {
  4136. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4138. }
  4139. }
  4140. }
  4141. }
  4142. } else {
  4143. if execution_state > 0 {
  4144. if cost_type > 0 {
  4145. if len(execution_frequency) > 0 {
  4146. if len(keyword) > 0 {
  4147. 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 ?"
  4148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4149. } else {
  4150. 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 = ?"
  4151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4152. }
  4153. } else {
  4154. if len(keyword) > 0 {
  4155. 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 ?"
  4156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4157. } else {
  4158. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4160. }
  4161. }
  4162. } else {
  4163. if len(execution_frequency) > 0 {
  4164. if len(keyword) > 0 {
  4165. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4167. } else {
  4168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4170. }
  4171. } else {
  4172. if len(keyword) > 0 {
  4173. 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 ?"
  4174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4175. } else {
  4176. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4178. }
  4179. }
  4180. }
  4181. } else {
  4182. if cost_type > 0 {
  4183. if len(execution_frequency) > 0 {
  4184. if len(keyword) > 0 {
  4185. 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 ?"
  4186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4187. } else {
  4188. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4189. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4190. }
  4191. } else {
  4192. if len(keyword) > 0 {
  4193. 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 ?"
  4194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4195. } else {
  4196. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4198. }
  4199. }
  4200. } else {
  4201. if len(execution_frequency) > 0 {
  4202. if len(keyword) > 0 {
  4203. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4204. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4205. } else {
  4206. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4207. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4208. }
  4209. } else {
  4210. if len(keyword) > 0 {
  4211. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and advice_name like ?"
  4212. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4213. } else {
  4214. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4215. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4216. }
  4217. }
  4218. }
  4219. }
  4220. }
  4221. } else if patientType == 1 {
  4222. if patient_id > 0 {
  4223. if execution_state > 0 {
  4224. if cost_type > 0 {
  4225. if len(execution_frequency) > 0 {
  4226. if len(keyword) > 0 {
  4227. 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 ?"
  4228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4229. } else {
  4230. 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 = ?"
  4231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4232. }
  4233. } else {
  4234. if len(keyword) > 0 {
  4235. 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 ?"
  4236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4237. } else {
  4238. 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 = ?"
  4239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4240. }
  4241. }
  4242. } else {
  4243. if len(execution_frequency) > 0 {
  4244. if len(keyword) > 0 {
  4245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ? and advice_name like ?"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4247. } else {
  4248. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ? and execution_frequency = ?"
  4249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4250. }
  4251. } else {
  4252. if len(keyword) > 0 {
  4253. 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 ?"
  4254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4255. } else {
  4256. 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= ?"
  4257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4258. }
  4259. }
  4260. }
  4261. } else {
  4262. if cost_type > 0 {
  4263. if len(execution_frequency) > 0 {
  4264. if len(keyword) > 0 {
  4265. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and execution_frequency = ? and advice_name like ?"
  4266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4267. } else {
  4268. 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 = ?"
  4269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4270. }
  4271. } else {
  4272. if len(keyword) > 0 {
  4273. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle=? and advice_name like ?"
  4274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4275. } else {
  4276. 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=?"
  4277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4278. }
  4279. }
  4280. } else {
  4281. if len(execution_frequency) > 0 {
  4282. if len(keyword) > 0 {
  4283. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4285. } else {
  4286. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4287. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4288. }
  4289. } else {
  4290. if len(keyword) > 0 {
  4291. 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 ?"
  4292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4293. } else {
  4294. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4295. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4296. }
  4297. }
  4298. }
  4299. }
  4300. } else {
  4301. if execution_state > 0 {
  4302. if cost_type > 0 {
  4303. if len(execution_frequency) > 0 {
  4304. if len(keyword) > 0 {
  4305. 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 ?"
  4306. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4307. } else {
  4308. 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 = ?"
  4309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4310. }
  4311. } else {
  4312. if len(keyword) > 0 {
  4313. 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 ?"
  4314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4315. } else {
  4316. 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=?"
  4317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4318. }
  4319. }
  4320. } else {
  4321. if len(execution_frequency) > 0 {
  4322. if len(keyword) > 0 {
  4323. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4325. } else {
  4326. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4328. }
  4329. } else {
  4330. if len(keyword) > 0 {
  4331. 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 ?"
  4332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4333. } else {
  4334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4336. }
  4337. }
  4338. }
  4339. } else {
  4340. if cost_type > 0 {
  4341. if len(execution_frequency) > 0 {
  4342. if len(keyword) > 0 {
  4343. 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 ?"
  4344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4345. } else {
  4346. 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 = ?"
  4347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4348. }
  4349. } else {
  4350. if len(keyword) > 0 {
  4351. 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 ?"
  4352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4353. } else {
  4354. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4355. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4356. }
  4357. }
  4358. } else {
  4359. if len(execution_frequency) > 0 {
  4360. if len(keyword) > 0 {
  4361. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4363. } else {
  4364. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4366. }
  4367. } else {
  4368. if len(keyword) > 0 {
  4369. 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 ?"
  4370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4371. } else {
  4372. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4374. }
  4375. }
  4376. }
  4377. }
  4378. }
  4379. } else if patientType == 2 {
  4380. if patient_id > 0 {
  4381. if execution_state > 0 {
  4382. if cost_type > 0 {
  4383. if len(execution_frequency) > 0 {
  4384. if len(keyword) > 0 {
  4385. 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 ?"
  4386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4387. } else {
  4388. 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 = ?"
  4389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4390. }
  4391. } else {
  4392. if len(keyword) > 0 {
  4393. 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 ?"
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4395. } else {
  4396. 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=?"
  4397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4398. }
  4399. }
  4400. } else {
  4401. if len(execution_frequency) > 0 {
  4402. if len(keyword) > 0 {
  4403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?and execution_frequency = ? and advice_name like ?"
  4404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4405. } else {
  4406. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?and execution_frequency = ?"
  4407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4408. }
  4409. } else {
  4410. if len(keyword) > 0 {
  4411. 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 ?"
  4412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4413. } else {
  4414. 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 = ?"
  4415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4416. }
  4417. }
  4418. }
  4419. } else {
  4420. if cost_type > 0 {
  4421. if len(execution_frequency) > 0 {
  4422. if len(keyword) > 0 {
  4423. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and execution_frequency = ? and advice_name like ?"
  4424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4425. } else {
  4426. 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 = ?"
  4427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4428. }
  4429. } else {
  4430. if len(keyword) > 0 {
  4431. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and is_settle=? and advice_name like ?"
  4432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4433. } else {
  4434. 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=?"
  4435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4436. }
  4437. }
  4438. } else {
  4439. if len(execution_frequency) > 0 {
  4440. if len(keyword) > 0 {
  4441. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)and execution_frequency = ? and advice_name like ?"
  4442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4443. } else {
  4444. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)and execution_frequency = ?"
  4445. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4446. }
  4447. } else {
  4448. if len(keyword) > 0 {
  4449. 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 ?"
  4450. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4451. } else {
  4452. 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 = ?)"
  4453. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4454. }
  4455. }
  4456. }
  4457. }
  4458. } else {
  4459. if execution_state > 0 {
  4460. if cost_type > 0 {
  4461. if len(execution_frequency) > 0 {
  4462. if len(keyword) > 0 {
  4463. 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 ?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4465. } else {
  4466. 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 = ?"
  4467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4468. }
  4469. } else {
  4470. if len(keyword) > 0 {
  4471. 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 ?"
  4472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4473. } else {
  4474. 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=?"
  4475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4476. }
  4477. }
  4478. } else {
  4479. if len(execution_frequency) > 0 {
  4480. if len(keyword) > 0 {
  4481. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4482. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4483. } else {
  4484. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and execution_frequency = ?"
  4485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4486. }
  4487. } else {
  4488. if len(keyword) > 0 {
  4489. 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 ?"
  4490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4491. } else {
  4492. 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 = ?"
  4493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4494. }
  4495. }
  4496. }
  4497. } else {
  4498. if cost_type > 0 {
  4499. if len(execution_frequency) > 0 {
  4500. if len(keyword) > 0 {
  4501. 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 ?"
  4502. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4503. } else {
  4504. 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 = ?"
  4505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4506. }
  4507. } else {
  4508. if len(keyword) > 0 {
  4509. 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 ?"
  4510. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4511. } else {
  4512. 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 = ?"
  4513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4514. }
  4515. }
  4516. } else {
  4517. if len(execution_frequency) > 0 {
  4518. if len(keyword) > 0 {
  4519. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ? and advice_name like ?"
  4520. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4521. } else {
  4522. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4524. }
  4525. } else {
  4526. if len(keyword) > 0 {
  4527. 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 ?"
  4528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4529. } else {
  4530. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4532. }
  4533. }
  4534. }
  4535. }
  4536. }
  4537. }
  4538. } else if adviceType == 1 {
  4539. if patientType == 0 {
  4540. if patient_id > 0 {
  4541. if execution_state > 0 {
  4542. if cost_type > 0 {
  4543. if len(execution_frequency) > 0 {
  4544. if len(keyword) > 0 {
  4545. 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 ?"
  4546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4547. } else {
  4548. 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 = ?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4550. }
  4551. } else {
  4552. if len(keyword) > 0 {
  4553. 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 ?"
  4554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4555. } else {
  4556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4558. }
  4559. }
  4560. } else {
  4561. if len(execution_frequency) > 0 {
  4562. if len(keyword) > 0 {
  4563. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4565. } else {
  4566. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4567. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4568. }
  4569. } else {
  4570. if len(keyword) > 0 {
  4571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  4572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4573. } else {
  4574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4576. }
  4577. }
  4578. }
  4579. } else {
  4580. if cost_type > 0 {
  4581. if len(execution_frequency) > 0 {
  4582. if len(keyword) > 0 {
  4583. 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 ?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4585. } else {
  4586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4588. }
  4589. } else {
  4590. if len(keyword) > 0 {
  4591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ? "
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4593. } else {
  4594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4596. }
  4597. }
  4598. } else {
  4599. if len(execution_frequency) > 0 {
  4600. if len(keyword) > 0 {
  4601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and advice_name like ?"
  4602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4603. } else {
  4604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4606. }
  4607. }
  4608. }
  4609. }
  4610. } else {
  4611. if execution_state > 0 {
  4612. if cost_type > 0 {
  4613. if len(execution_frequency) > 0 {
  4614. if len(keyword) > 0 {
  4615. 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 ?"
  4616. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4617. } else {
  4618. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4620. }
  4621. } else {
  4622. if len(keyword) > 0 {
  4623. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  4624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4625. } else {
  4626. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4628. }
  4629. }
  4630. } else {
  4631. if len(execution_frequency) > 0 {
  4632. if len(keyword) > 0 {
  4633. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4634. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4635. } else {
  4636. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4638. }
  4639. } else {
  4640. if len(keyword) > 0 {
  4641. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and advice_name like ?"
  4642. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4643. } else {
  4644. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4645. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4646. }
  4647. }
  4648. }
  4649. } else {
  4650. if cost_type > 0 {
  4651. if len(keyword) > 0 {
  4652. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? and advice_name like ?"
  4653. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4654. } else {
  4655. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4656. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4657. }
  4658. } else {
  4659. if len(keyword) > 0 {
  4660. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and advice_name like ?"
  4661. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4662. } else {
  4663. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4664. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4665. }
  4666. }
  4667. }
  4668. }
  4669. } else if patientType == 1 {
  4670. if patient_id > 0 {
  4671. if execution_state > 0 {
  4672. if cost_type > 0 {
  4673. if len(execution_frequency) > 0 {
  4674. if len(keyword) > 0 {
  4675. 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 ?"
  4676. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4677. } else {
  4678. 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 = ?"
  4679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4680. }
  4681. } else {
  4682. if len(keyword) > 0 {
  4683. 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 ?"
  4684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  4685. } else {
  4686. 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 = ?"
  4687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4688. }
  4689. }
  4690. } else {
  4691. if len(execution_frequency) > 0 {
  4692. if len(keyword) > 0 {
  4693. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4694. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  4695. } else {
  4696. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4698. }
  4699. } else {
  4700. if len(keyword) > 0 {
  4701. 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 ?"
  4702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  4703. } else {
  4704. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4706. }
  4707. }
  4708. }
  4709. } else {
  4710. if cost_type > 0 {
  4711. if len(execution_frequency) > 0 {
  4712. if len(keyword) > 0 {
  4713. 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 ?"
  4714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  4715. } else {
  4716. 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 = ?"
  4717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4718. }
  4719. } else {
  4720. if len(keyword) > 0 {
  4721. 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 ?"
  4722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  4723. } else {
  4724. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4725. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4726. }
  4727. }
  4728. } else {
  4729. if len(execution_frequency) > 0 {
  4730. if len(keyword) > 0 {
  4731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  4733. } else {
  4734. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4736. }
  4737. } else {
  4738. if len(keyword) > 0 {
  4739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  4740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  4741. } else {
  4742. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4743. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4744. }
  4745. }
  4746. }
  4747. }
  4748. } else {
  4749. if execution_state > 0 {
  4750. if cost_type > 0 {
  4751. if len(execution_frequency) > 0 {
  4752. if len(keyword) > 0 {
  4753. 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 ?"
  4754. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  4755. } else {
  4756. 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 = ?"
  4757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4758. }
  4759. } else {
  4760. if len(keyword) > 0 {
  4761. 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 ?"
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  4763. } else {
  4764. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4766. }
  4767. }
  4768. } else {
  4769. if len(execution_frequency) > 0 {
  4770. if len(keyword) > 0 {
  4771. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  4772. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  4773. } else {
  4774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4776. }
  4777. } else {
  4778. if len(keyword) > 0 {
  4779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and advice_name like ?"
  4780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  4781. } else {
  4782. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4784. }
  4785. }
  4786. }
  4787. } else {
  4788. if cost_type > 0 {
  4789. if len(execution_frequency) > 0 {
  4790. if len(keyword) > 0 {
  4791. 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 ?"
  4792. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  4793. } else {
  4794. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4795. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4796. }
  4797. } else {
  4798. if len(keyword) > 0 {
  4799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  4800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  4801. } else {
  4802. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4803. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4804. }
  4805. }
  4806. } else {
  4807. if len(execution_frequency) > 0 {
  4808. if len(keyword) > 0 {
  4809. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  4811. } else {
  4812. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4813. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4814. }
  4815. } else {
  4816. if len(keyword) > 0 {
  4817. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and advice_name like ?"
  4818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  4819. } else {
  4820. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4822. }
  4823. }
  4824. }
  4825. }
  4826. }
  4827. } else if patientType == 2 {
  4828. if patient_id > 0 {
  4829. if execution_state > 0 {
  4830. if cost_type > 0 {
  4831. if len(execution_frequency) > 0 {
  4832. if len(keyword) > 0 {
  4833. 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 ?"
  4834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4835. } else {
  4836. 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 = ?"
  4837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4838. }
  4839. } else {
  4840. if len(keyword) > 0 {
  4841. 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 ?"
  4842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  4843. } else {
  4844. 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 = ?"
  4845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4846. }
  4847. }
  4848. } else {
  4849. if len(execution_frequency) > 0 {
  4850. if len(keyword) > 0 {
  4851. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4852. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  4853. } else {
  4854. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4856. }
  4857. } else {
  4858. if len(keyword) > 0 {
  4859. 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 ?"
  4860. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  4861. } else {
  4862. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4864. }
  4865. }
  4866. }
  4867. } else {
  4868. if cost_type > 0 {
  4869. if len(execution_frequency) > 0 {
  4870. if len(keyword) > 0 {
  4871. 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 ?"
  4872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  4873. } else {
  4874. 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 = ?"
  4875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4876. }
  4877. } else {
  4878. if len(keyword) > 0 {
  4879. 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 ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  4881. } else {
  4882. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4884. }
  4885. }
  4886. } else {
  4887. if len(execution_frequency) > 0 {
  4888. if len(keyword) > 0 {
  4889. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  4890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  4891. } else {
  4892. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4894. }
  4895. } else {
  4896. if len(keyword) > 0 {
  4897. 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 ?"
  4898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  4899. } else {
  4900. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4901. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4902. }
  4903. }
  4904. }
  4905. }
  4906. } else {
  4907. if execution_state > 0 {
  4908. if cost_type > 0 {
  4909. if len(execution_frequency) > 0 {
  4910. if len(keyword) > 0 {
  4911. 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 ?"
  4912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  4913. } else {
  4914. 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 = ?"
  4915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4916. }
  4917. } else {
  4918. if len(keyword) > 0 {
  4919. 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 ?"
  4920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  4921. } else {
  4922. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4924. }
  4925. }
  4926. } else {
  4927. if len(execution_frequency) > 0 {
  4928. if len(keyword) > 0 {
  4929. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  4930. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  4931. } else {
  4932. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4934. }
  4935. } else {
  4936. if len(keyword) > 0 {
  4937. 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 ?"
  4938. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  4939. } else {
  4940. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4942. }
  4943. }
  4944. }
  4945. } else {
  4946. if cost_type > 0 {
  4947. if len(execution_frequency) > 0 {
  4948. if len(keyword) > 0 {
  4949. 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 ?"
  4950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  4951. } else {
  4952. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4954. }
  4955. } else {
  4956. if len(keyword) > 0 {
  4957. 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 ?"
  4958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  4959. } else {
  4960. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4962. }
  4963. }
  4964. } else {
  4965. if len(execution_frequency) > 0 {
  4966. if len(keyword) > 0 {
  4967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  4968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  4969. } else {
  4970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4971. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4972. }
  4973. } else {
  4974. if len(keyword) > 0 {
  4975. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and advice_name like ?"
  4976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  4977. } else {
  4978. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4980. }
  4981. }
  4982. }
  4983. }
  4984. }
  4985. }
  4986. } else if adviceType == 3 {
  4987. if patientType == 0 {
  4988. if patient_id > 0 {
  4989. if execution_state > 0 {
  4990. if cost_type > 0 {
  4991. if len(execution_frequency) > 0 {
  4992. if len(keyword) > 0 {
  4993. 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 ?"
  4994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  4995. } else {
  4996. 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 =?"
  4997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4998. }
  4999. } else {
  5000. if len(keyword) > 0 {
  5001. 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 ?"
  5002. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5003. } else {
  5004. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5006. }
  5007. }
  5008. } else {
  5009. if len(execution_frequency) > 0 {
  5010. if len(keyword) > 0 {
  5011. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =? and advice_name like ?"
  5012. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5013. } else {
  5014. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  5015. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5016. }
  5017. } else {
  5018. if len(keyword) > 0 {
  5019. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5020. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5021. } else {
  5022. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5024. }
  5025. }
  5026. }
  5027. } else {
  5028. if cost_type > 0 {
  5029. if len(execution_frequency) > 0 {
  5030. if len(keyword) > 0 {
  5031. 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 ?"
  5032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5033. } else {
  5034. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  5035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5036. }
  5037. } else {
  5038. if len(keyword) > 0 {
  5039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5041. } else {
  5042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5044. }
  5045. }
  5046. } else {
  5047. if len(execution_frequency) > 0 {
  5048. if len(keyword) > 0 {
  5049. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =? and advice_name like ?"
  5050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5051. } else {
  5052. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  5053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5054. }
  5055. } else {
  5056. if len(keyword) > 0 {
  5057. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and advice_name like ?"
  5058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5059. } else {
  5060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5062. }
  5063. }
  5064. }
  5065. }
  5066. } else {
  5067. if execution_state > 0 {
  5068. if cost_type > 0 {
  5069. if len(execution_frequency) > 0 {
  5070. if len(keyword) > 0 {
  5071. 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 ?"
  5072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5073. } else {
  5074. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  5075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5076. }
  5077. } else {
  5078. if len(keyword) > 0 {
  5079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and advice_name like ?"
  5080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5081. } else {
  5082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5084. }
  5085. }
  5086. } else {
  5087. if len(execution_frequency) > 0 {
  5088. if len(keyword) > 0 {
  5089. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =? and advice_name like ?"
  5090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5091. } else {
  5092. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  5093. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5094. }
  5095. } else {
  5096. if len(keyword) > 0 {
  5097. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and advice_name like ?"
  5098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5099. } else {
  5100. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5102. }
  5103. }
  5104. }
  5105. } else {
  5106. if cost_type > 0 {
  5107. if len(execution_frequency) > 0 {
  5108. if len(keyword) > 0 {
  5109. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =? and advice_name like ?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5111. } else {
  5112. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  5113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5114. }
  5115. } else {
  5116. if len(keyword) > 0 {
  5117. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and advice_name like ?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5119. } else {
  5120. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5122. }
  5123. }
  5124. } else {
  5125. if len(execution_frequency) > 0 {
  5126. if len(keyword) > 0 {
  5127. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =? and advice_name like ?"
  5128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5129. } else {
  5130. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  5131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5132. }
  5133. } else {
  5134. if len(keyword) > 0 {
  5135. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and advice_name like ?"
  5136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5137. } else {
  5138. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5140. }
  5141. }
  5142. }
  5143. }
  5144. }
  5145. } else if patientType == 1 {
  5146. if patient_id > 0 {
  5147. if execution_state > 0 {
  5148. if cost_type > 0 {
  5149. if len(execution_frequency) > 0 {
  5150. if len(keyword) > 0 {
  5151. 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 ?"
  5152. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5153. } else {
  5154. 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 = ?"
  5155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5156. }
  5157. } else {
  5158. if len(keyword) > 0 {
  5159. 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 ?"
  5160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  5161. } else {
  5162. 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 = ?"
  5163. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5164. }
  5165. }
  5166. } else {
  5167. if len(execution_frequency) > 0 {
  5168. if len(keyword) > 0 {
  5169. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5170. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  5171. } else {
  5172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5174. }
  5175. } else {
  5176. if len(keyword) > 0 {
  5177. 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 ?"
  5178. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  5179. } else {
  5180. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5181. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5182. }
  5183. }
  5184. }
  5185. } else {
  5186. if cost_type > 0 {
  5187. if len(execution_frequency) > 0 {
  5188. if len(keyword) > 0 {
  5189. 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 ?"
  5190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  5191. } else {
  5192. 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 = ?"
  5193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5194. }
  5195. } else {
  5196. if len(keyword) > 0 {
  5197. 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 ?"
  5198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  5199. } else {
  5200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5202. }
  5203. }
  5204. } else {
  5205. if len(execution_frequency) > 0 {
  5206. if len(keyword) > 0 {
  5207. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  5209. } else {
  5210. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5212. }
  5213. } else {
  5214. if len(keyword) > 0 {
  5215. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  5216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  5217. } else {
  5218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5220. }
  5221. }
  5222. }
  5223. }
  5224. } else {
  5225. if execution_state > 0 {
  5226. if cost_type > 0 {
  5227. if len(execution_frequency) > 0 {
  5228. if len(keyword) > 0 {
  5229. 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 ?"
  5230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  5231. } else {
  5232. 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 = ?"
  5233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5234. }
  5235. } else {
  5236. if len(keyword) > 0 {
  5237. 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 ?"
  5238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  5239. } else {
  5240. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5242. }
  5243. }
  5244. } else {
  5245. if len(execution_frequency) > 0 {
  5246. if len(keyword) > 0 {
  5247. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? and avice_name like ? "
  5248. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  5249. } else {
  5250. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  5251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5252. }
  5253. } else {
  5254. if len(keyword) > 0 {
  5255. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and advice_name like ?"
  5256. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  5257. } else {
  5258. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5260. }
  5261. }
  5262. }
  5263. } else {
  5264. if cost_type > 0 {
  5265. if len(execution_frequency) > 0 {
  5266. if len(keyword) > 0 {
  5267. 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 ?"
  5268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  5269. } else {
  5270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5272. }
  5273. } else {
  5274. if len(keyword) > 0 {
  5275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  5276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  5277. } else {
  5278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5280. }
  5281. }
  5282. } else {
  5283. if len(execution_frequency) > 0 {
  5284. if len(keyword) > 0 {
  5285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  5286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  5287. } else {
  5288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  5289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5290. }
  5291. } else {
  5292. if len(keyword) > 0 {
  5293. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and advice_name like ?"
  5294. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  5295. } else {
  5296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5298. }
  5299. }
  5300. }
  5301. }
  5302. }
  5303. } else if patientType == 2 {
  5304. if patient_id > 0 {
  5305. if execution_state > 0 {
  5306. if cost_type > 0 {
  5307. if len(execution_frequency) > 0 {
  5308. if len(keyword) > 0 {
  5309. 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 ?"
  5310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5311. } else {
  5312. 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 = ?"
  5313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5314. }
  5315. } else {
  5316. if len(keyword) > 0 {
  5317. 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 ?"
  5318. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5319. } else {
  5320. 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 = ?"
  5321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5322. }
  5323. }
  5324. } else {
  5325. if len(execution_frequency) > 0 {
  5326. if len(keyword) > 0 {
  5327. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5328. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5329. } else {
  5330. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5331. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5332. }
  5333. } else {
  5334. if len(keyword) > 0 {
  5335. 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 ?"
  5336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5337. } else {
  5338. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5339. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5340. }
  5341. }
  5342. }
  5343. } else {
  5344. if cost_type > 0 {
  5345. if len(execution_frequency) > 0 {
  5346. if len(keyword) > 0 {
  5347. 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 ?"
  5348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5349. } else {
  5350. 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 = ?"
  5351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5352. }
  5353. } else {
  5354. if len(keyword) > 0 {
  5355. 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 ?"
  5356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5357. } else {
  5358. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5360. }
  5361. }
  5362. } else {
  5363. if len(execution_frequency) > 0 {
  5364. if len(keyword) > 0 {
  5365. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5366. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5367. } else {
  5368. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  5369. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5370. }
  5371. } else {
  5372. if len(keyword) > 0 {
  5373. 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 ?"
  5374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  5375. } else {
  5376. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5377. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5378. }
  5379. }
  5380. }
  5381. }
  5382. } else {
  5383. if execution_state > 0 {
  5384. if cost_type > 0 {
  5385. if len(execution_frequency) > 0 {
  5386. if len(keyword) > 0 {
  5387. 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 ?"
  5388. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  5389. } else {
  5390. 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 = ?"
  5391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5392. }
  5393. } else {
  5394. if len(keyword) > 0 {
  5395. 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 ?"
  5396. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  5397. } else {
  5398. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5400. }
  5401. }
  5402. } else {
  5403. if len(execution_frequency) > 0 {
  5404. if len(keyword) > 0 {
  5405. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ? and advice_name like ?"
  5406. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  5407. } else {
  5408. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  5409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5410. }
  5411. } else {
  5412. if len(keyword) > 0 {
  5413. 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 ?"
  5414. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  5415. } else {
  5416. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5418. }
  5419. }
  5420. }
  5421. } else {
  5422. if cost_type > 0 {
  5423. if len(execution_frequency) > 0 {
  5424. if len(keyword) > 0 {
  5425. 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 ?"
  5426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  5427. } else {
  5428. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5429. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5430. }
  5431. } else {
  5432. if len(keyword) > 0 {
  5433. 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 ?"
  5434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  5435. } else {
  5436. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5437. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5438. }
  5439. }
  5440. } else {
  5441. if len(execution_frequency) > 0 {
  5442. if len(keyword) > 0 {
  5443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  5444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  5445. } else {
  5446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  5447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5448. }
  5449. } else {
  5450. if len(keyword) > 0 {
  5451. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and advice_name like ?"
  5452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  5453. } else {
  5454. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5456. }
  5457. }
  5458. }
  5459. }
  5460. }
  5461. }
  5462. } else if adviceType == 2 && len(deliverWay) > 0 {
  5463. if patientType == 0 {
  5464. if patient_id > 0 {
  5465. if execution_state > 0 {
  5466. if cost_type > 0 {
  5467. if len(execution_frequency) > 0 {
  5468. if len(keyword) > 0 {
  5469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5471. } else {
  5472. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5473. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5474. }
  5475. } else {
  5476. if len(keyword) > 0 {
  5477. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5479. } else {
  5480. 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 = ?"
  5481. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5482. }
  5483. }
  5484. } else {
  5485. if len(execution_frequency) > 0 {
  5486. if len(keyword) > 0 {
  5487. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5489. } else {
  5490. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5492. }
  5493. } else {
  5494. if len(keyword) > 0 {
  5495. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5497. } else {
  5498. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5499. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5500. }
  5501. }
  5502. }
  5503. } else {
  5504. if cost_type > 0 {
  5505. if len(execution_frequency) > 0 {
  5506. if len(keyword) > 0 {
  5507. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5509. } else {
  5510. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5512. }
  5513. } else {
  5514. if len(keyword) > 0 {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5517. } else {
  5518. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5520. }
  5521. }
  5522. } else {
  5523. if len(execution_frequency) > 0 {
  5524. if len(keyword) > 0 {
  5525. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5527. } else {
  5528. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5529. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5530. }
  5531. } else {
  5532. if len(keyword) > 0 {
  5533. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and advice_name like ?"
  5534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5535. } else {
  5536. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5537. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5538. }
  5539. }
  5540. }
  5541. }
  5542. } else {
  5543. if execution_state > 0 {
  5544. if cost_type > 0 {
  5545. if len(execution_frequency) > 0 {
  5546. if len(keyword) > 0 {
  5547. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5548. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5549. } else {
  5550. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5552. }
  5553. } else {
  5554. if len(keyword) > 0 {
  5555. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5556. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5557. } else {
  5558. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5560. }
  5561. }
  5562. } else {
  5563. if len(execution_frequency) > 0 {
  5564. if len(keyword) > 0 {
  5565. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5567. } else {
  5568. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5569. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5570. }
  5571. } else {
  5572. if len(keyword) > 0 {
  5573. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5575. } else {
  5576. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5577. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5578. }
  5579. }
  5580. }
  5581. } else {
  5582. if cost_type > 0 {
  5583. if len(execution_frequency) > 0 {
  5584. if len(keyword) > 0 {
  5585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency, keyword)
  5587. } else {
  5588. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  5590. }
  5591. } else {
  5592. if len(keyword) > 0 {
  5593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5595. } else {
  5596. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5598. }
  5599. }
  5600. } else {
  5601. if len(execution_frequency) > 0 {
  5602. if len(keyword) > 0 {
  5603. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ? and advice_name like ?"
  5604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency, keyword)
  5605. } else {
  5606. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  5607. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  5608. }
  5609. } else {
  5610. if len(keyword) > 0 {
  5611. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and advice_name like ?"
  5612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5613. } else {
  5614. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5615. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5616. }
  5617. }
  5618. }
  5619. }
  5620. }
  5621. } else if patientType == 1 {
  5622. if patient_id > 0 {
  5623. if execution_state > 0 {
  5624. if cost_type > 0 {
  5625. if len(execution_frequency) > 0 {
  5626. if len(keyword) > 0 {
  5627. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5628. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5629. } else {
  5630. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5631. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5632. }
  5633. } else {
  5634. if len(keyword) > 0 {
  5635. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5636. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, keyword)
  5637. } else {
  5638. 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 = ?"
  5639. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5640. }
  5641. }
  5642. } else {
  5643. if len(execution_frequency) > 0 {
  5644. if len(keyword) > 0 {
  5645. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5646. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5647. } else {
  5648. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  5650. }
  5651. } else {
  5652. if len(keyword) > 0 {
  5653. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5654. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, keyword)
  5655. } else {
  5656. 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 = ?"
  5657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5658. }
  5659. }
  5660. }
  5661. } else {
  5662. if cost_type > 0 {
  5663. if len(execution_frequency) > 0 {
  5664. if len(keyword) > 0 {
  5665. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5666. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5667. } else {
  5668. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5669. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  5670. }
  5671. } else {
  5672. if len(keyword) > 0 {
  5673. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5674. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, keyword)
  5675. } else {
  5676. 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 = ?"
  5677. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5678. }
  5679. }
  5680. } else {
  5681. if len(execution_frequency) > 0 {
  5682. if len(keyword) > 0 {
  5683. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency, keyword)
  5685. } else {
  5686. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  5688. }
  5689. } else {
  5690. if len(keyword) > 0 {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ? and avice_name like ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, keyword)
  5693. } else {
  5694. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5696. }
  5697. }
  5698. }
  5699. }
  5700. } else {
  5701. if execution_state > 0 {
  5702. if cost_type > 0 {
  5703. if len(execution_frequency) > 0 {
  5704. if len(keyword) > 0 {
  5705. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5706. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5707. } else {
  5708. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5709. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  5710. }
  5711. } else {
  5712. if len(keyword) > 0 {
  5713. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5714. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, keyword)
  5715. } else {
  5716. 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 = ?"
  5717. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5718. }
  5719. }
  5720. } else {
  5721. if len(execution_frequency) > 0 {
  5722. if len(keyword) > 0 {
  5723. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency, keyword)
  5725. } else {
  5726. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  5728. }
  5729. } else {
  5730. if len(keyword) > 0 {
  5731. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and advice_name like ?"
  5732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, keyword)
  5733. } else {
  5734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5736. }
  5737. }
  5738. }
  5739. } else {
  5740. if cost_type > 0 {
  5741. if len(execution_frequency) > 0 {
  5742. if len(keyword) > 0 {
  5743. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency, keyword)
  5745. } else {
  5746. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  5747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  5748. }
  5749. } else {
  5750. if len(keyword) > 0 {
  5751. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ? and advice_name like ?"
  5752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, keyword)
  5753. } else {
  5754. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5756. }
  5757. }
  5758. } else {
  5759. if len(execution_frequency) > 0 {
  5760. if len(keyword) > 0 {
  5761. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ? and advic_name like ?"
  5762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency, keyword)
  5763. } else {
  5764. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  5765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  5766. }
  5767. } else {
  5768. if len(keyword) > 0 {
  5769. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and advice_name like ?"
  5770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, keyword)
  5771. } else {
  5772. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5774. }
  5775. }
  5776. }
  5777. }
  5778. }
  5779. } else if patientType == 2 {
  5780. if patient_id > 0 {
  5781. if execution_state > 0 {
  5782. if cost_type > 0 {
  5783. if len(execution_frequency) > 0 {
  5784. if len(keyword) > 0 {
  5785. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5787. } else {
  5788. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  5790. }
  5791. } else {
  5792. if len(keyword) > 0 {
  5793. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, keyword)
  5795. } else {
  5796. 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 = ?"
  5797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5798. }
  5799. }
  5800. } else {
  5801. if len(execution_frequency) > 0 {
  5802. if len(keyword) > 0 {
  5803. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency, keyword)
  5805. } else {
  5806. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  5808. }
  5809. } else {
  5810. if len(keyword) > 0 {
  5811. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5812. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, keyword)
  5813. } else {
  5814. 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 = ?"
  5815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5816. }
  5817. }
  5818. }
  5819. } else {
  5820. if cost_type > 0 {
  5821. if len(execution_frequency) > 0 {
  5822. if len(keyword) > 0 {
  5823. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency, keyword)
  5825. } else {
  5826. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  5828. }
  5829. } else {
  5830. if len(keyword) > 0 {
  5831. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, keyword)
  5833. } else {
  5834. 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 = ?"
  5835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5836. }
  5837. }
  5838. } else {
  5839. if len(execution_frequency) > 0 {
  5840. if len(keyword) > 0 {
  5841. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency, keyword)
  5843. } else {
  5844. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  5845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  5846. }
  5847. } else {
  5848. if len(keyword) > 0 {
  5849. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ? and advice_name like ?"
  5850. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, keyword)
  5851. } else {
  5852. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5854. }
  5855. }
  5856. }
  5857. }
  5858. } else {
  5859. if execution_state > 0 {
  5860. if cost_type > 0 {
  5861. if len(execution_frequency) > 0 {
  5862. if len(keyword) > 0 {
  5863. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5864. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency, keyword)
  5865. } else {
  5866. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5867. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  5868. }
  5869. } else {
  5870. if len(keyword) > 0 {
  5871. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, keyword)
  5873. } else {
  5874. 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 = ?"
  5875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5876. }
  5877. }
  5878. } else {
  5879. if len(execution_frequency) > 0 {
  5880. if len(keyword) > 0 {
  5881. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5882. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency, keyword)
  5883. } else {
  5884. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  5885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  5886. }
  5887. } else {
  5888. if len(keyword) > 0 {
  5889. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and advice_name like ?"
  5890. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, keyword)
  5891. } else {
  5892. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5894. }
  5895. }
  5896. }
  5897. } else {
  5898. if cost_type > 0 {
  5899. if len(execution_frequency) > 0 {
  5900. if len(keyword) > 0 {
  5901. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5903. } else {
  5904. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5906. }
  5907. } else {
  5908. if len(keyword) > 0 {
  5909. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ? and advice_name like ?"
  5910. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, keyword)
  5911. } else {
  5912. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5913. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5914. }
  5915. }
  5916. } else {
  5917. if len(keyword) > 0 {
  5918. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and advice_name like ?"
  5919. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, keyword)
  5920. } else {
  5921. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5922. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5923. }
  5924. }
  5925. }
  5926. }
  5927. }
  5928. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5929. if patientType == 0 {
  5930. if patient_id > 0 {
  5931. if execution_state > 0 {
  5932. if cost_type > 0 {
  5933. if len(execution_frequency) > 0 {
  5934. if len(keyword) > 0 {
  5935. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  5937. } else {
  5938. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  5939. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5940. }
  5941. } else {
  5942. if len(keyword) > 0 {
  5943. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  5944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  5945. } else {
  5946. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5947. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5948. }
  5949. }
  5950. } else {
  5951. if len(execution_frequency) > 0 {
  5952. if len(keyword) > 0 {
  5953. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  5954. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  5955. } else {
  5956. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  5957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5958. }
  5959. } else {
  5960. if len(keyword) > 0 {
  5961. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  5962. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  5963. } else {
  5964. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5966. }
  5967. }
  5968. }
  5969. } else {
  5970. if cost_type > 0 {
  5971. if len(execution_frequency) > 0 {
  5972. if len(keyword) > 0 {
  5973. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  5974. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  5975. } else {
  5976. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  5977. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5978. }
  5979. } else {
  5980. if len(keyword) > 0 {
  5981. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  5982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  5983. } else {
  5984. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5985. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5986. }
  5987. }
  5988. } else {
  5989. if len(execution_frequency) > 0 {
  5990. if len(keyword) > 0 {
  5991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  5992. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  5993. } else {
  5994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  5995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5996. }
  5997. } else {
  5998. if len(keyword) > 0 {
  5999. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and advice_name like ?"
  6000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6001. } else {
  6002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6004. }
  6005. }
  6006. }
  6007. }
  6008. } else {
  6009. if execution_state > 0 {
  6010. if cost_type > 0 {
  6011. if len(execution_frequency) > 0 {
  6012. if len(keyword) > 0 {
  6013. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6015. } else {
  6016. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6017. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6018. }
  6019. } else {
  6020. if len(keyword) > 0 {
  6021. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6023. } else {
  6024. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6026. }
  6027. }
  6028. } else {
  6029. if len(execution_frequency) > 0 {
  6030. if len(keyword) > 0 {
  6031. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ? and advice_name like ?"
  6032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6033. } else {
  6034. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  6035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6036. }
  6037. } else {
  6038. if len(keyword) > 0 {
  6039. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and advice_name like ?"
  6040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6041. } else {
  6042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6044. }
  6045. }
  6046. }
  6047. } else {
  6048. if cost_type > 0 {
  6049. if len(execution_frequency) > 0 {
  6050. if len(keyword) > 0 {
  6051. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6053. } else {
  6054. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  6055. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6056. }
  6057. }
  6058. } else {
  6059. if len(execution_frequency) > 0 {
  6060. if len(keyword) > 0 {
  6061. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ? and advice_name like ?"
  6062. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6063. } else {
  6064. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  6065. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6066. }
  6067. } else {
  6068. if len(keyword) > 0 {
  6069. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and advice_name like ?"
  6070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6071. } else {
  6072. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6074. }
  6075. }
  6076. }
  6077. }
  6078. }
  6079. } else if patientType == 1 {
  6080. if patient_id > 0 {
  6081. if execution_state > 0 {
  6082. if cost_type > 0 {
  6083. if len(execution_frequency) > 0 {
  6084. if len(keyword) > 0 {
  6085. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6087. } else {
  6088. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6090. }
  6091. } else {
  6092. if len(keyword) > 0 {
  6093. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, keyword)
  6095. } else {
  6096. 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 = ?"
  6097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6098. }
  6099. }
  6100. } else {
  6101. if len(execution_frequency) > 0 {
  6102. if len(keyword) > 0 {
  6103. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  6105. } else {
  6106. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  6108. }
  6109. } else {
  6110. if len(keyword) > 0 {
  6111. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  6112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, keyword)
  6113. } else {
  6114. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6115. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6116. }
  6117. }
  6118. }
  6119. } else {
  6120. if cost_type > 0 {
  6121. if len(execution_frequency) > 0 {
  6122. if len(keyword) > 0 {
  6123. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  6125. } else {
  6126. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  6128. }
  6129. } else {
  6130. if len(keyword) > 0 {
  6131. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  6132. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, keyword)
  6133. } else {
  6134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6136. }
  6137. }
  6138. } else {
  6139. if len(execution_frequency) > 0 {
  6140. if len(keyword) > 0 {
  6141. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  6142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency, keyword)
  6143. } else {
  6144. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  6146. }
  6147. } else {
  6148. if len(keyword) > 0 {
  6149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  6150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, keyword)
  6151. } else {
  6152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6154. }
  6155. }
  6156. }
  6157. }
  6158. } else {
  6159. if execution_state > 0 {
  6160. if cost_type > 0 {
  6161. if len(execution_frequency) > 0 {
  6162. if len(keyword) > 0 {
  6163. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  6165. } else {
  6166. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  6168. }
  6169. } else {
  6170. if len(keyword) > 0 {
  6171. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, keyword)
  6173. } else {
  6174. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6176. }
  6177. }
  6178. } else {
  6179. if len(execution_frequency) > 0 {
  6180. if len(keyword) > 0 {
  6181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency, keyword)
  6183. } else {
  6184. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  6185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  6186. }
  6187. } else {
  6188. if len(keyword) > 0 {
  6189. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and advice_name like ?"
  6190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, keyword)
  6191. } else {
  6192. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6194. }
  6195. }
  6196. }
  6197. } else {
  6198. if cost_type > 0 {
  6199. if len(execution_frequency) > 0 {
  6200. if len(keyword) > 0 {
  6201. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6202. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency, keyword)
  6203. } else {
  6204. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  6206. }
  6207. } else {
  6208. if len(keyword) > 0 {
  6209. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  6210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, keyword)
  6211. } else {
  6212. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6214. }
  6215. }
  6216. } else {
  6217. if len(execution_frequency) > 0 {
  6218. if len(keyword) > 0 {
  6219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  6220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency, keyword)
  6221. } else {
  6222. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  6223. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  6224. }
  6225. } else {
  6226. if len(keyword) > 0 {
  6227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and advice_name like ?"
  6228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, keyword)
  6229. } else {
  6230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6232. }
  6233. }
  6234. }
  6235. }
  6236. }
  6237. } else if patientType == 2 {
  6238. if patient_id > 0 {
  6239. if execution_state > 0 {
  6240. if cost_type > 0 {
  6241. if len(execution_frequency) > 0 {
  6242. if len(keyword) > 0 {
  6243. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency, keyword)
  6245. } else {
  6246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency=?"
  6247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  6248. }
  6249. } else {
  6250. if len(keyword) > 0 {
  6251. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  6252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, keyword)
  6253. } else {
  6254. 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 = ?"
  6255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6256. }
  6257. }
  6258. } else {
  6259. if len(execution_frequency) > 0 {
  6260. if len(keyword) > 0 {
  6261. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=? and advice_name like ?"
  6262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency, keyword)
  6263. } else {
  6264. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency=?"
  6265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  6266. }
  6267. } else {
  6268. if len(keyword) > 0 {
  6269. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ? and advice_name like ?"
  6270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, keyword)
  6271. } else {
  6272. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6274. }
  6275. }
  6276. }
  6277. } else {
  6278. if cost_type > 0 {
  6279. if len(execution_frequency) > 0 {
  6280. if len(keyword) > 0 {
  6281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=? and advice_name like ?"
  6282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency, keyword)
  6283. } else {
  6284. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency=?"
  6285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  6286. }
  6287. } else {
  6288. if len(keyword) > 0 {
  6289. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ? and advice_name like ?"
  6290. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, keyword)
  6291. } else {
  6292. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6294. }
  6295. }
  6296. } else {
  6297. if len(execution_frequency) > 0 {
  6298. if len(keyword) > 0 {
  6299. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=? and advice_name like ?"
  6300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency, keyword)
  6301. } else {
  6302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  6303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  6304. }
  6305. } else {
  6306. if len(keyword) > 0 {
  6307. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  6308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, keyword)
  6309. } else {
  6310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6312. }
  6313. }
  6314. }
  6315. }
  6316. } else {
  6317. if execution_state > 0 {
  6318. if cost_type > 0 {
  6319. if len(execution_frequency) > 0 {
  6320. if len(keyword) > 0 {
  6321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency, keyword)
  6323. } else {
  6324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  6326. }
  6327. } else {
  6328. if len(keyword) > 0 {
  6329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  6330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, keyword)
  6331. } else {
  6332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6334. }
  6335. }
  6336. } else {
  6337. if len(execution_frequency) > 0 {
  6338. if len(keyword) > 0 {
  6339. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  6340. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency, keyword)
  6341. } else {
  6342. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ? "
  6343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  6344. }
  6345. } else {
  6346. if len(keyword) > 0 {
  6347. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  6348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, keyword)
  6349. } else {
  6350. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6352. }
  6353. }
  6354. }
  6355. } else {
  6356. if cost_type > 0 {
  6357. if len(execution_frequency) > 0 {
  6358. if len(keyword) > 0 {
  6359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ? and advice_name like ?"
  6360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency, keyword)
  6361. } else {
  6362. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6363. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  6364. }
  6365. } else {
  6366. if len(keyword) > 0 {
  6367. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  6368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, keyword)
  6369. } else {
  6370. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6372. }
  6373. }
  6374. } else {
  6375. if len(execution_frequency) > 0 {
  6376. if len(keyword) > 0 {
  6377. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  6378. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency, keyword)
  6379. } else {
  6380. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  6381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  6382. }
  6383. } else {
  6384. if len(keyword) > 0 {
  6385. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and advice_name like ?"
  6386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, keyword)
  6387. } else {
  6388. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6390. }
  6391. }
  6392. }
  6393. }
  6394. }
  6395. }
  6396. }
  6397. db := readDb.Table("xt_schedule")
  6398. if scheduleType > 0 {
  6399. db = db.Where("schedule_type = ?", scheduleType)
  6400. }
  6401. if partitonType > 0 {
  6402. db = db.Where("partition_id = ?", partitonType)
  6403. }
  6404. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6405. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6406. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6407. }).
  6408. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6409. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6410. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6411. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6412. Preload("DoctorAdvices", adviceCondition...).
  6413. Where("status = 1 AND user_org_id = ?", orgID)
  6414. if scheduleDate != 0 {
  6415. db = db.Where("schedule_date = ?", scheduleDate)
  6416. }
  6417. err := db.Find(&vms).Error
  6418. return vms, err
  6419. }
  6420. 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) {
  6421. var vms []*MScheduleDoctorAdviceVM
  6422. adviceWhere := ""
  6423. adviceCondition := []interface{}{}
  6424. if adviceType == 0 {
  6425. if patientType == 0 {
  6426. if patient_id > 0 {
  6427. if execution_state > 0 {
  6428. if cost_type > 0 {
  6429. 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 = ?"
  6430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6431. } else {
  6432. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  6433. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6434. }
  6435. } else {
  6436. if cost_type > 0 {
  6437. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  6438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6439. } else {
  6440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6442. }
  6443. }
  6444. } else {
  6445. if execution_state > 0 {
  6446. if cost_type > 0 {
  6447. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  6448. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6449. } else {
  6450. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  6451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6452. }
  6453. } else {
  6454. if cost_type > 0 {
  6455. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  6456. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6457. } else {
  6458. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  6459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6460. }
  6461. }
  6462. }
  6463. } else if patientType == 1 {
  6464. if patient_id > 0 {
  6465. if execution_state > 0 {
  6466. if cost_type > 0 {
  6467. 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 = ?"
  6468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6469. } else {
  6470. 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= ?"
  6471. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6472. }
  6473. } else {
  6474. if cost_type > 0 {
  6475. 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=?"
  6476. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6477. } else {
  6478. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  6479. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6480. }
  6481. }
  6482. } else {
  6483. if execution_state > 0 {
  6484. if cost_type > 0 {
  6485. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=?"
  6486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6487. } else {
  6488. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6489. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6490. }
  6491. } else {
  6492. if cost_type > 0 {
  6493. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  6494. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6495. } else {
  6496. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  6497. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6498. }
  6499. }
  6500. }
  6501. } else if patientType == 2 {
  6502. if patient_id > 0 {
  6503. if execution_state > 0 {
  6504. if cost_type > 0 {
  6505. 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=?"
  6506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6507. } else {
  6508. 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 = ?"
  6509. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6510. }
  6511. } else {
  6512. if cost_type > 0 {
  6513. 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=?"
  6514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6515. } else {
  6516. 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 = ?)"
  6517. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6518. }
  6519. }
  6520. } else {
  6521. if execution_state > 0 {
  6522. if cost_type > 0 {
  6523. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ? and is_settle=?"
  6524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6525. } else {
  6526. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  6527. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6528. }
  6529. } else {
  6530. if cost_type > 0 {
  6531. 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 = ?"
  6532. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6533. } else {
  6534. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  6535. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6536. }
  6537. }
  6538. }
  6539. }
  6540. } else if adviceType == 1 {
  6541. if patientType == 0 {
  6542. if patient_id > 0 {
  6543. if execution_state > 0 {
  6544. if cost_type > 0 {
  6545. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6547. } else {
  6548. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  6549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6550. }
  6551. } else {
  6552. if cost_type > 0 {
  6553. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  6554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6555. } else {
  6556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  6557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6558. }
  6559. }
  6560. } else {
  6561. if execution_state > 0 {
  6562. if cost_type > 0 {
  6563. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  6564. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6565. } else {
  6566. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  6567. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6568. }
  6569. } else {
  6570. if cost_type > 0 {
  6571. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  6572. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6573. } else {
  6574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  6575. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6576. }
  6577. }
  6578. }
  6579. } else if patientType == 1 {
  6580. if patient_id > 0 {
  6581. if execution_state > 0 {
  6582. if cost_type > 0 {
  6583. 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 = ?"
  6584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6585. } else {
  6586. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6587. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6588. }
  6589. } else {
  6590. if cost_type > 0 {
  6591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6593. } else {
  6594. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  6595. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6596. }
  6597. }
  6598. } else {
  6599. if execution_state > 0 {
  6600. if cost_type > 0 {
  6601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6603. } else {
  6604. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  6605. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6606. }
  6607. } else {
  6608. if cost_type > 0 {
  6609. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  6610. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6611. } else {
  6612. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  6613. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6614. }
  6615. }
  6616. }
  6617. } else if patientType == 2 {
  6618. if patient_id > 0 {
  6619. if execution_state > 0 {
  6620. if cost_type > 0 {
  6621. 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 = ?"
  6622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6623. } else {
  6624. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6625. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6626. }
  6627. } else {
  6628. if cost_type > 0 {
  6629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6631. } else {
  6632. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  6633. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6634. }
  6635. }
  6636. } else {
  6637. if execution_state > 0 {
  6638. if cost_type > 0 {
  6639. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6641. } else {
  6642. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  6643. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6644. }
  6645. } else {
  6646. if cost_type > 0 {
  6647. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  6648. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6649. } else {
  6650. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  6651. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6652. }
  6653. }
  6654. }
  6655. }
  6656. } else if adviceType == 3 {
  6657. if patientType == 0 {
  6658. if patient_id > 0 {
  6659. if execution_state > 0 {
  6660. if cost_type > 0 {
  6661. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6663. } else {
  6664. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  6665. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6666. }
  6667. } else {
  6668. if cost_type > 0 {
  6669. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  6670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6671. } else {
  6672. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  6673. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6674. }
  6675. }
  6676. } else {
  6677. if execution_state > 0 {
  6678. if cost_type > 0 {
  6679. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  6680. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6681. } else {
  6682. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  6683. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6684. }
  6685. } else {
  6686. if cost_type > 0 {
  6687. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  6688. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6689. } else {
  6690. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  6691. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6692. }
  6693. }
  6694. }
  6695. } else if patientType == 1 {
  6696. if patient_id > 0 {
  6697. if execution_state > 0 {
  6698. if cost_type > 0 {
  6699. 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 = ?"
  6700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6701. } else {
  6702. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6703. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6704. }
  6705. } else {
  6706. if cost_type > 0 {
  6707. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6709. } else {
  6710. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  6711. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6712. }
  6713. }
  6714. } else {
  6715. if execution_state > 0 {
  6716. if cost_type > 0 {
  6717. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  6718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6719. } else {
  6720. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  6721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6722. }
  6723. } else {
  6724. if cost_type > 0 {
  6725. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  6726. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6727. } else {
  6728. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  6729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6730. }
  6731. }
  6732. }
  6733. } else if patientType == 2 {
  6734. if patient_id > 0 {
  6735. if execution_state > 0 {
  6736. if cost_type > 0 {
  6737. 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 = ?"
  6738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6739. } else {
  6740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6742. }
  6743. } else {
  6744. if cost_type > 0 {
  6745. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6746. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6747. } else {
  6748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  6749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6750. }
  6751. }
  6752. } else {
  6753. if execution_state > 0 {
  6754. if cost_type > 0 {
  6755. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  6756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6757. } else {
  6758. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  6759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6760. }
  6761. } else {
  6762. if cost_type > 0 {
  6763. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  6764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6765. } else {
  6766. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  6767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6768. }
  6769. }
  6770. }
  6771. }
  6772. } else if adviceType == 2 && len(deliverWay) > 0 {
  6773. if patientType == 0 {
  6774. if patient_id > 0 {
  6775. if execution_state > 0 {
  6776. if cost_type > 0 {
  6777. 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 = ?"
  6778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6779. } else {
  6780. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  6781. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6782. }
  6783. } else {
  6784. if cost_type > 0 {
  6785. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  6786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6787. } else {
  6788. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  6789. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6790. }
  6791. }
  6792. } else {
  6793. if execution_state > 0 {
  6794. if cost_type > 0 {
  6795. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6797. } else {
  6798. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  6799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6800. }
  6801. } else {
  6802. if cost_type > 0 {
  6803. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  6804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6805. } else {
  6806. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  6807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6808. }
  6809. }
  6810. }
  6811. } else if patientType == 1 {
  6812. if patient_id > 0 {
  6813. if execution_state > 0 {
  6814. if cost_type > 0 {
  6815. 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 = ?"
  6816. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  6817. } else {
  6818. 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 = ?"
  6819. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  6820. }
  6821. } else {
  6822. if cost_type > 0 {
  6823. 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 = ?"
  6824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  6825. } else {
  6826. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  6827. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  6828. }
  6829. }
  6830. } else {
  6831. if execution_state > 0 {
  6832. if cost_type > 0 {
  6833. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  6834. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  6835. } else {
  6836. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  6837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  6838. }
  6839. } else {
  6840. if cost_type > 0 {
  6841. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  6842. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  6843. } else {
  6844. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  6845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  6846. }
  6847. }
  6848. }
  6849. } else if patientType == 2 {
  6850. if patient_id > 0 {
  6851. if execution_state > 0 {
  6852. if cost_type > 0 {
  6853. 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 = ?"
  6854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  6855. } else {
  6856. 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 = ?"
  6857. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  6858. }
  6859. } else {
  6860. if cost_type > 0 {
  6861. 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 = ?"
  6862. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  6863. } else {
  6864. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  6865. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  6866. }
  6867. }
  6868. } else {
  6869. if execution_state > 0 {
  6870. if cost_type > 0 {
  6871. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ? and is_settle = ?"
  6872. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  6873. } else {
  6874. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  6875. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  6876. }
  6877. } else {
  6878. if cost_type > 0 {
  6879. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  6880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  6881. } else {
  6882. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  6883. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  6884. }
  6885. }
  6886. }
  6887. }
  6888. } else if adviceType == 2 && len(deliverWay) <= 0 {
  6889. if patientType == 0 {
  6890. if patient_id > 0 {
  6891. if execution_state > 0 {
  6892. if cost_type > 0 {
  6893. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6894. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6895. } else {
  6896. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  6897. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6898. }
  6899. } else {
  6900. if cost_type > 0 {
  6901. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  6902. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6903. } else {
  6904. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  6905. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6906. }
  6907. }
  6908. } else {
  6909. if execution_state > 0 {
  6910. if cost_type > 0 {
  6911. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  6912. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6913. } else {
  6914. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  6915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6916. }
  6917. } else {
  6918. if cost_type > 0 {
  6919. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  6920. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6921. } else {
  6922. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  6923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  6924. }
  6925. }
  6926. }
  6927. } else if patientType == 1 {
  6928. if patient_id > 0 {
  6929. if execution_state > 0 {
  6930. if cost_type > 0 {
  6931. 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 = ?"
  6932. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  6933. } else {
  6934. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6935. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  6936. }
  6937. } else {
  6938. if cost_type > 0 {
  6939. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  6941. } else {
  6942. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  6943. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  6944. }
  6945. }
  6946. } else {
  6947. if execution_state > 0 {
  6948. if cost_type > 0 {
  6949. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  6950. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  6951. } else {
  6952. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  6953. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  6954. }
  6955. } else {
  6956. if cost_type > 0 {
  6957. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  6958. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  6959. } else {
  6960. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  6961. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  6962. }
  6963. }
  6964. }
  6965. } else if patientType == 2 {
  6966. if patient_id > 0 {
  6967. if execution_state > 0 {
  6968. if cost_type > 0 {
  6969. 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 = ?"
  6970. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  6971. } else {
  6972. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  6974. }
  6975. } else {
  6976. if cost_type > 0 {
  6977. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  6979. } else {
  6980. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  6981. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  6982. }
  6983. }
  6984. } else {
  6985. if execution_state > 0 {
  6986. if cost_type > 0 {
  6987. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6988. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  6989. } else {
  6990. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  6991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  6992. }
  6993. } else {
  6994. if cost_type > 0 {
  6995. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  6996. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  6997. } else {
  6998. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  6999. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  7000. }
  7001. }
  7002. }
  7003. }
  7004. }
  7005. db := readDb.Table("xt_schedule")
  7006. if scheduleType > 0 {
  7007. db = db.Where("schedule_type = ?", scheduleType)
  7008. }
  7009. if partitonType > 0 {
  7010. db = db.Where("partition_id = ?", partitonType)
  7011. }
  7012. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7013. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7014. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7015. }).
  7016. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7017. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7018. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7019. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7020. Preload("DoctorAdvices", adviceCondition...).
  7021. Where("status = 1 AND user_org_id = ?", orgID)
  7022. if scheduleDate != 0 {
  7023. db = db.Where("schedule_date = ?", scheduleDate)
  7024. }
  7025. err := db.Find(&vms).Error
  7026. return vms, err
  7027. }
  7028. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  7029. order := models.XtDialysisOrder{}
  7030. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  7031. return order, err
  7032. }
  7033. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  7034. order := models.XtPatients{}
  7035. 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
  7036. 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
  7037. return err
  7038. }
  7039. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7040. order := models.BloodDialysisOrderCount{}
  7041. db := XTReadDB().Table("xt_dialysis_order as o")
  7042. 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
  7043. return order, err
  7044. }
  7045. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  7046. order := models.BloodDialysisOrderCount{}
  7047. db := XTReadDB().Table("xt_dialysis_order as o")
  7048. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1704038400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  7049. return order, err
  7050. }
  7051. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  7052. order := models.DialysisOrder{}
  7053. 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
  7054. return order, err
  7055. }
  7056. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  7057. information := models.DeviceInformation{}
  7058. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  7059. return err
  7060. }
  7061. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  7062. var record models.DoubleCheck
  7063. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  7064. return record, err
  7065. }
  7066. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  7067. record := models.MonitoringRecord{}
  7068. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  7069. return record, err
  7070. }
  7071. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  7072. record := models.MonitoringRecord{}
  7073. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  7074. return record, err
  7075. }
  7076. 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) {
  7077. var vms []*HisMScheduleDoctorAdviceVM
  7078. if len(deliverWay) > 0 {
  7079. db := readDb.Table("xt_schedule")
  7080. if scheduleType > 0 {
  7081. db = db.Where("schedule_type = ?", scheduleType)
  7082. }
  7083. if partitionType > 0 {
  7084. db = db.Where("partition_id = ?", partitionType)
  7085. }
  7086. if patient_id > 0 {
  7087. if execution_state > 0 {
  7088. if cost_type > 0 {
  7089. if len(execution_frequency) > 0 {
  7090. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7091. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7092. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7093. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7094. 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).
  7095. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7096. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7097. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7098. Where("status = 1 AND user_org_id = ?", orgID)
  7099. if scheduleDate != 0 {
  7100. db = db.Where("schedule_date = ?", scheduleDate)
  7101. }
  7102. err = db.Find(&vms).Error
  7103. } else {
  7104. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7105. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7106. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7107. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7108. 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).
  7109. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7110. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7111. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7112. Where("status = 1 AND user_org_id = ?", orgID)
  7113. if scheduleDate != 0 {
  7114. db = db.Where("schedule_date = ?", scheduleDate)
  7115. }
  7116. err = db.Find(&vms).Error
  7117. }
  7118. } else {
  7119. if len(execution_frequency) > 0 {
  7120. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7121. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7122. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7123. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7124. 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).
  7125. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7126. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7127. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  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. } else {
  7134. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7135. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7136. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7137. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7138. 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).
  7139. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7140. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7141. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7142. Where("status = 1 AND user_org_id = ?", orgID)
  7143. if scheduleDate != 0 {
  7144. db = db.Where("schedule_date = ?", scheduleDate)
  7145. }
  7146. err = db.Find(&vms).Error
  7147. }
  7148. }
  7149. } else {
  7150. if cost_type > 0 {
  7151. if len(execution_frequency) > 0 {
  7152. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7153. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7154. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7155. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7156. 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).
  7157. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7158. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7159. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7160. Where("status = 1 AND user_org_id = ?", orgID)
  7161. if scheduleDate != 0 {
  7162. db = db.Where("schedule_date = ?", scheduleDate)
  7163. }
  7164. err = db.Find(&vms).Error
  7165. } else {
  7166. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7167. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7168. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7169. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7170. 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).
  7171. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7172. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7173. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7174. Where("status = 1 AND user_org_id = ?", orgID)
  7175. if scheduleDate != 0 {
  7176. db = db.Where("schedule_date = ?", scheduleDate)
  7177. }
  7178. err = db.Find(&vms).Error
  7179. }
  7180. } else {
  7181. if len(execution_frequency) > 0 {
  7182. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7183. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7184. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7185. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7186. 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).
  7187. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7188. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7189. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7190. Where("status = 1 AND user_org_id = ?", orgID)
  7191. if scheduleDate != 0 {
  7192. db = db.Where("schedule_date = ?", scheduleDate)
  7193. }
  7194. err = db.Find(&vms).Error
  7195. } else {
  7196. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  7197. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7198. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7199. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7200. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  7201. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7202. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7203. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7204. Where("status = 1 AND user_org_id = ?", orgID)
  7205. if scheduleDate != 0 {
  7206. db = db.Where("schedule_date = ?", scheduleDate)
  7207. }
  7208. err = db.Find(&vms).Error
  7209. }
  7210. }
  7211. }
  7212. } else {
  7213. if execution_state > 0 {
  7214. if cost_type > 0 {
  7215. if len(execution_frequency) > 0 {
  7216. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7217. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7218. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7219. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7220. 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).
  7221. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7222. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7223. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7224. Where("status = 1 AND user_org_id = ?", orgID)
  7225. if scheduleDate != 0 {
  7226. db = db.Where("schedule_date = ?", scheduleDate)
  7227. }
  7228. err = db.Find(&vms).Error
  7229. } else {
  7230. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7231. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7232. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7233. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7234. 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).
  7235. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7236. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7237. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7238. Where("status = 1 AND user_org_id = ?", orgID)
  7239. if scheduleDate != 0 {
  7240. db = db.Where("schedule_date = ?", scheduleDate)
  7241. }
  7242. err = db.Find(&vms).Error
  7243. }
  7244. } else {
  7245. if len(execution_frequency) > 0 {
  7246. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7247. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7248. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7249. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7250. 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).
  7251. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7252. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7253. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7254. Where("status = 1 AND user_org_id = ?", orgID)
  7255. if scheduleDate != 0 {
  7256. db = db.Where("schedule_date = ?", scheduleDate)
  7257. }
  7258. err = db.Find(&vms).Error
  7259. } else {
  7260. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7261. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7262. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7263. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7264. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  7265. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7266. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7267. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7268. Where("status = 1 AND user_org_id = ?", orgID)
  7269. if scheduleDate != 0 {
  7270. db = db.Where("schedule_date = ?", scheduleDate)
  7271. }
  7272. err = db.Find(&vms).Error
  7273. }
  7274. }
  7275. } else {
  7276. if cost_type > 0 {
  7277. if len(execution_frequency) > 0 {
  7278. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7279. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7280. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7281. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7282. 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).
  7283. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7284. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7285. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7286. Where("status = 1 AND user_org_id = ?", orgID)
  7287. if scheduleDate != 0 {
  7288. db = db.Where("schedule_date = ?", scheduleDate)
  7289. }
  7290. err = db.Find(&vms).Error
  7291. } else {
  7292. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7293. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7294. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7295. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7296. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  7297. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7298. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7299. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7300. Where("status = 1 AND user_org_id = ?", orgID)
  7301. if scheduleDate != 0 {
  7302. db = db.Where("schedule_date = ?", scheduleDate)
  7303. }
  7304. err = db.Find(&vms).Error
  7305. }
  7306. } else {
  7307. if len(execution_frequency) > 0 {
  7308. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7309. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7310. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7311. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7312. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  7313. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7314. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7315. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7316. Where("status = 1 AND user_org_id = ?", orgID)
  7317. if scheduleDate != 0 {
  7318. db = db.Where("schedule_date = ?", scheduleDate)
  7319. }
  7320. err = db.Find(&vms).Error
  7321. } else {
  7322. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7323. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7324. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7325. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7326. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  7327. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7328. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7329. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7330. Where("status = 1 AND user_org_id = ?", orgID)
  7331. if scheduleDate != 0 {
  7332. db = db.Where("schedule_date = ?", scheduleDate)
  7333. }
  7334. err = db.Find(&vms).Error
  7335. }
  7336. }
  7337. }
  7338. }
  7339. } else {
  7340. db := readDb.Table("xt_schedule")
  7341. if scheduleType > 0 {
  7342. db = db.Where("schedule_type = ?", scheduleType)
  7343. }
  7344. if partitionType > 0 {
  7345. db = db.Where("partition_id = ?", partitionType)
  7346. }
  7347. if patient_id > 0 {
  7348. if execution_state > 0 {
  7349. fmt.Println("execution_state---------------------", execution_state)
  7350. if cost_type > 0 {
  7351. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7352. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7353. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7354. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7355. 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).
  7356. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7357. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7358. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7359. Where("status = 1 AND user_org_id = ?", orgID)
  7360. if scheduleDate != 0 {
  7361. db = db.Where("schedule_date = ?", scheduleDate)
  7362. }
  7363. err = db.Find(&vms).Error
  7364. } else {
  7365. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7368. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7369. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  7370. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7371. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7372. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7373. Where("status = 1 AND user_org_id = ?", orgID)
  7374. if scheduleDate != 0 {
  7375. db = db.Where("schedule_date = ?", scheduleDate)
  7376. }
  7377. err = db.Find(&vms).Error
  7378. }
  7379. } else {
  7380. if cost_type > 0 {
  7381. if len(execution_frequency) > 0 {
  7382. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7383. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7384. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7385. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7386. 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).
  7387. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7388. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7389. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7390. Where("status = 1 AND user_org_id = ?", orgID)
  7391. if scheduleDate != 0 {
  7392. db = db.Where("schedule_date = ?", scheduleDate)
  7393. }
  7394. err = db.Find(&vms).Error
  7395. } else {
  7396. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7397. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7398. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7399. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7400. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  7401. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7402. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7403. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7404. Where("status = 1 AND user_org_id = ?", orgID)
  7405. if scheduleDate != 0 {
  7406. db = db.Where("schedule_date = ?", scheduleDate)
  7407. }
  7408. err = db.Find(&vms).Error
  7409. }
  7410. } else {
  7411. if len(execution_frequency) > 0 {
  7412. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7413. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7414. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7415. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7416. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  7417. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7418. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7419. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7420. Where("status = 1 AND user_org_id = ?", orgID)
  7421. if scheduleDate != 0 {
  7422. db = db.Where("schedule_date = ?", scheduleDate)
  7423. }
  7424. err = db.Find(&vms).Error
  7425. } else {
  7426. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  7427. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7428. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7429. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7430. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  7431. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7432. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7433. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7434. Where("status = 1 AND user_org_id = ?", orgID)
  7435. if scheduleDate != 0 {
  7436. db = db.Where("schedule_date = ?", scheduleDate)
  7437. }
  7438. err = db.Find(&vms).Error
  7439. }
  7440. }
  7441. }
  7442. } else {
  7443. if execution_state > 0 {
  7444. if cost_type > 0 {
  7445. if len(execution_frequency) > 0 {
  7446. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7447. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7448. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7449. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7450. 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).
  7451. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7452. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7453. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7454. Where("status = 1 AND user_org_id = ?", orgID)
  7455. if scheduleDate != 0 {
  7456. db = db.Where("schedule_date = ?", scheduleDate)
  7457. }
  7458. err = db.Find(&vms).Error
  7459. } else {
  7460. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7461. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7462. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7463. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7464. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  7465. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7466. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7467. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7468. Where("status = 1 AND user_org_id = ?", orgID)
  7469. if scheduleDate != 0 {
  7470. db = db.Where("schedule_date = ?", scheduleDate)
  7471. }
  7472. err = db.Find(&vms).Error
  7473. }
  7474. } else {
  7475. if len(execution_frequency) > 0 {
  7476. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7477. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7478. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7479. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7480. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  7481. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7482. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7483. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7484. Where("status = 1 AND user_org_id = ?", orgID)
  7485. if scheduleDate != 0 {
  7486. db = db.Where("schedule_date = ?", scheduleDate)
  7487. }
  7488. err = db.Find(&vms).Error
  7489. } else {
  7490. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7493. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7494. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  7495. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7496. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7497. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7498. Where("status = 1 AND user_org_id = ?", orgID)
  7499. if scheduleDate != 0 {
  7500. db = db.Where("schedule_date = ?", scheduleDate)
  7501. }
  7502. err = db.Find(&vms).Error
  7503. }
  7504. }
  7505. } else {
  7506. if cost_type > 0 {
  7507. if len(execution_frequency) > 0 {
  7508. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7509. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7510. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7511. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7512. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  7513. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7514. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7515. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7516. Where("status = 1 AND user_org_id = ?", orgID)
  7517. if scheduleDate != 0 {
  7518. db = db.Where("schedule_date = ?", scheduleDate)
  7519. }
  7520. err = db.Find(&vms).Error
  7521. } else {
  7522. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7523. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7524. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7525. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7526. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  7527. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7528. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7529. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7530. Where("status = 1 AND user_org_id = ?", orgID)
  7531. if scheduleDate != 0 {
  7532. db = db.Where("schedule_date = ?", scheduleDate)
  7533. }
  7534. err = db.Find(&vms).Error
  7535. }
  7536. } else {
  7537. if len(execution_frequency) > 0 {
  7538. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7539. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7540. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7541. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7542. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  7543. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7544. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7545. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7546. Where("status = 1 AND user_org_id = ?", orgID)
  7547. if scheduleDate != 0 {
  7548. db = db.Where("schedule_date = ?", scheduleDate)
  7549. }
  7550. err = db.Find(&vms).Error
  7551. } else {
  7552. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  7553. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  7554. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  7555. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  7556. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  7557. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  7558. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  7559. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  7560. Where("status = 1 AND user_org_id = ?", orgID)
  7561. if scheduleDate != 0 {
  7562. db = db.Where("schedule_date = ?", scheduleDate)
  7563. }
  7564. err = db.Find(&vms).Error
  7565. }
  7566. }
  7567. }
  7568. }
  7569. }
  7570. return vms, err
  7571. }
  7572. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  7573. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  7574. return weight, err
  7575. }
  7576. 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) {
  7577. var vms []*MScheduleDoctorAdviceVM
  7578. adviceWhere := ""
  7579. keyword = "%" + keyword + "%"
  7580. adviceCondition := []interface{}{}
  7581. if adviceType == 1 {
  7582. if patientType == 0 {
  7583. if patient_id > 0 {
  7584. if execution_state > 0 {
  7585. if cost_type > 0 {
  7586. if len(execution_frequency) > 0 {
  7587. if len(keyword) > 0 {
  7588. 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 ?"
  7589. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7590. } else {
  7591. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7592. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7593. }
  7594. } else {
  7595. if len(keyword) > 0 {
  7596. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and advice_name like ?"
  7597. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7598. } else {
  7599. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  7600. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7601. }
  7602. }
  7603. } else {
  7604. if len(execution_frequency) > 0 {
  7605. if len(keyword) > 0 {
  7606. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7607. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7608. } else {
  7609. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7610. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7611. }
  7612. } else {
  7613. if len(keyword) > 0 {
  7614. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and advice_name like ?"
  7615. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7616. } else {
  7617. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  7618. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7619. }
  7620. }
  7621. }
  7622. } else {
  7623. if cost_type > 0 {
  7624. if len(execution_frequency) > 0 {
  7625. if len(keyword) > 0 {
  7626. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7627. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7628. } else {
  7629. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7630. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7631. }
  7632. } else {
  7633. if len(keyword) > 0 {
  7634. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and advice_name like ?"
  7635. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7636. } else {
  7637. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  7638. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7639. }
  7640. }
  7641. } else {
  7642. if len(execution_frequency) > 0 {
  7643. if len(keyword) > 0 {
  7644. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7645. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7646. } else {
  7647. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  7648. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7649. }
  7650. } else {
  7651. if len(keyword) > 0 {
  7652. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and advice_name like ?"
  7653. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7654. } else {
  7655. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  7656. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7657. }
  7658. }
  7659. }
  7660. }
  7661. } else {
  7662. if execution_state > 0 {
  7663. if cost_type > 0 {
  7664. if len(execution_frequency) > 0 {
  7665. if len(keyword) > 0 {
  7666. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7667. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7668. } else {
  7669. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7670. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7671. }
  7672. } else {
  7673. if len(keyword) > 0 {
  7674. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and advice_name like ?"
  7675. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7676. } else {
  7677. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  7678. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7679. }
  7680. }
  7681. } else {
  7682. if len(execution_frequency) > 0 {
  7683. if len(keyword) > 0 {
  7684. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ? and advice_name like ?"
  7685. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7686. } else {
  7687. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  7688. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7689. }
  7690. } else {
  7691. if len(keyword) > 0 {
  7692. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and advice_name like ?"
  7693. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7694. } else {
  7695. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  7696. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7697. }
  7698. }
  7699. }
  7700. } else {
  7701. if cost_type > 0 {
  7702. if len(keyword) > 0 {
  7703. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? and advice_name like ?"
  7704. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  7705. } else {
  7706. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  7707. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  7708. }
  7709. } else {
  7710. if len(keyword) > 0 {
  7711. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and advice_name like ?"
  7712. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  7713. } else {
  7714. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  7715. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  7716. }
  7717. }
  7718. }
  7719. }
  7720. } else if patientType == 1 {
  7721. if patient_id > 0 {
  7722. if execution_state > 0 {
  7723. if cost_type > 0 {
  7724. if len(execution_frequency) > 0 {
  7725. if len(keyword) > 0 {
  7726. 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 ?"
  7727. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7728. } else {
  7729. 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 = ?"
  7730. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  7731. }
  7732. } else {
  7733. if len(keyword) > 0 {
  7734. 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 ?"
  7735. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, keyword)
  7736. } else {
  7737. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  7738. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  7739. }
  7740. }
  7741. } else {
  7742. if len(execution_frequency) > 0 {
  7743. if len(keyword) > 0 {
  7744. 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 ?"
  7745. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency, keyword)
  7746. } else {
  7747. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7748. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  7749. }
  7750. } else {
  7751. if len(keyword) > 0 {
  7752. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and advice_name like ?"
  7753. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, keyword)
  7754. } else {
  7755. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  7756. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  7757. }
  7758. }
  7759. }
  7760. } else {
  7761. if cost_type > 0 {
  7762. if len(execution_frequency) > 0 {
  7763. if len(keyword) > 0 {
  7764. 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 ?"
  7765. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency, keyword)
  7766. } else {
  7767. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  7768. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  7769. }
  7770. } else {
  7771. if len(keyword) > 0 {
  7772. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ? and advice_name like ?"
  7773. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, keyword)
  7774. } else {
  7775. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  7776. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  7777. }
  7778. }
  7779. } else {
  7780. if len(execution_frequency) > 0 {
  7781. if len(keyword) > 0 {
  7782. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ? and advice_name like ?"
  7783. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency, keyword)
  7784. } else {
  7785. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  7786. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  7787. }
  7788. } else {
  7789. if len(keyword) > 0 {
  7790. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and advice_name like ?"
  7791. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, keyword)
  7792. } else {
  7793. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  7794. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  7795. }
  7796. }
  7797. }
  7798. }
  7799. } else {
  7800. if execution_state > 0 {
  7801. if cost_type > 0 {
  7802. if len(execution_frequency) > 0 {
  7803. if len(keyword) > 0 {
  7804. 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 ?"
  7805. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency, keyword)
  7806. } else {
  7807. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  7808. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  7809. }
  7810. } else {
  7811. if len(keyword) > 0 {
  7812. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ? and advice_name like ?"
  7813. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, keyword)
  7814. } else {
  7815. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  7816. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  7817. }
  7818. }
  7819. } else {
  7820. if len(execution_frequency) > 0 {
  7821. if len(keyword) > 0 {
  7822. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ? and advice_name like ?"
  7823. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency, keyword)
  7824. } else {
  7825. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  7826. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  7827. }
  7828. } else {
  7829. if len(keyword) > 0 {
  7830. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and advice_name like ?"
  7831. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, keyword)
  7832. } else {
  7833. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  7834. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  7835. }
  7836. }
  7837. }
  7838. } else {
  7839. if cost_type > 0 {
  7840. if len(execution_frequency) > 0 {
  7841. if len(keyword) > 0 {
  7842. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ? and advice_name like ?"
  7843. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency, keyword)
  7844. } else {
  7845. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  7846. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  7847. }
  7848. } else {
  7849. if len(keyword) > 0 {
  7850. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and advice_name like ?"
  7851. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, keyword)
  7852. } else {
  7853. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  7854. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  7855. }
  7856. }
  7857. } else {
  7858. if len(execution_frequency) > 0 {
  7859. if len(keyword) > 0 {
  7860. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ? and advice_name like ?"
  7861. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency, keyword)
  7862. } else {
  7863. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  7864. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  7865. }
  7866. } else {
  7867. if len(keyword) > 0 {
  7868. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and advice_name like ?"
  7869. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, keyword)
  7870. } else {
  7871. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  7872. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  7873. }
  7874. }
  7875. }
  7876. }
  7877. }
  7878. } else if patientType == 2 {
  7879. if patient_id > 0 {
  7880. if execution_state > 0 {
  7881. if cost_type > 0 {
  7882. if len(execution_frequency) > 0 {
  7883. if len(keyword) > 0 {
  7884. 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 ?"
  7885. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency, keyword)
  7886. } else {
  7887. 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 = ?"
  7888. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  7889. }
  7890. } else {
  7891. if len(keyword) > 0 {
  7892. 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 ?"
  7893. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, keyword)
  7894. } else {
  7895. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  7896. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  7897. }
  7898. }
  7899. } else {
  7900. if len(execution_frequency) > 0 {
  7901. if len(keyword) > 0 {
  7902. 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 ?"
  7903. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency, keyword)
  7904. } else {
  7905. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  7906. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  7907. }
  7908. } else {
  7909. if len(keyword) > 0 {
  7910. 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 ?"
  7911. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, keyword)
  7912. } else {
  7913. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  7914. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  7915. }
  7916. }
  7917. }
  7918. } else {
  7919. if cost_type > 0 {
  7920. if len(execution_frequency) > 0 {
  7921. if len(keyword) > 0 {
  7922. 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 ?"
  7923. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency, keyword)
  7924. } else {
  7925. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  7926. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  7927. }
  7928. } else {
  7929. if len(keyword) > 0 {
  7930. 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 ?"
  7931. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, keyword)
  7932. } else {
  7933. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  7934. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  7935. }
  7936. }
  7937. } else {
  7938. if len(execution_frequency) > 0 {
  7939. if len(keyword) > 0 {
  7940. 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 ?"
  7941. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency, keyword)
  7942. } else {
  7943. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  7944. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  7945. }
  7946. } else {
  7947. if len(keyword) > 0 {
  7948. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and advice_name like ?"
  7949. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, keyword)
  7950. } else {
  7951. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  7952. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  7953. }
  7954. }
  7955. }
  7956. }
  7957. } else {
  7958. if execution_state > 0 {
  7959. if cost_type > 0 {
  7960. if len(execution_frequency) > 0 {
  7961. if len(keyword) > 0 {
  7962. 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 ?"
  7963. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency, keyword)
  7964. } else {
  7965. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  7966. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  7967. }
  7968. } else {
  7969. if len(keyword) > 0 {
  7970. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and advice_name like ?"
  7971. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, keyword)
  7972. } else {
  7973. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  7974. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  7975. }
  7976. }
  7977. } else {
  7978. if len(execution_frequency) > 0 {
  7979. if len(keyword) > 0 {
  7980. 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 ?"
  7981. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency, keyword)
  7982. } else {
  7983. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  7984. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  7985. }
  7986. } else {
  7987. if len(keyword) > 0 {
  7988. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and advice_name like ?"
  7989. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, keyword)
  7990. } else {
  7991. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  7992. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  7993. }
  7994. }
  7995. }
  7996. } else {
  7997. if cost_type > 0 {
  7998. if len(execution_frequency) > 0 {
  7999. if len(keyword) > 0 {
  8000. 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 ?"
  8001. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency, keyword)
  8002. } else {
  8003. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  8004. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  8005. }
  8006. } else {
  8007. if len(keyword) > 0 {
  8008. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and advice_name like ?"
  8009. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, keyword)
  8010. } else {
  8011. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  8012. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  8013. }
  8014. }
  8015. } else {
  8016. if len(execution_frequency) > 0 {
  8017. if len(keyword) > 0 {
  8018. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ? and advice_name like ?"
  8019. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency, keyword)
  8020. } else {
  8021. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  8022. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  8023. }
  8024. } else {
  8025. if len(keyword) > 0 {
  8026. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and advice_name like ?"
  8027. adviceCondition = append(adviceCondition, adviceWhere, orgID, keyword)
  8028. } else {
  8029. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  8030. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  8031. }
  8032. }
  8033. }
  8034. }
  8035. }
  8036. }
  8037. }
  8038. db := readDb.Table("xt_schedule")
  8039. if scheduleType > 0 {
  8040. db = db.Where("schedule_type = ?", scheduleType)
  8041. }
  8042. if partitonType > 0 {
  8043. db = db.Where("partition_id = ?", partitonType)
  8044. }
  8045. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  8046. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  8047. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  8048. }).
  8049. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  8050. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  8051. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  8052. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  8053. Preload("DoctorAdvices", adviceCondition...).
  8054. Where("status = 1 AND user_org_id = ?", orgID)
  8055. if scheduleDate != 0 {
  8056. db = db.Where("schedule_date = ?", scheduleDate)
  8057. }
  8058. err := db.Find(&vms).Error
  8059. return vms, err
  8060. }
  8061. func GetLastAcceptTreatment(user_org_id int64, patient_id int64) (models.ReceiveTreatmentAsses, error) {
  8062. treatmentAsses := models.ReceiveTreatmentAsses{}
  8063. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and status=1 and admission_number<>''", user_org_id, patient_id).Last(&treatmentAsses).Error
  8064. return treatmentAsses, err
  8065. }