mobile_dialysis_service.go 391KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543
  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.Preload("DialysisLastOrder", func(db *gorm.DB) *gorm.DB {
  37. return db.Order("dialysis_date desc").Where(" status = 1 AND user_org_id = ? and dialysis_date>=1672502400 && dialysis_date < ?", orgID, scheduleDate)
  38. }).Preload("DialysisSolution", "status = 1 and user_org_id = ? and solution_status = 1", orgID).Find(&vms).Error
  39. return vms, err
  40. }
  41. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  42. var vms []*MDialysisScheduleVM
  43. db := readDb.
  44. Table("xt_schedule as sch").
  45. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  46. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  47. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  48. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  49. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  50. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  51. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  52. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  53. Preload("TreatmentMode", "status = 1").
  54. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  55. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  56. if scheduleDate != 0 {
  57. db = db.Where("schedule_date = ?", scheduleDate)
  58. }
  59. err := db.Find(&vms).Error
  60. return vms, err
  61. }
  62. type VMTreatmentSummary struct {
  63. ID int64 `gorm:"column:id" json:"id"`
  64. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  65. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  66. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  67. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  68. }
  69. func (VMTreatmentSummary) TableName() string {
  70. return "xt_treatment_summary"
  71. }
  72. type AssessmentAfterDislysis struct {
  73. ID int64 `gorm:"column:id" json:"id"`
  74. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  75. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  76. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  77. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  78. Status int64 `gorm:"column:status" json:"status"`
  79. }
  80. func (AssessmentAfterDislysis) TableName() string {
  81. return "xt_assessment_after_dislysis"
  82. }
  83. type MDialysisScheduleVM struct {
  84. ID int64 `gorm:"column:id" json:"id"`
  85. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  86. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  87. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  88. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  89. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  90. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  91. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  92. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  93. Status int64 `gorm:"column:status" json:"status"`
  94. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  95. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  96. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  97. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  98. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  99. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  100. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  101. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  102. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  103. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  104. }
  105. func (MDialysisScheduleVM) TableName() string {
  106. return "xt_schedule"
  107. }
  108. type MDialysisScheduleVMForList struct {
  109. ID int64 `gorm:"column:id" json:"id"`
  110. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  111. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  112. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  113. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  114. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  115. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  116. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  117. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  118. Status int64 `gorm:"column:status" json:"status"`
  119. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  120. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  121. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  122. DialysisLastOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"last_order"`
  123. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  124. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  125. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  126. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  127. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  128. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  129. DialysisSolution *models.DialysisSolution `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"dialysis_solution"`
  130. DoubleCheck *models.DoubleCheck `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dobule_check"`
  131. NewDeviceInformation *NewDeviceInformation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"device_information"`
  132. }
  133. func (MDialysisScheduleVMForList) TableName() string {
  134. return "xt_schedule"
  135. }
  136. type MDeviceNumberVM struct {
  137. models.DeviceNumber
  138. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  139. }
  140. func (MDeviceNumberVM) TableName() string {
  141. return "xt_device_number"
  142. }
  143. type MSchedualPatientVMList struct {
  144. ID int64 `gorm:"column:id" json:"id" form:"id"`
  145. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  146. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  147. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  148. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  149. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  150. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  151. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  152. Age int64 `gorm:"column:age" json:"age"`
  153. Name string `gorm:"column:name" json:"name" form:"name"`
  154. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  155. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  156. TrobleShoot int64 `gorm:"column:troble_shoot" json:"troble_shoot" form:"troble_shoot"`
  157. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  158. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  159. }
  160. func (MSchedualPatientVMList) TableName() string {
  161. return "xt_patients"
  162. }
  163. type MSchedualPatientVM struct {
  164. ID int64 `gorm:"column:id" json:"id" form:"id"`
  165. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  166. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  167. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  168. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  169. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  170. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  171. Source int64 `gorm:"column:source" json:"source" form:"source"`
  172. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  173. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  174. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  175. Name string `gorm:"column:name" json:"name" form:"name"`
  176. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  177. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  178. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  179. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  180. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  181. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  182. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  183. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  184. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  185. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  186. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  187. Height int64 `gorm:"column:height" json:"height" form:"height"`
  188. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  189. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  190. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  191. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  192. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  193. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  194. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  195. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  196. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  197. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  198. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  199. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  200. Children int64 `gorm:"column:children" json:"children" form:"children"`
  201. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  202. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  203. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  204. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  205. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  206. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  207. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  208. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  209. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  210. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  211. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  212. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  213. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  214. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  215. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  216. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  217. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  218. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  219. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  220. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  221. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  222. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  223. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  224. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  225. Status int64 `gorm:"column:status" json:"status" form:"status"`
  226. Age int64 `gorm:"column:age" json:"age"`
  227. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  228. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  229. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  230. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  231. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  232. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  233. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  234. }
  235. func (MSchedualPatientVM) TableName() string {
  236. return "xt_patients"
  237. }
  238. type MDialysisOrderVM struct {
  239. ID int64 `gorm:"column:id" json:"id"`
  240. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  241. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  242. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  243. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  244. Stage int64 `gorm:"column:stage" json:"stage"`
  245. // Remark string `gorm:"column:remark" json:"remark"`
  246. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  247. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  248. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  249. Status int64 `gorm:"column:status" json:"status"`
  250. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  251. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  252. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  253. Creator int64 `gorm:"column:creator" json:"creator"`
  254. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  255. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  256. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  257. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  258. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  259. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  260. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  261. }
  262. func (MDialysisOrderVM) TableName() string {
  263. return "xt_dialysis_order"
  264. }
  265. type MDialysisOrderVMList struct {
  266. ID int64 `gorm:"column:id" json:"id"`
  267. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  268. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  269. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  270. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  271. Stage int64 `gorm:"column:stage" json:"stage"`
  272. // Remark string `gorm:"column:remark" json:"remark"`
  273. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  274. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  275. Status int64 `gorm:"column:status" json:"status"`
  276. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  277. Creator int64 `gorm:"column:creator" json:"creator"`
  278. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  279. NucleinDate int64 `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
  280. DialysisIrrigation string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
  281. DialysisDialyszers string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
  282. ScheduleRemark string `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
  283. }
  284. func (MDialysisOrderVMList) TableName() string {
  285. return "xt_dialysis_order"
  286. }
  287. type VMDoctorAdvice struct {
  288. ID int64 `gorm:"column:id" json:"id" form:"id"`
  289. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  290. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  291. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  292. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  293. Status int64 `gorm:"column:status" json:"status" form:"status"`
  294. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  295. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  296. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  297. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  298. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  299. }
  300. func (VMDoctorAdvice) TableName() string {
  301. return "xt_doctor_advice"
  302. }
  303. type VMHisDoctorAdviceInfo struct {
  304. ID int64 `gorm:"column:id" json:"id" form:"id"`
  305. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  306. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  307. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  308. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  309. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  310. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  311. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  312. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  313. }
  314. func (VMHisDoctorAdviceInfo) TableName() string {
  315. return "his_doctor_advice_info"
  316. }
  317. type VMAssessmentAfterDislysis struct {
  318. ID int64 `gorm:"column:id" json:"id"`
  319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  320. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  321. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  322. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  323. Status int64 `gorm:"column:status" json:"status"`
  324. }
  325. func (VMAssessmentAfterDislysis) TableName() string {
  326. return "xt_assessment_after_dislysis"
  327. }
  328. type NewDeviceInformation struct {
  329. ID int64 `gorm:"column:id" json:"id" form:"id"`
  330. Date int64 `gorm:"column:date" json:"date" form:"date"`
  331. Class int64 `gorm:"column:class" json:"class" form:"class"`
  332. Zone int64 `gorm:"column:zone" json:"zone" form:"zone"`
  333. BedNumber int64 `gorm:"column:bed_number" json:"bed_number" form:"bed_number"`
  334. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  335. Status int64 `gorm:"column:status" json:"status" form:"status"`
  336. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  337. EquimentId int64 `gorm:"column:equiment_id" json:"equiment_id" form:"equiment_id"`
  338. Bed string `gorm:"column:bed" json:"bed" form:"bed"`
  339. Stime int64 `gorm:"column:stime" json:"stime" form:"stime"`
  340. }
  341. func (NewDeviceInformation) TableName() string {
  342. return "xt_device_information"
  343. }
  344. // 获取透析记录
  345. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  346. var record models.DialysisOrder
  347. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  348. if err != nil {
  349. if err == gorm.ErrRecordNotFound {
  350. return nil, nil
  351. } else {
  352. return nil, err
  353. }
  354. }
  355. return &record, nil
  356. }
  357. // 用户基本信息
  358. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  359. var patient MPatient
  360. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  361. //if err != nil {
  362. // if err == gorm.ErrRecordNotFound {
  363. // return nil, nil
  364. // } else {
  365. // return nil, err
  366. // }
  367. //}
  368. //return &patient, nil
  369. redis := RedisClient()
  370. defer redis.Close()
  371. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  372. patient_info_str, _ := redis.Get(key).Result()
  373. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  374. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  375. if err != nil {
  376. if err == gorm.ErrRecordNotFound {
  377. return &patient, nil
  378. } else {
  379. return &patient, err
  380. }
  381. } else {
  382. if patient.ID > 0 {
  383. //缓存数据
  384. patient_info_json, err := json.Marshal(&patient)
  385. if err == nil {
  386. redis.Set(key, patient_info_json, time.Second*60*60*18)
  387. }
  388. }
  389. return &patient, nil
  390. }
  391. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  392. json.Unmarshal([]byte(patient_info_str), &patient)
  393. return &patient, nil
  394. }
  395. }
  396. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  397. var vm MDialysisScheduleVM
  398. err := readDb.
  399. Table("xt_schedule").
  400. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  401. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  402. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  403. First(&vm).Error
  404. return &vm, err
  405. }
  406. // 用户排班信息
  407. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  408. var vm MDialysisScheduleVM
  409. err := readDb.
  410. Table("xt_schedule").
  411. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  412. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  413. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  414. First(&vm).Error
  415. if err != nil {
  416. if err == gorm.ErrRecordNotFound {
  417. return nil, nil
  418. } else {
  419. return nil, err
  420. }
  421. }
  422. return &vm, err
  423. }
  424. // 用户排班信息
  425. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  426. redis := RedisClient()
  427. defer redis.Close()
  428. var vm MDialysisScheduleVM
  429. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  430. redis.Set(key, "", time.Second)
  431. schedual_detail_str, _ := redis.Get(key).Result()
  432. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  433. err := readDb.
  434. Table("xt_schedule").
  435. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  436. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  437. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  438. First(&vm).Error
  439. if err != nil {
  440. if err == gorm.ErrRecordNotFound {
  441. return nil, nil
  442. } else {
  443. return nil, err
  444. }
  445. } else {
  446. if vm.ID > 0 {
  447. //缓存数据
  448. schedual_detail_str, err := json.Marshal(vm)
  449. if err == nil {
  450. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  451. }
  452. } else {
  453. redis.Set(key, "null", time.Second*60*60*18)
  454. }
  455. return &vm, nil
  456. }
  457. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  458. if schedual_detail_str == "null" {
  459. return &vm, nil
  460. }
  461. json.Unmarshal([]byte(schedual_detail_str), &vm)
  462. return &vm, nil
  463. }
  464. }
  465. // 用户排班信息
  466. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  467. var schedule models.Schedule
  468. err := readDb.
  469. Table("xt_schedule").
  470. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  471. First(&schedule).Error
  472. if err != nil {
  473. if err == gorm.ErrRecordNotFound {
  474. return nil, nil
  475. } else {
  476. return nil, err
  477. }
  478. }
  479. return &schedule, nil
  480. }
  481. type MPatient struct {
  482. ID int64 `gorm:"column:id" json:"id" form:"id"`
  483. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  484. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  485. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  486. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  487. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  488. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  489. Source int64 `gorm:"column:source" json:"source" form:"source"`
  490. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  491. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  492. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  493. Name string `gorm:"column:name" json:"name" form:"name"`
  494. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  495. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  496. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  497. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  498. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  499. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  500. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  501. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  502. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  503. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  504. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  505. Height int64 `gorm:"column:height" json:"height" form:"height"`
  506. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  507. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  508. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  509. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  510. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  511. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  512. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  513. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  514. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  515. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  516. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  517. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  518. Children int64 `gorm:"column:children" json:"children" form:"children"`
  519. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  520. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  521. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  522. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  523. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  524. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  525. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  526. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  527. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  528. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  529. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  530. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  531. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  532. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  533. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  534. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  535. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  536. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  537. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  538. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  539. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  540. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  541. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  542. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  543. Status int64 `gorm:"column:status" json:"status" form:"status"`
  544. Age int64 `gorm:"column:age" json:"age"`
  545. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  546. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  547. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  548. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  549. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  550. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  551. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  552. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  553. }
  554. func (MPatient) TableName() string {
  555. return "xt_patients"
  556. }
  557. // 接诊评估
  558. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  559. var record models.ReceiveTreatmentAsses
  560. redis := RedisClient()
  561. defer redis.Close()
  562. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  563. receive_treatment_asses_str, _ := redis.Get(key).Result()
  564. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  565. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  566. if err != nil {
  567. if err == gorm.ErrRecordNotFound {
  568. if record.ID <= 0 {
  569. redis.Set(key, "", time.Second*60*60*18)
  570. }
  571. return nil, nil
  572. } else {
  573. return nil, err
  574. }
  575. } else {
  576. if record.ID > 0 {
  577. //缓存数据
  578. receive_treatment_asses_str, err := json.Marshal(record)
  579. if err == nil {
  580. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  581. }
  582. } else {
  583. redis.Set(key, "null", time.Second*60*60*18)
  584. }
  585. return &record, nil
  586. }
  587. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  588. if receive_treatment_asses_str == "null" {
  589. return &record, nil
  590. }
  591. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  592. return &record, nil
  593. }
  594. }
  595. // 透前评估
  596. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  597. var record models.PredialysisEvaluation
  598. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  599. if err != nil {
  600. if err == gorm.ErrRecordNotFound {
  601. return nil, nil
  602. } else {
  603. return nil, err
  604. }
  605. }
  606. return &record, nil
  607. }
  608. func MobileGetPredialysisEvaluationTwo(orgID int64, patientID int64, recordDate int64) (models.PredialysisEvaluation, error) {
  609. var record models.PredialysisEvaluation
  610. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  611. return record, err
  612. }
  613. // 透前评估
  614. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  615. var record models.PredialysisEvaluation
  616. redis := RedisClient()
  617. defer redis.Close()
  618. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  619. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  620. redis.Set(key, "", time.Second)
  621. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  622. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  623. if err != nil {
  624. if err == gorm.ErrRecordNotFound {
  625. if record.ID <= 0 {
  626. redis.Set(key, "", time.Second*60*60*18)
  627. }
  628. return nil, nil
  629. } else {
  630. return nil, err
  631. }
  632. } else {
  633. if record.ID > 0 {
  634. //缓存数据
  635. assessment_before_dislysis_str, err := json.Marshal(record)
  636. if err == nil {
  637. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  638. }
  639. } else {
  640. redis.Set(key, "null", time.Second*60*60*18)
  641. }
  642. return &record, nil
  643. }
  644. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  645. if assessment_before_dislysis_str == "null" {
  646. return &record, nil
  647. } else {
  648. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  649. return &record, nil
  650. }
  651. }
  652. }
  653. // 获取 maxDate 之前一次的透前评估记录
  654. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  655. var record models.PredialysisEvaluation
  656. 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
  657. if err != nil {
  658. if err == gorm.ErrRecordNotFound {
  659. return nil, nil
  660. } else {
  661. return nil, err
  662. }
  663. }
  664. return &record, nil
  665. }
  666. // 获取 maxDate 之前一次的透前评估记录
  667. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  668. var record models.PredialysisEvaluation
  669. redis := RedisClient()
  670. defer redis.Close()
  671. // cur_date := time.Now().Format("2006-01-02")
  672. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  673. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  674. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  675. 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
  676. if err != nil {
  677. if err == gorm.ErrRecordNotFound {
  678. if record.ID <= 0 {
  679. redis.Set(key, "", time.Second*60*60*18)
  680. }
  681. return nil, nil
  682. } else {
  683. return nil, err
  684. }
  685. } else {
  686. if record.ID > 0 {
  687. //缓存数据
  688. assessment_before_dislysis_last_str, err := json.Marshal(record)
  689. if err == nil {
  690. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  691. }
  692. } else {
  693. redis.Set(key, "null", time.Second*60*60*18)
  694. }
  695. return &record, nil
  696. }
  697. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  698. if assessment_before_dislysis_last_str == "null" {
  699. return &record, nil
  700. } else {
  701. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  702. return &record, nil
  703. }
  704. }
  705. }
  706. // 临时医嘱
  707. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  708. var records []*models.DoctorAdvice
  709. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  710. err := readDb.
  711. Model(&models.DoctorAdvice{}).
  712. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  713. 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").
  714. Order("start_time asc, groupno desc, advice_order desc, id").
  715. Scan(&records).Error
  716. if err != nil {
  717. return nil, err
  718. }
  719. return records, nil
  720. }
  721. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  722. var records []*models.DoctorAdvice
  723. redis := RedisClient()
  724. defer redis.Close()
  725. // cur_date := time.Now().Format("2006-01-02")
  726. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  727. //fmt.Println("key23233232323323wi", key)
  728. redis.Set(key, "", time.Second)
  729. doctor_advices_str, _ := redis.Get(key).Result()
  730. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  731. err := readDb.Model(&models.DoctorAdvice{}).
  732. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  733. 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").
  734. Order("start_time asc, groupno desc, advice_order desc, id asc").
  735. Scan(&records).Error
  736. if err != nil {
  737. if err == gorm.ErrRecordNotFound {
  738. if len(records) <= 0 {
  739. redis.Set(key, "", time.Second*60*60*18)
  740. }
  741. return nil, nil
  742. } else {
  743. return nil, err
  744. }
  745. } else {
  746. if len(records) > 0 {
  747. //缓存数据
  748. doctor_advices_str, err := json.Marshal(records)
  749. if err == nil {
  750. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  751. return records, nil
  752. }
  753. } else {
  754. redis.Set(key, "null", time.Second*60*60*18)
  755. return records, nil
  756. }
  757. return records, nil
  758. }
  759. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  760. if doctor_advices_str == "null" {
  761. return records, nil
  762. } else {
  763. json.Unmarshal([]byte(doctor_advices_str), &records)
  764. return records, nil
  765. }
  766. }
  767. }
  768. // 透析记录
  769. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  770. var record models.DialysisOrder
  771. 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
  772. if err != nil {
  773. if err == gorm.ErrRecordNotFound {
  774. return nil, nil
  775. } else {
  776. return nil, err
  777. }
  778. }
  779. return &record, nil
  780. }
  781. //func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  782. // var record models.DialysisOrder
  783. //
  784. // 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
  785. //
  786. //
  787. // return &record,err
  788. //}
  789. // 透析记录
  790. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  791. var record models.DialysisOrder
  792. redis := RedisClient()
  793. defer redis.Close()
  794. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  795. dialysis_order_str, _ := redis.Get(key).Result()
  796. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  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. if err != nil {
  799. if err == gorm.ErrRecordNotFound {
  800. return nil, nil
  801. } else {
  802. return nil, err
  803. }
  804. } else {
  805. if record.ID > 0 {
  806. //缓存数据
  807. dialysis_order_str, err := json.Marshal(record)
  808. if err == nil {
  809. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  810. }
  811. } else {
  812. redis.Set(key, "null", time.Second*60*60*18)
  813. }
  814. return &record, nil
  815. }
  816. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  817. if dialysis_order_str == "null" {
  818. 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
  819. return &record, nil
  820. } else {
  821. json.Unmarshal([]byte(dialysis_order_str), &record)
  822. return &record, nil
  823. }
  824. }
  825. }
  826. // 双人核对
  827. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  828. var record models.DoubleCheck
  829. redis := RedisClient()
  830. defer redis.Close()
  831. // cur_date := time.Now().Format("2006-01-02")
  832. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  833. double_check_str, _ := redis.Get(key).Result()
  834. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  835. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  836. if err != nil {
  837. if err == gorm.ErrRecordNotFound {
  838. if record.ID <= 0 {
  839. redis.Set(key, "null", time.Second*60*60*18)
  840. }
  841. return nil, nil
  842. } else {
  843. return nil, err
  844. }
  845. } else {
  846. if record.ID > 0 {
  847. //缓存数据
  848. double_check_str, err := json.Marshal(record)
  849. if err == nil {
  850. redis.Set(key, double_check_str, time.Second*60*60*18)
  851. }
  852. } else {
  853. redis.Set(key, "null", time.Second*60*60*18)
  854. }
  855. return &record, nil
  856. }
  857. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  858. if double_check_str == "null" {
  859. return &record, nil
  860. } else {
  861. json.Unmarshal([]byte(double_check_str), &record)
  862. return &record, nil
  863. }
  864. }
  865. }
  866. // 透析监测记录
  867. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  868. var records []*models.MonitoringRecord
  869. redis := RedisClient()
  870. defer redis.Close()
  871. // cur_date := time.Now().Format("2006-01-02")
  872. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  873. redis.Set(key, "", time.Second)
  874. monitor_records_str, _ := redis.Get(key).Result()
  875. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  876. 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
  877. if err != nil {
  878. if err == gorm.ErrRecordNotFound {
  879. //if len(records) <= 0 {
  880. // redis.Set(key, "null", time.Second*60*60*18)
  881. //}
  882. return nil, nil
  883. } else {
  884. return nil, err
  885. }
  886. } else {
  887. if len(records) > 0 {
  888. //缓存数据
  889. monitor_records_str, err := json.Marshal(records)
  890. if err == nil {
  891. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  892. }
  893. } else {
  894. redis.Set(key, "null", time.Second*60*60*18)
  895. }
  896. return records, nil
  897. }
  898. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  899. if monitor_records_str == "null" {
  900. return records, nil
  901. } else {
  902. json.Unmarshal([]byte(monitor_records_str), &records)
  903. return records, nil
  904. }
  905. }
  906. }
  907. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  908. var records models.MonitoringRecord
  909. 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
  910. if err != nil {
  911. return nil, err
  912. }
  913. return &records, nil
  914. }
  915. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  916. var record models.MonitoringRecord
  917. 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
  918. if err != nil {
  919. if err == gorm.ErrRecordNotFound {
  920. return nil, nil
  921. } else {
  922. return nil, err
  923. }
  924. }
  925. return &record, nil
  926. }
  927. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  928. var record models.MonitoringRecord
  929. redis := RedisClient()
  930. defer redis.Close()
  931. // cur_date := time.Now().Format("2006-01-02")
  932. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  933. monitor_record_last_str, _ := redis.Get(key).Result()
  934. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  935. 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
  936. if err != nil {
  937. if err == gorm.ErrRecordNotFound {
  938. if record.ID <= 0 {
  939. redis.Set(key, "null", time.Second*60*60*18)
  940. }
  941. return nil, nil
  942. } else {
  943. return nil, err
  944. }
  945. } else {
  946. if record.ID > 0 {
  947. //缓存数据
  948. monitor_record_last_str, err := json.Marshal(record)
  949. if err == nil {
  950. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  951. }
  952. } else {
  953. redis.Set(key, "null", time.Second*60*60*18)
  954. }
  955. return &record, nil
  956. }
  957. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  958. if monitor_record_last_str == "null" {
  959. return &record, nil
  960. } else {
  961. json.Unmarshal([]byte(monitor_record_last_str), &record)
  962. return &record, nil
  963. }
  964. }
  965. }
  966. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  967. var record models.AssessmentAfterDislysis
  968. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  969. if err != nil {
  970. if err == gorm.ErrRecordNotFound {
  971. return nil, nil
  972. } else {
  973. return nil, err
  974. }
  975. }
  976. return &record, nil
  977. }
  978. // 透后评估
  979. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  980. var record models.AssessmentAfterDislysis
  981. redis := RedisClient()
  982. defer redis.Close()
  983. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  984. redis.Set(key, "", time.Second)
  985. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  986. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  987. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  988. if err != nil {
  989. if err == gorm.ErrRecordNotFound {
  990. if record.ID <= 0 {
  991. redis.Set(key, "null", time.Second*60*60*18)
  992. }
  993. return nil, nil
  994. } else {
  995. return nil, err
  996. }
  997. } else {
  998. if record.ID > 0 {
  999. //缓存数据
  1000. assessment_after_dislysis_str, err := json.Marshal(record)
  1001. if err == nil {
  1002. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  1003. }
  1004. } else {
  1005. redis.Set(key, "null", time.Second*60*60*18)
  1006. }
  1007. return &record, nil
  1008. }
  1009. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1010. if assessment_after_dislysis_str == "null" {
  1011. return &record, nil
  1012. } else {
  1013. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  1014. return &record, nil
  1015. }
  1016. }
  1017. }
  1018. // 获取 maxDate 之前一次的透后评估记录
  1019. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1020. var record models.AssessmentAfterDislysis
  1021. redis := RedisClient()
  1022. defer redis.Close()
  1023. // cur_date := time.Now().Format("2006-01-02")
  1024. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  1025. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  1026. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1027. 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
  1028. if err != nil {
  1029. if err == gorm.ErrRecordNotFound {
  1030. if record.ID <= 0 {
  1031. redis.Set(key, "null", time.Second*60*60*18)
  1032. }
  1033. return nil, nil
  1034. } else {
  1035. return nil, err
  1036. }
  1037. } else {
  1038. if record.ID > 0 {
  1039. //缓存数据
  1040. assessment_after_dislysis_last_str, err := json.Marshal(record)
  1041. if err == nil {
  1042. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  1043. }
  1044. } else {
  1045. redis.Set(key, "null", time.Second*60*60*18)
  1046. }
  1047. return &record, nil
  1048. }
  1049. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1050. if assessment_after_dislysis_last_str == "null" {
  1051. return &record, nil
  1052. } else {
  1053. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1054. return &record, nil
  1055. }
  1056. }
  1057. }
  1058. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1059. var record models.AssessmentAfterDislysis
  1060. 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
  1061. if err != nil {
  1062. if err == gorm.ErrRecordNotFound {
  1063. return nil, nil
  1064. } else {
  1065. return nil, err
  1066. }
  1067. }
  1068. return &record, nil
  1069. }
  1070. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1071. dislysis := models.AssessmentAfterDislysis{}
  1072. 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
  1073. return dislysis, err
  1074. }
  1075. // 治疗小结
  1076. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1077. var record models.TreatmentSummary
  1078. redis := RedisClient()
  1079. defer redis.Close()
  1080. // cur_date := time.Now().Format("2006-01-02")
  1081. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1082. treatment_summary_str, _ := redis.Get(key).Result()
  1083. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1084. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1085. if err != nil {
  1086. if err == gorm.ErrRecordNotFound {
  1087. if record.ID <= 0 {
  1088. redis.Set(key, "null", time.Second*60*60*18)
  1089. }
  1090. return nil, nil
  1091. } else {
  1092. return nil, err
  1093. }
  1094. } else {
  1095. if record.ID > 0 {
  1096. //缓存数据
  1097. treatment_summary_str, err := json.Marshal(record)
  1098. if err == nil {
  1099. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1100. }
  1101. } else {
  1102. redis.Set(key, "null", time.Second*60*60*18)
  1103. }
  1104. return &record, nil
  1105. }
  1106. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1107. if treatment_summary_str == "null" {
  1108. return &record, nil
  1109. } else {
  1110. json.Unmarshal([]byte(treatment_summary_str), &record)
  1111. return &record, nil
  1112. }
  1113. }
  1114. }
  1115. // 透析处方
  1116. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1117. var record models.DialysisPrescription
  1118. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1119. if err != nil {
  1120. if err == gorm.ErrRecordNotFound {
  1121. return nil, nil
  1122. } else {
  1123. return nil, err
  1124. }
  1125. }
  1126. return &record, nil
  1127. }
  1128. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1129. var schedule models.XtSchedule
  1130. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1131. if err != nil {
  1132. if err == gorm.ErrRecordNotFound {
  1133. return nil, nil
  1134. } else {
  1135. return nil, err
  1136. }
  1137. }
  1138. return &schedule, nil
  1139. }
  1140. // 透析方案
  1141. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1142. var record models.DialysisSolution
  1143. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1144. if err != nil {
  1145. if err == gorm.ErrRecordNotFound {
  1146. return nil, nil
  1147. } else {
  1148. return nil, err
  1149. }
  1150. }
  1151. return &record, nil
  1152. }
  1153. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1154. var patient models.Patients
  1155. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1156. if err != nil {
  1157. if err == gorm.ErrRecordNotFound {
  1158. return nil, nil
  1159. } else {
  1160. return nil, err
  1161. }
  1162. }
  1163. return &patient, nil
  1164. }
  1165. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1166. fmt.Println()
  1167. tx := writeDb.Begin()
  1168. updateTime := time.Now().Unix()
  1169. 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
  1170. if err != nil {
  1171. tx.Rollback()
  1172. return err
  1173. }
  1174. tx.Commit()
  1175. return nil
  1176. }
  1177. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1178. var monitor models.MonitoringRecord
  1179. var err error
  1180. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1181. if err == gorm.ErrRecordNotFound {
  1182. return nil, nil
  1183. }
  1184. if err != nil {
  1185. return nil, err
  1186. }
  1187. return &monitor, nil
  1188. }
  1189. type MScheduleDoctorAdviceVM struct {
  1190. ID int64 `gorm:"column:id" json:"id"`
  1191. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1192. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1193. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1194. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1195. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1196. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1197. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1198. Status int64 `gorm:"column:status" json:"status"`
  1199. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1200. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1201. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1202. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1203. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1204. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1205. }
  1206. func (MScheduleDoctorAdviceVM) TableName() string {
  1207. return "xt_schedule"
  1208. }
  1209. type MScheduleDoctorAdviceVMOne struct {
  1210. ID int64 `gorm:"column:id" json:"id"`
  1211. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1212. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1213. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1214. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1215. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1216. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1217. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1218. Status int64 `gorm:"column:status" json:"status"`
  1219. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1220. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1221. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1222. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1223. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1224. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1225. }
  1226. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1227. return "xt_schedule"
  1228. }
  1229. type MDoctorAdviceVM struct {
  1230. ID int64 `gorm:"column:id" json:"id"`
  1231. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1232. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1233. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1234. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1235. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1236. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1237. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1238. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1239. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1240. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1241. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1242. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1243. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1244. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1245. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1246. Status int64 `gorm:"column:status" json:"status"`
  1247. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1248. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1249. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1250. Remark string `gorm:"column:remark" json:"remark"`
  1251. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1252. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1253. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1254. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1255. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1256. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1257. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1258. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1259. Checker int64 `gorm:"column:checker" json:"checker"`
  1260. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1261. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1262. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1263. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1264. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1265. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1266. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1267. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1268. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1269. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1270. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1271. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1272. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1273. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1274. IsSettle int64 `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
  1275. }
  1276. func (MDoctorAdviceVM) TableName() string {
  1277. return "xt_doctor_advice"
  1278. }
  1279. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1280. var vms []*MScheduleDoctorAdviceVM
  1281. adviceWhere := ""
  1282. adviceCondition := []interface{}{}
  1283. if adviceType == 0 {
  1284. if patientType == 0 {
  1285. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1286. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1287. } else if patientType == 1 {
  1288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1290. } else if patientType == 2 {
  1291. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1293. }
  1294. } else if adviceType == 1 {
  1295. if patientType == 0 {
  1296. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1298. } else if patientType == 1 {
  1299. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1301. } else if patientType == 2 {
  1302. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1304. }
  1305. } else if adviceType == 3 {
  1306. if patientType == 0 {
  1307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1309. } else if patientType == 1 {
  1310. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1312. } else if patientType == 2 {
  1313. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1315. }
  1316. } else if adviceType == 2 && len(deliverWay) > 0 {
  1317. if patientType == 0 {
  1318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1320. } else if patientType == 1 {
  1321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1323. } else if patientType == 2 {
  1324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1326. }
  1327. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1328. if patientType == 0 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1331. } else if patientType == 1 {
  1332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1334. } else if patientType == 2 {
  1335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1337. }
  1338. }
  1339. db := readDb.
  1340. Table("xt_schedule").
  1341. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1342. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1343. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1344. }).
  1345. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1346. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1347. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1348. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1349. Preload("DoctorAdvices", adviceCondition...).
  1350. Where("status = 1 AND user_org_id = ?", orgID)
  1351. if scheduleDate != 0 {
  1352. db = db.Where("schedule_date = ?", scheduleDate)
  1353. }
  1354. err := db.Find(&vms).Error
  1355. return vms, err
  1356. }
  1357. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1358. var vms []*MScheduleDoctorAdviceVMOne
  1359. adviceWhere := ""
  1360. adviceCondition := []interface{}{}
  1361. if adviceType == 0 {
  1362. if patientType == 0 {
  1363. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1365. } else if patientType == 1 {
  1366. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1368. } else if patientType == 2 {
  1369. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1371. } else if patientType == 3 {
  1372. 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"
  1373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1374. } else if patientType == 4 {
  1375. 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)"
  1376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1377. }
  1378. } else if adviceType == 1 {
  1379. if patientType == 0 {
  1380. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1382. } else if patientType == 1 {
  1383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1385. } else if patientType == 2 {
  1386. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1387. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1388. } else if patientType == 3 {
  1389. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = 1"
  1390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1391. } else if patientType == 4 {
  1392. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and (is_settle = 0 or is_settle = 2)"
  1393. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1394. }
  1395. } else if adviceType == 3 {
  1396. if patientType == 0 {
  1397. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1398. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1399. } else if patientType == 1 {
  1400. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1401. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1402. } else if patientType == 2 {
  1403. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1404. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1405. } else if patientType == 3 {
  1406. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and is_settle = 1"
  1407. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1408. } else if patientType == 4 {
  1409. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 and (is_settle = 0 or is_settle = 2)"
  1410. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1411. }
  1412. } else if adviceType == 2 && len(deliverWay) > 0 {
  1413. if patientType == 0 {
  1414. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1415. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1416. } else if patientType == 1 {
  1417. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1418. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1419. } else if patientType == 2 {
  1420. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1422. } else if patientType == 3 {
  1423. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and delivery_way = ? and is_settle = 1"
  1424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1425. } else if patientType == 4 {
  1426. 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)"
  1427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1428. }
  1429. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1430. if patientType == 0 {
  1431. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1432. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1433. } else if patientType == 1 {
  1434. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1436. } else if patientType == 2 {
  1437. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1439. } else if patientType == 3 {
  1440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and is_settle = 1"
  1441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1442. } else if patientType == 4 {
  1443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 and (is_settle = 0 or is_settle = 2)"
  1444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1445. }
  1446. }
  1447. db := readDb.
  1448. Table("xt_schedule").
  1449. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1450. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1451. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1452. //}).
  1453. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1454. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1455. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1456. Preload("DoctorAdvices", adviceCondition...).
  1457. Where("status = 1 AND user_org_id = ?", orgID)
  1458. if scheduleDate != 0 {
  1459. db = db.Where("schedule_date = ?", scheduleDate)
  1460. }
  1461. err := db.Find(&vms).Error
  1462. return vms, err
  1463. }
  1464. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1465. var vms []*HisMScheduleDoctorAdviceVM
  1466. if len(deliverWay) > 0 {
  1467. if patientType == 0 {
  1468. db := readDb.
  1469. Table("xt_schedule").
  1470. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1471. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1472. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1473. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1474. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1475. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1476. }).
  1477. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1478. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1479. Where("status = 1 AND user_org_id = ?", orgID)
  1480. if scheduleDate != 0 {
  1481. db = db.Where("schedule_date = ?", scheduleDate)
  1482. }
  1483. err = db.Find(&vms).Error
  1484. }
  1485. if patientType > 0 {
  1486. db := readDb.
  1487. Table("xt_schedule").
  1488. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1489. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1490. 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).
  1491. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1492. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1493. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1494. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1495. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1496. }).Where("status = 1 AND user_org_id = ?", orgID)
  1497. if scheduleDate != 0 {
  1498. db = db.Where("schedule_date = ?", scheduleDate)
  1499. }
  1500. err = db.Find(&vms).Error
  1501. }
  1502. } else {
  1503. if patientType == 0 {
  1504. db := readDb.
  1505. Table("xt_schedule").
  1506. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1507. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1508. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1509. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1510. }).
  1511. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1512. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1513. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1514. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1515. Where("status = 1 AND user_org_id = ?", orgID)
  1516. if scheduleDate != 0 {
  1517. db = db.Where("schedule_date = ?", scheduleDate)
  1518. }
  1519. err = db.Find(&vms).Error
  1520. }
  1521. if patientType > 0 {
  1522. db := readDb.
  1523. Table("xt_schedule").
  1524. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1525. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1526. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1527. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1528. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1529. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1530. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1531. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1532. Where("status = 1 AND user_org_id = ?", orgID)
  1533. if scheduleDate != 0 {
  1534. db = db.Where("schedule_date = ?", scheduleDate)
  1535. }
  1536. err = db.Find(&vms).Error
  1537. }
  1538. }
  1539. return vms, err
  1540. }
  1541. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1542. var vms []*HisMScheduleDoctorAdviceVMOne
  1543. if len(deliverWay) > 0 {
  1544. if patientType == 0 {
  1545. db := readDb.
  1546. Table("xt_schedule").
  1547. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1548. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1549. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1550. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1551. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1552. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1553. }).
  1554. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1555. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1556. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1557. Where("status = 1 AND user_org_id = ?", orgID)
  1558. if scheduleDate != 0 {
  1559. db = db.Where("schedule_date = ?", scheduleDate)
  1560. }
  1561. err = db.Find(&vms).Error
  1562. }
  1563. if patientType > 0 {
  1564. if patientType == 1 {
  1565. db := readDb.
  1566. Table("xt_schedule").
  1567. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1568. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1569. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1570. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1571. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1572. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1573. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1574. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1575. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1576. Where("status = 1 AND user_org_id = ?", orgID)
  1577. if scheduleDate != 0 {
  1578. db = db.Where("schedule_date = ?", scheduleDate)
  1579. }
  1580. err = db.Find(&vms).Error
  1581. }
  1582. if patientType == 2 {
  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).Where("status = 1 AND user_org_id = ?", orgID)
  1594. if scheduleDate != 0 {
  1595. db = db.Where("schedule_date = ?", scheduleDate)
  1596. }
  1597. err = db.Find(&vms).Error
  1598. }
  1599. if patientType == 3 {
  1600. db := readDb.
  1601. Table("xt_schedule").
  1602. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1603. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1604. 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).
  1605. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1606. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1607. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1608. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1609. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1610. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1611. if scheduleDate != 0 {
  1612. db = db.Where("schedule_date = ?", scheduleDate)
  1613. }
  1614. err = db.Find(&vms).Error
  1615. }
  1616. if patientType == 4 {
  1617. db := readDb.
  1618. Table("xt_schedule").
  1619. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1620. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1621. 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).
  1622. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1623. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1624. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1625. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1626. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1627. }).Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Where("status = 1 AND user_org_id = ?", orgID)
  1628. if scheduleDate != 0 {
  1629. db = db.Where("schedule_date = ?", scheduleDate)
  1630. }
  1631. err = db.Find(&vms).Error
  1632. }
  1633. }
  1634. } else {
  1635. if patientType == 0 {
  1636. db := readDb.
  1637. Table("xt_schedule").
  1638. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1639. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1640. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1641. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1642. }).
  1643. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1644. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1645. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1646. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1647. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1648. Where("status = 1 AND user_org_id = ?", orgID)
  1649. if scheduleDate != 0 {
  1650. db = db.Where("schedule_date = ?", scheduleDate)
  1651. }
  1652. err = db.Find(&vms).Error
  1653. }
  1654. if patientType > 0 {
  1655. if patientType == 1 {
  1656. db := readDb.
  1657. Table("xt_schedule").
  1658. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1659. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1660. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1661. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1662. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1663. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1664. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1665. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1666. Preload("DialysisAssesmentBefor", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  1667. Where("status = 1 AND user_org_id = ?", orgID)
  1668. if scheduleDate != 0 {
  1669. db = db.Where("schedule_date = ?", scheduleDate)
  1670. }
  1671. err = db.Find(&vms).Error
  1672. }
  1673. if patientType == 2 {
  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 == 3 {
  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 = ?) and is_settle = 1", 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 == 4 {
  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 = 0 or is_settle =2) ", 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. }
  1728. }
  1729. return vms, err
  1730. }
  1731. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1732. var vms []*HisMScheduleProjectVM
  1733. //if patientType == 0 {
  1734. // db := readDb.
  1735. // Table("xt_schedule").
  1736. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1737. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1738. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1739. // }).
  1740. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1741. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1742. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1743. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1744. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1745. // }).
  1746. // Where("status = 1 AND user_org_id = ?", orgID)
  1747. // if scheduleDate != 0 {
  1748. // db = db.Where("schedule_date = ?", scheduleDate)
  1749. // }
  1750. // err = db.Find(&vms).Error
  1751. //}
  1752. //if patientType > 0 {
  1753. // db := readDb.
  1754. // Table("xt_schedule").
  1755. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1756. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1757. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1758. // }).
  1759. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1760. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1761. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1762. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1763. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1764. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1765. // }).
  1766. // Where("status = 1 AND user_org_id = ?", orgID)
  1767. // if scheduleDate != 0 {
  1768. // db = db.Where("schedule_date = ?", scheduleDate)
  1769. // }
  1770. // err = db.Find(&vms).Error
  1771. //}
  1772. db := readDb.Table("xt_schedule").Where("status = 1")
  1773. if orgID > 0 {
  1774. db = db.Where("user_org_id = ?", orgID)
  1775. }
  1776. if scheduleDate > 0 {
  1777. db = db.Where("schedule_date =?", scheduleDate)
  1778. }
  1779. err = db.Find(&vms).Error
  1780. if patientType == 0 {
  1781. db := readDb.
  1782. Table("xt_schedule").
  1783. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1784. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1785. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1786. }).
  1787. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1788. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1789. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1790. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1791. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1792. }).
  1793. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1794. 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")
  1795. }).
  1796. Where("status = 1 AND user_org_id = ?", orgID)
  1797. if scheduleDate != 0 {
  1798. db = db.Where("schedule_date = ?", scheduleDate)
  1799. }
  1800. err = db.Find(&vms).Error
  1801. }
  1802. if patientType > 0 {
  1803. db := readDb.
  1804. Table("xt_schedule").
  1805. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1806. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1807. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1808. }).
  1809. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1810. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1811. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1812. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1813. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1814. }).
  1815. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1816. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1817. }).
  1818. Where("status = 1 AND user_org_id = ?", orgID)
  1819. if scheduleDate != 0 {
  1820. db = db.Where("schedule_date = ?", scheduleDate)
  1821. }
  1822. err = db.Find(&vms).Error
  1823. }
  1824. return vms, err
  1825. }
  1826. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1827. now := time.Now()
  1828. tx := writeDb.Begin()
  1829. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1830. tx.Rollback()
  1831. return createOrderErr
  1832. }
  1833. // 更新透析记录 ID
  1834. // 透析处方
  1835. 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 {
  1836. tx.Rollback()
  1837. return err
  1838. }
  1839. // 接诊评估
  1840. 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 {
  1841. tx.Rollback()
  1842. return err
  1843. }
  1844. // 透前评估
  1845. 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 {
  1846. tx.Rollback()
  1847. return err
  1848. }
  1849. // 临时医嘱
  1850. 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 {
  1851. tx.Rollback()
  1852. return err
  1853. }
  1854. // 双人核对
  1855. 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 {
  1856. tx.Rollback()
  1857. return err
  1858. }
  1859. // 透后评估
  1860. 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 {
  1861. tx.Rollback()
  1862. return err
  1863. }
  1864. // 治疗小结
  1865. 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 {
  1866. tx.Rollback()
  1867. return err
  1868. }
  1869. // 透析监测
  1870. 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 {
  1871. tx.Rollback()
  1872. return err
  1873. }
  1874. tx.Commit()
  1875. return nil
  1876. }
  1877. type MobileUrgentSchedulePatientVM struct {
  1878. ID int64 `gorm:"column:id" json:"id"`
  1879. Name string `gorm:"column:name" json:"name"`
  1880. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1881. }
  1882. func (MobileUrgentSchedulePatientVM) TableName() string {
  1883. return "xt_patients"
  1884. }
  1885. type MobileUrgentScheduleTreatmentModeVM struct {
  1886. ID int64 `gorm:"column:id" json:"id"`
  1887. Name string `gorm:"column:name" json:"name"`
  1888. }
  1889. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1890. return "xt_treatment_mode"
  1891. }
  1892. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1893. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1894. 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()
  1895. defer rows.Close()
  1896. if err != nil {
  1897. return nil, err
  1898. }
  1899. for rows.Next() {
  1900. var vm MobileUrgentSchedulePatientVM
  1901. readDb.ScanRows(rows, &vm)
  1902. vms = append(vms, &vm)
  1903. }
  1904. return vms, nil
  1905. }
  1906. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1907. var modes []*MobileUrgentScheduleTreatmentModeVM
  1908. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1909. if err != nil {
  1910. return nil, err
  1911. }
  1912. return modes, nil
  1913. }
  1914. type MobileUrgentScheduleScheduleListVM struct {
  1915. ID int64 `gorm:"column:id" json:"id"`
  1916. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1917. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1918. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1919. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1920. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1921. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1922. }
  1923. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1924. return "xt_schedule"
  1925. }
  1926. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1927. db := readDb.
  1928. Model(&MobileUrgentScheduleScheduleListVM{}).
  1929. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1930. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1931. err = db.Find(&schedules).Error
  1932. if err != nil {
  1933. return nil, err
  1934. }
  1935. return schedules, nil
  1936. }
  1937. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1938. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1939. 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()
  1940. defer rows.Close()
  1941. if err != nil {
  1942. return nil, err
  1943. }
  1944. for rows.Next() {
  1945. var vm MobileUrgentScheduleScheduleListVM
  1946. readDb.ScanRows(rows, &vm)
  1947. vms = append(vms, &vm)
  1948. }
  1949. return vms, nil
  1950. }
  1951. type MobileUrgentScheduleDeviceNumberVM struct {
  1952. ID int64 `gorm:"column:id" json:"id"`
  1953. Number string `gorm:"column:number" json:"number"`
  1954. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1955. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1956. }
  1957. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1958. return "xt_device_number"
  1959. }
  1960. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1961. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1962. 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()
  1963. defer rows.Close()
  1964. if err != nil {
  1965. return nil, err
  1966. }
  1967. for rows.Next() {
  1968. var vm DeviceNumberViewModel
  1969. readDb.ScanRows(rows, &vm)
  1970. vms = append(vms, &vm)
  1971. }
  1972. return vms, nil
  1973. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1974. //db := readDb.
  1975. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1976. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1977. // Where("status = 1 AND org_id = ?", orgID)
  1978. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1979. //if err != nil {
  1980. // return nil, err
  1981. //}
  1982. //return deviceNumbers, nil
  1983. }
  1984. func GetValidScheduleMonitorRecordCount() (int64, error) {
  1985. var total int64
  1986. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  1987. return total, err
  1988. }
  1989. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  1990. var monitors []*models.MonitoringRecord
  1991. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  1992. if err != nil {
  1993. return nil, err
  1994. }
  1995. return monitors, nil
  1996. }
  1997. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  1998. tx := writeDb.Begin()
  1999. for index := 0; index < len(monitors); index++ {
  2000. tx.Save(monitors[index])
  2001. }
  2002. return tx.Commit().Error
  2003. }
  2004. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  2005. tx := writeDb.Begin()
  2006. updateTime := time.Now().Unix()
  2007. 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}).Error
  2008. if err != nil {
  2009. tx.Rollback()
  2010. return err
  2011. }
  2012. tx.Commit()
  2013. return err
  2014. }
  2015. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  2016. tx := writeDb.Begin()
  2017. updateTime := time.Now().Unix()
  2018. 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}).Error
  2019. if err != nil {
  2020. tx.Rollback()
  2021. return err
  2022. }
  2023. tx.Commit()
  2024. return err
  2025. }
  2026. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2027. var record models.SgjPatientDryweight
  2028. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2029. if err != nil {
  2030. if err == gorm.ErrRecordNotFound {
  2031. return nil, nil
  2032. } else {
  2033. return nil, err
  2034. }
  2035. }
  2036. return &record, nil
  2037. }
  2038. //func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2039. // var record models.SgjPatientDryweight
  2040. // redis := RedisClient()
  2041. // defer redis.Close()
  2042. //
  2043. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  2044. // last_dry_weight_str, _ := redis.Get(key).Result()
  2045. //
  2046. // if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2047. // err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2048. // if err != nil {
  2049. // if err == gorm.ErrRecordNotFound {
  2050. // if record.ID <= 0 {
  2051. // redis.Set(key, "null", time.Second*60*60*18)
  2052. // }
  2053. // return nil, nil
  2054. // } else {
  2055. // return nil, err
  2056. // }
  2057. // } else {
  2058. // if record.ID > 0 {
  2059. // //缓存数据
  2060. // last_dry_weight_str, err := json.Marshal(record)
  2061. // if err == nil {
  2062. // redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  2063. // return nil, err
  2064. // }
  2065. // } else {
  2066. // redis.Set(key, "null", time.Second*60*60*18)
  2067. // return nil, err
  2068. // }
  2069. // return &record, nil
  2070. // }
  2071. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2072. // if last_dry_weight_str == "null" {
  2073. // return &record, nil
  2074. // } else {
  2075. // json.Unmarshal([]byte(last_dry_weight_str), &record)
  2076. // return &record, nil
  2077. // }
  2078. //
  2079. // }
  2080. //}
  2081. // 透析方案
  2082. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2083. var record models.DialysisSolution
  2084. 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
  2085. if err != nil {
  2086. if err == gorm.ErrRecordNotFound {
  2087. return nil, nil
  2088. } else {
  2089. return nil, err
  2090. }
  2091. }
  2092. return &record, nil
  2093. }
  2094. // 透析方案
  2095. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2096. var record models.DialysisSolution
  2097. redis := RedisClient()
  2098. defer redis.Close()
  2099. // cur_date := time.Now().Format("2006-01-02")
  2100. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2101. dialysis_solution_str, _ := redis.Get(key).Result()
  2102. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2103. 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
  2104. if err != nil {
  2105. if err == gorm.ErrRecordNotFound {
  2106. if record.ID <= 0 {
  2107. redis.Set(key, "null", time.Second*60*60*18)
  2108. }
  2109. return nil, nil
  2110. } else {
  2111. return nil, err
  2112. }
  2113. } else {
  2114. if record.ID > 0 {
  2115. //缓存数据
  2116. dialysis_solution_str, err := json.Marshal(record)
  2117. if err == nil {
  2118. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  2119. }
  2120. } else {
  2121. redis.Set(key, "null", time.Second*60*60*18)
  2122. }
  2123. return &record, nil
  2124. }
  2125. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2126. if dialysis_solution_str == "null" {
  2127. return &record, nil
  2128. } else {
  2129. json.Unmarshal([]byte(dialysis_solution_str), &record)
  2130. return &record, nil
  2131. }
  2132. }
  2133. }
  2134. // 透析处方
  2135. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2136. var record models.DialysisPrescription
  2137. redis := RedisClient()
  2138. defer redis.Close()
  2139. // cur_date := time.Now().Format("2006-01-02")
  2140. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2141. redis.Set(key, "", time.Second)
  2142. dialysis_prescribe_str, _ := redis.Get(key).Result()
  2143. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2144. 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
  2145. if err != nil {
  2146. if err == gorm.ErrRecordNotFound {
  2147. if record.ID <= 0 {
  2148. redis.Set(key, "null", time.Second*60*60*18)
  2149. }
  2150. return nil, nil
  2151. } else {
  2152. return nil, err
  2153. }
  2154. } else {
  2155. if record.ID > 0 {
  2156. //缓存数据
  2157. dialysis_prescribe_str, err := json.Marshal(record)
  2158. if err == nil {
  2159. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  2160. }
  2161. } else {
  2162. redis.Set(key, "null", time.Second*60*60*18)
  2163. }
  2164. return &record, nil
  2165. }
  2166. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2167. if dialysis_prescribe_str == "null" {
  2168. return &record, nil
  2169. } else {
  2170. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  2171. return &record, nil
  2172. }
  2173. }
  2174. }
  2175. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  2176. var record models.DialysisPrescription
  2177. 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
  2178. if err != nil {
  2179. if err == gorm.ErrRecordNotFound {
  2180. return nil, nil
  2181. } else {
  2182. return nil, err
  2183. }
  2184. }
  2185. return &record, nil
  2186. }
  2187. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2188. var record models.DialysisPrescription
  2189. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2190. if err != nil {
  2191. if err == gorm.ErrRecordNotFound {
  2192. return nil, nil
  2193. } else {
  2194. return nil, err
  2195. }
  2196. }
  2197. return &record, nil
  2198. }
  2199. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2200. // var record models.DialysisPrescription
  2201. // redis := RedisClient()
  2202. // defer redis.Close()
  2203. //
  2204. // // cur_date := time.Now().Format("2006-01-02")
  2205. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  2206. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  2207. //
  2208. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2209. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2210. // if err != nil {
  2211. // if err == gorm.ErrRecordNotFound {
  2212. // if record.ID <= 0 {
  2213. // redis.Set(key, "null", time.Second*60*60*18)
  2214. // }
  2215. // return nil, nil
  2216. // } else {
  2217. // return nil, err
  2218. // }
  2219. // } else {
  2220. //
  2221. // if record.ID > 0 {
  2222. // //缓存数据
  2223. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2224. //
  2225. // if err == nil {
  2226. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2227. // return nil, err
  2228. // }
  2229. // } else {
  2230. // redis.Set(key, "null", time.Second*60*60*18)
  2231. // return nil, err
  2232. // }
  2233. // return &record, nil
  2234. // }
  2235. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2236. // if dialysis_prescribe_by_mode_str == "null" {
  2237. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2238. // return &record, nil
  2239. // } else {
  2240. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2241. // return &record, nil
  2242. // }
  2243. //
  2244. // }
  2245. //}
  2246. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2247. var record models.DialysisPrescription
  2248. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2249. if err != nil {
  2250. if err == gorm.ErrRecordNotFound {
  2251. return nil, nil
  2252. } else {
  2253. return nil, err
  2254. }
  2255. }
  2256. return &record, nil
  2257. }
  2258. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2259. var record models.DialysisPrescription
  2260. 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
  2261. if err != nil {
  2262. if err == gorm.ErrRecordNotFound {
  2263. return nil, nil
  2264. } else {
  2265. return nil, err
  2266. }
  2267. }
  2268. return &record, nil
  2269. }
  2270. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2271. var record models.DialysisPrescription
  2272. redis := RedisClient()
  2273. defer redis.Close()
  2274. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2275. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2276. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2277. 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
  2278. if err != nil {
  2279. if err == gorm.ErrRecordNotFound {
  2280. if record.ID <= 0 {
  2281. redis.Set(key, "null", time.Second*60*60*18)
  2282. }
  2283. return nil, nil
  2284. } else {
  2285. return nil, err
  2286. }
  2287. } else {
  2288. if record.ID > 0 {
  2289. //缓存数据
  2290. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2291. if err == nil {
  2292. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2293. return nil, err
  2294. }
  2295. } else {
  2296. redis.Set(key, "null", time.Second*60*60*18)
  2297. return nil, err
  2298. }
  2299. return &record, nil
  2300. }
  2301. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2302. if dialysis_prescribe_by_mode_id == "null" {
  2303. return &record, nil
  2304. } else {
  2305. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2306. return &record, nil
  2307. }
  2308. }
  2309. }
  2310. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2311. var record models.DialysisPrescription
  2312. 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
  2313. return record, err
  2314. }
  2315. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2316. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2317. 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()
  2318. defer rows.Close()
  2319. if err != nil {
  2320. return nil, err
  2321. }
  2322. for rows.Next() {
  2323. var vm DeviceNumberViewModel
  2324. readDb.ScanRows(rows, &vm)
  2325. vms = append(vms, &vm)
  2326. }
  2327. return vms, nil
  2328. }
  2329. // 获取 maxDate 之前一次的透前评估记录
  2330. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2331. var record models.PredialysisEvaluation
  2332. 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
  2333. if err != nil {
  2334. if err == gorm.ErrRecordNotFound {
  2335. return nil, nil
  2336. } else {
  2337. return nil, err
  2338. }
  2339. }
  2340. return &record, nil
  2341. }
  2342. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2343. var record models.DialysisOrder
  2344. 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
  2345. if err != nil {
  2346. if err == gorm.ErrRecordNotFound {
  2347. return nil, nil
  2348. } else {
  2349. return nil, err
  2350. }
  2351. }
  2352. return &record, nil
  2353. }
  2354. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2355. var record models.MonitoringRecord
  2356. 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
  2357. if err != nil {
  2358. if err == gorm.ErrRecordNotFound {
  2359. return nil, nil
  2360. } else {
  2361. return nil, err
  2362. }
  2363. }
  2364. return &record, nil
  2365. }
  2366. // 获取 maxDate 之前一次的透后评估记录
  2367. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2368. var record models.AssessmentAfterDislysis
  2369. 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
  2370. if err != nil {
  2371. if err == gorm.ErrRecordNotFound {
  2372. return nil, nil
  2373. } else {
  2374. return nil, err
  2375. }
  2376. }
  2377. return &record, nil
  2378. }
  2379. // 透析处方
  2380. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2381. var record models.DialysisPrescription
  2382. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2383. if err != nil {
  2384. if err == gorm.ErrRecordNotFound {
  2385. return nil, nil
  2386. } else {
  2387. return nil, err
  2388. }
  2389. }
  2390. return &record, nil
  2391. }
  2392. // 透析方案
  2393. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
  2394. var record models.DialysisSolution
  2395. 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
  2396. return record, err
  2397. }
  2398. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2399. var record models.DialysisSolution
  2400. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2401. if err != nil {
  2402. if err == gorm.ErrRecordNotFound {
  2403. return nil, nil
  2404. } else {
  2405. return nil, err
  2406. }
  2407. }
  2408. return &record, nil
  2409. }
  2410. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2411. var record models.DialysisPrescription
  2412. 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
  2413. if err != nil {
  2414. if err == gorm.ErrRecordNotFound {
  2415. return nil, nil
  2416. } else {
  2417. return nil, err
  2418. }
  2419. }
  2420. return &record, nil
  2421. }
  2422. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2423. var record models.SgjPatientDryweight
  2424. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2425. if err != nil {
  2426. if err == gorm.ErrRecordNotFound {
  2427. return nil, nil
  2428. } else {
  2429. return nil, err
  2430. }
  2431. }
  2432. return &record, nil
  2433. }
  2434. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2435. var record models.SystemPrescription
  2436. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2437. if err != nil {
  2438. if err == gorm.ErrRecordNotFound {
  2439. return nil, nil
  2440. } else {
  2441. return nil, err
  2442. }
  2443. }
  2444. return &record, nil
  2445. }
  2446. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2447. var record models.SystemPrescription
  2448. redis := RedisClient()
  2449. defer redis.Close()
  2450. // cur_date := time.Now().Format("2006-01-02")
  2451. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2452. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2453. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2454. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2455. if err != nil {
  2456. if err == gorm.ErrRecordNotFound {
  2457. if record.ID <= 0 {
  2458. redis.Set(key, "null", time.Second*60*60*18)
  2459. }
  2460. return nil, nil
  2461. } else {
  2462. return nil, err
  2463. }
  2464. } else {
  2465. if record.ID > 0 {
  2466. //缓存数据
  2467. system_dialysis_prescribe_str, err := json.Marshal(record)
  2468. if err == nil {
  2469. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2470. }
  2471. } else {
  2472. redis.Set(key, "null", time.Second*60*60*18)
  2473. }
  2474. return &record, nil
  2475. }
  2476. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2477. if system_dialysis_prescribe_str == "null" {
  2478. return &record, nil
  2479. } else {
  2480. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2481. return &record, nil
  2482. }
  2483. }
  2484. }
  2485. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2486. var record models.SystemPrescription
  2487. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2488. return record, err
  2489. }
  2490. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2491. var record models.SystemPrescription
  2492. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2493. if err != nil {
  2494. if err == gorm.ErrRecordNotFound {
  2495. return nil, nil
  2496. } else {
  2497. return nil, err
  2498. }
  2499. }
  2500. return &record, nil
  2501. }
  2502. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2503. 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
  2504. return
  2505. }
  2506. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2507. 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
  2508. return
  2509. }
  2510. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2511. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2512. return
  2513. }
  2514. func GetFirstDateOfMonth(d time.Time) time.Time {
  2515. d = d.AddDate(0, 0, -d.Day()+1)
  2516. return GetZeroTime(d)
  2517. }
  2518. func GetZeroTime(d time.Time) time.Time {
  2519. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2520. }
  2521. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2522. db := XTReadDB().Table("xt_dialysis_order as o")
  2523. 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
  2524. return order, err
  2525. }
  2526. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2527. 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
  2528. return
  2529. }
  2530. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2531. 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
  2532. return
  2533. }
  2534. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2535. 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
  2536. return
  2537. }
  2538. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2539. // 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
  2540. // return
  2541. //}
  2542. //
  2543. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2544. 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
  2545. return
  2546. }
  2547. type GoodsType struct {
  2548. ID int64 `gorm:"column:id" json:"id"`
  2549. TypeName string `gorm:"column:type_name" json:"type_name"`
  2550. Remark string `gorm:"column:remark" json:"remark"`
  2551. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2552. Status int64 `gorm:"column:status" json:"status"`
  2553. Type int64 `gorm:"column:type" json:"type"`
  2554. }
  2555. func (GoodsType) TableName() string {
  2556. return "xt_goods_type"
  2557. }
  2558. type VMGoodInfo struct {
  2559. ID int64 `gorm:"column:id" json:"id"`
  2560. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2561. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2562. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2563. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2564. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2565. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2566. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2567. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2568. }
  2569. func (VMGoodInfo) TableName() string {
  2570. return "xt_good_information"
  2571. }
  2572. type AutomaticReduceDetail struct {
  2573. ID int64 `gorm:"column:id" json:"id"`
  2574. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2575. Status int64 `gorm:"column:status" json:"status"`
  2576. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2577. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2578. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2579. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2580. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2581. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2582. Count int64 `gorm:"column:count" json:"count"`
  2583. }
  2584. func (AutomaticReduceDetail) TableName() string {
  2585. return "xt_automatic_reduce_detail"
  2586. }
  2587. type DialysisBeforePrepare struct {
  2588. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2589. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2590. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2591. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2592. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2593. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2594. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2595. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2596. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2597. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2598. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2599. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2600. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2601. }
  2602. func (DialysisBeforePrepare) TableName() string {
  2603. return "dialysis_before_prepare"
  2604. }
  2605. type MDialysisGoodsVM struct {
  2606. ID int64 `gorm:"column:id" json:"id"`
  2607. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2608. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2609. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2610. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2611. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2612. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2613. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2614. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2615. Status int64 `gorm:"column:status" json:"status"`
  2616. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2617. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2618. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2619. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2620. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2621. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2622. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2623. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2624. }
  2625. func (MDialysisGoodsVM) TableName() string {
  2626. return "xt_schedule"
  2627. }
  2628. type VMWarehouseOutInfo struct {
  2629. ID int64 `gorm:"column:id" json:"id"`
  2630. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2631. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2632. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2633. Count int64 `gorm:"column:count" json:"count"`
  2634. Price float64 `gorm:"column:price" json:"price"`
  2635. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2636. Status int64 `gorm:"column:status" json:"status"`
  2637. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2638. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2639. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2640. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2641. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2642. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2643. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2644. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2645. }
  2646. func (VMWarehouseOutInfo) TableName() string {
  2647. return "xt_warehouse_out_info"
  2648. }
  2649. type DialysisGoodsDate struct {
  2650. RecordDate int64
  2651. }
  2652. type DialysisGoodsDetailDate struct {
  2653. RecordTime int64
  2654. }
  2655. 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) {
  2656. var vms []*MDialysisGoodsVM
  2657. var total int64
  2658. db := readDb.
  2659. Table("xt_schedule as sch").
  2660. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2661. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2662. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2663. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2664. 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)
  2665. }).
  2666. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2667. 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")
  2668. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2669. if scheduleDate != 0 {
  2670. db = db.Where("schedule_date = ?", scheduleDate)
  2671. }
  2672. if schedule_type != 0 {
  2673. db = db.Where("schedule_type = ?", schedule_type)
  2674. }
  2675. if partition_id != 0 {
  2676. db = db.Where("partition_id = ?", partition_id)
  2677. }
  2678. if patient_id != 0 {
  2679. db = db.Where("patient_id = ?", patient_id)
  2680. }
  2681. err := db.Find(&vms).Error
  2682. return vms, err, total
  2683. }
  2684. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2685. var Id []*DialysisGoodsDetailDate
  2686. 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
  2687. if len(Id) > 0 {
  2688. 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
  2689. }
  2690. return
  2691. }
  2692. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2693. var Id []*DialysisGoodsDate
  2694. 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
  2695. if len(Id) > 0 {
  2696. 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
  2697. }
  2698. return
  2699. }
  2700. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2701. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2702. return info, err
  2703. }
  2704. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2705. db := readDb.Model(&models.StockInfo{})
  2706. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2707. 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")
  2708. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2709. 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)
  2710. })
  2711. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2712. err = db.Order("ctime desc").Find(&list).Error
  2713. return
  2714. }
  2715. 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) {
  2716. var vms []*MDialysisGoodsVM
  2717. var total int64
  2718. db := readDb.
  2719. Model(&models.Schedule{}).
  2720. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2721. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2722. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2723. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2724. 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)
  2725. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2726. 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)
  2727. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2728. if scheduleDate != 0 {
  2729. db = db.Where("schedule_date = ?", scheduleDate)
  2730. }
  2731. if patient_id != 0 {
  2732. db = db.Where("patient_id = ?", patient_id)
  2733. }
  2734. if len(keywords) != 0 {
  2735. keywords = "%" + keywords + "%"
  2736. 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)
  2737. if schedule_type != 0 {
  2738. db = db.Where("schedule_type = ?", schedule_type)
  2739. }
  2740. if partition_id != 0 {
  2741. db = db.Where("partition_id = ?", partition_id)
  2742. }
  2743. if good_type == 1 {
  2744. db = db.Where("patient_id in(?)", ids)
  2745. }
  2746. if good_type == 2 {
  2747. if len(ids) > 0 {
  2748. db = db.Where("patient_id not in(?)", ids)
  2749. }
  2750. }
  2751. } else {
  2752. if schedule_type != 0 {
  2753. db = db.Where("schedule_type = ?", schedule_type)
  2754. }
  2755. if partition_id != 0 {
  2756. db = db.Where("partition_id = ?", partition_id)
  2757. }
  2758. if good_type == 1 {
  2759. db = db.Where("patient_id in(?)", ids)
  2760. }
  2761. if good_type == 2 {
  2762. if len(ids) > 0 {
  2763. db = db.Where("patient_id not in(?)", ids)
  2764. }
  2765. }
  2766. db = db.Count(&total)
  2767. offset := (page - 1) * limit
  2768. db = db.Offset(offset).Limit(limit)
  2769. }
  2770. err := db.Find(&vms).Error
  2771. return vms, err, total
  2772. }
  2773. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2774. var Id []*DialysisGoodsDetailDate
  2775. 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
  2776. if len(Id) > 0 {
  2777. 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
  2778. }
  2779. return
  2780. }
  2781. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2782. var Id []*DialysisGoodsDate
  2783. 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
  2784. if len(Id) > 0 {
  2785. 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
  2786. }
  2787. return
  2788. }
  2789. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2790. evaluation := models.PredialysisEvaluation{}
  2791. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2792. if err == gorm.ErrRecordNotFound {
  2793. return nil, err
  2794. }
  2795. if err != nil {
  2796. return nil, err
  2797. }
  2798. return &evaluation, nil
  2799. }
  2800. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2801. evaluation := models.PredialysisEvaluation{}
  2802. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2803. return evaluation, err
  2804. }
  2805. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2806. redis := RedisClient()
  2807. defer redis.Close()
  2808. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2809. his_doctor_advice_str, _ := redis.Get(key).Result()
  2810. redis.Set(key, "", time.Second)
  2811. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2812. 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
  2813. if err != nil {
  2814. if err == gorm.ErrRecordNotFound {
  2815. if len(his) <= 0 {
  2816. redis.Set(key, "null", time.Second*60*60*18)
  2817. }
  2818. return his, nil
  2819. } else {
  2820. return his, err
  2821. }
  2822. } else {
  2823. if len(his) > 0 {
  2824. //缓存数据
  2825. his_doctor_advice_str, err := json.Marshal(his)
  2826. if err == nil {
  2827. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2828. }
  2829. } else {
  2830. redis.Set(key, "null", time.Second*60*60*18)
  2831. }
  2832. return his, nil
  2833. }
  2834. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2835. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2836. return his, nil
  2837. }
  2838. }
  2839. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2840. prescription := models.DialysisPrescription{}
  2841. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2842. if err == gorm.ErrRecordNotFound {
  2843. return nil, err
  2844. }
  2845. if err != nil {
  2846. return nil, err
  2847. }
  2848. return &prescription, nil
  2849. }
  2850. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2851. prescription := models.DialysisPrescription{}
  2852. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2853. return prescription, err
  2854. }
  2855. type HisMScheduleDoctorAdviceVM struct {
  2856. ID int64 `gorm:"column:id" json:"id"`
  2857. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2858. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2859. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2860. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2861. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2862. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2863. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2864. Status int64 `gorm:"column:status" json:"status"`
  2865. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2866. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2867. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2868. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2869. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2870. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2871. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2872. }
  2873. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2874. return "xt_schedule"
  2875. }
  2876. type HisMScheduleDoctorAdviceVMOne struct {
  2877. ID int64 `gorm:"column:id" json:"id"`
  2878. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2879. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2880. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2881. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2882. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2883. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2884. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2885. Status int64 `gorm:"column:status" json:"status"`
  2886. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2887. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2888. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2889. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2890. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2891. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2892. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2893. }
  2894. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2895. return "xt_schedule"
  2896. }
  2897. type HisMScheduleProjectVM struct {
  2898. ID int64 `gorm:"column:id" json:"id"`
  2899. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2900. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2901. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2902. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2903. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2904. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2905. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2906. Status int64 `gorm:"column:status" json:"status"`
  2907. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2908. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2909. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2910. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2911. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2912. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2913. }
  2914. func (HisMScheduleProjectVM) TableName() string {
  2915. return "xt_schedule"
  2916. }
  2917. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2918. config := models.XtHisConfig{}
  2919. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2920. return config, err
  2921. }
  2922. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2923. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2924. if orgid > 0 {
  2925. db = db.Where("x.user_org_id = ?", orgid)
  2926. }
  2927. if patientid > 0 {
  2928. db = db.Where("x.patient_id =?", patientid)
  2929. }
  2930. if recordtime > 0 {
  2931. db = db.Where("x.advice_date = ?", recordtime)
  2932. }
  2933. 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
  2934. return advice, err
  2935. }
  2936. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2937. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2938. if startime > 0 {
  2939. db = db.Where("x.advice_date >= ?", startime)
  2940. }
  2941. if endtime > 0 {
  2942. db = db.Where("x.advice_date<=?", endtime)
  2943. }
  2944. if orgid > 0 {
  2945. db = db.Where("x.user_org_id = ?", orgid)
  2946. }
  2947. if len(deliveway) > 0 {
  2948. db = db.Where("x.delivery_way = ?", deliveway)
  2949. }
  2950. 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
  2951. return advice, err
  2952. }
  2953. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2954. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2955. if startime > 0 {
  2956. db = db.Where("x.advice_date >= ?", startime)
  2957. }
  2958. if endtime > 0 {
  2959. db = db.Where("x.advice_date<=?", endtime)
  2960. }
  2961. if orgid > 0 {
  2962. db = db.Where("x.user_org_id = ?", orgid)
  2963. }
  2964. if len(deliveway) > 0 {
  2965. db = db.Where("x.delivery_way = ?", deliveway)
  2966. }
  2967. 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
  2968. return advice, err
  2969. }
  2970. 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) {
  2971. var vms []*MScheduleDoctorAdviceVM
  2972. adviceWhere := ""
  2973. adviceCondition := []interface{}{}
  2974. if adviceType == 0 {
  2975. if patientType == 0 {
  2976. if patient_id > 0 {
  2977. if execution_state > 0 {
  2978. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  2979. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2980. } else {
  2981. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2982. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2983. }
  2984. } else {
  2985. if execution_state > 0 {
  2986. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  2987. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2988. } else {
  2989. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2990. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2991. }
  2992. }
  2993. } else if patientType == 1 {
  2994. if patient_id > 0 {
  2995. if execution_state > 0 {
  2996. 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= ?"
  2997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  2998. } else {
  2999. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3000. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3001. }
  3002. } else {
  3003. if execution_state > 0 {
  3004. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3005. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3006. } else {
  3007. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3008. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3009. }
  3010. }
  3011. } else if patientType == 2 {
  3012. if patient_id > 0 {
  3013. if execution_state > 0 {
  3014. 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 = ?"
  3015. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3016. } else {
  3017. 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 = ?)"
  3018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3019. }
  3020. } else {
  3021. if execution_state > 0 {
  3022. 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 = ?"
  3023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3024. } else {
  3025. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3027. }
  3028. }
  3029. }
  3030. } else if adviceType == 1 {
  3031. if patientType == 0 {
  3032. if patient_id > 0 {
  3033. if execution_state > 0 {
  3034. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3036. } else {
  3037. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3038. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3039. }
  3040. } else {
  3041. if execution_state > 0 {
  3042. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3044. } else {
  3045. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3046. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3047. }
  3048. }
  3049. } else if patientType == 1 {
  3050. if patient_id > 0 {
  3051. if execution_state > 0 {
  3052. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3054. } else {
  3055. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3056. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3057. }
  3058. } else {
  3059. if execution_state > 0 {
  3060. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3062. } else {
  3063. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3065. }
  3066. }
  3067. } else if patientType == 2 {
  3068. if patient_id > 0 {
  3069. if execution_state > 0 {
  3070. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3072. } else {
  3073. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3074. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3075. }
  3076. } else {
  3077. if execution_state > 0 {
  3078. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3080. } else {
  3081. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3083. }
  3084. }
  3085. }
  3086. } else if adviceType == 3 {
  3087. if patientType == 0 {
  3088. if patient_id > 0 {
  3089. if execution_state > 0 {
  3090. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3092. } else {
  3093. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3095. }
  3096. } else {
  3097. if execution_state > 0 {
  3098. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3100. } else {
  3101. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3103. }
  3104. }
  3105. } else if patientType == 1 {
  3106. if patient_id > 0 {
  3107. if execution_state > 0 {
  3108. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3110. } else {
  3111. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3113. }
  3114. } else {
  3115. if execution_state > 0 {
  3116. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3117. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3118. } else {
  3119. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3121. }
  3122. }
  3123. } else if patientType == 2 {
  3124. if patient_id > 0 {
  3125. if execution_state > 0 {
  3126. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3128. } else {
  3129. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3131. }
  3132. } else {
  3133. if execution_state > 0 {
  3134. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3136. } else {
  3137. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3139. }
  3140. }
  3141. }
  3142. } else if adviceType == 2 && len(deliverWay) > 0 {
  3143. if patientType == 0 {
  3144. if patient_id > 0 {
  3145. if execution_state > 0 {
  3146. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3148. } else {
  3149. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3151. }
  3152. } else {
  3153. if execution_state > 0 {
  3154. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3156. } else {
  3157. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3159. }
  3160. }
  3161. } else if patientType == 1 {
  3162. if patient_id > 0 {
  3163. if execution_state > 0 {
  3164. 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 = ?"
  3165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3166. } else {
  3167. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3169. }
  3170. } else {
  3171. if execution_state > 0 {
  3172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3174. } else {
  3175. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3177. }
  3178. }
  3179. } else if patientType == 2 {
  3180. if patient_id > 0 {
  3181. if execution_state > 0 {
  3182. 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 = ?"
  3183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3184. } else {
  3185. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3187. }
  3188. } else {
  3189. if execution_state > 0 {
  3190. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3192. } else {
  3193. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3195. }
  3196. }
  3197. }
  3198. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3199. if patientType == 0 {
  3200. if patient_id > 0 {
  3201. if execution_state > 0 {
  3202. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3203. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3204. } else {
  3205. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3206. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3207. }
  3208. } else {
  3209. if execution_state > 0 {
  3210. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3211. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3212. } else {
  3213. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3214. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3215. }
  3216. }
  3217. } else if patientType == 1 {
  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 advice_doctor = ? and patient_id = ? and execution_state = ?"
  3221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3222. } else {
  3223. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3224. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, 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 advice_doctor = ? and execution_state = ?"
  3229. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3230. } else {
  3231. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3233. }
  3234. }
  3235. } else if patientType == 2 {
  3236. if patient_id > 0 {
  3237. if execution_state > 0 {
  3238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3240. } else {
  3241. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3242. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3243. }
  3244. } else {
  3245. if execution_state > 0 {
  3246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3248. } else {
  3249. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3250. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3251. }
  3252. }
  3253. }
  3254. }
  3255. db := readDb.Table("xt_schedule")
  3256. if scheduleType > 0 {
  3257. db = db.Where("schedule_type = ?", scheduleType)
  3258. }
  3259. if partitonType > 0 {
  3260. db = db.Where("partition_id = ?", partitonType)
  3261. }
  3262. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3263. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3264. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3265. }).
  3266. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3267. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3268. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3269. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3270. Preload("DoctorAdvices", adviceCondition...).
  3271. Where("status = 1 AND user_org_id = ?", orgID)
  3272. if scheduleDate != 0 {
  3273. db = db.Where("schedule_date = ?", scheduleDate)
  3274. }
  3275. err := db.Find(&vms).Error
  3276. return vms, err
  3277. }
  3278. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3279. var vms []*HisMScheduleDoctorAdviceVM
  3280. if len(deliverWay) > 0 {
  3281. db := readDb.Table("xt_schedule")
  3282. if scheduleType > 0 {
  3283. db = db.Where("schedule_type = ?", scheduleType)
  3284. }
  3285. if partitionType > 0 {
  3286. db = db.Where("partition_id = ?", partitionType)
  3287. }
  3288. if patient_id > 0 {
  3289. if execution_state > 0 {
  3290. if cost_type > 0 {
  3291. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3292. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3293. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3294. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3295. 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).
  3296. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3297. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3298. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3299. Where("status = 1 AND user_org_id = ?", orgID)
  3300. if scheduleDate != 0 {
  3301. db = db.Where("schedule_date = ?", scheduleDate)
  3302. }
  3303. err = db.Find(&vms).Error
  3304. } else {
  3305. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3306. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3307. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3308. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3309. 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).
  3310. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3311. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3312. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3313. Where("status = 1 AND user_org_id = ?", orgID)
  3314. if scheduleDate != 0 {
  3315. db = db.Where("schedule_date = ?", scheduleDate)
  3316. }
  3317. err = db.Find(&vms).Error
  3318. }
  3319. } else {
  3320. if cost_type > 0 {
  3321. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3322. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3323. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3324. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3325. 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).
  3326. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3327. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3328. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3329. Where("status = 1 AND user_org_id = ?", orgID)
  3330. if scheduleDate != 0 {
  3331. db = db.Where("schedule_date = ?", scheduleDate)
  3332. }
  3333. err = db.Find(&vms).Error
  3334. } else {
  3335. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3336. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3337. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3338. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3339. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3340. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3341. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3342. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3343. Where("status = 1 AND user_org_id = ?", orgID)
  3344. if scheduleDate != 0 {
  3345. db = db.Where("schedule_date = ?", scheduleDate)
  3346. }
  3347. err = db.Find(&vms).Error
  3348. }
  3349. }
  3350. } else {
  3351. if execution_state > 0 {
  3352. if cost_type > 0 {
  3353. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3354. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3355. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3356. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3357. 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).
  3358. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3359. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3360. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3361. Where("status = 1 AND user_org_id = ?", orgID)
  3362. if scheduleDate != 0 {
  3363. db = db.Where("schedule_date = ?", scheduleDate)
  3364. }
  3365. err = db.Find(&vms).Error
  3366. } else {
  3367. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3368. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3369. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3370. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3371. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3372. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3373. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3374. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3375. Where("status = 1 AND user_org_id = ?", orgID)
  3376. if scheduleDate != 0 {
  3377. db = db.Where("schedule_date = ?", scheduleDate)
  3378. }
  3379. err = db.Find(&vms).Error
  3380. }
  3381. } else {
  3382. if cost_type > 0 {
  3383. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3384. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3385. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3386. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3387. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3388. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3389. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3390. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3391. Where("status = 1 AND user_org_id = ?", orgID)
  3392. if scheduleDate != 0 {
  3393. db = db.Where("schedule_date = ?", scheduleDate)
  3394. }
  3395. err = db.Find(&vms).Error
  3396. } else {
  3397. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3398. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3399. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3400. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3401. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3402. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3403. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3404. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3405. Where("status = 1 AND user_org_id = ?", orgID)
  3406. if scheduleDate != 0 {
  3407. db = db.Where("schedule_date = ?", scheduleDate)
  3408. }
  3409. err = db.Find(&vms).Error
  3410. }
  3411. }
  3412. }
  3413. } else {
  3414. db := readDb.Table("xt_schedule")
  3415. if scheduleType > 0 {
  3416. db = db.Where("schedule_type = ?", scheduleType)
  3417. }
  3418. if partitionType > 0 {
  3419. db = db.Where("partition_id = ?", partitionType)
  3420. }
  3421. if patient_id > 0 {
  3422. if execution_state > 0 {
  3423. if cost_type > 0 {
  3424. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3425. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3426. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3427. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3428. 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).
  3429. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3430. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3431. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3432. Where("status = 1 AND user_org_id = ?", orgID)
  3433. if scheduleDate != 0 {
  3434. db = db.Where("schedule_date = ?", scheduleDate)
  3435. }
  3436. err = db.Find(&vms).Error
  3437. } else {
  3438. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3439. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3440. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3441. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3442. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3443. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3444. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3445. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3446. Where("status = 1 AND user_org_id = ?", orgID)
  3447. if scheduleDate != 0 {
  3448. db = db.Where("schedule_date = ?", scheduleDate)
  3449. }
  3450. err = db.Find(&vms).Error
  3451. }
  3452. } else {
  3453. if cost_type > 0 {
  3454. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3455. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3456. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3457. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3458. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3459. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3460. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3461. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3462. Where("status = 1 AND user_org_id = ?", orgID)
  3463. if scheduleDate != 0 {
  3464. db = db.Where("schedule_date = ?", scheduleDate)
  3465. }
  3466. err = db.Find(&vms).Error
  3467. } else {
  3468. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3469. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3470. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3471. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3472. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3473. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3474. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3475. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3476. Where("status = 1 AND user_org_id = ?", orgID)
  3477. if scheduleDate != 0 {
  3478. db = db.Where("schedule_date = ?", scheduleDate)
  3479. }
  3480. err = db.Find(&vms).Error
  3481. }
  3482. }
  3483. } else {
  3484. if execution_state > 0 {
  3485. if cost_type > 0 {
  3486. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3487. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3488. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3489. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3490. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3491. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3492. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3493. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3494. Where("status = 1 AND user_org_id = ?", orgID)
  3495. if scheduleDate != 0 {
  3496. db = db.Where("schedule_date = ?", scheduleDate)
  3497. }
  3498. err = db.Find(&vms).Error
  3499. } else {
  3500. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3501. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3502. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3503. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3504. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3505. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3506. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3507. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3508. Where("status = 1 AND user_org_id = ?", orgID)
  3509. if scheduleDate != 0 {
  3510. db = db.Where("schedule_date = ?", scheduleDate)
  3511. }
  3512. err = db.Find(&vms).Error
  3513. }
  3514. } else {
  3515. if cost_type > 0 {
  3516. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3517. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3518. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3519. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3520. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3521. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3522. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3523. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3524. Where("status = 1 AND user_org_id = ?", orgID)
  3525. if scheduleDate != 0 {
  3526. db = db.Where("schedule_date = ?", scheduleDate)
  3527. }
  3528. err = db.Find(&vms).Error
  3529. } else {
  3530. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3531. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3532. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3533. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3534. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3535. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3536. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3537. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3538. Where("status = 1 AND user_org_id = ?", orgID)
  3539. if scheduleDate != 0 {
  3540. db = db.Where("schedule_date = ?", scheduleDate)
  3541. }
  3542. err = db.Find(&vms).Error
  3543. }
  3544. }
  3545. }
  3546. }
  3547. return vms, err
  3548. }
  3549. func BatchDeleteMonitor(ids []string) (err error) {
  3550. if len(ids) == 1 {
  3551. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3552. } else {
  3553. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3554. }
  3555. return
  3556. }
  3557. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3558. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3559. //table := XTReadDB().Table("xt_schedule as s")
  3560. //fmt.Println(table)
  3561. if patientid > 0 {
  3562. db = db.Where("x.patient_id = ?", patientid)
  3563. }
  3564. if startime > 0 {
  3565. db = db.Where("x.dialysis_date>=?", startime)
  3566. }
  3567. if endtime > 0 {
  3568. db = db.Where("x.dialysis_date <= ?", endtime)
  3569. }
  3570. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Scan(&order).Error
  3571. return order, err
  3572. }
  3573. func BatchDeleteAdvice(ids []string) (err error) {
  3574. if len(ids) == 1 {
  3575. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3576. } else {
  3577. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3578. }
  3579. return
  3580. }
  3581. func BatchDeleteHisAdvice(ids []string) (err error) {
  3582. if len(ids) == 1 {
  3583. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3584. } else {
  3585. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3586. }
  3587. return
  3588. }
  3589. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3590. detail := models.AutomaticReduceDetail{}
  3591. 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
  3592. return detail, err
  3593. }
  3594. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3595. detail := models.AutomaticReduceDetail{}
  3596. 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
  3597. return err
  3598. }
  3599. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3600. detail := models.DialysisBeforePrepare{}
  3601. 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
  3602. return err
  3603. }
  3604. func BatchAdviceCheck(ids []string, creator int64) error {
  3605. advice := models.XtDoctorAdvice{}
  3606. 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
  3607. return err
  3608. }
  3609. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3610. advice := models.HisDoctorAdviceInfo{}
  3611. 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
  3612. return err
  3613. }
  3614. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3615. advice := models.XtDoctorAdvice{}
  3616. 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
  3617. return err
  3618. }
  3619. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3620. advice := models.HisDoctorAdviceInfo{}
  3621. 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
  3622. return err
  3623. }
  3624. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3625. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3626. return doctor, err
  3627. }
  3628. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3629. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3630. return doctor, err
  3631. }
  3632. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3633. config := models.XtHisProjectConfig{}
  3634. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3635. return config, err
  3636. }
  3637. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3638. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3639. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3640. }).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
  3641. return
  3642. }
  3643. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3644. var vms []*HisMScheduleProjectVM
  3645. if patientType == 0 {
  3646. if patient_id > 0 {
  3647. if execution_state == 1 {
  3648. db := readDb.
  3649. Table("xt_schedule").
  3650. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3651. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3652. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3653. }).
  3654. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3655. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3656. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3657. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3658. 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")
  3659. }).
  3660. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3661. 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")
  3662. }).Where("status = 1 AND user_org_id = ?", orgID)
  3663. if scheduleDate != 0 {
  3664. db = db.Where("schedule_date = ?", scheduleDate)
  3665. }
  3666. err = db.Find(&vms).Error
  3667. } else if execution_state == 2 {
  3668. db := readDb.
  3669. Table("xt_schedule").
  3670. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3671. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3672. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3673. }).
  3674. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3675. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3676. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3677. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3678. 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")
  3679. }).
  3680. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3681. 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")
  3682. }).Where("status = 1 AND user_org_id = ?", orgID)
  3683. if scheduleDate != 0 {
  3684. db = db.Where("schedule_date = ?", scheduleDate)
  3685. }
  3686. err = db.Find(&vms).Error
  3687. } else if execution_state == 0 {
  3688. db := readDb.
  3689. Table("xt_schedule").
  3690. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3691. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3692. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3693. }).
  3694. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3695. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3696. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3697. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3698. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3699. }).
  3700. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3701. 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")
  3702. }).Where("status = 1 AND user_org_id = ?", orgID)
  3703. if scheduleDate != 0 {
  3704. db = db.Where("schedule_date = ?", scheduleDate)
  3705. }
  3706. err = db.Find(&vms).Error
  3707. }
  3708. } else {
  3709. if patient_id > 0 {
  3710. if execution_state == 1 {
  3711. db := readDb.
  3712. Table("xt_schedule").
  3713. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3714. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3715. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3716. }).
  3717. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3718. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3719. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3720. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3721. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3722. }).
  3723. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3724. 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")
  3725. }).Where("status = 1 AND user_org_id = ?", orgID)
  3726. if scheduleDate != 0 {
  3727. db = db.Where("schedule_date = ?", scheduleDate)
  3728. }
  3729. err = db.Find(&vms).Error
  3730. } else if execution_state == 2 {
  3731. db := readDb.
  3732. Table("xt_schedule").
  3733. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3734. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3735. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3736. }).
  3737. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3738. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3739. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3740. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3741. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3742. }).
  3743. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3744. 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")
  3745. }).Where("status = 1 AND user_org_id = ?", orgID)
  3746. if scheduleDate != 0 {
  3747. db = db.Where("schedule_date = ?", scheduleDate)
  3748. }
  3749. err = db.Find(&vms).Error
  3750. } else if execution_state == 0 {
  3751. db := readDb.
  3752. Table("xt_schedule").
  3753. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3754. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3755. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3756. }).
  3757. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3758. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3759. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3760. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3761. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3762. }).
  3763. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3764. 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")
  3765. }).Where("status = 1 AND user_org_id = ?", orgID)
  3766. if scheduleDate != 0 {
  3767. db = db.Where("schedule_date = ?", scheduleDate)
  3768. }
  3769. err = db.Find(&vms).Error
  3770. }
  3771. } else {
  3772. if execution_state == 1 {
  3773. db := readDb.
  3774. Table("xt_schedule").
  3775. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3776. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3777. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3778. }).
  3779. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3780. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3781. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3782. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3783. 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")
  3784. }).
  3785. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3786. 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")
  3787. }).Where("status = 1 AND user_org_id = ?", orgID)
  3788. if scheduleDate != 0 {
  3789. db = db.Where("schedule_date = ?", scheduleDate)
  3790. }
  3791. err = db.Find(&vms).Error
  3792. } else if execution_state == 2 {
  3793. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3794. db := readDb.
  3795. Table("xt_schedule").
  3796. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3797. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3798. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3799. }).
  3800. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3801. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3802. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3803. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3804. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state =0 ", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3805. }).
  3806. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3807. 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")
  3808. }).Where("status = 1 AND user_org_id = ?", orgID)
  3809. if scheduleDate != 0 {
  3810. db = db.Where("schedule_date = ?", scheduleDate)
  3811. }
  3812. err = db.Find(&vms).Error
  3813. } else if execution_state == 0 {
  3814. db := readDb.
  3815. Table("xt_schedule").
  3816. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3817. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3818. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3819. }).
  3820. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3821. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3822. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3823. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3824. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3825. }).
  3826. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3827. 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")
  3828. }).Where("status = 1 AND user_org_id = ?", orgID)
  3829. if scheduleDate != 0 {
  3830. db = db.Where("schedule_date = ?", scheduleDate)
  3831. }
  3832. err = db.Find(&vms).Error
  3833. }
  3834. }
  3835. }
  3836. }
  3837. if patientType > 0 {
  3838. if execution_state == 1 {
  3839. db := readDb.
  3840. Table("xt_schedule").
  3841. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3842. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3843. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3844. }).
  3845. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3846. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3847. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3848. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3849. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3850. 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")
  3851. }).
  3852. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3853. 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")
  3854. }).Where("status = 1 AND user_org_id = ?", orgID)
  3855. if scheduleDate != 0 {
  3856. db = db.Where("schedule_date = ?", scheduleDate)
  3857. }
  3858. err = db.Find(&vms).Error
  3859. } else if execution_state == 2 {
  3860. db := readDb.
  3861. Table("xt_schedule").
  3862. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3863. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3864. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3865. }).
  3866. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3867. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3868. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3869. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3870. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3871. 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")
  3872. }).
  3873. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3874. 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")
  3875. }).Where("status = 1 AND user_org_id = ?", orgID)
  3876. if scheduleDate != 0 {
  3877. db = db.Where("schedule_date = ?", scheduleDate)
  3878. }
  3879. err = db.Find(&vms).Error
  3880. } else if execution_state == 0 {
  3881. db := readDb.
  3882. Table("xt_schedule").
  3883. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3884. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3885. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3886. }).
  3887. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3888. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3889. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3890. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3891. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3892. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3893. }).
  3894. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3895. 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")
  3896. }).Where("status = 1 AND user_org_id = ?", orgID)
  3897. if scheduleDate != 0 {
  3898. db = db.Where("schedule_date = ?", scheduleDate)
  3899. }
  3900. err = db.Find(&vms).Error
  3901. }
  3902. }
  3903. return vms, err
  3904. }
  3905. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3906. prepare := models.DialysisBeforePrepare{}
  3907. var err error
  3908. if count > 0 {
  3909. 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
  3910. }
  3911. if count <= 0 {
  3912. 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
  3913. }
  3914. return err
  3915. }
  3916. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3917. detail := models.AutomaticReduceDetail{}
  3918. 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
  3919. return err
  3920. }
  3921. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3922. var record models.DialysisSolution
  3923. 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
  3924. if err != nil {
  3925. if err == gorm.ErrRecordNotFound {
  3926. return nil, nil
  3927. } else {
  3928. return nil, err
  3929. }
  3930. }
  3931. return &record, nil
  3932. }
  3933. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3934. var record models.DialysisPrescription
  3935. 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
  3936. if err != nil {
  3937. if err == gorm.ErrRecordNotFound {
  3938. return nil, nil
  3939. } else {
  3940. return nil, err
  3941. }
  3942. }
  3943. return &record, nil
  3944. }
  3945. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  3946. prescription := models.DialysisPrescriptionThrity{}
  3947. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  3948. return prescription, err
  3949. }
  3950. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3951. var record models.SystemPrescription
  3952. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3953. if err != nil {
  3954. if err == gorm.ErrRecordNotFound {
  3955. return nil, nil
  3956. } else {
  3957. return nil, err
  3958. }
  3959. }
  3960. return &record, nil
  3961. }
  3962. // 透前评估
  3963. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3964. var record models.PredialysisEvaluation
  3965. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3966. if err != nil {
  3967. if err == gorm.ErrRecordNotFound {
  3968. return nil, nil
  3969. } else {
  3970. return nil, err
  3971. }
  3972. }
  3973. return &record, nil
  3974. }
  3975. //
  3976. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3977. //
  3978. // 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
  3979. // return prepare, err
  3980. //}
  3981. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3982. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  3983. return auto, err
  3984. }
  3985. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  3986. role := models.SgjUserAdminRole{}
  3987. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  3988. return role, err
  3989. }
  3990. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3991. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  3992. return auto, err
  3993. }
  3994. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  3995. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  3996. return outifno, err
  3997. }
  3998. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  3999. order := models.DialysisOrder{}
  4000. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4001. return order, err
  4002. }
  4003. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4004. record := models.MonitoringRecord{}
  4005. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4006. return record, err
  4007. }
  4008. func GetFistMonitorSix(orgid int64, patient_id int64, dialysis_date int64) (record []*models.MonitoringRecord, err error) {
  4009. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4010. return record, err
  4011. }
  4012. 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) ([]*MScheduleDoctorAdviceVM, error) {
  4013. var vms []*MScheduleDoctorAdviceVM
  4014. adviceWhere := ""
  4015. adviceCondition := []interface{}{}
  4016. if adviceType == 0 {
  4017. if patientType == 0 {
  4018. if patient_id > 0 {
  4019. if execution_state > 0 {
  4020. if cost_type > 0 {
  4021. if len(execution_frequency) > 0 {
  4022. 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 = ?"
  4023. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4024. } else {
  4025. 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 = ?"
  4026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4027. }
  4028. } else {
  4029. if len(execution_frequency) > 0 {
  4030. 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 = ?"
  4031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4032. } else {
  4033. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4035. }
  4036. }
  4037. } else {
  4038. if cost_type > 0 {
  4039. if len(execution_frequency) > 0 {
  4040. 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 = ?"
  4041. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4042. } else {
  4043. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  4044. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4045. }
  4046. } else {
  4047. if len(execution_frequency) > 0 {
  4048. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4050. } else {
  4051. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4053. }
  4054. }
  4055. }
  4056. } else {
  4057. if execution_state > 0 {
  4058. if cost_type > 0 {
  4059. if len(execution_frequency) > 0 {
  4060. 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 = ?"
  4061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4062. } else {
  4063. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  4064. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4065. }
  4066. } else {
  4067. if len(execution_frequency) > 0 {
  4068. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4070. } else {
  4071. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4073. }
  4074. }
  4075. } else {
  4076. if cost_type > 0 {
  4077. if len(execution_frequency) > 0 {
  4078. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ? and execution_frequency = ?"
  4079. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4080. } else {
  4081. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4082. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4083. }
  4084. } else {
  4085. if len(execution_frequency) > 0 {
  4086. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4088. } else {
  4089. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4091. }
  4092. }
  4093. }
  4094. }
  4095. } else if patientType == 1 {
  4096. if patient_id > 0 {
  4097. if execution_state > 0 {
  4098. if cost_type > 0 {
  4099. if len(execution_frequency) > 0 {
  4100. 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 = ?"
  4101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4102. } else {
  4103. 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 = ?"
  4104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4105. }
  4106. } else {
  4107. if len(execution_frequency) > 0 {
  4108. 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 = ?"
  4109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4110. } else {
  4111. 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= ?"
  4112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4113. }
  4114. }
  4115. } else {
  4116. if cost_type > 0 {
  4117. if len(execution_frequency) > 0 {
  4118. 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 = ?"
  4119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4120. } else {
  4121. 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=?"
  4122. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4123. }
  4124. } else {
  4125. if len(execution_frequency) > 0 {
  4126. 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 = ?"
  4127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4128. } else {
  4129. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4131. }
  4132. }
  4133. }
  4134. } else {
  4135. if execution_state > 0 {
  4136. if cost_type > 0 {
  4137. if len(execution_frequency) > 0 {
  4138. 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 = ?"
  4139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4140. } else {
  4141. 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=?"
  4142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4143. }
  4144. } else {
  4145. if len(execution_frequency) > 0 {
  4146. 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 = ?"
  4147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4148. } else {
  4149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4151. }
  4152. }
  4153. } else {
  4154. if cost_type > 0 {
  4155. if len(execution_frequency) > 0 {
  4156. 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 = ?"
  4157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4158. } else {
  4159. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  4160. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4161. }
  4162. } else {
  4163. if len(execution_frequency) > 0 {
  4164. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4166. } else {
  4167. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4169. }
  4170. }
  4171. }
  4172. }
  4173. } else if patientType == 2 {
  4174. if patient_id > 0 {
  4175. if execution_state > 0 {
  4176. if cost_type > 0 {
  4177. if len(execution_frequency) > 0 {
  4178. 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 = ?"
  4179. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4180. } else {
  4181. 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=?"
  4182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4183. }
  4184. } else {
  4185. if len(execution_frequency) > 0 {
  4186. 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 = ?"
  4187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4188. } else {
  4189. 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 = ?"
  4190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4191. }
  4192. }
  4193. } else {
  4194. if cost_type > 0 {
  4195. if len(execution_frequency) > 0 {
  4196. 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 = ?"
  4197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4198. } else {
  4199. 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=?"
  4200. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4201. }
  4202. } else {
  4203. if len(execution_frequency) > 0 {
  4204. 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 = ?"
  4205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4206. } else {
  4207. 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 = ?)"
  4208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4209. }
  4210. }
  4211. }
  4212. } else {
  4213. if execution_state > 0 {
  4214. if cost_type > 0 {
  4215. if len(execution_frequency) > 0 {
  4216. 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 = ?"
  4217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4218. } else {
  4219. 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=?"
  4220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4221. }
  4222. } else {
  4223. if len(execution_frequency) > 0 {
  4224. 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 = ?"
  4225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4226. } else {
  4227. 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 = ?"
  4228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4229. }
  4230. }
  4231. } else {
  4232. if cost_type > 0 {
  4233. if len(execution_frequency) > 0 {
  4234. 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 = ?"
  4235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4236. } else {
  4237. 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 = ?"
  4238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4239. }
  4240. } else {
  4241. if len(execution_frequency) > 0 {
  4242. 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 = ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4244. } else {
  4245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4247. }
  4248. }
  4249. }
  4250. }
  4251. }
  4252. } else if adviceType == 1 {
  4253. if patientType == 0 {
  4254. if patient_id > 0 {
  4255. if execution_state > 0 {
  4256. if cost_type > 0 {
  4257. if len(execution_frequency) > 0 {
  4258. 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 = ?"
  4259. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4260. } else {
  4261. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4262. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4263. }
  4264. } else {
  4265. if len(execution_frequency) > 0 {
  4266. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4268. } else {
  4269. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4271. }
  4272. }
  4273. } else {
  4274. if cost_type > 0 {
  4275. if len(execution_frequency) > 0 {
  4276. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4277. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4278. } else {
  4279. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4280. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4281. }
  4282. } else {
  4283. if len(execution_frequency) > 0 {
  4284. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4286. } else {
  4287. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4289. }
  4290. }
  4291. }
  4292. } else {
  4293. if execution_state > 0 {
  4294. if cost_type > 0 {
  4295. if len(execution_frequency) > 0 {
  4296. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4298. } else {
  4299. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4301. }
  4302. } else {
  4303. if len(execution_frequency) > 0 {
  4304. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4306. } else {
  4307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4309. }
  4310. }
  4311. } else {
  4312. if cost_type > 0 {
  4313. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4315. } else {
  4316. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4317. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4318. }
  4319. }
  4320. }
  4321. } else if patientType == 1 {
  4322. if patient_id > 0 {
  4323. if execution_state > 0 {
  4324. if cost_type > 0 {
  4325. if len(execution_frequency) > 0 {
  4326. 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 = ?"
  4327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4328. } else {
  4329. 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 = ?"
  4330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4331. }
  4332. } else {
  4333. if len(execution_frequency) > 0 {
  4334. 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 = ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4336. } else {
  4337. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4339. }
  4340. }
  4341. } else {
  4342. if cost_type > 0 {
  4343. if len(execution_frequency) > 0 {
  4344. 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 = ?"
  4345. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4346. } else {
  4347. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4348. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4349. }
  4350. } else {
  4351. if len(execution_frequency) > 0 {
  4352. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4354. } else {
  4355. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4357. }
  4358. }
  4359. }
  4360. } else {
  4361. if execution_state > 0 {
  4362. if cost_type > 0 {
  4363. if len(execution_frequency) > 0 {
  4364. 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 = ?"
  4365. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4366. } else {
  4367. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  4368. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4369. }
  4370. } else {
  4371. if len(execution_frequency) > 0 {
  4372. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4374. } else {
  4375. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4377. }
  4378. }
  4379. } else {
  4380. if cost_type > 0 {
  4381. if len(execution_frequency) > 0 {
  4382. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4383. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4384. } else {
  4385. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4386. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4387. }
  4388. } else {
  4389. if len(execution_frequency) > 0 {
  4390. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4392. } else {
  4393. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4395. }
  4396. }
  4397. }
  4398. }
  4399. } else if patientType == 2 {
  4400. if patient_id > 0 {
  4401. if execution_state > 0 {
  4402. if cost_type > 0 {
  4403. if len(execution_frequency) > 0 {
  4404. 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 = ?"
  4405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4406. } else {
  4407. 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 = ?"
  4408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4409. }
  4410. } else {
  4411. if len(execution_frequency) > 0 {
  4412. 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 = ?"
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4414. } else {
  4415. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4417. }
  4418. }
  4419. } else {
  4420. if cost_type > 0 {
  4421. if len(execution_frequency) > 0 {
  4422. 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 = ?"
  4423. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4424. } else {
  4425. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4426. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4427. }
  4428. } else {
  4429. if len(execution_frequency) > 0 {
  4430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4432. } else {
  4433. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4435. }
  4436. }
  4437. }
  4438. } else {
  4439. if execution_state > 0 {
  4440. if cost_type > 0 {
  4441. if len(execution_frequency) > 0 {
  4442. 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 = ?"
  4443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4444. } else {
  4445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  4446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4447. }
  4448. } else {
  4449. if len(execution_frequency) > 0 {
  4450. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4452. } else {
  4453. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4455. }
  4456. }
  4457. } else {
  4458. if cost_type > 0 {
  4459. if len(execution_frequency) > 0 {
  4460. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4461. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4462. } else {
  4463. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4464. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4465. }
  4466. } else {
  4467. if len(execution_frequency) > 0 {
  4468. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4470. } else {
  4471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4473. }
  4474. }
  4475. }
  4476. }
  4477. }
  4478. } else if adviceType == 3 {
  4479. if patientType == 0 {
  4480. if patient_id > 0 {
  4481. if execution_state > 0 {
  4482. if cost_type > 0 {
  4483. if len(execution_frequency) > 0 {
  4484. 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 =?"
  4485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4486. } else {
  4487. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4489. }
  4490. } else {
  4491. if len(execution_frequency) > 0 {
  4492. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  4493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4494. } else {
  4495. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  4496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4497. }
  4498. }
  4499. } else {
  4500. if cost_type > 0 {
  4501. if len(execution_frequency) > 0 {
  4502. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency =?"
  4503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4504. } else {
  4505. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  4506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4507. }
  4508. } else {
  4509. if len(execution_frequency) > 0 {
  4510. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  4511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4512. } else {
  4513. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  4514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4515. }
  4516. }
  4517. }
  4518. } else {
  4519. if execution_state > 0 {
  4520. if cost_type > 0 {
  4521. if len(execution_frequency) > 0 {
  4522. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ? and execution_frequency =?"
  4523. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4524. } else {
  4525. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  4526. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4527. }
  4528. } else {
  4529. if len(execution_frequency) > 0 {
  4530. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4532. } else {
  4533. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  4534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4535. }
  4536. }
  4537. } else {
  4538. if cost_type > 0 {
  4539. if len(execution_frequency) > 0 {
  4540. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  4541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4542. } else {
  4543. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  4544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4545. }
  4546. } else {
  4547. if len(execution_frequency) > 0 {
  4548. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4550. } else {
  4551. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  4552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4553. }
  4554. }
  4555. }
  4556. }
  4557. } else if patientType == 1 {
  4558. if patient_id > 0 {
  4559. if execution_state > 0 {
  4560. if cost_type > 0 {
  4561. if len(execution_frequency) > 0 {
  4562. 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 = ?"
  4563. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  4564. } else {
  4565. 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 = ?"
  4566. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4567. }
  4568. } else {
  4569. if len(execution_frequency) > 0 {
  4570. 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 = ?"
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4572. } else {
  4573. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4575. }
  4576. }
  4577. } else {
  4578. if cost_type > 0 {
  4579. if len(execution_frequency) > 0 {
  4580. 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 = ?"
  4581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  4582. } else {
  4583. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  4584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4585. }
  4586. } else {
  4587. if len(execution_frequency) > 0 {
  4588. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4590. } else {
  4591. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4593. }
  4594. }
  4595. }
  4596. } else {
  4597. if execution_state > 0 {
  4598. if cost_type > 0 {
  4599. if len(execution_frequency) > 0 {
  4600. 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 = ?"
  4601. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  4602. } else {
  4603. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  4604. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4605. }
  4606. } else {
  4607. if len(execution_frequency) > 0 {
  4608. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  4609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4610. } else {
  4611. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  4612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4613. }
  4614. }
  4615. } else {
  4616. if cost_type > 0 {
  4617. if len(execution_frequency) > 0 {
  4618. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  4619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4620. } else {
  4621. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  4622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4623. }
  4624. } else {
  4625. if len(execution_frequency) > 0 {
  4626. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  4627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4628. } else {
  4629. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  4630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4631. }
  4632. }
  4633. }
  4634. }
  4635. } else if patientType == 2 {
  4636. if patient_id > 0 {
  4637. if execution_state > 0 {
  4638. if cost_type > 0 {
  4639. if len(execution_frequency) > 0 {
  4640. 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 = ?"
  4641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4642. } else {
  4643. 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 = ?"
  4644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4645. }
  4646. } else {
  4647. if len(execution_frequency) > 0 {
  4648. 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 = ?"
  4649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4650. } else {
  4651. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4653. }
  4654. }
  4655. } else {
  4656. if cost_type > 0 {
  4657. if len(execution_frequency) > 0 {
  4658. 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 = ?"
  4659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4660. } else {
  4661. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  4662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4663. }
  4664. } else {
  4665. if len(execution_frequency) > 0 {
  4666. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4668. } else {
  4669. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  4670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4671. }
  4672. }
  4673. }
  4674. } else {
  4675. if execution_state > 0 {
  4676. if cost_type > 0 {
  4677. if len(execution_frequency) > 0 {
  4678. 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 = ?"
  4679. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4680. } else {
  4681. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  4682. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4683. }
  4684. } else {
  4685. if len(execution_frequency) > 0 {
  4686. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  4687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4688. } else {
  4689. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  4690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4691. }
  4692. }
  4693. } else {
  4694. if cost_type > 0 {
  4695. if len(execution_frequency) > 0 {
  4696. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  4697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4698. } else {
  4699. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  4700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4701. }
  4702. } else {
  4703. if len(execution_frequency) > 0 {
  4704. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  4705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4706. } else {
  4707. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  4708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4709. }
  4710. }
  4711. }
  4712. }
  4713. }
  4714. } else if adviceType == 2 && len(deliverWay) > 0 {
  4715. if patientType == 0 {
  4716. if patient_id > 0 {
  4717. if execution_state > 0 {
  4718. if cost_type > 0 {
  4719. if len(execution_frequency) > 0 {
  4720. 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 = ?"
  4721. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4722. } else {
  4723. 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 = ?"
  4724. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4725. }
  4726. } else {
  4727. if len(execution_frequency) > 0 {
  4728. 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 = ?"
  4729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4730. } else {
  4731. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  4732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4733. }
  4734. }
  4735. } else {
  4736. if cost_type > 0 {
  4737. if len(execution_frequency) > 0 {
  4738. 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 = ?"
  4739. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4740. } else {
  4741. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  4742. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4743. }
  4744. } else {
  4745. if len(execution_frequency) > 0 {
  4746. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  4747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4748. } else {
  4749. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  4750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4751. }
  4752. }
  4753. }
  4754. } else {
  4755. if execution_state > 0 {
  4756. if cost_type > 0 {
  4757. if len(execution_frequency) > 0 {
  4758. 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 = ?"
  4759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4760. } else {
  4761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  4762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4763. }
  4764. } else {
  4765. if len(execution_frequency) > 0 {
  4766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4768. } else {
  4769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  4770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4771. }
  4772. }
  4773. } else {
  4774. if cost_type > 0 {
  4775. if len(execution_frequency) > 0 {
  4776. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ? and execution_frequency = ?"
  4777. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  4778. } else {
  4779. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  4780. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4781. }
  4782. } else {
  4783. if len(execution_frequency) > 0 {
  4784. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  4785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  4786. } else {
  4787. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  4788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4789. }
  4790. }
  4791. }
  4792. }
  4793. } else if patientType == 1 {
  4794. if patient_id > 0 {
  4795. if execution_state > 0 {
  4796. if cost_type > 0 {
  4797. if len(execution_frequency) > 0 {
  4798. 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 = ?"
  4799. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4800. } else {
  4801. 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 = ?"
  4802. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  4803. }
  4804. } else {
  4805. if len(execution_frequency) > 0 {
  4806. 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 = ?"
  4807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  4808. } else {
  4809. 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 = ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  4811. }
  4812. }
  4813. } else {
  4814. if cost_type > 0 {
  4815. if len(execution_frequency) > 0 {
  4816. 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 = ?"
  4817. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, execution_frequency)
  4818. } else {
  4819. 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 = ?"
  4820. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  4821. }
  4822. } else {
  4823. if len(execution_frequency) > 0 {
  4824. 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 = ?"
  4825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  4826. } else {
  4827. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  4828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  4829. }
  4830. }
  4831. }
  4832. } else {
  4833. if execution_state > 0 {
  4834. if cost_type > 0 {
  4835. if len(execution_frequency) > 0 {
  4836. 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 = ?"
  4837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, execution_frequency)
  4838. } else {
  4839. 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 = ?"
  4840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  4841. }
  4842. } else {
  4843. if len(execution_frequency) > 0 {
  4844. 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 = ?"
  4845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  4846. } else {
  4847. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  4848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  4849. }
  4850. }
  4851. } else {
  4852. if cost_type > 0 {
  4853. if len(execution_frequency) > 0 {
  4854. 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 = ?"
  4855. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, execution_frequency)
  4856. } else {
  4857. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  4858. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  4859. }
  4860. } else {
  4861. if len(execution_frequency) > 0 {
  4862. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  4864. } else {
  4865. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  4867. }
  4868. }
  4869. }
  4870. }
  4871. } else if patientType == 2 {
  4872. if patient_id > 0 {
  4873. if execution_state > 0 {
  4874. if cost_type > 0 {
  4875. if len(execution_frequency) > 0 {
  4876. 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 = ?"
  4877. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, execution_frequency)
  4878. } else {
  4879. 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 = ?"
  4880. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4881. }
  4882. } else {
  4883. if len(execution_frequency) > 0 {
  4884. 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 = ?"
  4885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4886. } else {
  4887. 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 = ?"
  4888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4889. }
  4890. }
  4891. } else {
  4892. if cost_type > 0 {
  4893. if len(execution_frequency) > 0 {
  4894. 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 = ?"
  4895. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, execution_frequency)
  4896. } else {
  4897. 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 = ?"
  4898. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4899. }
  4900. } else {
  4901. if len(execution_frequency) > 0 {
  4902. 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 = ?"
  4903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4904. } else {
  4905. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  4906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4907. }
  4908. }
  4909. }
  4910. } else {
  4911. if execution_state > 0 {
  4912. if cost_type > 0 {
  4913. if len(execution_frequency) > 0 {
  4914. 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 = ?"
  4915. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, execution_frequency)
  4916. } else {
  4917. 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 = ?"
  4918. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4919. }
  4920. } else {
  4921. if len(execution_frequency) > 0 {
  4922. 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 = ?"
  4923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4924. } else {
  4925. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  4926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4927. }
  4928. }
  4929. } else {
  4930. if cost_type > 0 {
  4931. if len(execution_frequency) > 0 {
  4932. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4933. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4934. } else {
  4935. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4936. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4937. }
  4938. } else {
  4939. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  4940. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4941. }
  4942. }
  4943. }
  4944. }
  4945. } else if adviceType == 2 && len(deliverWay) <= 0 {
  4946. fmt.Println("寄哪里233223322323233232", patientType)
  4947. fmt.Println("patient_id", patient_id)
  4948. fmt.Println("execution_state000000", execution_state)
  4949. fmt.Println("cost_type", cost_type)
  4950. fmt.Println("len23323232", len(execution_frequency))
  4951. if patientType == 0 {
  4952. if patient_id > 0 {
  4953. if execution_state > 0 {
  4954. if cost_type > 0 {
  4955. if len(execution_frequency) > 0 {
  4956. 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 = ?"
  4957. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  4958. } else {
  4959. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  4960. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4961. }
  4962. } else {
  4963. if len(execution_frequency) > 0 {
  4964. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4966. } else {
  4967. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  4968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4969. }
  4970. }
  4971. } else {
  4972. if cost_type > 0 {
  4973. if len(execution_frequency) > 0 {
  4974. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ? and execution_frequency = ?"
  4975. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4976. } else {
  4977. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  4978. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4979. }
  4980. } else {
  4981. if len(execution_frequency) > 0 {
  4982. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4984. } else {
  4985. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  4986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4987. }
  4988. }
  4989. }
  4990. } else {
  4991. if execution_state > 0 {
  4992. if cost_type > 0 {
  4993. if len(execution_frequency) > 0 {
  4994. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  4995. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4996. } else {
  4997. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  4998. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4999. }
  5000. } else {
  5001. if len(execution_frequency) > 0 {
  5002. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  5003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5004. } else {
  5005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5007. }
  5008. }
  5009. } else {
  5010. if cost_type > 0 {
  5011. if len(execution_frequency) > 0 {
  5012. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  5013. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5014. }
  5015. } else {
  5016. if len(execution_frequency) > 0 {
  5017. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  5018. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5019. } else {
  5020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5022. }
  5023. }
  5024. }
  5025. }
  5026. } else if patientType == 1 {
  5027. if patient_id > 0 {
  5028. if execution_state > 0 {
  5029. if cost_type > 0 {
  5030. if len(execution_frequency) > 0 {
  5031. 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 = ?"
  5032. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  5033. } else {
  5034. 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 = ?"
  5035. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5036. }
  5037. } else {
  5038. if len(execution_frequency) > 0 {
  5039. 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 = ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5041. } else {
  5042. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5044. }
  5045. }
  5046. } else {
  5047. if cost_type > 0 {
  5048. if len(execution_frequency) > 0 {
  5049. 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 = ?"
  5050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, execution_frequency)
  5051. } else {
  5052. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5054. }
  5055. } else {
  5056. if len(execution_frequency) > 0 {
  5057. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5059. } else {
  5060. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5062. }
  5063. }
  5064. }
  5065. } else {
  5066. if execution_state > 0 {
  5067. if cost_type > 0 {
  5068. if len(execution_frequency) > 0 {
  5069. 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 = ?"
  5070. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, execution_frequency)
  5071. } else {
  5072. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5073. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5074. }
  5075. } else {
  5076. if len(execution_frequency) > 0 {
  5077. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  5078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5079. } else {
  5080. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5082. }
  5083. }
  5084. } else {
  5085. if cost_type > 0 {
  5086. if len(execution_frequency) > 0 {
  5087. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  5088. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5089. } else {
  5090. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5092. }
  5093. } else {
  5094. if len(execution_frequency) > 0 {
  5095. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  5096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5097. } else {
  5098. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5100. }
  5101. }
  5102. }
  5103. }
  5104. } else if patientType == 2 {
  5105. if patient_id > 0 {
  5106. if execution_state > 0 {
  5107. if cost_type > 0 {
  5108. if len(execution_frequency) > 0 {
  5109. 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=?"
  5110. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, execution_frequency)
  5111. } else {
  5112. 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 = ?"
  5113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5114. }
  5115. } else {
  5116. if len(execution_frequency) > 0 {
  5117. 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=?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5119. } else {
  5120. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5122. }
  5123. }
  5124. } else {
  5125. if cost_type > 0 {
  5126. if len(execution_frequency) > 0 {
  5127. 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=?"
  5128. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  5129. } else {
  5130. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5131. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5132. }
  5133. } else {
  5134. if len(execution_frequency) > 0 {
  5135. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  5136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5137. } else {
  5138. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5140. }
  5141. }
  5142. }
  5143. } else {
  5144. if execution_state > 0 {
  5145. if cost_type > 0 {
  5146. if len(execution_frequency) > 0 {
  5147. 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 = ?"
  5148. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5149. } else {
  5150. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5151. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5152. }
  5153. } else {
  5154. if len(execution_frequency) > 0 {
  5155. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5157. } else {
  5158. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5160. }
  5161. }
  5162. } else {
  5163. if cost_type > 0 {
  5164. if len(execution_frequency) > 0 {
  5165. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  5166. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5167. } else {
  5168. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5170. }
  5171. } else {
  5172. if len(execution_frequency) > 0 {
  5173. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  5174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5175. } else {
  5176. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5178. }
  5179. }
  5180. }
  5181. }
  5182. }
  5183. }
  5184. db := readDb.Table("xt_schedule")
  5185. if scheduleType > 0 {
  5186. db = db.Where("schedule_type = ?", scheduleType)
  5187. }
  5188. if partitonType > 0 {
  5189. db = db.Where("partition_id = ?", partitonType)
  5190. }
  5191. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5192. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5193. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5194. }).
  5195. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5196. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5197. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5198. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5199. Preload("DoctorAdvices", adviceCondition...).
  5200. Where("status = 1 AND user_org_id = ?", orgID)
  5201. if scheduleDate != 0 {
  5202. db = db.Where("schedule_date = ?", scheduleDate)
  5203. }
  5204. err := db.Find(&vms).Error
  5205. return vms, err
  5206. }
  5207. 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) {
  5208. var vms []*MScheduleDoctorAdviceVM
  5209. adviceWhere := ""
  5210. adviceCondition := []interface{}{}
  5211. if adviceType == 0 {
  5212. if patientType == 0 {
  5213. if patient_id > 0 {
  5214. if execution_state > 0 {
  5215. if cost_type > 0 {
  5216. 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 = ?"
  5217. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5218. } else {
  5219. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  5220. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5221. }
  5222. } else {
  5223. if cost_type > 0 {
  5224. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  5225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5226. } else {
  5227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5229. }
  5230. }
  5231. } else {
  5232. if execution_state > 0 {
  5233. if cost_type > 0 {
  5234. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and is_settle = ?"
  5235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5236. } else {
  5237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  5238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5239. }
  5240. } else {
  5241. if cost_type > 0 {
  5242. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  5243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5244. } else {
  5245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  5246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5247. }
  5248. }
  5249. }
  5250. } else if patientType == 1 {
  5251. if patient_id > 0 {
  5252. if execution_state > 0 {
  5253. if cost_type > 0 {
  5254. 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 = ?"
  5255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5256. } else {
  5257. 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= ?"
  5258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5259. }
  5260. } else {
  5261. if cost_type > 0 {
  5262. 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=?"
  5263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5264. } else {
  5265. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5267. }
  5268. }
  5269. } else {
  5270. if execution_state > 0 {
  5271. if cost_type > 0 {
  5272. 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=?"
  5273. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5274. } else {
  5275. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  5276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5277. }
  5278. } else {
  5279. if cost_type > 0 {
  5280. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  5281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5282. } else {
  5283. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  5284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5285. }
  5286. }
  5287. }
  5288. } else if patientType == 2 {
  5289. if patient_id > 0 {
  5290. if execution_state > 0 {
  5291. if cost_type > 0 {
  5292. 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=?"
  5293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5294. } else {
  5295. 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 = ?"
  5296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5297. }
  5298. } else {
  5299. if cost_type > 0 {
  5300. 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=?"
  5301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5302. } else {
  5303. 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 = ?)"
  5304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5305. }
  5306. }
  5307. } else {
  5308. if execution_state > 0 {
  5309. if cost_type > 0 {
  5310. 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=?"
  5311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5312. } else {
  5313. 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 = ?"
  5314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5315. }
  5316. } else {
  5317. if cost_type > 0 {
  5318. 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 = ?"
  5319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5320. } else {
  5321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  5322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5323. }
  5324. }
  5325. }
  5326. }
  5327. } else if adviceType == 1 {
  5328. if patientType == 0 {
  5329. if patient_id > 0 {
  5330. if execution_state > 0 {
  5331. if cost_type > 0 {
  5332. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5334. } else {
  5335. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  5336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5337. }
  5338. } else {
  5339. if cost_type > 0 {
  5340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  5341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5342. } else {
  5343. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  5344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5345. }
  5346. }
  5347. } else {
  5348. if execution_state > 0 {
  5349. if cost_type > 0 {
  5350. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  5351. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5352. } else {
  5353. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  5354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5355. }
  5356. } else {
  5357. if cost_type > 0 {
  5358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  5359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5360. } else {
  5361. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  5362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5363. }
  5364. }
  5365. }
  5366. } else if patientType == 1 {
  5367. if patient_id > 0 {
  5368. if execution_state > 0 {
  5369. if cost_type > 0 {
  5370. 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 = ?"
  5371. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5372. } else {
  5373. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5374. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5375. }
  5376. } else {
  5377. if cost_type > 0 {
  5378. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5380. } else {
  5381. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  5382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5383. }
  5384. }
  5385. } else {
  5386. if execution_state > 0 {
  5387. if cost_type > 0 {
  5388. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  5389. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5390. } else {
  5391. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  5392. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5393. }
  5394. } else {
  5395. if cost_type > 0 {
  5396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  5397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5398. } else {
  5399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  5400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5401. }
  5402. }
  5403. }
  5404. } else if patientType == 2 {
  5405. if patient_id > 0 {
  5406. if execution_state > 0 {
  5407. if cost_type > 0 {
  5408. 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 = ?"
  5409. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5410. } else {
  5411. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5412. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5413. }
  5414. } else {
  5415. if cost_type > 0 {
  5416. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5418. } else {
  5419. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5421. }
  5422. }
  5423. } else {
  5424. if execution_state > 0 {
  5425. if cost_type > 0 {
  5426. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5427. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5428. } else {
  5429. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5430. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5431. }
  5432. } else {
  5433. if cost_type > 0 {
  5434. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5436. } else {
  5437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5439. }
  5440. }
  5441. }
  5442. }
  5443. } else if adviceType == 3 {
  5444. if patientType == 0 {
  5445. if patient_id > 0 {
  5446. if execution_state > 0 {
  5447. if cost_type > 0 {
  5448. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5449. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5450. } else {
  5451. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5453. }
  5454. } else {
  5455. if cost_type > 0 {
  5456. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5458. } else {
  5459. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5461. }
  5462. }
  5463. } else {
  5464. if execution_state > 0 {
  5465. if cost_type > 0 {
  5466. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5467. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5468. } else {
  5469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5470. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5471. }
  5472. } else {
  5473. if cost_type > 0 {
  5474. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5476. } else {
  5477. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5479. }
  5480. }
  5481. }
  5482. } else if patientType == 1 {
  5483. if patient_id > 0 {
  5484. if execution_state > 0 {
  5485. if cost_type > 0 {
  5486. 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 = ?"
  5487. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5488. } else {
  5489. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5490. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5491. }
  5492. } else {
  5493. if cost_type > 0 {
  5494. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5496. } else {
  5497. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5499. }
  5500. }
  5501. } else {
  5502. if execution_state > 0 {
  5503. if cost_type > 0 {
  5504. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5505. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5506. } else {
  5507. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5508. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5509. }
  5510. } else {
  5511. if cost_type > 0 {
  5512. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5514. } else {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5517. }
  5518. }
  5519. }
  5520. } else if patientType == 2 {
  5521. if patient_id > 0 {
  5522. if execution_state > 0 {
  5523. if cost_type > 0 {
  5524. 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 = ?"
  5525. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5526. } else {
  5527. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5528. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5529. }
  5530. } else {
  5531. if cost_type > 0 {
  5532. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5534. } else {
  5535. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5537. }
  5538. }
  5539. } else {
  5540. if execution_state > 0 {
  5541. if cost_type > 0 {
  5542. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and is_settle = ?"
  5543. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5544. } else {
  5545. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5546. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5547. }
  5548. } else {
  5549. if cost_type > 0 {
  5550. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5552. } else {
  5553. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5555. }
  5556. }
  5557. }
  5558. }
  5559. } else if adviceType == 2 && len(deliverWay) > 0 {
  5560. if patientType == 0 {
  5561. if patient_id > 0 {
  5562. if execution_state > 0 {
  5563. if cost_type > 0 {
  5564. 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 = ?"
  5565. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5566. } else {
  5567. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  5568. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5569. }
  5570. } else {
  5571. if cost_type > 0 {
  5572. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5574. } else {
  5575. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5577. }
  5578. }
  5579. } else {
  5580. if execution_state > 0 {
  5581. if cost_type > 0 {
  5582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5583. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5584. } else {
  5585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5586. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5587. }
  5588. } else {
  5589. if cost_type > 0 {
  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. } else {
  5593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5595. }
  5596. }
  5597. }
  5598. } else if patientType == 1 {
  5599. if patient_id > 0 {
  5600. if execution_state > 0 {
  5601. if cost_type > 0 {
  5602. 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 = ?"
  5603. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  5604. } else {
  5605. 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 = ?"
  5606. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5607. }
  5608. } else {
  5609. if cost_type > 0 {
  5610. 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 = ?"
  5611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5612. } else {
  5613. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5615. }
  5616. }
  5617. } else {
  5618. if execution_state > 0 {
  5619. if cost_type > 0 {
  5620. 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 = ?"
  5621. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  5622. } else {
  5623. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  5624. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5625. }
  5626. } else {
  5627. if cost_type > 0 {
  5628. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5630. } else {
  5631. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5633. }
  5634. }
  5635. }
  5636. } else if patientType == 2 {
  5637. if patient_id > 0 {
  5638. if execution_state > 0 {
  5639. if cost_type > 0 {
  5640. 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 = ?"
  5641. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  5642. } else {
  5643. 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 = ?"
  5644. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5645. }
  5646. } else {
  5647. if cost_type > 0 {
  5648. 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 = ?"
  5649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5650. } else {
  5651. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5653. }
  5654. }
  5655. } else {
  5656. if execution_state > 0 {
  5657. if cost_type > 0 {
  5658. 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 = ?"
  5659. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5660. } else {
  5661. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  5662. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5663. }
  5664. } else {
  5665. if cost_type > 0 {
  5666. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5668. } else {
  5669. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5671. }
  5672. }
  5673. }
  5674. }
  5675. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5676. if patientType == 0 {
  5677. if patient_id > 0 {
  5678. if execution_state > 0 {
  5679. if cost_type > 0 {
  5680. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5681. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5682. } else {
  5683. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5684. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5685. }
  5686. } else {
  5687. if cost_type > 0 {
  5688. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5690. } else {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5693. }
  5694. }
  5695. } else {
  5696. if execution_state > 0 {
  5697. if cost_type > 0 {
  5698. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5699. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5700. } else {
  5701. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5702. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5703. }
  5704. } else {
  5705. if cost_type > 0 {
  5706. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  5707. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5708. } else {
  5709. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5711. }
  5712. }
  5713. }
  5714. } else if patientType == 1 {
  5715. if patient_id > 0 {
  5716. if execution_state > 0 {
  5717. if cost_type > 0 {
  5718. 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 = ?"
  5719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5720. } else {
  5721. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5723. }
  5724. } else {
  5725. if cost_type > 0 {
  5726. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5728. } else {
  5729. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5731. }
  5732. }
  5733. } else {
  5734. if execution_state > 0 {
  5735. if cost_type > 0 {
  5736. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5738. } else {
  5739. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5741. }
  5742. } else {
  5743. if cost_type > 0 {
  5744. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5746. } else {
  5747. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5749. }
  5750. }
  5751. }
  5752. } else if patientType == 2 {
  5753. if patient_id > 0 {
  5754. if execution_state > 0 {
  5755. if cost_type > 0 {
  5756. 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 = ?"
  5757. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5758. } else {
  5759. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5760. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5761. }
  5762. } else {
  5763. if cost_type > 0 {
  5764. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5766. } else {
  5767. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5769. }
  5770. }
  5771. } else {
  5772. if execution_state > 0 {
  5773. if cost_type > 0 {
  5774. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  5775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5776. } else {
  5777. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5779. }
  5780. } else {
  5781. if cost_type > 0 {
  5782. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5784. } else {
  5785. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5787. }
  5788. }
  5789. }
  5790. }
  5791. }
  5792. db := readDb.Table("xt_schedule")
  5793. if scheduleType > 0 {
  5794. db = db.Where("schedule_type = ?", scheduleType)
  5795. }
  5796. if partitonType > 0 {
  5797. db = db.Where("partition_id = ?", partitonType)
  5798. }
  5799. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5800. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5801. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5802. }).
  5803. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5804. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5805. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5806. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5807. Preload("DoctorAdvices", adviceCondition...).
  5808. Where("status = 1 AND user_org_id = ?", orgID)
  5809. if scheduleDate != 0 {
  5810. db = db.Where("schedule_date = ?", scheduleDate)
  5811. }
  5812. err := db.Find(&vms).Error
  5813. return vms, err
  5814. }
  5815. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  5816. order := models.XtDialysisOrder{}
  5817. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  5818. return order, err
  5819. }
  5820. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  5821. order := models.XtPatients{}
  5822. 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
  5823. 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
  5824. return err
  5825. }
  5826. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5827. order := models.BloodDialysisOrderCount{}
  5828. db := XTReadDB().Table("xt_dialysis_order as o")
  5829. 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
  5830. return order, err
  5831. }
  5832. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5833. order := models.BloodDialysisOrderCount{}
  5834. db := XTReadDB().Table("xt_dialysis_order as o")
  5835. 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>=1672502400 and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
  5836. return order, err
  5837. }
  5838. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  5839. order := models.DialysisOrder{}
  5840. 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
  5841. return order, err
  5842. }
  5843. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  5844. information := models.DeviceInformation{}
  5845. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  5846. return err
  5847. }
  5848. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  5849. var record models.DoubleCheck
  5850. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  5851. return record, err
  5852. }
  5853. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  5854. record := models.MonitoringRecord{}
  5855. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  5856. return record, err
  5857. }
  5858. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  5859. record := models.MonitoringRecord{}
  5860. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  5861. return record, err
  5862. }
  5863. 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) {
  5864. var vms []*HisMScheduleDoctorAdviceVM
  5865. if len(deliverWay) > 0 {
  5866. db := readDb.Table("xt_schedule")
  5867. if scheduleType > 0 {
  5868. db = db.Where("schedule_type = ?", scheduleType)
  5869. }
  5870. if partitionType > 0 {
  5871. db = db.Where("partition_id = ?", partitionType)
  5872. }
  5873. if patient_id > 0 {
  5874. if execution_state > 0 {
  5875. if cost_type > 0 {
  5876. if len(execution_frequency) > 0 {
  5877. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5878. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5879. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5880. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5881. 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).
  5882. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5883. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5884. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5885. Where("status = 1 AND user_org_id = ?", orgID)
  5886. if scheduleDate != 0 {
  5887. db = db.Where("schedule_date = ?", scheduleDate)
  5888. }
  5889. err = db.Find(&vms).Error
  5890. } else {
  5891. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5892. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5893. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5894. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5895. 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).
  5896. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5897. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5898. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5899. Where("status = 1 AND user_org_id = ?", orgID)
  5900. if scheduleDate != 0 {
  5901. db = db.Where("schedule_date = ?", scheduleDate)
  5902. }
  5903. err = db.Find(&vms).Error
  5904. }
  5905. } else {
  5906. if len(execution_frequency) > 0 {
  5907. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5908. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5909. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5910. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5911. 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).
  5912. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5913. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5914. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5915. Where("status = 1 AND user_org_id = ?", orgID)
  5916. if scheduleDate != 0 {
  5917. db = db.Where("schedule_date = ?", scheduleDate)
  5918. }
  5919. err = db.Find(&vms).Error
  5920. } else {
  5921. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5922. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5923. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5924. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5925. 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).
  5926. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5927. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5928. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5929. Where("status = 1 AND user_org_id = ?", orgID)
  5930. if scheduleDate != 0 {
  5931. db = db.Where("schedule_date = ?", scheduleDate)
  5932. }
  5933. err = db.Find(&vms).Error
  5934. }
  5935. }
  5936. } else {
  5937. if cost_type > 0 {
  5938. if len(execution_frequency) > 0 {
  5939. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5940. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5941. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5942. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5943. 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).
  5944. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5945. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5946. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5947. Where("status = 1 AND user_org_id = ?", orgID)
  5948. if scheduleDate != 0 {
  5949. db = db.Where("schedule_date = ?", scheduleDate)
  5950. }
  5951. err = db.Find(&vms).Error
  5952. } else {
  5953. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5954. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5955. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5956. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5957. 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).
  5958. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5959. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5960. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5961. Where("status = 1 AND user_org_id = ?", orgID)
  5962. if scheduleDate != 0 {
  5963. db = db.Where("schedule_date = ?", scheduleDate)
  5964. }
  5965. err = db.Find(&vms).Error
  5966. }
  5967. } else {
  5968. if len(execution_frequency) > 0 {
  5969. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5970. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5971. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5972. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5973. 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).
  5974. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5975. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5976. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5977. Where("status = 1 AND user_org_id = ?", orgID)
  5978. if scheduleDate != 0 {
  5979. db = db.Where("schedule_date = ?", scheduleDate)
  5980. }
  5981. err = db.Find(&vms).Error
  5982. } else {
  5983. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5984. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5985. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5986. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5987. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  5988. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5989. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5990. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5991. Where("status = 1 AND user_org_id = ?", orgID)
  5992. if scheduleDate != 0 {
  5993. db = db.Where("schedule_date = ?", scheduleDate)
  5994. }
  5995. err = db.Find(&vms).Error
  5996. }
  5997. }
  5998. }
  5999. } else {
  6000. if execution_state > 0 {
  6001. if cost_type > 0 {
  6002. if len(execution_frequency) > 0 {
  6003. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6004. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6005. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6006. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6007. 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).
  6008. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6009. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6010. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6011. Where("status = 1 AND user_org_id = ?", orgID)
  6012. if scheduleDate != 0 {
  6013. db = db.Where("schedule_date = ?", scheduleDate)
  6014. }
  6015. err = db.Find(&vms).Error
  6016. } else {
  6017. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6018. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6019. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6020. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6021. 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).
  6022. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6023. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6024. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6025. Where("status = 1 AND user_org_id = ?", orgID)
  6026. if scheduleDate != 0 {
  6027. db = db.Where("schedule_date = ?", scheduleDate)
  6028. }
  6029. err = db.Find(&vms).Error
  6030. }
  6031. } else {
  6032. if len(execution_frequency) > 0 {
  6033. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6034. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6035. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6036. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6037. 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).
  6038. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6039. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6040. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6041. Where("status = 1 AND user_org_id = ?", orgID)
  6042. if scheduleDate != 0 {
  6043. db = db.Where("schedule_date = ?", scheduleDate)
  6044. }
  6045. err = db.Find(&vms).Error
  6046. } else {
  6047. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6048. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6049. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6050. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6051. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  6052. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6053. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6054. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6055. Where("status = 1 AND user_org_id = ?", orgID)
  6056. if scheduleDate != 0 {
  6057. db = db.Where("schedule_date = ?", scheduleDate)
  6058. }
  6059. err = db.Find(&vms).Error
  6060. }
  6061. }
  6062. } else {
  6063. if cost_type > 0 {
  6064. if len(execution_frequency) > 0 {
  6065. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6066. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6067. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6068. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6069. 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).
  6070. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6071. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6072. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6073. Where("status = 1 AND user_org_id = ?", orgID)
  6074. if scheduleDate != 0 {
  6075. db = db.Where("schedule_date = ?", scheduleDate)
  6076. }
  6077. err = db.Find(&vms).Error
  6078. } else {
  6079. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6080. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6081. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6082. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6083. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  6084. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6085. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6086. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6087. Where("status = 1 AND user_org_id = ?", orgID)
  6088. if scheduleDate != 0 {
  6089. db = db.Where("schedule_date = ?", scheduleDate)
  6090. }
  6091. err = db.Find(&vms).Error
  6092. }
  6093. } else {
  6094. if len(execution_frequency) > 0 {
  6095. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6096. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6097. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6098. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6099. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  6100. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6101. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6102. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6103. Where("status = 1 AND user_org_id = ?", orgID)
  6104. if scheduleDate != 0 {
  6105. db = db.Where("schedule_date = ?", scheduleDate)
  6106. }
  6107. err = db.Find(&vms).Error
  6108. } else {
  6109. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6110. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6111. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6112. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6113. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  6114. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6115. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6116. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6117. Where("status = 1 AND user_org_id = ?", orgID)
  6118. if scheduleDate != 0 {
  6119. db = db.Where("schedule_date = ?", scheduleDate)
  6120. }
  6121. err = db.Find(&vms).Error
  6122. }
  6123. }
  6124. }
  6125. }
  6126. } else {
  6127. db := readDb.Table("xt_schedule")
  6128. if scheduleType > 0 {
  6129. db = db.Where("schedule_type = ?", scheduleType)
  6130. }
  6131. if partitionType > 0 {
  6132. db = db.Where("partition_id = ?", partitionType)
  6133. }
  6134. if patient_id > 0 {
  6135. if execution_state > 0 {
  6136. if cost_type > 0 {
  6137. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6138. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6139. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6140. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6141. 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).
  6142. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6143. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6144. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6145. Where("status = 1 AND user_org_id = ?", orgID)
  6146. if scheduleDate != 0 {
  6147. db = db.Where("schedule_date = ?", scheduleDate)
  6148. }
  6149. err = db.Find(&vms).Error
  6150. } else {
  6151. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6152. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6153. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6154. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6155. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  6156. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6157. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6158. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6159. Where("status = 1 AND user_org_id = ?", orgID)
  6160. if scheduleDate != 0 {
  6161. db = db.Where("schedule_date = ?", scheduleDate)
  6162. }
  6163. err = db.Find(&vms).Error
  6164. }
  6165. } else {
  6166. if cost_type > 0 {
  6167. if len(execution_frequency) > 0 {
  6168. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6169. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6170. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6171. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6172. 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).
  6173. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6174. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6175. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6176. Where("status = 1 AND user_org_id = ?", orgID)
  6177. if scheduleDate != 0 {
  6178. db = db.Where("schedule_date = ?", scheduleDate)
  6179. }
  6180. err = db.Find(&vms).Error
  6181. } else {
  6182. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6183. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6184. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6185. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6186. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  6187. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6188. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6189. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6190. Where("status = 1 AND user_org_id = ?", orgID)
  6191. if scheduleDate != 0 {
  6192. db = db.Where("schedule_date = ?", scheduleDate)
  6193. }
  6194. err = db.Find(&vms).Error
  6195. }
  6196. } else {
  6197. if len(execution_frequency) > 0 {
  6198. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6199. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6200. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6201. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6202. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  6203. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6204. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6205. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6206. Where("status = 1 AND user_org_id = ?", orgID)
  6207. if scheduleDate != 0 {
  6208. db = db.Where("schedule_date = ?", scheduleDate)
  6209. }
  6210. err = db.Find(&vms).Error
  6211. } else {
  6212. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6213. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6214. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6215. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6216. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6217. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6218. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6219. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6220. Where("status = 1 AND user_org_id = ?", orgID)
  6221. if scheduleDate != 0 {
  6222. db = db.Where("schedule_date = ?", scheduleDate)
  6223. }
  6224. err = db.Find(&vms).Error
  6225. }
  6226. }
  6227. }
  6228. } else {
  6229. if execution_state > 0 {
  6230. if cost_type > 0 {
  6231. if len(execution_frequency) > 0 {
  6232. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6233. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6234. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6235. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6236. 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).
  6237. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6238. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6239. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6240. Where("status = 1 AND user_org_id = ?", orgID)
  6241. if scheduleDate != 0 {
  6242. db = db.Where("schedule_date = ?", scheduleDate)
  6243. }
  6244. err = db.Find(&vms).Error
  6245. } else {
  6246. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6247. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6248. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6249. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6250. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  6251. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6252. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6253. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6254. Where("status = 1 AND user_org_id = ?", orgID)
  6255. if scheduleDate != 0 {
  6256. db = db.Where("schedule_date = ?", scheduleDate)
  6257. }
  6258. err = db.Find(&vms).Error
  6259. }
  6260. } else {
  6261. if len(execution_frequency) > 0 {
  6262. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6263. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6264. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6265. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6266. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  6267. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6268. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6269. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6270. Where("status = 1 AND user_org_id = ?", orgID)
  6271. if scheduleDate != 0 {
  6272. db = db.Where("schedule_date = ?", scheduleDate)
  6273. }
  6274. err = db.Find(&vms).Error
  6275. } else {
  6276. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6277. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6278. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6279. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6280. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  6281. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6282. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6283. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6284. Where("status = 1 AND user_org_id = ?", orgID)
  6285. if scheduleDate != 0 {
  6286. db = db.Where("schedule_date = ?", scheduleDate)
  6287. }
  6288. err = db.Find(&vms).Error
  6289. }
  6290. }
  6291. } else {
  6292. if cost_type > 0 {
  6293. if len(execution_frequency) > 0 {
  6294. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6295. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6296. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6297. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6298. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  6299. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6300. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6301. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6302. Where("status = 1 AND user_org_id = ?", orgID)
  6303. if scheduleDate != 0 {
  6304. db = db.Where("schedule_date = ?", scheduleDate)
  6305. }
  6306. err = db.Find(&vms).Error
  6307. } else {
  6308. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6309. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6310. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6311. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6312. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  6313. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6314. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6315. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6316. Where("status = 1 AND user_org_id = ?", orgID)
  6317. if scheduleDate != 0 {
  6318. db = db.Where("schedule_date = ?", scheduleDate)
  6319. }
  6320. err = db.Find(&vms).Error
  6321. }
  6322. } else {
  6323. if len(execution_frequency) > 0 {
  6324. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6325. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6326. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6327. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6328. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  6329. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6330. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6331. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6332. Where("status = 1 AND user_org_id = ?", orgID)
  6333. if scheduleDate != 0 {
  6334. db = db.Where("schedule_date = ?", scheduleDate)
  6335. }
  6336. err = db.Find(&vms).Error
  6337. } else {
  6338. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6339. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6340. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6341. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6342. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  6343. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6344. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6345. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6346. Where("status = 1 AND user_org_id = ?", orgID)
  6347. if scheduleDate != 0 {
  6348. db = db.Where("schedule_date = ?", scheduleDate)
  6349. }
  6350. err = db.Find(&vms).Error
  6351. }
  6352. }
  6353. }
  6354. }
  6355. }
  6356. return vms, err
  6357. }
  6358. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  6359. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  6360. return weight, err
  6361. }
  6362. 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) {
  6363. var vms []*MScheduleDoctorAdviceVM
  6364. adviceWhere := ""
  6365. adviceCondition := []interface{}{}
  6366. if adviceType == 1 {
  6367. if patientType == 0 {
  6368. if patient_id > 0 {
  6369. if execution_state > 0 {
  6370. if cost_type > 0 {
  6371. if len(execution_frequency) > 0 {
  6372. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6373. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  6374. } else {
  6375. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
  6376. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  6377. }
  6378. } else {
  6379. if len(execution_frequency) > 0 {
  6380. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6381. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  6382. } else {
  6383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ?"
  6384. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  6385. }
  6386. }
  6387. } else {
  6388. if cost_type > 0 {
  6389. if len(execution_frequency) > 0 {
  6390. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6391. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  6392. } else {
  6393. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and is_settle = ? "
  6394. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  6395. }
  6396. } else {
  6397. if len(execution_frequency) > 0 {
  6398. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
  6399. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  6400. } else {
  6401. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
  6402. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  6403. }
  6404. }
  6405. }
  6406. } else {
  6407. if execution_state > 0 {
  6408. if cost_type > 0 {
  6409. if len(execution_frequency) > 0 {
  6410. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6411. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  6412. } else {
  6413. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and is_settle = ?"
  6414. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  6415. }
  6416. } else {
  6417. if len(execution_frequency) > 0 {
  6418. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ? and execution_frequency = ?"
  6419. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  6420. } else {
  6421. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and execution_state = ?"
  6422. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  6423. }
  6424. }
  6425. } else {
  6426. if cost_type > 0 {
  6427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and is_settle = ? "
  6428. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  6429. } else {
  6430. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 "
  6431. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  6432. }
  6433. }
  6434. }
  6435. } else if patientType == 1 {
  6436. if patient_id > 0 {
  6437. if execution_state > 0 {
  6438. if cost_type > 0 {
  6439. if len(execution_frequency) > 0 {
  6440. 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 = ?"
  6441. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
  6442. } else {
  6443. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  6444. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
  6445. }
  6446. } else {
  6447. if len(execution_frequency) > 0 {
  6448. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6449. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
  6450. } else {
  6451. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  6452. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
  6453. }
  6454. }
  6455. } else {
  6456. if cost_type > 0 {
  6457. if len(execution_frequency) > 0 {
  6458. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
  6459. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
  6460. } else {
  6461. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  6462. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
  6463. }
  6464. } else {
  6465. if len(execution_frequency) > 0 {
  6466. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  6467. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
  6468. } else {
  6469. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
  6470. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
  6471. }
  6472. }
  6473. }
  6474. } else {
  6475. if execution_state > 0 {
  6476. if cost_type > 0 {
  6477. if len(execution_frequency) > 0 {
  6478. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
  6479. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
  6480. } else {
  6481. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?"
  6482. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
  6483. }
  6484. } else {
  6485. if len(execution_frequency) > 0 {
  6486. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  6487. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
  6488. } else {
  6489. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=?"
  6490. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
  6491. }
  6492. }
  6493. } else {
  6494. if cost_type > 0 {
  6495. if len(execution_frequency) > 0 {
  6496. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? and execution_frequency = ?"
  6497. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
  6498. } else {
  6499. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and is_settle = ? "
  6500. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
  6501. }
  6502. } else {
  6503. if len(execution_frequency) > 0 {
  6504. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_frequency = ?"
  6505. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
  6506. } else {
  6507. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
  6508. adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
  6509. }
  6510. }
  6511. }
  6512. }
  6513. } else if patientType == 2 {
  6514. if patient_id > 0 {
  6515. if execution_state > 0 {
  6516. if cost_type > 0 {
  6517. if len(execution_frequency) > 0 {
  6518. 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 = ?"
  6519. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
  6520. } else {
  6521. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
  6522. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
  6523. }
  6524. } else {
  6525. if len(execution_frequency) > 0 {
  6526. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
  6527. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
  6528. } else {
  6529. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  6530. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
  6531. }
  6532. }
  6533. } else {
  6534. if cost_type > 0 {
  6535. if len(execution_frequency) > 0 {
  6536. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
  6537. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
  6538. } else {
  6539. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  6540. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
  6541. }
  6542. } else {
  6543. if len(execution_frequency) > 0 {
  6544. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  6545. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
  6546. } else {
  6547. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
  6548. adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
  6549. }
  6550. }
  6551. }
  6552. } else {
  6553. if execution_state > 0 {
  6554. if cost_type > 0 {
  6555. if len(execution_frequency) > 0 {
  6556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
  6557. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
  6558. } else {
  6559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
  6560. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
  6561. }
  6562. } else {
  6563. if len(execution_frequency) > 0 {
  6564. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  6565. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
  6566. } else {
  6567. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ?"
  6568. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
  6569. }
  6570. }
  6571. } else {
  6572. if cost_type > 0 {
  6573. if len(execution_frequency) > 0 {
  6574. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
  6575. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
  6576. } else {
  6577. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ?"
  6578. adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
  6579. }
  6580. } else {
  6581. if len(execution_frequency) > 0 {
  6582. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
  6583. adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
  6584. } else {
  6585. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0"
  6586. adviceCondition = append(adviceCondition, adviceWhere, orgID)
  6587. }
  6588. }
  6589. }
  6590. }
  6591. }
  6592. }
  6593. db := readDb.Table("xt_schedule")
  6594. if scheduleType > 0 {
  6595. db = db.Where("schedule_type = ?", scheduleType)
  6596. }
  6597. if partitonType > 0 {
  6598. db = db.Where("partition_id = ?", partitonType)
  6599. }
  6600. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6601. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6602. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6603. }).
  6604. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6605. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6606. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6607. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6608. Preload("DoctorAdvices", adviceCondition...).
  6609. Where("status = 1 AND user_org_id = ?", orgID)
  6610. if scheduleDate != 0 {
  6611. db = db.Where("schedule_date = ?", scheduleDate)
  6612. }
  6613. err := db.Find(&vms).Error
  6614. return vms, err
  6615. }