mobile_dialysis_service.go 377KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246
  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. if err != nil {
  2397. if err == gorm.ErrRecordNotFound {
  2398. return nil, nil
  2399. } else {
  2400. return nil, err
  2401. }
  2402. }
  2403. return &record, nil
  2404. }
  2405. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2406. var record models.DialysisSolution
  2407. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2408. if err != nil {
  2409. if err == gorm.ErrRecordNotFound {
  2410. return nil, nil
  2411. } else {
  2412. return nil, err
  2413. }
  2414. }
  2415. return &record, nil
  2416. }
  2417. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2418. var record models.DialysisPrescription
  2419. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2420. if err != nil {
  2421. if err == gorm.ErrRecordNotFound {
  2422. return nil, nil
  2423. } else {
  2424. return nil, err
  2425. }
  2426. }
  2427. return &record, nil
  2428. }
  2429. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2430. var record models.SgjPatientDryweight
  2431. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2432. if err != nil {
  2433. if err == gorm.ErrRecordNotFound {
  2434. return nil, nil
  2435. } else {
  2436. return nil, err
  2437. }
  2438. }
  2439. return &record, nil
  2440. }
  2441. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2442. var record models.SystemPrescription
  2443. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2444. if err != nil {
  2445. if err == gorm.ErrRecordNotFound {
  2446. return nil, nil
  2447. } else {
  2448. return nil, err
  2449. }
  2450. }
  2451. return &record, nil
  2452. }
  2453. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2454. var record models.SystemPrescription
  2455. redis := RedisClient()
  2456. defer redis.Close()
  2457. // cur_date := time.Now().Format("2006-01-02")
  2458. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2459. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2460. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2461. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2462. if err != nil {
  2463. if err == gorm.ErrRecordNotFound {
  2464. if record.ID <= 0 {
  2465. redis.Set(key, "null", time.Second*60*60*18)
  2466. }
  2467. return nil, nil
  2468. } else {
  2469. return nil, err
  2470. }
  2471. } else {
  2472. if record.ID > 0 {
  2473. //缓存数据
  2474. system_dialysis_prescribe_str, err := json.Marshal(record)
  2475. if err == nil {
  2476. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2477. }
  2478. } else {
  2479. redis.Set(key, "null", time.Second*60*60*18)
  2480. }
  2481. return &record, nil
  2482. }
  2483. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2484. if system_dialysis_prescribe_str == "null" {
  2485. return &record, nil
  2486. } else {
  2487. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2488. return &record, nil
  2489. }
  2490. }
  2491. }
  2492. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2493. var record models.SystemPrescription
  2494. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2495. return record, err
  2496. }
  2497. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2498. var record models.SystemPrescription
  2499. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2500. if err != nil {
  2501. if err == gorm.ErrRecordNotFound {
  2502. return nil, nil
  2503. } else {
  2504. return nil, err
  2505. }
  2506. }
  2507. return &record, nil
  2508. }
  2509. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2510. 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
  2511. return
  2512. }
  2513. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2514. 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
  2515. return
  2516. }
  2517. func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2518. 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
  2519. return
  2520. }
  2521. func GetFirstDateOfMonth(d time.Time) time.Time {
  2522. d = d.AddDate(0, 0, -d.Day()+1)
  2523. return GetZeroTime(d)
  2524. }
  2525. func GetZeroTime(d time.Time) time.Time {
  2526. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2527. }
  2528. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2529. db := XTReadDB().Table("xt_dialysis_order as o")
  2530. 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
  2531. return order, err
  2532. }
  2533. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2534. 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
  2535. return
  2536. }
  2537. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2538. 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
  2539. return
  2540. }
  2541. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2542. 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
  2543. return
  2544. }
  2545. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2546. // 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
  2547. // return
  2548. //}
  2549. //
  2550. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2551. 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
  2552. return
  2553. }
  2554. type GoodsType struct {
  2555. ID int64 `gorm:"column:id" json:"id"`
  2556. TypeName string `gorm:"column:type_name" json:"type_name"`
  2557. Remark string `gorm:"column:remark" json:"remark"`
  2558. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2559. Status int64 `gorm:"column:status" json:"status"`
  2560. Type int64 `gorm:"column:type" json:"type"`
  2561. }
  2562. func (GoodsType) TableName() string {
  2563. return "xt_goods_type"
  2564. }
  2565. type VMGoodInfo struct {
  2566. ID int64 `gorm:"column:id" json:"id"`
  2567. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2568. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2569. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2570. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2571. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2572. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2573. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  2574. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  2575. }
  2576. func (VMGoodInfo) TableName() string {
  2577. return "xt_good_information"
  2578. }
  2579. type AutomaticReduceDetail struct {
  2580. ID int64 `gorm:"column:id" json:"id"`
  2581. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2582. Status int64 `gorm:"column:status" json:"status"`
  2583. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2584. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2585. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2586. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2587. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2588. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2589. Count int64 `gorm:"column:count" json:"count"`
  2590. }
  2591. func (AutomaticReduceDetail) TableName() string {
  2592. return "xt_automatic_reduce_detail"
  2593. }
  2594. type DialysisBeforePrepare struct {
  2595. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2596. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2597. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2598. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2599. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2600. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2601. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2602. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2603. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2604. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2605. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2606. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2607. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2608. }
  2609. func (DialysisBeforePrepare) TableName() string {
  2610. return "dialysis_before_prepare"
  2611. }
  2612. type MDialysisGoodsVM struct {
  2613. ID int64 `gorm:"column:id" json:"id"`
  2614. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2615. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2616. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2617. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2618. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2619. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2620. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2621. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2622. Status int64 `gorm:"column:status" json:"status"`
  2623. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2624. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2625. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2626. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2627. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2628. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2629. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2630. //WarehouseOutInfo []*models.WarehouseOutInfoSeven `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,SysRecordTime" json:"ware_house_out_info"`
  2631. }
  2632. func (MDialysisGoodsVM) TableName() string {
  2633. return "xt_schedule"
  2634. }
  2635. type VMWarehouseOutInfo struct {
  2636. ID int64 `gorm:"column:id" json:"id"`
  2637. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2638. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2639. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2640. Count int64 `gorm:"column:count" json:"count"`
  2641. Price float64 `gorm:"column:price" json:"price"`
  2642. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2643. Status int64 `gorm:"column:status" json:"status"`
  2644. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2645. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2646. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2647. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2648. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2649. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2650. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2651. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2652. }
  2653. func (VMWarehouseOutInfo) TableName() string {
  2654. return "xt_warehouse_out_info"
  2655. }
  2656. type DialysisGoodsDate struct {
  2657. RecordDate int64
  2658. }
  2659. type DialysisGoodsDetailDate struct {
  2660. RecordTime int64
  2661. }
  2662. 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) {
  2663. var vms []*MDialysisGoodsVM
  2664. var total int64
  2665. db := readDb.
  2666. Table("xt_schedule as sch").
  2667. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2668. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2669. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2670. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2671. 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)
  2672. }).
  2673. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2674. 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")
  2675. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2676. if scheduleDate != 0 {
  2677. db = db.Where("schedule_date = ?", scheduleDate)
  2678. }
  2679. if schedule_type != 0 {
  2680. db = db.Where("schedule_type = ?", schedule_type)
  2681. }
  2682. if partition_id != 0 {
  2683. db = db.Where("partition_id = ?", partition_id)
  2684. }
  2685. if patient_id != 0 {
  2686. db = db.Where("patient_id = ?", patient_id)
  2687. }
  2688. err := db.Find(&vms).Error
  2689. return vms, err, total
  2690. }
  2691. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2692. var Id []*DialysisGoodsDetailDate
  2693. 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
  2694. if len(Id) > 0 {
  2695. 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
  2696. }
  2697. return
  2698. }
  2699. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2700. var Id []*DialysisGoodsDate
  2701. 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
  2702. if len(Id) > 0 {
  2703. 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
  2704. }
  2705. return
  2706. }
  2707. func GetAllWarehouseOutSumList(patient_id int64, orgID int64, record_time int64) (info []*models.WarehouseOutInfoSeven, err error) {
  2708. err = XTReadDB().Where("patient_id = ? and org_id = ? and sys_record_time = ? and status = 1", patient_id, orgID, record_time).Find(&info).Error
  2709. return info, err
  2710. }
  2711. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2712. db := readDb.Model(&models.StockInfo{})
  2713. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2714. 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")
  2715. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2716. 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)
  2717. })
  2718. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2719. err = db.Order("ctime desc").Find(&list).Error
  2720. return
  2721. }
  2722. 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) {
  2723. var vms []*MDialysisGoodsVM
  2724. var total int64
  2725. db := readDb.
  2726. Model(&models.Schedule{}).
  2727. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2728. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2729. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2730. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2731. 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)
  2732. }).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2733. 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)
  2734. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2735. if scheduleDate != 0 {
  2736. db = db.Where("schedule_date = ?", scheduleDate)
  2737. }
  2738. if patient_id != 0 {
  2739. db = db.Where("patient_id = ?", patient_id)
  2740. }
  2741. if len(keywords) != 0 {
  2742. keywords = "%" + keywords + "%"
  2743. 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)
  2744. if schedule_type != 0 {
  2745. db = db.Where("schedule_type = ?", schedule_type)
  2746. }
  2747. if partition_id != 0 {
  2748. db = db.Where("partition_id = ?", partition_id)
  2749. }
  2750. if good_type == 1 {
  2751. db = db.Where("patient_id in(?)", ids)
  2752. }
  2753. if good_type == 2 {
  2754. if len(ids) > 0 {
  2755. db = db.Where("patient_id not in(?)", ids)
  2756. }
  2757. }
  2758. } else {
  2759. if schedule_type != 0 {
  2760. db = db.Where("schedule_type = ?", schedule_type)
  2761. }
  2762. if partition_id != 0 {
  2763. db = db.Where("partition_id = ?", partition_id)
  2764. }
  2765. if good_type == 1 {
  2766. db = db.Where("patient_id in(?)", ids)
  2767. }
  2768. if good_type == 2 {
  2769. if len(ids) > 0 {
  2770. db = db.Where("patient_id not in(?)", ids)
  2771. }
  2772. }
  2773. db = db.Count(&total)
  2774. offset := (page - 1) * limit
  2775. db = db.Offset(offset).Limit(limit)
  2776. }
  2777. err := db.Find(&vms).Error
  2778. return vms, err, total
  2779. }
  2780. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2781. var Id []*DialysisGoodsDetailDate
  2782. 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
  2783. if len(Id) > 0 {
  2784. 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
  2785. }
  2786. return
  2787. }
  2788. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2789. var Id []*DialysisGoodsDate
  2790. 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
  2791. if len(Id) > 0 {
  2792. 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
  2793. }
  2794. return
  2795. }
  2796. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2797. evaluation := models.PredialysisEvaluation{}
  2798. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2799. if err == gorm.ErrRecordNotFound {
  2800. return nil, err
  2801. }
  2802. if err != nil {
  2803. return nil, err
  2804. }
  2805. return &evaluation, nil
  2806. }
  2807. func GetAssessmentBeforThrity(orgid int64, patientid int64, recorddate int64) (models.PredialysisEvaluation, error) {
  2808. evaluation := models.PredialysisEvaluation{}
  2809. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2810. return evaluation, err
  2811. }
  2812. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2813. redis := RedisClient()
  2814. defer redis.Close()
  2815. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2816. his_doctor_advice_str, _ := redis.Get(key).Result()
  2817. redis.Set(key, "", time.Second)
  2818. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2819. 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
  2820. if err != nil {
  2821. if err == gorm.ErrRecordNotFound {
  2822. if len(his) <= 0 {
  2823. redis.Set(key, "null", time.Second*60*60*18)
  2824. }
  2825. return his, nil
  2826. } else {
  2827. return his, err
  2828. }
  2829. } else {
  2830. if len(his) > 0 {
  2831. //缓存数据
  2832. his_doctor_advice_str, err := json.Marshal(his)
  2833. if err == nil {
  2834. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2835. }
  2836. } else {
  2837. redis.Set(key, "null", time.Second*60*60*18)
  2838. }
  2839. return his, nil
  2840. }
  2841. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2842. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2843. return his, nil
  2844. }
  2845. }
  2846. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2847. prescription := models.DialysisPrescription{}
  2848. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2849. if err == gorm.ErrRecordNotFound {
  2850. return nil, err
  2851. }
  2852. if err != nil {
  2853. return nil, err
  2854. }
  2855. return &prescription, nil
  2856. }
  2857. func GetLastDialysisPrescriptionByPatientIdTwo(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) {
  2858. prescription := models.DialysisPrescription{}
  2859. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2860. return prescription, err
  2861. }
  2862. type HisMScheduleDoctorAdviceVM struct {
  2863. ID int64 `gorm:"column:id" json:"id"`
  2864. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2865. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2866. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2867. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2868. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2869. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2870. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2871. Status int64 `gorm:"column:status" json:"status"`
  2872. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2873. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2874. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2875. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2876. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2877. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2878. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2879. }
  2880. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2881. return "xt_schedule"
  2882. }
  2883. type HisMScheduleDoctorAdviceVMOne struct {
  2884. ID int64 `gorm:"column:id" json:"id"`
  2885. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2886. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2887. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2888. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2889. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2890. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2891. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2892. Status int64 `gorm:"column:status" json:"status"`
  2893. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2894. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2895. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2896. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2897. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2898. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2899. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  2900. }
  2901. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2902. return "xt_schedule"
  2903. }
  2904. type HisMScheduleProjectVM struct {
  2905. ID int64 `gorm:"column:id" json:"id"`
  2906. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2907. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2908. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2909. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2910. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2911. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2912. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2913. Status int64 `gorm:"column:status" json:"status"`
  2914. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2915. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2916. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2917. Prescription *models.DialysisPrescriptionTwenty `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2918. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2919. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2920. }
  2921. func (HisMScheduleProjectVM) TableName() string {
  2922. return "xt_schedule"
  2923. }
  2924. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2925. config := models.XtHisConfig{}
  2926. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2927. return config, err
  2928. }
  2929. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2930. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2931. if orgid > 0 {
  2932. db = db.Where("x.user_org_id = ?", orgid)
  2933. }
  2934. if patientid > 0 {
  2935. db = db.Where("x.patient_id =?", patientid)
  2936. }
  2937. if recordtime > 0 {
  2938. db = db.Where("x.advice_date = ?", recordtime)
  2939. }
  2940. 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
  2941. return advice, err
  2942. }
  2943. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2944. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2945. if startime > 0 {
  2946. db = db.Where("x.advice_date >= ?", startime)
  2947. }
  2948. if endtime > 0 {
  2949. db = db.Where("x.advice_date<=?", endtime)
  2950. }
  2951. if orgid > 0 {
  2952. db = db.Where("x.user_org_id = ?", orgid)
  2953. }
  2954. if len(deliveway) > 0 {
  2955. db = db.Where("x.delivery_way = ?", deliveway)
  2956. }
  2957. 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
  2958. return advice, err
  2959. }
  2960. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2961. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2962. if startime > 0 {
  2963. db = db.Where("x.advice_date >= ?", startime)
  2964. }
  2965. if endtime > 0 {
  2966. db = db.Where("x.advice_date<=?", endtime)
  2967. }
  2968. if orgid > 0 {
  2969. db = db.Where("x.user_org_id = ?", orgid)
  2970. }
  2971. if len(deliveway) > 0 {
  2972. db = db.Where("x.delivery_way = ?", deliveway)
  2973. }
  2974. 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
  2975. return advice, err
  2976. }
  2977. 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) {
  2978. var vms []*MScheduleDoctorAdviceVM
  2979. adviceWhere := ""
  2980. adviceCondition := []interface{}{}
  2981. if adviceType == 0 {
  2982. if patientType == 0 {
  2983. if patient_id > 0 {
  2984. if execution_state > 0 {
  2985. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  2986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  2987. } else {
  2988. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2989. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2990. }
  2991. } else {
  2992. if execution_state > 0 {
  2993. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  2994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  2995. } else {
  2996. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2997. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2998. }
  2999. }
  3000. } else if patientType == 1 {
  3001. if patient_id > 0 {
  3002. if execution_state > 0 {
  3003. 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= ?"
  3004. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3005. } else {
  3006. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  3007. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3008. }
  3009. } else {
  3010. if execution_state > 0 {
  3011. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  3012. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3013. } else {
  3014. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  3015. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3016. }
  3017. }
  3018. } else if patientType == 2 {
  3019. if patient_id > 0 {
  3020. if execution_state > 0 {
  3021. 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 = ?"
  3022. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3023. } else {
  3024. 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 = ?)"
  3025. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3026. }
  3027. } else {
  3028. if execution_state > 0 {
  3029. 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 = ?"
  3030. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3031. } else {
  3032. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  3033. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3034. }
  3035. }
  3036. }
  3037. } else if adviceType == 1 {
  3038. if patientType == 0 {
  3039. if patient_id > 0 {
  3040. if execution_state > 0 {
  3041. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  3042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3043. } else {
  3044. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  3045. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3046. }
  3047. } else {
  3048. if execution_state > 0 {
  3049. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  3050. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3051. } else {
  3052. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  3053. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3054. }
  3055. }
  3056. } else if patientType == 1 {
  3057. if patient_id > 0 {
  3058. if execution_state > 0 {
  3059. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3061. } else {
  3062. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  3063. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3064. }
  3065. } else {
  3066. if execution_state > 0 {
  3067. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  3068. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3069. } else {
  3070. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  3071. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3072. }
  3073. }
  3074. } else if patientType == 2 {
  3075. if patient_id > 0 {
  3076. if execution_state > 0 {
  3077. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3079. } else {
  3080. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  3081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3082. }
  3083. } else {
  3084. if execution_state > 0 {
  3085. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  3086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3087. } else {
  3088. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  3089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3090. }
  3091. }
  3092. }
  3093. } else if adviceType == 3 {
  3094. if patientType == 0 {
  3095. if patient_id > 0 {
  3096. if execution_state > 0 {
  3097. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  3098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3099. } else {
  3100. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  3101. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3102. }
  3103. } else {
  3104. if execution_state > 0 {
  3105. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  3106. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3107. } else {
  3108. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  3109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3110. }
  3111. }
  3112. } else if patientType == 1 {
  3113. if patient_id > 0 {
  3114. if execution_state > 0 {
  3115. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3117. } else {
  3118. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  3119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3120. }
  3121. } else {
  3122. if execution_state > 0 {
  3123. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  3124. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3125. } else {
  3126. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  3127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3128. }
  3129. }
  3130. } else if patientType == 2 {
  3131. if patient_id > 0 {
  3132. if execution_state > 0 {
  3133. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3134. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3135. } else {
  3136. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  3137. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3138. }
  3139. } else {
  3140. if execution_state > 0 {
  3141. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  3142. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3143. } else {
  3144. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  3145. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3146. }
  3147. }
  3148. }
  3149. } else if adviceType == 2 && len(deliverWay) > 0 {
  3150. if patientType == 0 {
  3151. if patient_id > 0 {
  3152. if execution_state > 0 {
  3153. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  3154. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3155. } else {
  3156. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  3157. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3158. }
  3159. } else {
  3160. if execution_state > 0 {
  3161. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  3162. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3163. } else {
  3164. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  3165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3166. }
  3167. }
  3168. } else if patientType == 1 {
  3169. if patient_id > 0 {
  3170. if execution_state > 0 {
  3171. 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 = ?"
  3172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  3173. } else {
  3174. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  3175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  3176. }
  3177. } else {
  3178. if execution_state > 0 {
  3179. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  3180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  3181. } else {
  3182. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  3183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  3184. }
  3185. }
  3186. } else if patientType == 2 {
  3187. if patient_id > 0 {
  3188. if execution_state > 0 {
  3189. 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 = ?"
  3190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  3191. } else {
  3192. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  3193. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  3194. }
  3195. } else {
  3196. if execution_state > 0 {
  3197. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  3198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  3199. } else {
  3200. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  3201. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  3202. }
  3203. }
  3204. }
  3205. } else if adviceType == 2 && len(deliverWay) <= 0 {
  3206. if patientType == 0 {
  3207. if patient_id > 0 {
  3208. if execution_state > 0 {
  3209. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  3210. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3211. } else {
  3212. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  3213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3214. }
  3215. } else {
  3216. if execution_state > 0 {
  3217. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  3218. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3219. } else {
  3220. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  3221. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3222. }
  3223. }
  3224. } else if patientType == 1 {
  3225. if patient_id > 0 {
  3226. if execution_state > 0 {
  3227. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  3228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  3229. } else {
  3230. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  3231. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  3232. }
  3233. } else {
  3234. if execution_state > 0 {
  3235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  3236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  3237. } else {
  3238. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  3239. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  3240. }
  3241. }
  3242. } else if patientType == 2 {
  3243. if patient_id > 0 {
  3244. if execution_state > 0 {
  3245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  3246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  3247. } else {
  3248. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  3249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  3250. }
  3251. } else {
  3252. if execution_state > 0 {
  3253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  3254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  3255. } else {
  3256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  3257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  3258. }
  3259. }
  3260. }
  3261. }
  3262. db := readDb.Table("xt_schedule")
  3263. if scheduleType > 0 {
  3264. db = db.Where("schedule_type = ?", scheduleType)
  3265. }
  3266. if partitonType > 0 {
  3267. db = db.Where("partition_id = ?", partitonType)
  3268. }
  3269. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3270. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3271. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3272. }).
  3273. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3274. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3275. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3276. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3277. Preload("DoctorAdvices", adviceCondition...).
  3278. Where("status = 1 AND user_org_id = ?", orgID)
  3279. if scheduleDate != 0 {
  3280. db = db.Where("schedule_date = ?", scheduleDate)
  3281. }
  3282. err := db.Find(&vms).Error
  3283. return vms, err
  3284. }
  3285. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64, cost_type int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  3286. var vms []*HisMScheduleDoctorAdviceVM
  3287. if len(deliverWay) > 0 {
  3288. db := readDb.Table("xt_schedule")
  3289. if scheduleType > 0 {
  3290. db = db.Where("schedule_type = ?", scheduleType)
  3291. }
  3292. if partitionType > 0 {
  3293. db = db.Where("partition_id = ?", partitionType)
  3294. }
  3295. if patient_id > 0 {
  3296. if execution_state > 0 {
  3297. if cost_type > 0 {
  3298. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3299. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3300. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3301. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3302. 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).
  3303. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3304. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3305. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3306. Where("status = 1 AND user_org_id = ?", orgID)
  3307. if scheduleDate != 0 {
  3308. db = db.Where("schedule_date = ?", scheduleDate)
  3309. }
  3310. err = db.Find(&vms).Error
  3311. } else {
  3312. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3313. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3314. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3315. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3316. 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).
  3317. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3318. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3319. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3320. Where("status = 1 AND user_org_id = ?", orgID)
  3321. if scheduleDate != 0 {
  3322. db = db.Where("schedule_date = ?", scheduleDate)
  3323. }
  3324. err = db.Find(&vms).Error
  3325. }
  3326. } else {
  3327. if cost_type > 0 {
  3328. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3329. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3330. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3331. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3332. 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).
  3333. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3334. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3335. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3336. Where("status = 1 AND user_org_id = ?", orgID)
  3337. if scheduleDate != 0 {
  3338. db = db.Where("schedule_date = ?", scheduleDate)
  3339. }
  3340. err = db.Find(&vms).Error
  3341. } else {
  3342. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  3343. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3344. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3345. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3346. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  3347. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3348. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3349. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3350. Where("status = 1 AND user_org_id = ?", orgID)
  3351. if scheduleDate != 0 {
  3352. db = db.Where("schedule_date = ?", scheduleDate)
  3353. }
  3354. err = db.Find(&vms).Error
  3355. }
  3356. }
  3357. } else {
  3358. if execution_state > 0 {
  3359. if cost_type > 0 {
  3360. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3361. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3362. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3363. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3364. 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).
  3365. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3366. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3367. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3368. Where("status = 1 AND user_org_id = ?", orgID)
  3369. if scheduleDate != 0 {
  3370. db = db.Where("schedule_date = ?", scheduleDate)
  3371. }
  3372. err = db.Find(&vms).Error
  3373. } else {
  3374. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3375. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3376. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3377. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3378. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  3379. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3380. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3381. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3382. Where("status = 1 AND user_org_id = ?", orgID)
  3383. if scheduleDate != 0 {
  3384. db = db.Where("schedule_date = ?", scheduleDate)
  3385. }
  3386. err = db.Find(&vms).Error
  3387. }
  3388. } else {
  3389. if cost_type > 0 {
  3390. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3391. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3392. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3393. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3394. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  3395. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3396. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3397. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3398. Where("status = 1 AND user_org_id = ?", orgID)
  3399. if scheduleDate != 0 {
  3400. db = db.Where("schedule_date = ?", scheduleDate)
  3401. }
  3402. err = db.Find(&vms).Error
  3403. } else {
  3404. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3405. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3406. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3407. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3408. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  3409. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3410. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3411. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3412. Where("status = 1 AND user_org_id = ?", orgID)
  3413. if scheduleDate != 0 {
  3414. db = db.Where("schedule_date = ?", scheduleDate)
  3415. }
  3416. err = db.Find(&vms).Error
  3417. }
  3418. }
  3419. }
  3420. } else {
  3421. db := readDb.Table("xt_schedule")
  3422. if scheduleType > 0 {
  3423. db = db.Where("schedule_type = ?", scheduleType)
  3424. }
  3425. if partitionType > 0 {
  3426. db = db.Where("partition_id = ?", partitionType)
  3427. }
  3428. if patient_id > 0 {
  3429. if execution_state > 0 {
  3430. if cost_type > 0 {
  3431. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3432. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3433. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3434. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3435. 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).
  3436. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3437. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3438. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3439. Where("status = 1 AND user_org_id = ?", orgID)
  3440. if scheduleDate != 0 {
  3441. db = db.Where("schedule_date = ?", scheduleDate)
  3442. }
  3443. err = db.Find(&vms).Error
  3444. } else {
  3445. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3446. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3447. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3448. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3449. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  3450. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3451. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3452. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3453. Where("status = 1 AND user_org_id = ?", orgID)
  3454. if scheduleDate != 0 {
  3455. db = db.Where("schedule_date = ?", scheduleDate)
  3456. }
  3457. err = db.Find(&vms).Error
  3458. }
  3459. } else {
  3460. if cost_type > 0 {
  3461. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3462. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3463. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3464. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3465. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  3466. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3467. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3468. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3469. Where("status = 1 AND user_org_id = ?", orgID)
  3470. if scheduleDate != 0 {
  3471. db = db.Where("schedule_date = ?", scheduleDate)
  3472. }
  3473. err = db.Find(&vms).Error
  3474. } else {
  3475. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  3476. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3477. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3478. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3479. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3480. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3481. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3482. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3483. Where("status = 1 AND user_org_id = ?", orgID)
  3484. if scheduleDate != 0 {
  3485. db = db.Where("schedule_date = ?", scheduleDate)
  3486. }
  3487. err = db.Find(&vms).Error
  3488. }
  3489. }
  3490. } else {
  3491. if execution_state > 0 {
  3492. if cost_type > 0 {
  3493. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3494. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3495. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3496. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3497. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  3498. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3499. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3500. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3501. Where("status = 1 AND user_org_id = ?", orgID)
  3502. if scheduleDate != 0 {
  3503. db = db.Where("schedule_date = ?", scheduleDate)
  3504. }
  3505. err = db.Find(&vms).Error
  3506. } else {
  3507. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3508. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3509. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3510. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3511. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  3512. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3513. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3514. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3515. Where("status = 1 AND user_org_id = ?", orgID)
  3516. if scheduleDate != 0 {
  3517. db = db.Where("schedule_date = ?", scheduleDate)
  3518. }
  3519. err = db.Find(&vms).Error
  3520. }
  3521. } else {
  3522. if cost_type > 0 {
  3523. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3524. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3525. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3526. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3527. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  3528. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3529. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3530. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3531. Where("status = 1 AND user_org_id = ?", orgID)
  3532. if scheduleDate != 0 {
  3533. db = db.Where("schedule_date = ?", scheduleDate)
  3534. }
  3535. err = db.Find(&vms).Error
  3536. } else {
  3537. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3538. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3539. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3540. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3541. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  3542. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3543. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3544. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  3545. Where("status = 1 AND user_org_id = ?", orgID)
  3546. if scheduleDate != 0 {
  3547. db = db.Where("schedule_date = ?", scheduleDate)
  3548. }
  3549. err = db.Find(&vms).Error
  3550. }
  3551. }
  3552. }
  3553. }
  3554. return vms, err
  3555. }
  3556. func BatchDeleteMonitor(ids []string) (err error) {
  3557. if len(ids) == 1 {
  3558. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3559. } else {
  3560. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3561. }
  3562. return
  3563. }
  3564. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  3565. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  3566. //table := XTReadDB().Table("xt_schedule as s")
  3567. //fmt.Println(table)
  3568. if patientid > 0 {
  3569. db = db.Where("x.patient_id = ?", patientid)
  3570. }
  3571. if startime > 0 {
  3572. db = db.Where("x.dialysis_date>=?", startime)
  3573. }
  3574. if endtime > 0 {
  3575. db = db.Where("x.dialysis_date <= ?", endtime)
  3576. }
  3577. 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
  3578. return order, err
  3579. }
  3580. func BatchDeleteAdvice(ids []string) (err error) {
  3581. if len(ids) == 1 {
  3582. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3583. } else {
  3584. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3585. }
  3586. return
  3587. }
  3588. func BatchDeleteHisAdvice(ids []string) (err error) {
  3589. if len(ids) == 1 {
  3590. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3591. } else {
  3592. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  3593. }
  3594. return
  3595. }
  3596. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3597. detail := models.AutomaticReduceDetail{}
  3598. 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
  3599. return detail, err
  3600. }
  3601. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3602. detail := models.AutomaticReduceDetail{}
  3603. 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
  3604. return err
  3605. }
  3606. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3607. detail := models.DialysisBeforePrepare{}
  3608. 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
  3609. return err
  3610. }
  3611. func BatchAdviceCheck(ids []string, creator int64) error {
  3612. advice := models.XtDoctorAdvice{}
  3613. 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
  3614. return err
  3615. }
  3616. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3617. advice := models.HisDoctorAdviceInfo{}
  3618. 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
  3619. return err
  3620. }
  3621. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3622. advice := models.XtDoctorAdvice{}
  3623. 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
  3624. return err
  3625. }
  3626. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3627. advice := models.HisDoctorAdviceInfo{}
  3628. 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
  3629. return err
  3630. }
  3631. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3632. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3633. return doctor, err
  3634. }
  3635. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3636. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3637. return doctor, err
  3638. }
  3639. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3640. config := models.XtHisProjectConfig{}
  3641. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3642. return config, err
  3643. }
  3644. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3645. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3646. return db.Preload("GoodsType", "status = 1").Where("status = 1 and is_warehouse = 1")
  3647. }).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
  3648. return
  3649. }
  3650. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
  3651. var vms []*HisMScheduleProjectVM
  3652. if patientType == 0 {
  3653. if patient_id > 0 {
  3654. if execution_state == 1 {
  3655. db := readDb.
  3656. Table("xt_schedule").
  3657. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3658. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3659. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3660. }).
  3661. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3662. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3663. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3664. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3665. 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")
  3666. }).
  3667. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3668. 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")
  3669. }).Where("status = 1 AND user_org_id = ?", orgID)
  3670. if scheduleDate != 0 {
  3671. db = db.Where("schedule_date = ?", scheduleDate)
  3672. }
  3673. err = db.Find(&vms).Error
  3674. } else if execution_state == 2 {
  3675. db := readDb.
  3676. Table("xt_schedule").
  3677. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3678. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3679. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3680. }).
  3681. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3682. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3683. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3684. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3685. 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")
  3686. }).
  3687. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3688. 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")
  3689. }).Where("status = 1 AND user_org_id = ?", orgID)
  3690. if scheduleDate != 0 {
  3691. db = db.Where("schedule_date = ?", scheduleDate)
  3692. }
  3693. err = db.Find(&vms).Error
  3694. } else if execution_state == 0 {
  3695. db := readDb.
  3696. Table("xt_schedule").
  3697. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3698. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3699. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3700. }).
  3701. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3702. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3703. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3704. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3705. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3706. }).
  3707. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3708. 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")
  3709. }).Where("status = 1 AND user_org_id = ?", orgID)
  3710. if scheduleDate != 0 {
  3711. db = db.Where("schedule_date = ?", scheduleDate)
  3712. }
  3713. err = db.Find(&vms).Error
  3714. }
  3715. } else {
  3716. if patient_id > 0 {
  3717. if execution_state == 1 {
  3718. db := readDb.
  3719. Table("xt_schedule").
  3720. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3721. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3722. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3723. }).
  3724. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3725. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3726. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3727. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3728. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
  3729. }).
  3730. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3731. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3732. }).Where("status = 1 AND user_org_id = ?", orgID)
  3733. if scheduleDate != 0 {
  3734. db = db.Where("schedule_date = ?", scheduleDate)
  3735. }
  3736. err = db.Find(&vms).Error
  3737. } else if execution_state == 2 {
  3738. db := readDb.
  3739. Table("xt_schedule").
  3740. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3741. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3742. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3743. }).
  3744. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3745. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3746. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3747. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3748. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3749. }).
  3750. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3751. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3752. }).Where("status = 1 AND user_org_id = ?", orgID)
  3753. if scheduleDate != 0 {
  3754. db = db.Where("schedule_date = ?", scheduleDate)
  3755. }
  3756. err = db.Find(&vms).Error
  3757. } else if execution_state == 0 {
  3758. db := readDb.
  3759. Table("xt_schedule").
  3760. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3761. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3762. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3763. }).
  3764. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3765. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3766. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3767. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3768. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3769. }).
  3770. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3771. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3772. }).Where("status = 1 AND user_org_id = ?", orgID)
  3773. if scheduleDate != 0 {
  3774. db = db.Where("schedule_date = ?", scheduleDate)
  3775. }
  3776. err = db.Find(&vms).Error
  3777. }
  3778. } else {
  3779. if execution_state == 1 {
  3780. db := readDb.
  3781. Table("xt_schedule").
  3782. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3783. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3784. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3785. }).
  3786. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3787. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3788. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3789. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3790. 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")
  3791. }).
  3792. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3793. 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")
  3794. }).Where("status = 1 AND user_org_id = ?", orgID)
  3795. if scheduleDate != 0 {
  3796. db = db.Where("schedule_date = ?", scheduleDate)
  3797. }
  3798. err = db.Find(&vms).Error
  3799. } else if execution_state == 2 {
  3800. fmt.Println("j氯332n323232n323ℹ️33232323232")
  3801. db := readDb.
  3802. Table("xt_schedule").
  3803. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3804. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3805. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3806. }).
  3807. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3808. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3809. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3810. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3811. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state =0 ", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3812. }).
  3813. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3814. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state =0 ", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3815. }).Where("status = 1 AND user_org_id = ?", orgID)
  3816. if scheduleDate != 0 {
  3817. db = db.Where("schedule_date = ?", scheduleDate)
  3818. }
  3819. err = db.Find(&vms).Error
  3820. } else if execution_state == 0 {
  3821. db := readDb.
  3822. Table("xt_schedule").
  3823. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3824. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3825. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3826. }).
  3827. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3828. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3829. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3830. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3831. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3832. }).
  3833. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3834. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3835. }).Where("status = 1 AND user_org_id = ?", orgID)
  3836. if scheduleDate != 0 {
  3837. db = db.Where("schedule_date = ?", scheduleDate)
  3838. }
  3839. err = db.Find(&vms).Error
  3840. }
  3841. }
  3842. }
  3843. }
  3844. if patientType > 0 {
  3845. if execution_state == 1 {
  3846. db := readDb.
  3847. Table("xt_schedule").
  3848. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3849. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3850. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3851. }).
  3852. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3853. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3854. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3855. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3856. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3857. 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")
  3858. }).
  3859. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3860. 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")
  3861. }).Where("status = 1 AND user_org_id = ?", orgID)
  3862. if scheduleDate != 0 {
  3863. db = db.Where("schedule_date = ?", scheduleDate)
  3864. }
  3865. err = db.Find(&vms).Error
  3866. } else if execution_state == 2 {
  3867. db := readDb.
  3868. Table("xt_schedule").
  3869. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3870. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3871. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3872. }).
  3873. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3874. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3875. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3876. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3877. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3878. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3879. }).
  3880. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3881. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3882. }).Where("status = 1 AND user_org_id = ?", orgID)
  3883. if scheduleDate != 0 {
  3884. db = db.Where("schedule_date = ?", scheduleDate)
  3885. }
  3886. err = db.Find(&vms).Error
  3887. } else if execution_state == 0 {
  3888. db := readDb.
  3889. Table("xt_schedule").
  3890. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3891. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3892. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3893. }).
  3894. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3895. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3896. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3897. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3898. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3899. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3900. }).
  3901. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3902. 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")
  3903. }).Where("status = 1 AND user_org_id = ?", orgID)
  3904. if scheduleDate != 0 {
  3905. db = db.Where("schedule_date = ?", scheduleDate)
  3906. }
  3907. err = db.Find(&vms).Error
  3908. }
  3909. }
  3910. return vms, err
  3911. }
  3912. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3913. prepare := models.DialysisBeforePrepare{}
  3914. var err error
  3915. if count > 0 {
  3916. 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
  3917. }
  3918. if count <= 0 {
  3919. 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
  3920. }
  3921. return err
  3922. }
  3923. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3924. detail := models.AutomaticReduceDetail{}
  3925. 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
  3926. return err
  3927. }
  3928. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3929. var record models.DialysisSolution
  3930. 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
  3931. if err != nil {
  3932. if err == gorm.ErrRecordNotFound {
  3933. return nil, nil
  3934. } else {
  3935. return nil, err
  3936. }
  3937. }
  3938. return &record, nil
  3939. }
  3940. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3941. var record models.DialysisPrescription
  3942. 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
  3943. if err != nil {
  3944. if err == gorm.ErrRecordNotFound {
  3945. return nil, nil
  3946. } else {
  3947. return nil, err
  3948. }
  3949. }
  3950. return &record, nil
  3951. }
  3952. func MobileGetLastDialysisPrescription(patientID int64, orgID int64) (models.DialysisPrescriptionThrity, error) {
  3953. prescription := models.DialysisPrescriptionThrity{}
  3954. err := readDb.Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and remark<>''", patientID, orgID).Last(&prescription).Error
  3955. return prescription, err
  3956. }
  3957. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3958. var record models.SystemPrescription
  3959. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3960. if err != nil {
  3961. if err == gorm.ErrRecordNotFound {
  3962. return nil, nil
  3963. } else {
  3964. return nil, err
  3965. }
  3966. }
  3967. return &record, nil
  3968. }
  3969. // 透前评估
  3970. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3971. var record models.PredialysisEvaluation
  3972. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3973. if err != nil {
  3974. if err == gorm.ErrRecordNotFound {
  3975. return nil, nil
  3976. } else {
  3977. return nil, err
  3978. }
  3979. }
  3980. return &record, nil
  3981. }
  3982. //
  3983. //func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3984. //
  3985. // 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
  3986. // return prepare, err
  3987. //}
  3988. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3989. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  3990. return auto, err
  3991. }
  3992. func GetRoleList(orgid int64, admin_user_id int64) (models.SgjUserAdminRole, error) {
  3993. role := models.SgjUserAdminRole{}
  3994. err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
  3995. return role, err
  3996. }
  3997. func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3998. err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
  3999. return auto, err
  4000. }
  4001. func GetGoodWarehouseOutInfo(orgId int64, patient_id int64, sys_record_time int64) (outifno []*models.WarehouseOutInfoSeven, err error) {
  4002. err = readDb.Where("org_id = ? and patient_id = ? and sys_record_time = ? and status = 1", orgId, patient_id, sys_record_time).Find(&outifno).Error
  4003. return outifno, err
  4004. }
  4005. func GetLastDilysisOrder(orgid int64, patient_id int64, dialysis_date int64) (models.DialysisOrder, error) {
  4006. order := models.DialysisOrder{}
  4007. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status= 1", orgid, patient_id, dialysis_date).Last(&order).Error
  4008. return order, err
  4009. }
  4010. func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.MonitoringRecord, error) {
  4011. record := models.MonitoringRecord{}
  4012. err := XTReadDB().Where("org_id = ? and patient_id = ? and monitoring_date = ? and status = 1", orgid, patient_id, dialysis_date).Find(&record).Error
  4013. return record, err
  4014. }
  4015. 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) {
  4016. fmt.Println("execution_frequency---------------------------", execution_frequency)
  4017. fmt.Println("cost_type-----------", cost_type)
  4018. fmt.Println("adviceType-----------", adviceType)
  4019. fmt.Println("patientType---------", patientType)
  4020. fmt.Println("len(deliverWay)--------", len(deliverWay))
  4021. var vms []*MScheduleDoctorAdviceVM
  4022. adviceWhere := ""
  4023. adviceCondition := []interface{}{}
  4024. if adviceType == 0 {
  4025. if patientType == 0 {
  4026. if patient_id > 0 {
  4027. if execution_state > 0 {
  4028. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4031. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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= ? and is_settle = ?"
  4034. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4035. }
  4036. } else {
  4037. if len(execution_frequency) > 0 {
  4038. 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 = ?"
  4039. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4040. } else {
  4041. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
  4042. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4043. }
  4044. }
  4045. } else {
  4046. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4049. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, 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 = ? and is_settle = ?"
  4052. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4053. }
  4054. } else {
  4055. if len(execution_frequency) > 0 {
  4056. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_frequency = ?"
  4057. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4058. } else {
  4059. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4060. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4061. }
  4062. }
  4063. }
  4064. } else {
  4065. if execution_state > 0 {
  4066. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, 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= ? and is_settle = ?"
  4072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4073. }
  4074. } else {
  4075. if len(execution_frequency) > 0 {
  4076. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ? and execution_frequency = ?"
  4077. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4078. } else {
  4079. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  4080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4081. }
  4082. }
  4083. } else {
  4084. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4087. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4088. } else {
  4089. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  4090. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4091. }
  4092. } else {
  4093. if len(execution_frequency) > 0 {
  4094. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4095. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4096. } else {
  4097. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  4098. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4099. }
  4100. }
  4101. }
  4102. }
  4103. } else if patientType == 1 {
  4104. if patient_id > 0 {
  4105. if execution_state > 0 {
  4106. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4109. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, 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= ? and is_settle = ?"
  4112. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4113. }
  4114. } else {
  4115. if len(execution_frequency) > 0 {
  4116. 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 = ?"
  4117. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4118. } else {
  4119. 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= ?"
  4120. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4121. }
  4122. }
  4123. } else {
  4124. if cost_type > 0 {
  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 is_settle=? and execution_frequency = ?"
  4127. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, 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 = ? and is_settle=?"
  4130. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4131. }
  4132. } else {
  4133. if len(execution_frequency) > 0 {
  4134. 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 = ?"
  4135. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4136. } else {
  4137. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  4138. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4139. }
  4140. }
  4141. }
  4142. } else {
  4143. if execution_state > 0 {
  4144. if cost_type > 0 {
  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 is_settle=? and execution_frequency = ?"
  4147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, 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 = ? and is_settle=?"
  4150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4151. }
  4152. } else {
  4153. if len(execution_frequency) > 0 {
  4154. 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 = ?"
  4155. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4156. } else {
  4157. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
  4158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4159. }
  4160. }
  4161. } else {
  4162. if cost_type > 0 {
  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 is_settle=? and execution_frequency = ?"
  4165. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, 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) and is_settle=?"
  4168. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4169. }
  4170. } else {
  4171. if len(execution_frequency) > 0 {
  4172. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_frequency = ?"
  4173. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4174. } else {
  4175. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  4176. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4177. }
  4178. }
  4179. }
  4180. }
  4181. } else if patientType == 2 {
  4182. if patient_id > 0 {
  4183. if execution_state > 0 {
  4184. if cost_type > 0 {
  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 is_settle=? and execution_frequency = ?"
  4187. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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 = ? and is_settle=?"
  4190. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4191. }
  4192. } else {
  4193. if len(execution_frequency) > 0 {
  4194. 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 = ?"
  4195. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4196. } else {
  4197. 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 = ?"
  4198. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4199. }
  4200. }
  4201. } else {
  4202. if cost_type > 0 {
  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 is_settle=? and execution_frequency = ?"
  4205. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, 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 = ?) and is_settle=?"
  4208. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4209. }
  4210. } else {
  4211. if len(execution_frequency) > 0 {
  4212. 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 = ?"
  4213. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4214. } else {
  4215. 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 = ?)"
  4216. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4217. }
  4218. }
  4219. }
  4220. } else {
  4221. if execution_state > 0 {
  4222. if cost_type > 0 {
  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 is_settle=? and execution_frequency = ?"
  4225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, 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 = ? and is_settle=?"
  4228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4229. }
  4230. } else {
  4231. if len(execution_frequency) > 0 {
  4232. 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 = ?"
  4233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4234. } else {
  4235. 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 = ?"
  4236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4237. }
  4238. }
  4239. } else {
  4240. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, 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) and is_settle = ?"
  4246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4247. }
  4248. } else {
  4249. if len(execution_frequency) > 0 {
  4250. 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 = ?"
  4251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4252. } else {
  4253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  4254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4255. }
  4256. }
  4257. }
  4258. }
  4259. }
  4260. } else if adviceType == 1 {
  4261. if patientType == 0 {
  4262. if patient_id > 0 {
  4263. if execution_state > 0 {
  4264. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4267. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4270. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4271. }
  4272. } else {
  4273. if len(execution_frequency) > 0 {
  4274. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4275. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4276. } else {
  4277. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  4278. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4279. }
  4280. }
  4281. } else {
  4282. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4285. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4286. } else {
  4287. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  4288. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4289. }
  4290. } else {
  4291. if len(execution_frequency) > 0 {
  4292. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4293. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4294. } else {
  4295. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  4296. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4297. }
  4298. }
  4299. }
  4300. } else {
  4301. if execution_state > 0 {
  4302. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4305. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4306. } else {
  4307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  4308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4309. }
  4310. } else {
  4311. if len(execution_frequency) > 0 {
  4312. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and execution_frequency = ?"
  4313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4314. } else {
  4315. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  4316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4317. }
  4318. }
  4319. } else {
  4320. if cost_type > 0 {
  4321. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  4322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4323. } else {
  4324. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  4325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4326. }
  4327. }
  4328. }
  4329. } else if patientType == 1 {
  4330. if patient_id > 0 {
  4331. if execution_state > 0 {
  4332. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4339. }
  4340. } else {
  4341. if len(execution_frequency) > 0 {
  4342. 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 = ?"
  4343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4344. } else {
  4345. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4347. }
  4348. }
  4349. } else {
  4350. if cost_type > 0 {
  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 is_settle = ?and execution_frequency = ?"
  4353. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, 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 = ? and is_settle = ?"
  4356. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4357. }
  4358. } else {
  4359. if len(execution_frequency) > 0 {
  4360. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4361. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4362. } else {
  4363. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  4364. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4365. }
  4366. }
  4367. }
  4368. } else {
  4369. if execution_state > 0 {
  4370. if cost_type > 0 {
  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 is_settle = ?and execution_frequency = ?"
  4373. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, 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=? and is_settle = ?"
  4376. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4377. }
  4378. } else {
  4379. if len(execution_frequency) > 0 {
  4380. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
  4381. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4382. } else {
  4383. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  4384. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4385. }
  4386. }
  4387. } else {
  4388. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4391. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4392. } else {
  4393. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  4394. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4395. }
  4396. } else {
  4397. if len(execution_frequency) > 0 {
  4398. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_frequency = ?"
  4399. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4400. } else {
  4401. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  4402. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4403. }
  4404. }
  4405. }
  4406. }
  4407. } else if patientType == 2 {
  4408. if patient_id > 0 {
  4409. if execution_state > 0 {
  4410. if cost_type > 0 {
  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 is_settle = ?and execution_frequency = ?"
  4413. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4416. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4417. }
  4418. } else {
  4419. if len(execution_frequency) > 0 {
  4420. 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 = ?"
  4421. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4422. } else {
  4423. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4424. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4425. }
  4426. }
  4427. } else {
  4428. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4431. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, 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 = ? and is_settle = ?"
  4434. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4435. }
  4436. } else {
  4437. if len(execution_frequency) > 0 {
  4438. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4439. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4440. } else {
  4441. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  4442. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4443. }
  4444. }
  4445. }
  4446. } else {
  4447. if execution_state > 0 {
  4448. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4451. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, 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 = ? and is_settle = ?"
  4454. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4455. }
  4456. } else {
  4457. if len(execution_frequency) > 0 {
  4458. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  4459. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4460. } else {
  4461. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  4462. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4463. }
  4464. }
  4465. } else {
  4466. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4470. } else {
  4471. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  4472. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4473. }
  4474. } else {
  4475. if len(execution_frequency) > 0 {
  4476. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_frequency = ?"
  4477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4478. } else {
  4479. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  4480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4481. }
  4482. }
  4483. }
  4484. }
  4485. }
  4486. } else if adviceType == 3 {
  4487. if patientType == 0 {
  4488. if patient_id > 0 {
  4489. if execution_state > 0 {
  4490. if cost_type > 0 {
  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 is_settle = ? and execution_frequency =?"
  4493. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4496. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4497. }
  4498. } else {
  4499. if len(execution_frequency) > 0 {
  4500. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency =?"
  4501. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4502. } else {
  4503. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  4504. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4505. }
  4506. }
  4507. } else {
  4508. if cost_type > 0 {
  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 is_settle = ? and execution_frequency =?"
  4511. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4512. } else {
  4513. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  4514. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4515. }
  4516. } else {
  4517. if len(execution_frequency) > 0 {
  4518. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_frequency =?"
  4519. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4520. } else {
  4521. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  4522. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4523. }
  4524. }
  4525. }
  4526. } else {
  4527. if execution_state > 0 {
  4528. if cost_type > 0 {
  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 is_settle = ? and execution_frequency =?"
  4531. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  4532. } else {
  4533. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  4534. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4535. }
  4536. } else {
  4537. if len(execution_frequency) > 0 {
  4538. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and execution_frequency =?"
  4539. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4540. } else {
  4541. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  4542. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4543. }
  4544. }
  4545. } else {
  4546. if cost_type > 0 {
  4547. if len(execution_frequency) > 0 {
  4548. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? and execution_frequency =?"
  4549. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4550. } else {
  4551. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  4552. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4553. }
  4554. } else {
  4555. if len(execution_frequency) > 0 {
  4556. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_frequency =?"
  4557. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4558. } else {
  4559. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  4560. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4561. }
  4562. }
  4563. }
  4564. }
  4565. } else if patientType == 1 {
  4566. if patient_id > 0 {
  4567. if execution_state > 0 {
  4568. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4571. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4574. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  4575. }
  4576. } else {
  4577. if len(execution_frequency) > 0 {
  4578. 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 = ?"
  4579. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  4580. } else {
  4581. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  4582. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  4583. }
  4584. }
  4585. } else {
  4586. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4589. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, 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 = ? and is_settle = ?"
  4592. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  4593. }
  4594. } else {
  4595. if len(execution_frequency) > 0 {
  4596. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  4597. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  4598. } else {
  4599. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  4600. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  4601. }
  4602. }
  4603. }
  4604. } else {
  4605. if execution_state > 0 {
  4606. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4609. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, 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 =? and is_settle = ?"
  4612. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  4613. }
  4614. } else {
  4615. if len(execution_frequency) > 0 {
  4616. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =?and execution_frequency = ? "
  4617. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  4618. } else {
  4619. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  4620. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  4621. }
  4622. }
  4623. } else {
  4624. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4627. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  4628. } else {
  4629. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  4630. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  4631. }
  4632. } else {
  4633. if len(execution_frequency) > 0 {
  4634. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_frequency = ?"
  4635. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  4636. } else {
  4637. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  4638. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  4639. }
  4640. }
  4641. }
  4642. }
  4643. } else if patientType == 2 {
  4644. if patient_id > 0 {
  4645. if execution_state > 0 {
  4646. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4653. }
  4654. } else {
  4655. if len(execution_frequency) > 0 {
  4656. 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 = ?"
  4657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4658. } else {
  4659. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  4660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4661. }
  4662. }
  4663. } else {
  4664. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, 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 = ? and is_settle = ?"
  4670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4671. }
  4672. } else {
  4673. if len(execution_frequency) > 0 {
  4674. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and execution_frequency = ?"
  4675. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4676. } else {
  4677. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  4678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4679. }
  4680. }
  4681. }
  4682. } else {
  4683. if execution_state > 0 {
  4684. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4687. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, 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= ? and is_settle = ?"
  4690. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  4691. }
  4692. } else {
  4693. if len(execution_frequency) > 0 {
  4694. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ? and execution_frequency = ?"
  4695. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  4696. } else {
  4697. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  4698. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  4699. }
  4700. }
  4701. } else {
  4702. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4705. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  4706. } else {
  4707. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  4708. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  4709. }
  4710. } else {
  4711. if len(execution_frequency) > 0 {
  4712. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_frequency = ?"
  4713. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  4714. } else {
  4715. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  4716. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  4717. }
  4718. }
  4719. }
  4720. }
  4721. }
  4722. } else if adviceType == 2 && len(deliverWay) > 0 {
  4723. if patientType == 0 {
  4724. if patient_id > 0 {
  4725. if execution_state > 0 {
  4726. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4729. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4732. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4733. }
  4734. } else {
  4735. if len(execution_frequency) > 0 {
  4736. 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 = ?"
  4737. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4738. } else {
  4739. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
  4740. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4741. }
  4742. }
  4743. } else {
  4744. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4747. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, 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 = ? and is_settle = ?"
  4750. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4751. }
  4752. } else {
  4753. if len(execution_frequency) > 0 {
  4754. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_frequency = ?"
  4755. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4756. } else {
  4757. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  4758. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4759. }
  4760. }
  4761. }
  4762. } else {
  4763. if execution_state > 0 {
  4764. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, 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 = ? and is_settle = ?"
  4770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4771. }
  4772. } else {
  4773. if len(execution_frequency) > 0 {
  4774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and execution_frequency = ?"
  4775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4776. } else {
  4777. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  4778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4779. }
  4780. }
  4781. } else {
  4782. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type, execution_frequency)
  4786. } else {
  4787. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  4788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4789. }
  4790. } else {
  4791. if len(execution_frequency) > 0 {
  4792. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_frequency = ?"
  4793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_frequency)
  4794. } else {
  4795. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  4796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4797. }
  4798. }
  4799. }
  4800. }
  4801. } else if patientType == 1 {
  4802. if patient_id > 0 {
  4803. if execution_state > 0 {
  4804. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4807. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4810. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, cost_type)
  4811. }
  4812. } else {
  4813. if len(execution_frequency) > 0 {
  4814. 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 = ?"
  4815. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, execution_frequency)
  4816. } else {
  4817. 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 = ?"
  4818. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  4819. }
  4820. }
  4821. } else {
  4822. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4825. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type, 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 = ? and is_settle = ?"
  4828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  4829. }
  4830. } else {
  4831. if len(execution_frequency) > 0 {
  4832. 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 = ?"
  4833. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_frequency)
  4834. } else {
  4835. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  4836. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  4837. }
  4838. }
  4839. }
  4840. } else {
  4841. if execution_state > 0 {
  4842. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4845. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type, 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 = ? and is_settle = ?"
  4848. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, cost_type)
  4849. }
  4850. } else {
  4851. if len(execution_frequency) > 0 {
  4852. 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 = ?"
  4853. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, execution_frequency)
  4854. } else {
  4855. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_state = ?"
  4856. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  4857. }
  4858. }
  4859. } else {
  4860. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4863. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type, 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 = ? and is_settle = ?"
  4866. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  4867. }
  4868. } else {
  4869. if len(execution_frequency) > 0 {
  4870. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and execution_frequency = ?"
  4871. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_frequency)
  4872. } else {
  4873. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  4874. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  4875. }
  4876. }
  4877. }
  4878. }
  4879. } else if patientType == 2 {
  4880. if patient_id > 0 {
  4881. if execution_state > 0 {
  4882. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4885. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4888. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, cost_type)
  4889. }
  4890. } else {
  4891. if len(execution_frequency) > 0 {
  4892. 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 = ?"
  4893. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, execution_frequency)
  4894. } else {
  4895. 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 = ?"
  4896. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  4897. }
  4898. }
  4899. } else {
  4900. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4903. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type, 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 = ? and is_settle = ?"
  4906. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  4907. }
  4908. } else {
  4909. if len(execution_frequency) > 0 {
  4910. 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 = ?"
  4911. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_frequency)
  4912. } else {
  4913. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  4914. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  4915. }
  4916. }
  4917. }
  4918. } else {
  4919. if execution_state > 0 {
  4920. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4923. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type, 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 = ? and is_settle = ?"
  4926. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  4927. }
  4928. } else {
  4929. if len(execution_frequency) > 0 {
  4930. 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 = ?"
  4931. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, execution_frequency)
  4932. } else {
  4933. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
  4934. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  4935. }
  4936. }
  4937. } else {
  4938. if cost_type > 0 {
  4939. if len(execution_frequency) > 0 {
  4940. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4941. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4942. } else {
  4943. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  4944. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  4945. }
  4946. } else {
  4947. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  4948. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  4949. }
  4950. }
  4951. }
  4952. }
  4953. } else if adviceType == 2 && len(deliverWay) <= 0 {
  4954. fmt.Println("寄哪里233223322323233232", patientType)
  4955. fmt.Println("patient_id", patient_id)
  4956. fmt.Println("execution_state000000", execution_state)
  4957. fmt.Println("cost_type", cost_type)
  4958. fmt.Println("len23323232", len(execution_frequency))
  4959. if patientType == 0 {
  4960. if patient_id > 0 {
  4961. if execution_state > 0 {
  4962. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4965. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  4968. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  4969. }
  4970. } else {
  4971. if len(execution_frequency) > 0 {
  4972. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
  4973. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  4974. } else {
  4975. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  4976. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  4977. }
  4978. }
  4979. } else {
  4980. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  4983. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, execution_frequency)
  4984. } else {
  4985. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  4986. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  4987. }
  4988. } else {
  4989. if len(execution_frequency) > 0 {
  4990. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_frequency = ?"
  4991. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  4992. } else {
  4993. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  4994. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  4995. }
  4996. }
  4997. }
  4998. } else {
  4999. if execution_state > 0 {
  5000. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  5003. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, execution_frequency)
  5004. } else {
  5005. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5006. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5007. }
  5008. } else {
  5009. if len(execution_frequency) > 0 {
  5010. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?and execution_frequency = ?"
  5011. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5012. } else {
  5013. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5014. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5015. }
  5016. }
  5017. } else {
  5018. if cost_type > 0 {
  5019. if len(execution_frequency) > 0 {
  5020. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ? and execution_frequency = ?"
  5021. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5022. }
  5023. } else {
  5024. if len(execution_frequency) > 0 {
  5025. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
  5026. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5027. } else {
  5028. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5029. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5030. }
  5031. }
  5032. }
  5033. }
  5034. } else if patientType == 1 {
  5035. if patient_id > 0 {
  5036. if execution_state > 0 {
  5037. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  5040. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  5043. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, cost_type)
  5044. }
  5045. } else {
  5046. if len(execution_frequency) > 0 {
  5047. 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 = ?"
  5048. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, execution_frequency)
  5049. } else {
  5050. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
  5051. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5052. }
  5053. }
  5054. } else {
  5055. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  5058. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type, 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 = ? and is_settle = ?"
  5061. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5062. }
  5063. } else {
  5064. if len(execution_frequency) > 0 {
  5065. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
  5066. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_frequency)
  5067. } else {
  5068. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5070. }
  5071. }
  5072. }
  5073. } else {
  5074. if execution_state > 0 {
  5075. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  5078. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type, 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 = ? and is_settle = ?"
  5081. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5082. }
  5083. } else {
  5084. if len(execution_frequency) > 0 {
  5085. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and execution_frequency = ?"
  5086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, execution_frequency)
  5087. } else {
  5088. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5089. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5090. }
  5091. }
  5092. } else {
  5093. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  5096. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type, execution_frequency)
  5097. } else {
  5098. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5099. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5100. }
  5101. } else {
  5102. if len(execution_frequency) > 0 {
  5103. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_frequency = ?"
  5104. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_frequency)
  5105. } else {
  5106. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5107. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5108. }
  5109. }
  5110. }
  5111. }
  5112. } else if patientType == 2 {
  5113. if patient_id > 0 {
  5114. if execution_state > 0 {
  5115. if cost_type > 0 {
  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 is_settle = ? and execution_frequency=?"
  5118. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type, 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 = ? and is_settle = ?"
  5121. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5122. }
  5123. } else {
  5124. if len(execution_frequency) > 0 {
  5125. 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=?"
  5126. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, execution_frequency)
  5127. } else {
  5128. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_state = ?"
  5129. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5130. }
  5131. }
  5132. } else {
  5133. if cost_type > 0 {
  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 is_settle = ? and execution_frequency=?"
  5136. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type, 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 = ? and is_settle = ?"
  5139. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5140. }
  5141. } else {
  5142. if len(execution_frequency) > 0 {
  5143. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and execution_frequency=?"
  5144. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_frequency)
  5145. } else {
  5146. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5148. }
  5149. }
  5150. }
  5151. } else {
  5152. if execution_state > 0 {
  5153. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  5156. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type, 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 = ? and is_settle = ?"
  5159. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5160. }
  5161. } else {
  5162. if len(execution_frequency) > 0 {
  5163. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
  5164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, execution_frequency)
  5165. } else {
  5166. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5167. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5168. }
  5169. }
  5170. } else {
  5171. if cost_type > 0 {
  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 is_settle = ? and execution_frequency = ?"
  5174. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type, execution_frequency)
  5175. } else {
  5176. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5177. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5178. }
  5179. } else {
  5180. if len(execution_frequency) > 0 {
  5181. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_frequency = ?"
  5182. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
  5183. } else {
  5184. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5185. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5186. }
  5187. }
  5188. }
  5189. }
  5190. }
  5191. }
  5192. db := readDb.Table("xt_schedule")
  5193. if scheduleType > 0 {
  5194. db = db.Where("schedule_type = ?", scheduleType)
  5195. }
  5196. if partitonType > 0 {
  5197. db = db.Where("partition_id = ?", partitonType)
  5198. }
  5199. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5200. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5201. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5202. }).
  5203. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5204. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5205. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5206. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5207. Preload("DoctorAdvices", adviceCondition...).
  5208. Where("status = 1 AND user_org_id = ?", orgID)
  5209. if scheduleDate != 0 {
  5210. db = db.Where("schedule_date = ?", scheduleDate)
  5211. }
  5212. err := db.Find(&vms).Error
  5213. return vms, err
  5214. }
  5215. 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) {
  5216. var vms []*MScheduleDoctorAdviceVM
  5217. adviceWhere := ""
  5218. adviceCondition := []interface{}{}
  5219. if adviceType == 0 {
  5220. if patientType == 0 {
  5221. if patient_id > 0 {
  5222. if execution_state > 0 {
  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 execution_state= ? and is_settle = ?"
  5225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, 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 = ? and execution_state= ?"
  5228. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5229. }
  5230. } else {
  5231. if cost_type > 0 {
  5232. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and is_settle = ?"
  5233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5234. } else {
  5235. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5237. }
  5238. }
  5239. } else {
  5240. if execution_state > 0 {
  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 execution_state= ? and is_settle = ?"
  5243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5244. } else {
  5245. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
  5246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5247. }
  5248. } else {
  5249. if cost_type > 0 {
  5250. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and is_settle = ?"
  5251. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5252. } else {
  5253. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  5254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5255. }
  5256. }
  5257. }
  5258. } else if patientType == 1 {
  5259. if patient_id > 0 {
  5260. if execution_state > 0 {
  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 execution_state= ? and is_settle = ?"
  5263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, 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 = ? and execution_state= ?"
  5266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5267. }
  5268. } else {
  5269. if cost_type > 0 {
  5270. 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=?"
  5271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5272. } else {
  5273. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  5274. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5275. }
  5276. }
  5277. } else {
  5278. if execution_state > 0 {
  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 execution_state = ? and is_settle=?"
  5281. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, 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) and execution_state = ?"
  5284. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5285. }
  5286. } else {
  5287. if cost_type > 0 {
  5288. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and is_settle=?"
  5289. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5290. } else {
  5291. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  5292. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5293. }
  5294. }
  5295. }
  5296. } else if patientType == 2 {
  5297. if patient_id > 0 {
  5298. if execution_state > 0 {
  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 execution_state = ? and is_settle=?"
  5301. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, 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 = ?) and execution_state = ?"
  5304. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5305. }
  5306. } else {
  5307. if cost_type > 0 {
  5308. 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=?"
  5309. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5310. } else {
  5311. 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 = ?)"
  5312. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5313. }
  5314. }
  5315. } else {
  5316. if execution_state > 0 {
  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 execution_state = ? and is_settle=?"
  5319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, 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) and execution_state = ?"
  5322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5323. }
  5324. } else {
  5325. if cost_type > 0 {
  5326. 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 = ?"
  5327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5328. } else {
  5329. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  5330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5331. }
  5332. }
  5333. }
  5334. }
  5335. } else if adviceType == 1 {
  5336. if patientType == 0 {
  5337. if patient_id > 0 {
  5338. if execution_state > 0 {
  5339. if cost_type > 0 {
  5340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5342. } else {
  5343. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
  5344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5345. }
  5346. } else {
  5347. if cost_type > 0 {
  5348. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and is_settle = ? "
  5349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5350. } else {
  5351. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  5352. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5353. }
  5354. }
  5355. } else {
  5356. if execution_state > 0 {
  5357. if cost_type > 0 {
  5358. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ? and is_settle = ?"
  5359. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5360. } else {
  5361. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
  5362. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5363. }
  5364. } else {
  5365. if cost_type > 0 {
  5366. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and is_settle = ? "
  5367. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5368. } else {
  5369. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  5370. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5371. }
  5372. }
  5373. }
  5374. } else if patientType == 1 {
  5375. if patient_id > 0 {
  5376. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5379. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, 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 = ? and execution_state = ?"
  5382. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5383. }
  5384. } else {
  5385. if cost_type > 0 {
  5386. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5387. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5388. } else {
  5389. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  5390. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5391. }
  5392. }
  5393. } else {
  5394. if execution_state > 0 {
  5395. if cost_type > 0 {
  5396. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=? and is_settle = ?"
  5397. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5398. } else {
  5399. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
  5400. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5401. }
  5402. } else {
  5403. if cost_type > 0 {
  5404. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and is_settle = ? "
  5405. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5406. } else {
  5407. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  5408. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5409. }
  5410. }
  5411. }
  5412. } else if patientType == 2 {
  5413. if patient_id > 0 {
  5414. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5417. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, 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 = ? and execution_state = ?"
  5420. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5421. }
  5422. } else {
  5423. if cost_type > 0 {
  5424. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5425. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5426. } else {
  5427. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  5428. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5429. }
  5430. }
  5431. } else {
  5432. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5435. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5436. } else {
  5437. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
  5438. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5439. }
  5440. } else {
  5441. if cost_type > 0 {
  5442. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and is_settle = ?"
  5443. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5444. } else {
  5445. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  5446. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5447. }
  5448. }
  5449. }
  5450. }
  5451. } else if adviceType == 3 {
  5452. if patientType == 0 {
  5453. if patient_id > 0 {
  5454. if execution_state > 0 {
  5455. if cost_type > 0 {
  5456. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5457. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5458. } else {
  5459. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and execution_state = ?"
  5460. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5461. }
  5462. } else {
  5463. if cost_type > 0 {
  5464. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and is_settle = ? "
  5465. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5466. } else {
  5467. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  5468. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5469. }
  5470. }
  5471. } else {
  5472. if execution_state > 0 {
  5473. if cost_type > 0 {
  5474. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? and is_settle = ?"
  5475. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5476. } else {
  5477. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
  5478. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5479. }
  5480. } else {
  5481. if cost_type > 0 {
  5482. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and is_settle = ? "
  5483. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5484. } else {
  5485. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  5486. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5487. }
  5488. }
  5489. }
  5490. } else if patientType == 1 {
  5491. if patient_id > 0 {
  5492. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5495. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, 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 = ? and execution_state = ?"
  5498. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5499. }
  5500. } else {
  5501. if cost_type > 0 {
  5502. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5503. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5504. } else {
  5505. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  5506. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5507. }
  5508. }
  5509. } else {
  5510. if execution_state > 0 {
  5511. if cost_type > 0 {
  5512. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? and is_settle = ?"
  5513. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5514. } else {
  5515. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
  5516. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5517. }
  5518. } else {
  5519. if cost_type > 0 {
  5520. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and is_settle = ?"
  5521. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5522. } else {
  5523. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  5524. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5525. }
  5526. }
  5527. }
  5528. } else if patientType == 2 {
  5529. if patient_id > 0 {
  5530. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5533. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, 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 = ? and execution_state = ?"
  5536. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5537. }
  5538. } else {
  5539. if cost_type > 0 {
  5540. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5541. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5542. } else {
  5543. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  5544. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5545. }
  5546. }
  5547. } else {
  5548. if execution_state > 0 {
  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 execution_state= ? and is_settle = ?"
  5551. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5552. } else {
  5553. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and execution_state= ?"
  5554. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5555. }
  5556. } else {
  5557. if cost_type > 0 {
  5558. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and is_settle = ?"
  5559. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5560. } else {
  5561. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  5562. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5563. }
  5564. }
  5565. }
  5566. }
  5567. } else if adviceType == 2 && len(deliverWay) > 0 {
  5568. if patientType == 0 {
  5569. if patient_id > 0 {
  5570. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5573. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, 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 = ? and execution_state = ?"
  5576. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5577. }
  5578. } else {
  5579. if cost_type > 0 {
  5580. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and is_settle = ?"
  5581. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5582. } else {
  5583. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  5584. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5585. }
  5586. }
  5587. } else {
  5588. if execution_state > 0 {
  5589. if cost_type > 0 {
  5590. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ? and is_settle = ?"
  5591. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, cost_type)
  5592. } else {
  5593. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
  5594. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5595. }
  5596. } else {
  5597. if cost_type > 0 {
  5598. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and is_settle = ?"
  5599. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5600. } else {
  5601. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  5602. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5603. }
  5604. }
  5605. }
  5606. } else if patientType == 1 {
  5607. if patient_id > 0 {
  5608. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5611. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state, 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 = ? and execution_state = ?"
  5614. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
  5615. }
  5616. } else {
  5617. if cost_type > 0 {
  5618. 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 = ?"
  5619. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, cost_type)
  5620. } else {
  5621. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  5622. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  5623. }
  5624. }
  5625. } else {
  5626. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5629. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state, 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 = ? and execution_state = ?"
  5632. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
  5633. }
  5634. } else {
  5635. if cost_type > 0 {
  5636. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and is_settle = ?"
  5637. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, cost_type)
  5638. } else {
  5639. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  5640. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  5641. }
  5642. }
  5643. }
  5644. } else if patientType == 2 {
  5645. if patient_id > 0 {
  5646. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5649. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state, 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 = ? and execution_state = ?"
  5652. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
  5653. }
  5654. } else {
  5655. if cost_type > 0 {
  5656. 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 = ?"
  5657. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, cost_type)
  5658. } else {
  5659. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
  5660. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  5661. }
  5662. }
  5663. } else {
  5664. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5667. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state, 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 = ? and execution_state = ?"
  5670. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
  5671. }
  5672. } else {
  5673. if cost_type > 0 {
  5674. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ? and is_settle = ?"
  5675. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, cost_type)
  5676. } else {
  5677. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  5678. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  5679. }
  5680. }
  5681. }
  5682. }
  5683. } else if adviceType == 2 && len(deliverWay) <= 0 {
  5684. if patientType == 0 {
  5685. if patient_id > 0 {
  5686. if execution_state > 0 {
  5687. if cost_type > 0 {
  5688. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ? and is_settle = ?"
  5689. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, cost_type)
  5690. } else {
  5691. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
  5692. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5693. }
  5694. } else {
  5695. if cost_type > 0 {
  5696. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and is_settle = ?"
  5697. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5698. } else {
  5699. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  5700. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5701. }
  5702. }
  5703. } else {
  5704. if execution_state > 0 {
  5705. if cost_type > 0 {
  5706. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ? and is_settle = ?"
  5707. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5708. } else {
  5709. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
  5710. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5711. }
  5712. } else {
  5713. if cost_type > 0 {
  5714. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and is_settle = ?"
  5715. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5716. } else {
  5717. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  5718. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5719. }
  5720. }
  5721. }
  5722. } else if patientType == 1 {
  5723. if patient_id > 0 {
  5724. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state, 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 = ? and execution_state = ?"
  5730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
  5731. }
  5732. } else {
  5733. if cost_type > 0 {
  5734. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
  5735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, cost_type)
  5736. } else {
  5737. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  5738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  5739. }
  5740. }
  5741. } else {
  5742. if execution_state > 0 {
  5743. if cost_type > 0 {
  5744. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ? and is_settle = ?"
  5745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state, cost_type)
  5746. } else {
  5747. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
  5748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
  5749. }
  5750. } else {
  5751. if cost_type > 0 {
  5752. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and is_settle = ?"
  5753. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, cost_type)
  5754. } else {
  5755. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  5756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  5757. }
  5758. }
  5759. }
  5760. } else if patientType == 2 {
  5761. if patient_id > 0 {
  5762. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5765. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state, 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 = ? and execution_state = ?"
  5768. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
  5769. }
  5770. } else {
  5771. if cost_type > 0 {
  5772. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ? and is_settle = ?"
  5773. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, cost_type)
  5774. } else {
  5775. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  5776. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  5777. }
  5778. }
  5779. } else {
  5780. if execution_state > 0 {
  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 execution_state = ? and is_settle = ?"
  5783. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state, cost_type)
  5784. } else {
  5785. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and execution_state = ?"
  5786. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
  5787. }
  5788. } else {
  5789. if cost_type > 0 {
  5790. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and is_settle = ?"
  5791. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, cost_type)
  5792. } else {
  5793. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  5794. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  5795. }
  5796. }
  5797. }
  5798. }
  5799. }
  5800. db := readDb.Table("xt_schedule")
  5801. if scheduleType > 0 {
  5802. db = db.Where("schedule_type = ?", scheduleType)
  5803. }
  5804. if partitonType > 0 {
  5805. db = db.Where("partition_id = ?", partitonType)
  5806. }
  5807. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  5808. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5809. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5810. }).
  5811. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5812. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5813. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  5814. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5815. Preload("DoctorAdvices", adviceCondition...).
  5816. Where("status = 1 AND user_org_id = ?", orgID)
  5817. if scheduleDate != 0 {
  5818. db = db.Where("schedule_date = ?", scheduleDate)
  5819. }
  5820. err := db.Find(&vms).Error
  5821. return vms, err
  5822. }
  5823. func GetLastPatientOrder(id int64) (models.XtDialysisOrder, error) {
  5824. order := models.XtDialysisOrder{}
  5825. err := XTReadDB().Where("id = ? and status = 1", id).Find(&order).Error
  5826. return order, err
  5827. }
  5828. func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string) error {
  5829. order := models.XtPatients{}
  5830. 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
  5831. 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
  5832. return err
  5833. }
  5834. func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5835. order := models.BloodDialysisOrderCount{}
  5836. db := XTReadDB().Table("xt_dialysis_order as o")
  5837. 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
  5838. return order, err
  5839. }
  5840. func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
  5841. order := models.BloodDialysisOrderCount{}
  5842. db := XTReadDB().Table("xt_dialysis_order as o")
  5843. 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
  5844. return order, err
  5845. }
  5846. func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  5847. order := models.DialysisOrder{}
  5848. 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
  5849. return order, err
  5850. }
  5851. func UpdateDeviceInformation(patientid int64, dialysis_date int64) error {
  5852. information := models.DeviceInformation{}
  5853. err := UserWriteDB().Model(&information).Where("patient_id = ? and date = ? and status = 1", patientid, dialysis_date).Update(map[string]interface{}{"status": 0}).Error
  5854. return err
  5855. }
  5856. func MobileGetDoubleCheckSix(orgID int64, patientID int64, recordDate int64) (models.DoubleCheck, error) {
  5857. var record models.DoubleCheck
  5858. err := readDb.Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  5859. return record, err
  5860. }
  5861. func GetFirstMonitor(patient_id int64, monit_date int64) (models.MonitoringRecord, error) {
  5862. record := models.MonitoringRecord{}
  5863. err := XTReadDB().Where("patient_id = ? and monitoring_date = ? and status=1", patient_id, monit_date).First(&record).Error
  5864. return record, err
  5865. }
  5866. func UpdateFirstMonitor(id int64, catheter_operation string) (models.MonitoringRecord, error) {
  5867. record := models.MonitoringRecord{}
  5868. err := XTWriteDB().Model(&record).Where("id = ? and status= 1", id).Updates(map[string]interface{}{"dispose": catheter_operation}).Error
  5869. return record, err
  5870. }
  5871. 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) {
  5872. var vms []*HisMScheduleDoctorAdviceVM
  5873. if len(deliverWay) > 0 {
  5874. db := readDb.Table("xt_schedule")
  5875. if scheduleType > 0 {
  5876. db = db.Where("schedule_type = ?", scheduleType)
  5877. }
  5878. if partitionType > 0 {
  5879. db = db.Where("partition_id = ?", partitionType)
  5880. }
  5881. if patient_id > 0 {
  5882. if execution_state > 0 {
  5883. if cost_type > 0 {
  5884. if len(execution_frequency) > 0 {
  5885. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5886. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5887. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5888. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5889. 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).
  5890. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5891. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5892. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5893. Where("status = 1 AND user_org_id = ?", orgID)
  5894. if scheduleDate != 0 {
  5895. db = db.Where("schedule_date = ?", scheduleDate)
  5896. }
  5897. err = db.Find(&vms).Error
  5898. } else {
  5899. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5900. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5901. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5902. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5903. 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).
  5904. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5905. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5906. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5907. Where("status = 1 AND user_org_id = ?", orgID)
  5908. if scheduleDate != 0 {
  5909. db = db.Where("schedule_date = ?", scheduleDate)
  5910. }
  5911. err = db.Find(&vms).Error
  5912. }
  5913. } else {
  5914. if len(execution_frequency) > 0 {
  5915. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5916. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5917. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5918. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5919. 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).
  5920. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5921. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5922. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5923. Where("status = 1 AND user_org_id = ?", orgID)
  5924. if scheduleDate != 0 {
  5925. db = db.Where("schedule_date = ?", scheduleDate)
  5926. }
  5927. err = db.Find(&vms).Error
  5928. } else {
  5929. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5930. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5931. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5932. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5933. 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).
  5934. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5935. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5936. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5937. Where("status = 1 AND user_org_id = ?", orgID)
  5938. if scheduleDate != 0 {
  5939. db = db.Where("schedule_date = ?", scheduleDate)
  5940. }
  5941. err = db.Find(&vms).Error
  5942. }
  5943. }
  5944. } else {
  5945. if cost_type > 0 {
  5946. if len(execution_frequency) > 0 {
  5947. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5948. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5949. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5950. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5951. 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).
  5952. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5953. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5954. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5955. Where("status = 1 AND user_org_id = ?", orgID)
  5956. if scheduleDate != 0 {
  5957. db = db.Where("schedule_date = ?", scheduleDate)
  5958. }
  5959. err = db.Find(&vms).Error
  5960. } else {
  5961. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5962. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5963. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5964. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5965. 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).
  5966. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5967. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5968. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5969. Where("status = 1 AND user_org_id = ?", orgID)
  5970. if scheduleDate != 0 {
  5971. db = db.Where("schedule_date = ?", scheduleDate)
  5972. }
  5973. err = db.Find(&vms).Error
  5974. }
  5975. } else {
  5976. if len(execution_frequency) > 0 {
  5977. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5978. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5979. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5980. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5981. 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).
  5982. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5983. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5984. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5985. Where("status = 1 AND user_org_id = ?", orgID)
  5986. if scheduleDate != 0 {
  5987. db = db.Where("schedule_date = ?", scheduleDate)
  5988. }
  5989. err = db.Find(&vms).Error
  5990. } else {
  5991. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  5992. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  5993. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  5994. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  5995. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  5996. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  5997. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  5998. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  5999. Where("status = 1 AND user_org_id = ?", orgID)
  6000. if scheduleDate != 0 {
  6001. db = db.Where("schedule_date = ?", scheduleDate)
  6002. }
  6003. err = db.Find(&vms).Error
  6004. }
  6005. }
  6006. }
  6007. } else {
  6008. if execution_state > 0 {
  6009. if cost_type > 0 {
  6010. if len(execution_frequency) > 0 {
  6011. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6012. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6013. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6014. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6015. 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).
  6016. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6017. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6018. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6019. Where("status = 1 AND user_org_id = ?", orgID)
  6020. if scheduleDate != 0 {
  6021. db = db.Where("schedule_date = ?", scheduleDate)
  6022. }
  6023. err = db.Find(&vms).Error
  6024. } else {
  6025. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6026. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6027. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6028. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6029. 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).
  6030. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6031. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6032. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6033. Where("status = 1 AND user_org_id = ?", orgID)
  6034. if scheduleDate != 0 {
  6035. db = db.Where("schedule_date = ?", scheduleDate)
  6036. }
  6037. err = db.Find(&vms).Error
  6038. }
  6039. } else {
  6040. if len(execution_frequency) > 0 {
  6041. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6042. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6043. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6044. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6045. 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).
  6046. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6047. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6048. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6049. Where("status = 1 AND user_org_id = ?", orgID)
  6050. if scheduleDate != 0 {
  6051. db = db.Where("schedule_date = ?", scheduleDate)
  6052. }
  6053. err = db.Find(&vms).Error
  6054. } else {
  6055. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6056. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6057. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6058. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6059. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
  6060. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6061. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6062. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6063. Where("status = 1 AND user_org_id = ?", orgID)
  6064. if scheduleDate != 0 {
  6065. db = db.Where("schedule_date = ?", scheduleDate)
  6066. }
  6067. err = db.Find(&vms).Error
  6068. }
  6069. }
  6070. } else {
  6071. if cost_type > 0 {
  6072. if len(execution_frequency) > 0 {
  6073. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6074. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6075. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6076. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6077. 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).
  6078. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6079. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6080. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6081. Where("status = 1 AND user_org_id = ?", orgID)
  6082. if scheduleDate != 0 {
  6083. db = db.Where("schedule_date = ?", scheduleDate)
  6084. }
  6085. err = db.Find(&vms).Error
  6086. } else {
  6087. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6088. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6089. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6090. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6091. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and is_settle = ?", orgID, scheduleDate, deliverWay, cost_type).
  6092. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6093. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6094. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6095. Where("status = 1 AND user_org_id = ?", orgID)
  6096. if scheduleDate != 0 {
  6097. db = db.Where("schedule_date = ?", scheduleDate)
  6098. }
  6099. err = db.Find(&vms).Error
  6100. }
  6101. } else {
  6102. if len(execution_frequency) > 0 {
  6103. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6104. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6105. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6106. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6107. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_frequency = ?", orgID, scheduleDate, deliverWay, execution_frequency).
  6108. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6109. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6110. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6111. Where("status = 1 AND user_org_id = ?", orgID)
  6112. if scheduleDate != 0 {
  6113. db = db.Where("schedule_date = ?", scheduleDate)
  6114. }
  6115. err = db.Find(&vms).Error
  6116. } else {
  6117. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6118. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6119. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6120. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6121. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  6122. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6123. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6124. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6125. Where("status = 1 AND user_org_id = ?", orgID)
  6126. if scheduleDate != 0 {
  6127. db = db.Where("schedule_date = ?", scheduleDate)
  6128. }
  6129. err = db.Find(&vms).Error
  6130. }
  6131. }
  6132. }
  6133. }
  6134. } else {
  6135. db := readDb.Table("xt_schedule")
  6136. if scheduleType > 0 {
  6137. db = db.Where("schedule_type = ?", scheduleType)
  6138. }
  6139. if partitionType > 0 {
  6140. db = db.Where("partition_id = ?", partitionType)
  6141. }
  6142. if patient_id > 0 {
  6143. if execution_state > 0 {
  6144. if cost_type > 0 {
  6145. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6146. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6147. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6148. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6149. 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).
  6150. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6151. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6152. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6153. Where("status = 1 AND user_org_id = ?", orgID)
  6154. if scheduleDate != 0 {
  6155. db = db.Where("schedule_date = ?", scheduleDate)
  6156. }
  6157. err = db.Find(&vms).Error
  6158. } else {
  6159. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6160. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6161. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6162. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6163. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
  6164. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6165. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6166. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6167. Where("status = 1 AND user_org_id = ?", orgID)
  6168. if scheduleDate != 0 {
  6169. db = db.Where("schedule_date = ?", scheduleDate)
  6170. }
  6171. err = db.Find(&vms).Error
  6172. }
  6173. } else {
  6174. if cost_type > 0 {
  6175. if len(execution_frequency) > 0 {
  6176. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6177. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6178. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6179. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6180. 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).
  6181. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6182. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6183. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6184. Where("status = 1 AND user_org_id = ?", orgID)
  6185. if scheduleDate != 0 {
  6186. db = db.Where("schedule_date = ?", scheduleDate)
  6187. }
  6188. err = db.Find(&vms).Error
  6189. } else {
  6190. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6191. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6192. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6193. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6194. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and is_settle = ?", orgID, scheduleDate, patient_id, cost_type).
  6195. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6196. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6197. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6198. Where("status = 1 AND user_org_id = ?", orgID)
  6199. if scheduleDate != 0 {
  6200. db = db.Where("schedule_date = ?", scheduleDate)
  6201. }
  6202. err = db.Find(&vms).Error
  6203. }
  6204. } else {
  6205. if len(execution_frequency) > 0 {
  6206. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6207. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6208. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6209. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6210. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_frequency = ?", orgID, scheduleDate, patient_id, execution_frequency).
  6211. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6212. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6213. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6214. Where("status = 1 AND user_org_id = ?", orgID)
  6215. if scheduleDate != 0 {
  6216. db = db.Where("schedule_date = ?", scheduleDate)
  6217. }
  6218. err = db.Find(&vms).Error
  6219. } else {
  6220. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  6221. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6222. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6223. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6224. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  6225. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6226. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6227. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6228. Where("status = 1 AND user_org_id = ?", orgID)
  6229. if scheduleDate != 0 {
  6230. db = db.Where("schedule_date = ?", scheduleDate)
  6231. }
  6232. err = db.Find(&vms).Error
  6233. }
  6234. }
  6235. }
  6236. } else {
  6237. if execution_state > 0 {
  6238. if cost_type > 0 {
  6239. if len(execution_frequency) > 0 {
  6240. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6241. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6242. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6243. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6244. 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).
  6245. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6246. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6247. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6248. Where("status = 1 AND user_org_id = ?", orgID)
  6249. if scheduleDate != 0 {
  6250. db = db.Where("schedule_date = ?", scheduleDate)
  6251. }
  6252. err = db.Find(&vms).Error
  6253. } else {
  6254. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6255. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6256. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6257. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6258. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and is_settle = ?", orgID, scheduleDate, execution_state, cost_type).
  6259. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6260. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6261. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6262. Where("status = 1 AND user_org_id = ?", orgID)
  6263. if scheduleDate != 0 {
  6264. db = db.Where("schedule_date = ?", scheduleDate)
  6265. }
  6266. err = db.Find(&vms).Error
  6267. }
  6268. } else {
  6269. if len(execution_frequency) > 0 {
  6270. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6271. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6272. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6273. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6274. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ? and execution_frequency = ?", orgID, scheduleDate, execution_state, execution_frequency).
  6275. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6276. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6277. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6278. Where("status = 1 AND user_org_id = ?", orgID)
  6279. if scheduleDate != 0 {
  6280. db = db.Where("schedule_date = ?", scheduleDate)
  6281. }
  6282. err = db.Find(&vms).Error
  6283. } else {
  6284. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6285. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6286. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6287. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6288. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
  6289. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6290. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6291. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6292. Where("status = 1 AND user_org_id = ?", orgID)
  6293. if scheduleDate != 0 {
  6294. db = db.Where("schedule_date = ?", scheduleDate)
  6295. }
  6296. err = db.Find(&vms).Error
  6297. }
  6298. }
  6299. } else {
  6300. if cost_type > 0 {
  6301. if len(execution_frequency) > 0 {
  6302. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6303. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6304. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6305. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6306. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ?", orgID, scheduleDate, cost_type).
  6307. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6308. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6309. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6310. Where("status = 1 AND user_org_id = ?", orgID)
  6311. if scheduleDate != 0 {
  6312. db = db.Where("schedule_date = ?", scheduleDate)
  6313. }
  6314. err = db.Find(&vms).Error
  6315. } else {
  6316. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6317. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6318. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6319. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6320. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and is_settle = ? and execution_frequency = ?", orgID, scheduleDate, cost_type, execution_frequency).
  6321. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6322. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6323. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6324. Where("status = 1 AND user_org_id = ?", orgID)
  6325. if scheduleDate != 0 {
  6326. db = db.Where("schedule_date = ?", scheduleDate)
  6327. }
  6328. err = db.Find(&vms).Error
  6329. }
  6330. } else {
  6331. if len(execution_frequency) > 0 {
  6332. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6333. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6334. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6335. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6336. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_frequency = ?", orgID, scheduleDate, execution_frequency).
  6337. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6338. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6339. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6340. Where("status = 1 AND user_org_id = ?", orgID)
  6341. if scheduleDate != 0 {
  6342. db = db.Where("schedule_date = ?", scheduleDate)
  6343. }
  6344. err = db.Find(&vms).Error
  6345. } else {
  6346. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  6347. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  6348. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  6349. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  6350. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  6351. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  6352. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  6353. }).Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  6354. Where("status = 1 AND user_org_id = ?", orgID)
  6355. if scheduleDate != 0 {
  6356. db = db.Where("schedule_date = ?", scheduleDate)
  6357. }
  6358. err = db.Find(&vms).Error
  6359. }
  6360. }
  6361. }
  6362. }
  6363. }
  6364. return vms, err
  6365. }
  6366. func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPatientDryweight, err error) {
  6367. err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status =1", org_id, patient_id).Order("id desc").Limit(6).Find(&weight).Error
  6368. return weight, err
  6369. }