mobile_dialysis_service.go 479KB

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