dialysis_api_controller.go 478KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. his_bed = lastAcceptTreatment.HisBed
  1124. his_department = lastAcceptTreatment.HisDepartment
  1125. tumble = lastAcceptTreatment.Tumble
  1126. }
  1127. }
  1128. }
  1129. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1130. UserOrgId: adminUserInfo.Org.Id,
  1131. PatientId: id,
  1132. RecordDate: recordDate.Unix(),
  1133. Way: way,
  1134. Consciousness: consciousness,
  1135. Appetite: appetite,
  1136. Condition: condition,
  1137. SickCondition: sick_condition,
  1138. DangerLevel: danger_level,
  1139. Intake: intake,
  1140. Nutrition: nutrition,
  1141. PsychologicalAssessment: psychological_assessment,
  1142. PsychologicalAssessmentOther: psychological_assessment_other,
  1143. SickConditionOther: sick_condition_other,
  1144. Posture: posture,
  1145. CreatedTime: time.Now().Unix(),
  1146. UpdateTime: time.Now().Unix(),
  1147. Status: 1,
  1148. Score: score,
  1149. Precaution: precaution,
  1150. PrecautionOther: precaution_other,
  1151. PsychologicalOther: psychological_other,
  1152. AdmissionNumber: admission_number,
  1153. Tumble: tumble,
  1154. Diacrisis: diacrisis,
  1155. HisBed: his_bed,
  1156. HisDepartment: his_department,
  1157. }
  1158. if receiveTreatment.ID == 0 { //新增
  1159. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1160. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1161. finish := models.XtDialysisFinish{
  1162. IsFinish: 1,
  1163. UserOrgId: adminUserInfo.Org.Id,
  1164. Status: 1,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: 0,
  1167. Module: 2,
  1168. RecordDate: recordDate.Unix(),
  1169. Sourse: 1,
  1170. PatientId: id,
  1171. }
  1172. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1173. if dialysisFinish.ID == 0 {
  1174. service.CreateDialysisFinish(finish)
  1175. }
  1176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1177. redis := service.RedisClient()
  1178. defer redis.Close()
  1179. //清空key 值
  1180. redis.Set(key, "", time.Second)
  1181. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1182. redis.Set(keyOne, "", time.Second)
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "receiveTreatmentAsses": receiveTreatmentAsses,
  1186. })
  1187. }
  1188. } else { //修改
  1189. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. // 查询信息规挡的设置天数
  1200. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1201. if infor.ID > 0 && infor.WeekDay > 0 {
  1202. var cha_time int64
  1203. timeNowStr := time.Now().Format("2006-01-02")
  1204. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1205. //今日的日期减去设置的日期
  1206. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1207. if cha_time >= recordDate.Unix() {
  1208. //查询审核是否允许
  1209. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1210. //申请状态不允许的情况 拒绝修改
  1211. if infor.ApplicationStatus != 1 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1213. return
  1214. }
  1215. }
  1216. }
  1217. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1218. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1219. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1220. receiveTreatmentAsses.ID = receiveTreatment.ID
  1221. if adminUserInfo.Org.Id == 10340 {
  1222. if condition == 1 {
  1223. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1224. if receiveTreatmentAsses.AdmissionNumber == "" {
  1225. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1226. }
  1227. }
  1228. }
  1229. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1230. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. //清空key 值
  1234. redis.Set(key, "", time.Second)
  1235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1236. redis.Set(keyOne, "", time.Second)
  1237. if err == nil {
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "receiveTreatmentAsses": receiveTreatmentAsses,
  1240. })
  1241. }
  1242. }
  1243. }
  1244. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1245. id, _ := c.GetInt64("patient", 0)
  1246. recordDateStr := c.GetString("record_date")
  1247. weightAfter, _ := c.GetFloat("weight_after", 0)
  1248. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1249. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1250. fmt.Println("weight_loss", weightReduce)
  1251. temperature, _ := c.GetFloat("temperature", 0)
  1252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1253. breathing_rate := c.GetString("breathing_rate")
  1254. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1255. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1256. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1257. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1258. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1259. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1260. cruor := c.GetString("cruor")
  1261. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1262. internalFistula := c.GetString("internal_fistula")
  1263. catheter := c.GetString("catheter")
  1264. complications := c.GetString("complication")
  1265. remark := c.GetString("remark")
  1266. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1267. dialysis_intakes := c.GetString("dialysis_intakes")
  1268. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1269. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1270. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1271. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1272. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1273. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1274. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1275. patientGose, _ := c.GetInt64("patient_gose", 0)
  1276. inpatientDepartment := c.GetString("inpatient_department")
  1277. observationContent := c.GetString("observation_content")
  1278. observationContentOther := c.GetString("observation_content_other")
  1279. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1280. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1281. in_advance_reason := c.GetString("in_advance_reason")
  1282. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1283. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1284. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1285. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1286. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1287. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1288. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1289. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1290. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1291. is_eat, _ := c.GetInt64("is_eat", 0)
  1292. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1293. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1294. channels, _ := c.GetInt64("channel", 0)
  1295. return_blood, _ := c.GetInt64("return_blood", 0)
  1296. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1297. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1298. dialysis_during, _ := c.GetFloat("dialysis_during")
  1299. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1300. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1301. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1302. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1303. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1304. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1305. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1306. setting_pressure := c.GetString("setting_pressure")
  1307. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1308. diastolic_pressure := c.GetString("diastolic_pressure")
  1309. other_complication := c.GetString("other_complication")
  1310. ktv := c.GetString("ktv")
  1311. urr := c.GetString("urr")
  1312. hypertenison, _ := c.GetInt64("hypertenison")
  1313. hypopiesia, _ := c.GetInt64("hypopiesia")
  1314. leave_office_method, _ := c.GetInt64("leave_office_method")
  1315. lapse, _ := c.GetInt64("lapse")
  1316. consciousness, _ := c.GetInt64("consciousness")
  1317. fallrisk, _ := c.GetInt64("fallrisk")
  1318. machine_run := c.GetString("machine_run")
  1319. after_urea := c.GetString("after_urea")
  1320. pip_coagulation := c.GetString("pip_coagulation")
  1321. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1322. transfusion_volume := c.GetString("transfusion_volume")
  1323. last_after_weight := c.GetString("last_after_weight")
  1324. displace_liqui_value := c.GetString("displace_liqui_value")
  1325. start_time := c.GetString("start_time")
  1326. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1327. if id <= 0 {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. adminUserInfo := c.GetMobileAdminUserInfo()
  1332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1333. if patient.ID == 0 {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1335. return
  1336. }
  1337. if len(recordDateStr) == 0 {
  1338. recordDateStr = time.Now().Format("2006-01-02")
  1339. }
  1340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1341. fmt.Println("parseDateErr", parseDateErr)
  1342. if parseDateErr != nil {
  1343. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1348. //now := time.Now()
  1349. //year, month, day := now.Date()
  1350. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1351. //todayTimeStamp := today_time.Unix()
  1352. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1353. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1354. UserOrgId: adminUserInfo.Org.Id,
  1355. PatientId: id,
  1356. AssessmentDate: recordDate.Unix(),
  1357. Temperature: temperature,
  1358. PulseFrequency: pulse_frequency,
  1359. BreathingRate: breathing_rate,
  1360. SystolicBloodPressure: systolic_blood_pressure,
  1361. DiastolicBloodPressure: diastolic_blood_pressure,
  1362. ActualUltrafiltration: actual_ultrafiltration,
  1363. ActualDisplacement: actual_displacement,
  1364. ActualTreatmentHour: actualtreatHour,
  1365. ActualTreatmentMinute: actualtreatmin,
  1366. WeightAfter: weightAfter,
  1367. AdditionalWeight: additionalWeight,
  1368. WeightLoss: weightReduce,
  1369. Cruor: cruor,
  1370. SymptomAfterDialysis: symptomsAfterDialysi,
  1371. InternalFistula: internalFistula,
  1372. Catheter: catheter,
  1373. Complication: complications,
  1374. DialysisIntakes: dialysateVolume,
  1375. CreatedTime: time.Now().Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. Status: 1,
  1378. Remark: remark,
  1379. BloodAccessPartId: blood_access_part_id,
  1380. BloodAccessPartOperaId: blood_access_part_opera_id,
  1381. DialysisIntakesUnit: dialysis_intakes_unit,
  1382. PuncturePointOozingBlood: puncturePointOozingBlood,
  1383. PuncturePointHaematoma: puncturePointHaematoma,
  1384. InternalFistulaTremorAc: internalFistulaTremorAc,
  1385. PatientGose: patientGose,
  1386. InpatientDepartment: inpatientDepartment,
  1387. ObservationContent: observationContent,
  1388. ObservationContentOther: observationContentOther,
  1389. DialysisProcess: dialysis_process,
  1390. InAdvanceMinute: in_advance_minute,
  1391. InAdvanceReason: in_advance_reason,
  1392. HemostasisMinute: hemostasis_minute,
  1393. HemostasisOpera: hemostasis_opera,
  1394. TremorNoise: tremor_noise,
  1395. DisequilibriumSyndrome: disequilibrium_syndrome,
  1396. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1397. ArterialTube: arterial_tube,
  1398. IntravenousTube: intravenous_tube,
  1399. Dialyzer: dialyzer,
  1400. InAdvanceReasonOther: in_advance_reason_other,
  1401. IsEat: is_eat,
  1402. CvcA: cvc_a,
  1403. CvcV: cvc_v,
  1404. Channel: channels,
  1405. ReturnBlood: return_blood,
  1406. RehydrationVolume: rehydration_volume,
  1407. DialysisDuring: dialysis_during,
  1408. StrokeVolume: stroke_volume,
  1409. BloodFlow: blood_flow,
  1410. SealingFluidDispose: sealing_fluid_dispose,
  1411. SealingFluidSpecial: sealing_fluid_special,
  1412. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1413. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1414. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1415. SettingPressure: setting_pressure,
  1416. DiastolicPressure: diastolic_pressure,
  1417. OtherComplication: other_complication,
  1418. Ktv: ktv,
  1419. Urr: urr,
  1420. Hypopiesia: hypopiesia,
  1421. Hypertenison: hypertenison,
  1422. Lapse: lapse,
  1423. LeaveOfficeMethod: leave_office_method,
  1424. Consciousness: consciousness,
  1425. Fallrisk: fallrisk,
  1426. MachineRun: machine_run,
  1427. AfterUrea: after_urea,
  1428. PipCoagulation: pip_coagulation,
  1429. AccumulatedBloodVolume: accumulated_blood_volume,
  1430. TransfusionVolume: transfusion_volume,
  1431. LastAfterWeight: last_after_weight,
  1432. DisplaceLiquiValue: displace_liqui_value,
  1433. RecordTime: startDate.Unix(),
  1434. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1435. }
  1436. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1437. // 查询信息规挡的设置天数
  1438. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1439. if infor.ID > 0 && infor.WeekDay > 0 {
  1440. var cha_time int64
  1441. timeNowStr := time.Now().Format("2006-01-02")
  1442. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1443. //今日的日期减去设置的日期
  1444. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1445. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1446. if cha_time >= recordDate.Unix() {
  1447. //查询审核是否允许
  1448. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1449. //申请状态不允许的情况 拒绝修改
  1450. if infor.ApplicationStatus != 1 {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1457. if assessmentAfter.ID == 0 { //新增
  1458. if appRole.UserType == 2 || appRole.UserType == 1 {
  1459. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1460. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1461. } else {
  1462. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1463. }
  1464. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1465. if assessmentAfterDislysis.UserOrgId != 10340 {
  1466. if assessmentAfterDislysis.WeightAfter == 0 {
  1467. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1468. }
  1469. }
  1470. if adminUserInfo.Org.Id == 10693 {
  1471. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1472. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1473. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1474. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1475. }
  1476. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1477. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1478. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1479. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1480. }
  1481. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1482. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1483. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1484. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1485. }
  1486. if assessmentAfterDislysis.PulseFrequency == 0 {
  1487. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1488. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1489. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1490. }
  1491. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1492. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1493. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1494. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1495. }
  1496. }
  1497. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1498. //记录日志
  1499. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1500. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1501. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1502. PatientId: assessmentAfterDislysis.PatientId,
  1503. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1504. Status: 1,
  1505. ErrLog: string(byterequest),
  1506. AdminUserId: adminUserInfo.AdminUser.Id,
  1507. Ctime: 0,
  1508. Mtime: 0,
  1509. Source: "手机端保存透后评估",
  1510. }
  1511. service.CreateAfterDialysisLog(afterDialysisLog)
  1512. finish := models.XtDialysisFinish{
  1513. IsFinish: 1,
  1514. UserOrgId: adminUserInfo.Org.Id,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: 0,
  1518. Module: 9,
  1519. RecordDate: recordDate.Unix(),
  1520. Sourse: 1,
  1521. PatientId: id,
  1522. }
  1523. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1524. if dialysisFinish.ID == 0 {
  1525. service.CreateDialysisFinish(finish)
  1526. }
  1527. redis := service.RedisClient()
  1528. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1529. redis.Set(keyTwo, "", time.Second)
  1530. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1531. //清空key 值
  1532. redis.Set(key, "", time.Second)
  1533. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1534. redis.Set(keyOne, "", time.Second)
  1535. defer redis.Close()
  1536. if err == nil {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "assessmentAfterDislysis": assessmentAfterDislysis,
  1539. })
  1540. }
  1541. return
  1542. } else { //修改
  1543. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1544. if infor.ID > 0 && infor.WeekDay > 0 {
  1545. var cha_time int64
  1546. timeNowStr := time.Now().Format("2006-01-02")
  1547. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1548. //今日的日期减去设置的日期
  1549. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1550. if cha_time >= recordDate.Unix() {
  1551. //查询审核是否允许
  1552. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1553. //申请状态不允许的情况 拒绝修改
  1554. if infor.ApplicationStatus != 1 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1556. return
  1557. }
  1558. }
  1559. }
  1560. if appRole.UserType == 2 || appRole.UserType == 1 {
  1561. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1562. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1563. } else {
  1564. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1565. if assessmentAfterDislysis.Creater == 0 {
  1566. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1570. assessmentAfterDislysis.ID = assessmentAfter.ID
  1571. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1572. if assessmentAfterDislysis.UserOrgId != 10340 {
  1573. if assessmentAfterDislysis.WeightAfter == 0 {
  1574. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1575. }
  1576. }
  1577. if adminUserInfo.Org.Id == 10693 {
  1578. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1579. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1580. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1581. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1582. }
  1583. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1584. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1585. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1586. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1587. }
  1588. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1589. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1590. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1591. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1592. }
  1593. if assessmentAfterDislysis.PulseFrequency == 0 {
  1594. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1595. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1596. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1597. }
  1598. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1599. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1600. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1601. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1602. }
  1603. }
  1604. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1605. //记录日志
  1606. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1607. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1608. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1609. PatientId: assessmentAfterDislysis.PatientId,
  1610. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1611. Status: 1,
  1612. ErrLog: string(byterequest),
  1613. AdminUserId: adminUserInfo.AdminUser.Id,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: 0,
  1616. Source: "手机端修改保存透后评估",
  1617. }
  1618. service.CreateAfterDialysisLog(afterDialysisLog)
  1619. redis := service.RedisClient()
  1620. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1621. redis.Set(keyTwo, "", time.Second)
  1622. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1623. //清空key 值
  1624. redis.Set(key, "", time.Second)
  1625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1626. redis.Set(keyOne, "", time.Second)
  1627. if err == nil {
  1628. c.ServeSuccessJSON(map[string]interface{}{
  1629. "assessmentAfterDislysis": assessmentAfterDislysis,
  1630. })
  1631. return
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func (c *DialysisAPIController) PostDialysisPrescription() {
  1637. id, _ := c.GetInt64("patient", 0)
  1638. recordDateStr := c.GetString("record_date")
  1639. if id <= 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. adminUserInfo := c.GetMobileAdminUserInfo()
  1644. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1645. if patient.ID == 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1647. return
  1648. }
  1649. if len(recordDateStr) == 0 {
  1650. recordDateStr = time.Now().Format("2006-01-02")
  1651. }
  1652. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1653. if parseDateErr != nil {
  1654. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. mode_id, _ := c.GetInt64("mode_id", 0)
  1659. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1660. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1661. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1662. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1663. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1664. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1665. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1673. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1674. kalium, _ := c.GetFloat("kalium", 0)
  1675. sodium, _ := c.GetFloat("sodium", 0)
  1676. calcium, _ := c.GetFloat("calcium", 0)
  1677. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1678. glucose, _ := c.GetFloat("glucose", 0)
  1679. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1683. conductivity, _ := c.GetFloat("conductivity", 0)
  1684. remark := c.GetString("remark")
  1685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1691. special_medicine_other := c.GetString("special_medicine_other")
  1692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1694. blood_access, _ := c.GetInt64("blood_access", 0)
  1695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1696. body_fluid_other := c.GetString("body_fluid_other")
  1697. niprocart, _ := c.GetInt64("niprocart", 0)
  1698. jms, _ := c.GetInt64("jms", 0)
  1699. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1700. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1701. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1702. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1703. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1704. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1705. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1706. injector, _ := c.GetInt64("injector", 0)
  1707. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1708. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1709. safe_package, _ := c.GetInt64("package", 0)
  1710. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1711. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1714. blood := c.GetString("blood")
  1715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1718. displace_speed := c.GetString("displace_speed")
  1719. illness, _ := c.GetInt64("illness")
  1720. amylaceum := c.GetString("amylaceum")
  1721. single_time := c.GetString("single_time")
  1722. single_water := c.GetString("single_water")
  1723. replacement_flow := c.GetString("replacement_flow")
  1724. plasma_separator := c.GetString("plasma_separator")
  1725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1727. oxygen_flow := c.GetString("oxygen_flow")
  1728. oxygen_time := c.GetString("oxygen_time")
  1729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1731. puncture_needle := c.GetString("puncture_needle")
  1732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1733. epo := c.GetString("epo")
  1734. epo_count, _ := c.GetFloat("epo_count", 0)
  1735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1736. admin_user_id, _ := c.GetInt64("admin_user_id")
  1737. is_water := c.GetString("is_water")
  1738. var is_war int64
  1739. if is_water == "是" {
  1740. is_war = 1
  1741. }
  1742. if is_water == "否" {
  1743. is_war = 2
  1744. }
  1745. if is_water == "请选择" {
  1746. is_war = 0
  1747. }
  1748. drhy_water := c.GetString("drhy_water")
  1749. dry_water_hour := c.GetString("dry_water_hour")
  1750. water_machine := c.GetString("water_machine")
  1751. add_amount, _ := c.GetFloat("add_amount")
  1752. reduce_amount, _ := c.GetFloat("reduce_amount")
  1753. dialysis_remark := c.GetString("dialysis_remark")
  1754. prescribing_number, _ := c.GetFloat("prescribing_number")
  1755. prescription_sodium := c.GetString("prescription_sodium")
  1756. start_sodium := c.GetString("start_sodium")
  1757. sodium_curve := c.GetString("sodium_curve")
  1758. treatment_remark := c.GetString("treatment_remark")
  1759. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1760. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1761. prescription_water, _ := c.GetFloat("prescription_water")
  1762. dialysis_strainer := c.GetString("dialysis_strainer")
  1763. chaptalization := c.GetString("chaptalization")
  1764. washing_time := c.GetString("washing_time")
  1765. warsh_count := c.GetString("warsh_count")
  1766. blood_access_part_id := c.GetString("blood_access_part_id")
  1767. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1768. dialyzate := c.GetString("dialyzate")
  1769. first_super := c.GetString("first_super")
  1770. sterilization_water := c.GetString("sterilization_water")
  1771. five_glucose := c.GetString("five_glucose")
  1772. fifty_glucose := c.GetString("fifty_glucose")
  1773. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  1774. calcium_gluconate := c.GetString("calcium_gluconate")
  1775. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  1776. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  1777. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  1778. new_sty := c.GetString("new_sty")
  1779. var first_sup int64
  1780. if first_super == "是" {
  1781. first_sup = 1
  1782. }
  1783. if first_super == "否" {
  1784. first_sup = 2
  1785. }
  1786. if first_super == "请选择" {
  1787. first_sup = 0
  1788. }
  1789. is_sequential := c.GetString("is_sequential")
  1790. var is_sequent int64
  1791. if is_sequential == "是" {
  1792. is_sequent = 1
  1793. }
  1794. if is_sequential == "否" {
  1795. is_sequent = 2
  1796. }
  1797. if is_sequential == "请选择" {
  1798. is_sequent = 0
  1799. }
  1800. conduct := c.GetString("conduct")
  1801. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1802. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1803. //
  1804. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1805. // if appRole.UserType == 3 {
  1806. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1807. // if getPermissionErr != nil {
  1808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1809. // return
  1810. // } else if headNursePermission == nil {
  1811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1812. // return
  1813. // }
  1814. // }
  1815. //}
  1816. // 查询信息规挡的设置天数
  1817. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1818. if infor.ID > 0 && infor.WeekDay > 0 {
  1819. var cha_time int64
  1820. timeNowStr := time.Now().Format("2006-01-02")
  1821. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1822. //今日的日期减去设置的日期
  1823. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1824. if cha_time >= recordDate.Unix() {
  1825. //查询审核是否允许
  1826. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1827. //申请状态不允许的情况 拒绝修改
  1828. if infor.ApplicationStatus != 1 {
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1830. return
  1831. }
  1832. }
  1833. }
  1834. if mode_id > 0 {
  1835. var str string
  1836. //查找该机构用的是什么透析器
  1837. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1838. if filedConfig.ID > 0 {
  1839. str = dialyzerPerfusionApparatus
  1840. } else {
  1841. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1842. }
  1843. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1844. }
  1845. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1846. var dialysis_dialyszers_id int64
  1847. var dialysis_strainer_id int64
  1848. var dialysis_irrigation_id int64
  1849. if len(goodList) > 0 {
  1850. for _, item := range goodList {
  1851. if item.SpecificationName == dialysis_dialyszers {
  1852. dialysis_dialyszers_id = item.ID
  1853. }
  1854. if item.SpecificationName == dialysis_irrigation {
  1855. dialysis_irrigation_id = item.ID
  1856. }
  1857. if item.SpecificationName == dialysis_strainer {
  1858. dialysis_strainer_id = item.ID
  1859. }
  1860. }
  1861. }
  1862. //TODO 需要根据角色去判断
  1863. prescription := models.DialysisPrescription{
  1864. UserOrgId: adminUserInfo.Org.Id,
  1865. PatientId: id,
  1866. RecordDate: recordDate.Unix(),
  1867. ModeId: mode_id,
  1868. DialysisDuration: dialysis_duration,
  1869. Dialyzer: dialyzer,
  1870. PerfusionApparatus: perfusion_apparatus,
  1871. BloodFlowVolume: blood_flow_volume,
  1872. DewaterAmount: dewater_amount,
  1873. DisplaceLiqui: displace_liqui,
  1874. ReplacementWay: replacement_way,
  1875. Anticoagulant: anticoagulant,
  1876. AnticoagulantShouji: anticoagulant_shouji,
  1877. AnticoagulantWeichi: anticoagulant_weichi,
  1878. AnticoagulantZongliang: anticoagulant_zongliang,
  1879. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1880. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1881. Kalium: kalium,
  1882. Sodium: sodium,
  1883. Calcium: calcium,
  1884. Bicarbonate: bicarbonate,
  1885. Glucose: glucose,
  1886. // DryWeight: dry_weight,
  1887. DialysateFlow: dialysate_flow,
  1888. DialysateTemperature: dialysate_temperature,
  1889. // PrescriptionDoctor: prescription_doctor,
  1890. ReplacementTotal: replacement_total,
  1891. Conductivity: conductivity,
  1892. Remark: remark,
  1893. Status: 1,
  1894. CreatedTime: time.Now().Unix(),
  1895. UpdatedTime: time.Now().Unix(),
  1896. DialysisDurationMinute: dialysisDurationMinute,
  1897. DialysisDurationHour: dialysisDurationHour,
  1898. TargetUltrafiltration: targetUltrafiltration,
  1899. DialysateFormulation: dialysateFormulation,
  1900. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1901. BodyFluid: body_fluid,
  1902. SpecialMedicine: special_medicine,
  1903. SpecialMedicineOther: special_medicine_other,
  1904. DisplaceLiquiPart: displace_liqui_part,
  1905. DisplaceLiquiValue: displace_liqui_value,
  1906. BloodAccess: blood_access,
  1907. Ultrafiltration: ultrafiltration,
  1908. BodyFluidOther: body_fluid_other,
  1909. Niprocart: niprocart,
  1910. Jms: jms,
  1911. FistulaNeedleSet: fistula_needle_set,
  1912. FistulaNeedleSet16: fistula_needle_set_16,
  1913. Hemoperfusion: hemoperfusion,
  1914. DialyserSterilised: dialyser_sterilised,
  1915. Filtryzer: filtryzer,
  1916. Dialyzers: dialyzers,
  1917. Injector: injector,
  1918. Bloodlines: bloodlines,
  1919. TubingHemodialysis: tubing_hemodialysis,
  1920. Package: safe_package,
  1921. ALiquid: a_liquid,
  1922. TargetKtv: target_ktv,
  1923. PreImpulse: pre_impulse,
  1924. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1925. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1926. Blood: blood,
  1927. DialysisDialyszers: dialysis_dialyszers,
  1928. DialysisIrrigation: dialysis_irrigation,
  1929. AntioxidantCommodityName: antioxidant_commodity_name,
  1930. DisplaceSpeed: displace_speed,
  1931. Illness: illness,
  1932. Amylaceum: amylaceum,
  1933. SingleTime: single_time,
  1934. SingleWater: single_water,
  1935. ReplacementFlow: replacement_flow,
  1936. PlasmaSeparator: plasma_separator,
  1937. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1938. OxygenUptake: oxygen_uptake,
  1939. OxygenFlow: oxygen_flow,
  1940. OxygenTime: oxygen_time,
  1941. HemodialysisPipelines: hemodialysis_pipelines,
  1942. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1943. PunctureNeedle: puncture_needle,
  1944. PunctureNeedleCount: puncture_needle_count,
  1945. Epo: epo,
  1946. EpoCount: epo_count,
  1947. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1948. AdminUserId: admin_user_id,
  1949. IsWater: is_war,
  1950. DrhyWater: drhy_water,
  1951. DryWaterHour: dry_water_hour,
  1952. WaterMachine: water_machine,
  1953. AddAmount: add_amount,
  1954. ReduceAmount: reduce_amount,
  1955. DialysisRemark: dialysis_remark,
  1956. PrescribingNumber: prescribing_number,
  1957. StartSodium: start_sodium,
  1958. SodiumCurve: sodium_curve,
  1959. TreatmentRemark: treatment_remark,
  1960. PrescriptionSodium: prescription_sodium,
  1961. DialysisFluidFlow: dialysis_fluid_flow,
  1962. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1963. PrescriptionWater: prescription_water,
  1964. DialysisStrainer: dialysis_strainer,
  1965. Chaptalization: chaptalization,
  1966. WashingTime: washing_time,
  1967. WarshCount: warsh_count,
  1968. BloodAccessPartId: blood_access_part_id,
  1969. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1970. Dialyzate: dialyzate,
  1971. DialysisDialyszersId: dialysis_dialyszers_id,
  1972. DialysisIrrigationId: dialysis_irrigation_id,
  1973. DialysisStrainerId: dialysis_strainer_id,
  1974. FirstSuper: first_sup,
  1975. IsSequential: is_sequent,
  1976. Conduct: conduct,
  1977. SterilizationWater: sterilization_water,
  1978. FiveGlucose: five_glucose,
  1979. FiftyGlucose: fifty_glucose,
  1980. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  1981. CalciumGluconate: calcium_gluconate,
  1982. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  1983. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  1984. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  1985. NewSty: new_sty,
  1986. }
  1987. if prescription.ModeId != 13 {
  1988. prescription.SterilizationWater = ""
  1989. prescription.FiveGlucose = ""
  1990. prescription.FiftyGlucose = ""
  1991. prescription.MagnesiumSulfateInjection = ""
  1992. prescription.CalciumGluconate = ""
  1993. prescription.FivePotassiumChlorideInjection = ""
  1994. prescription.TenPotassiumChlorideInjection = ""
  1995. prescription.FiveSodiumBicarbonateInjection = ""
  1996. prescription.NewSty = ""
  1997. }
  1998. if adminUserInfo.Org.Id == 10721 {
  1999. if prescription.ModeId == 2 {
  2000. if prescription.ReplacementTotal == 0 {
  2001. prescription.ReplacementTotal = 15
  2002. }
  2003. }
  2004. }
  2005. //查询最近透析准备表里是否存在 透析器 灌流器
  2006. //
  2007. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2008. //
  2009. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2010. //
  2011. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2012. //if len(mation)>0{
  2013. // for _, item := range splitStr {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. //
  2017. // //查询最近一次的透析器
  2018. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2019. //
  2020. // if errcode == gorm.ErrRecordNotFound{
  2021. // //插入数据
  2022. // prepare := models.DialysisBeforePrepare{
  2023. // UserOrgId: adminUserInfo.Org.Id,
  2024. // PatientId: id,
  2025. // RecordDate: recordDate.Unix(),
  2026. // GoodTypeId: it.GoodTypeId,
  2027. // GoodId: it.ID,
  2028. // Count: 1,
  2029. // Ctime: time.Now().Unix(),
  2030. // Creater: adminUserInfo.AdminUser.Id,
  2031. // Status:1,
  2032. //
  2033. // }
  2034. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2035. // fmt.Println("",errcode)
  2036. // }
  2037. // }
  2038. // }
  2039. //
  2040. // }
  2041. //
  2042. // for _, item := range splitIrrigation {
  2043. // for _,it := range mation{
  2044. // if(item == it.SpecificationName){
  2045. // //查询最近一次的透析器
  2046. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2047. // if errcode == gorm.ErrRecordNotFound{
  2048. // //插入数据
  2049. // prepare := models.DialysisBeforePrepare{
  2050. // UserOrgId: adminUserInfo.Org.Id,
  2051. // PatientId: id,
  2052. // RecordDate: recordDate.Unix(),
  2053. // GoodTypeId: it.GoodTypeId,
  2054. // GoodId: it.ID,
  2055. // Count: 1,
  2056. // Ctime: time.Now().Unix(),
  2057. // Creater: adminUserInfo.AdminUser.Id,
  2058. // Status:1,
  2059. //
  2060. // }
  2061. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2062. // fmt.Println(errcode)
  2063. // }
  2064. // }
  2065. // }
  2066. // }
  2067. //}
  2068. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2069. if dialysisPrescription.ID == 0 { //新增
  2070. if appRole.UserType == 2 || appRole.UserType == 1 {
  2071. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2072. }
  2073. prescription.Creater = adminUserInfo.AdminUser.Id
  2074. //针对河间咸得
  2075. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2076. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2077. prescription.DisplaceLiquiPart = 0
  2078. prescription.DisplaceLiquiValue = 0
  2079. }
  2080. }
  2081. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2082. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2083. }
  2084. err := service.AddSigleRecord(&prescription)
  2085. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2086. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2087. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2088. if len(monitorList) > 0 {
  2089. var ultrafiltration_rate float64
  2090. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2091. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2092. var replacement_rate float64
  2093. if adminUserInfo.Org.Id == 10721 {
  2094. //乘10 除10是为了保留一位小数
  2095. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2096. }
  2097. if adminUserInfo.Org.Id == 9478 {
  2098. //乘10 除10是为了保留一位小数
  2099. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2100. }
  2101. if adminUserInfo.Org.Id == 10766 {
  2102. //乘10 除10是为了保留一位小数
  2103. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2104. }
  2105. var firstOpeateTime = monitorList[0].OperateTime
  2106. for _, item := range monitorList {
  2107. //超滤率
  2108. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2109. //置换率
  2110. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2111. //超滤量
  2112. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2113. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2114. //置换量
  2115. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2116. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2117. }
  2118. }
  2119. }
  2120. //记录日志
  2121. byterequest, _ := json.Marshal(prescription)
  2122. prescriptionLog := models.XtDialysisPrescriptionLog{
  2123. UserOrgId: prescription.UserOrgId,
  2124. Ctime: time.Now().Unix(),
  2125. Mtime: 0,
  2126. ErrLog: string(byterequest),
  2127. AdminUserId: adminUserInfo.AdminUser.Id,
  2128. RecordDate: prescription.RecordDate,
  2129. PatientId: prescription.PatientId,
  2130. Source: "手机端新增保存处方",
  2131. Status: 1,
  2132. }
  2133. service.CreatePrescriptionLog(prescriptionLog)
  2134. finish := models.XtDialysisFinish{
  2135. IsFinish: 1,
  2136. UserOrgId: adminUserInfo.Org.Id,
  2137. Status: 1,
  2138. Ctime: time.Now().Unix(),
  2139. Mtime: 0,
  2140. Module: 1,
  2141. RecordDate: recordDate.Unix(),
  2142. Sourse: 1,
  2143. PatientId: id,
  2144. }
  2145. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2146. if dialysisFinish.ID == 0 {
  2147. service.CreateDialysisFinish(finish)
  2148. }
  2149. //长沙南雅医院,自动生成抗凝剂的临时处方
  2150. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2151. if prescribing_number == 0 {
  2152. prescribing_number = 1
  2153. }
  2154. if prescribing_number == 0 && id == 14682 {
  2155. prescribing_number = 2
  2156. }
  2157. if prescribing_number == 0 && id == 18560 {
  2158. prescribing_number = 2
  2159. }
  2160. advice := models.DoctorAdvice{
  2161. UserOrgId: adminUserInfo.Org.Id,
  2162. PatientId: id,
  2163. GroupNo: 0,
  2164. AdviceType: 2,
  2165. RecordDate: recordDate.Unix(),
  2166. AdviceDate: recordDate.Unix(),
  2167. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2168. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2169. AdviceDesc: "",
  2170. ReminderDate: 0,
  2171. SingleDose: anticoagulant_zongliang,
  2172. SingleDoseUnit: "iu",
  2173. DrugSpec: 0,
  2174. DrugSpecUnit: "",
  2175. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2176. PrescribingNumberUnit: "支",
  2177. DeliveryWay: "静脉注射",
  2178. ExecutionFrequency: "上机前",
  2179. AdviceDoctor: 0,
  2180. Status: 1,
  2181. CreatedTime: time.Now().Unix(),
  2182. UpdatedTime: time.Now().Unix(),
  2183. IsPrescription: 1,
  2184. ExecutionState: 2,
  2185. StopState: 2,
  2186. IsSettle: 2,
  2187. }
  2188. // 查询排班信息
  2189. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2190. if schedulePatient.ID > 0 {
  2191. if schedulePatient.ScheduleType == 1 {
  2192. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2193. }
  2194. if schedulePatient.ScheduleType == 2 {
  2195. advice.StartTime = recordDate.Unix() + 9*60*60
  2196. }
  2197. }
  2198. // 抗凝剂名称
  2199. switch anticoagulant {
  2200. case 1:
  2201. advice.AdviceName = "无肝素"
  2202. break
  2203. case 2:
  2204. advice.AdviceName = "普通肝素"
  2205. break
  2206. case 3:
  2207. advice.AdviceName = "低分子肝素"
  2208. break
  2209. case 4:
  2210. advice.AdviceName = "阿加曲班"
  2211. break
  2212. case 5:
  2213. advice.AdviceName = "枸橼酸钠"
  2214. break
  2215. case 6:
  2216. advice.AdviceName = "低分子肝素钙"
  2217. break
  2218. case 7:
  2219. advice.AdviceName = "低分子肝素钠"
  2220. break
  2221. case 8:
  2222. advice.AdviceName = "依诺肝素"
  2223. break
  2224. case 9:
  2225. advice.AdviceName = "达肝素"
  2226. break
  2227. case 10:
  2228. advice.AdviceName = "体外抗凝"
  2229. break
  2230. case 11:
  2231. advice.AdviceName = "那曲肝素"
  2232. break
  2233. case 12:
  2234. advice.AdviceName = "无抗凝剂"
  2235. break
  2236. }
  2237. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2238. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2239. advice.AdviceDoctor = appRole.AdminUserId
  2240. }
  2241. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2242. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2243. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2244. advice.AdviceName = "低分子肝素钠注射液"
  2245. // 修改患者临时医嘱里的抗凝剂医嘱
  2246. advice.ID = advicePrescription.ID
  2247. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2248. } else {
  2249. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2250. advice.AdviceName = "低分子肝素钠注射液"
  2251. // 新增患者临时医嘱里的抗凝剂医嘱
  2252. service.CreateDoctorAdvice(&advice)
  2253. }
  2254. }
  2255. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2256. redis := service.RedisClient()
  2257. defer redis.Close()
  2258. //清空key 值
  2259. redis.Set(key, "", time.Second)
  2260. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2261. redis.Set(keyOne, "", time.Second)
  2262. }
  2263. //获取key,清空redis
  2264. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2265. redis := service.RedisClient()
  2266. //清空key 值
  2267. redis.Set(key, "", time.Second)
  2268. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2269. //清空key 值
  2270. redis.Set(keyOne, "", time.Second)
  2271. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2272. //清空key 值
  2273. redis.Set(keyTwo, "", time.Second)
  2274. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2275. redis.Set(keySix, "", time.Second)
  2276. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2277. redis.Set(keySeven, "", time.Second)
  2278. if err == nil {
  2279. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2280. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2281. //清空key 值
  2282. redis.Set(keyThree, "", time.Second)
  2283. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2284. //清空key 值
  2285. redis.Set(keyFour, "", time.Second)
  2286. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2287. redis.Set(keyFive, "", time.Second)
  2288. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2289. redis.Set(keySix, "", time.Second)
  2290. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2291. redis.Set(keySeven, "", time.Second)
  2292. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2293. //清空key 值
  2294. redis.Set(keyOne, "", time.Second)
  2295. if updateErr != nil {
  2296. utils.ErrorLog("%v", updateErr)
  2297. }
  2298. defer redis.Close()
  2299. c.ServeSuccessJSON(map[string]interface{}{
  2300. "prescription": prescription,
  2301. })
  2302. }
  2303. } else { //修改
  2304. //if mode_id > 0 {
  2305. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2306. //}
  2307. //if template.TemplateId == 1 {
  2308. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2309. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2310. // if getPermissionErr != nil {
  2311. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2312. // return
  2313. // } else if headNursePermission == nil {
  2314. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2315. // return
  2316. // }
  2317. // }
  2318. //}
  2319. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2320. prescription.Modifier = adminUserInfo.AdminUser.Id
  2321. if appRole.UserType == 2 || appRole.UserType == 1 {
  2322. prescription_doctor := adminUserInfo.AdminUser.Id
  2323. prescription.PrescriptionDoctor = prescription_doctor
  2324. } else {
  2325. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2326. }
  2327. if dialysisPrescription.Creater == 0 { //体重称
  2328. prescription.Creater = adminUserInfo.AdminUser.Id
  2329. } else {
  2330. prescription.Creater = dialysisPrescription.Creater
  2331. if adminUserInfo.Org.Id == 9882 {
  2332. if appRole.UserType == 2 || appRole.UserType == 1 {
  2333. prescription_doctor := adminUserInfo.AdminUser.Id
  2334. prescription.PrescriptionDoctor = prescription_doctor
  2335. prescription.Creater = prescription_doctor
  2336. }
  2337. }
  2338. }
  2339. prescription.ID = dialysisPrescription.ID
  2340. if adminUserInfo.Org.Id == 10721 {
  2341. if prescription.ModeId == 2 {
  2342. if prescription.ReplacementTotal == 0 {
  2343. prescription.ReplacementTotal = 15
  2344. }
  2345. }
  2346. }
  2347. service.UpDateDialysisPrescription(&prescription)
  2348. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2349. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2350. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2351. if len(monitorList) > 0 {
  2352. var ultrafiltration_rate float64
  2353. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2354. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2355. var replacement_rate float64
  2356. if adminUserInfo.Org.Id == 10721 {
  2357. //乘10 除10是为了保留一位小数
  2358. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2359. }
  2360. if adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  2361. //乘10 除10是为了保留一位小数
  2362. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2363. }
  2364. var firstOpeateTime = monitorList[0].OperateTime
  2365. for _, item := range monitorList {
  2366. //超滤率
  2367. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2368. //置换率
  2369. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2370. //超滤量
  2371. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2372. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2373. //置换量
  2374. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2375. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2376. }
  2377. }
  2378. }
  2379. //记录日志
  2380. byterequest, _ := json.Marshal(prescription)
  2381. prescriptionLog := models.XtDialysisPrescriptionLog{
  2382. UserOrgId: prescription.UserOrgId,
  2383. Ctime: time.Now().Unix(),
  2384. Mtime: 0,
  2385. ErrLog: string(byterequest),
  2386. AdminUserId: adminUserInfo.AdminUser.Id,
  2387. RecordDate: prescription.RecordDate,
  2388. PatientId: prescription.PatientId,
  2389. Source: "手机端修改处方",
  2390. Status: 1,
  2391. }
  2392. service.CreatePrescriptionLog(prescriptionLog)
  2393. finish := models.XtDialysisFinish{
  2394. IsFinish: 1,
  2395. UserOrgId: adminUserInfo.Org.Id,
  2396. Status: 1,
  2397. Ctime: time.Now().Unix(),
  2398. Mtime: 0,
  2399. Module: 1,
  2400. RecordDate: recordDate.Unix(),
  2401. Sourse: 1,
  2402. PatientId: id,
  2403. }
  2404. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2405. if dialysisFinish.ID == 0 {
  2406. service.CreateDialysisFinish(finish)
  2407. }
  2408. //修改处方
  2409. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2410. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2411. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2412. if advicePrescription.ID > 0 {
  2413. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2415. redis := service.RedisClient()
  2416. defer redis.Close()
  2417. //清空key 值
  2418. redis.Set(key, "", time.Second)
  2419. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2420. redis.Set(keyOne, "", time.Second)
  2421. }
  2422. }
  2423. //获取key,清空redis
  2424. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2425. redis := service.RedisClient()
  2426. //清空key 值
  2427. redis.Set(key, "", time.Second)
  2428. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2429. //清空key 值
  2430. redis.Set(keyOne, "", time.Second)
  2431. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2432. redis.Set(keySix, "", time.Second)
  2433. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2434. redis.Set(keySeven, "", time.Second)
  2435. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2436. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2437. //清空key 值
  2438. redis.Set(keyTwoOne, "", time.Second)
  2439. defer redis.Close()
  2440. if updateErr != nil {
  2441. utils.ErrorLog("%v", updateErr)
  2442. }
  2443. c.ServeSuccessJSON(map[string]interface{}{
  2444. "prescription": prescription,
  2445. })
  2446. }
  2447. }
  2448. func (c *DialysisAPIController) Finish() {
  2449. id, _ := c.GetInt64("patient", 0)
  2450. recordDateStr := c.GetString("record_date")
  2451. nurseID, _ := c.GetInt64("nurse")
  2452. end_time := c.GetString("end_time")
  2453. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2454. internal_fistula := c.GetString("blood_access_internal_fistula")
  2455. catheter := c.GetString("catheter")
  2456. cruor := c.GetString("cruor")
  2457. mission := c.GetString("mission")
  2458. condenser := c.GetString("condenser")
  2459. if id <= 0 || nurseID <= 0 {
  2460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2461. return
  2462. }
  2463. adminUserInfo := c.GetMobileAdminUserInfo()
  2464. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2465. if patient.ID == 0 {
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2467. return
  2468. }
  2469. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2470. if getNurseErr != nil {
  2471. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. } else if nurse == nil {
  2475. c.ErrorLog("护士不存在")
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. if len(recordDateStr) == 0 {
  2480. recordDateStr = time.Now().Format("2006-01-02")
  2481. }
  2482. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2483. if parseDateErr != nil {
  2484. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2486. return
  2487. }
  2488. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2489. if parseEndDateErr != nil {
  2490. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2492. return
  2493. }
  2494. // 查询信息规挡的设置天数
  2495. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2496. if infor.ID > 0 && infor.WeekDay > 0 {
  2497. var cha_time int64
  2498. timeNowStr := time.Now().Format("2006-01-02")
  2499. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2500. //今日的日期减去设置的日期
  2501. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2502. if cha_time >= recordDate.Unix() {
  2503. //查询审核是否允许
  2504. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2505. //申请状态不允许的情况 拒绝修改
  2506. if infor.ApplicationStatus != 1 {
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2508. return
  2509. }
  2510. }
  2511. }
  2512. //now := time.Now()
  2513. //year, month, day := now.Date()
  2514. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2515. //todayTimeStamp := today_time.Unix()
  2516. // 获取当天的第一条透析纪录
  2517. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2518. if getMonitorRecordsErr != nil {
  2519. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2521. return
  2522. }
  2523. // 获取当前的最后一条透析纪录
  2524. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2525. if getMonitorRecordsErr != nil {
  2526. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2528. return
  2529. }
  2530. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2531. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2532. if getAADErr != nil {
  2533. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2535. return
  2536. }
  2537. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2538. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2539. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2540. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2541. if assessmentAfterDislysis != nil {
  2542. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2543. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2544. } else {
  2545. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2546. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2547. tempassessmentAfterDislysis.Status = 1
  2548. tempassessmentAfterDislysis.PatientId = id
  2549. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2550. }
  2551. //长沙南雅
  2552. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2553. //获取最后一条透析处方数据
  2554. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2555. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2556. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2557. }
  2558. if dialysisOrder.Stage == 1 {
  2559. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2560. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2561. fmt.Println(value)
  2562. a, b := math.Modf(value)
  2563. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2564. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2565. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2566. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2567. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2568. }
  2569. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2570. //var num1 int64
  2571. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2572. //fmt.Println(num1)
  2573. //sub := float64(num1 / 3600)
  2574. //fmt.Println(sub)
  2575. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2576. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2577. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2578. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2579. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2580. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2581. if adminUserInfo.Org.Id != 10375 {
  2582. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2583. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2584. }
  2585. if adminUserInfo.Org.Id == 10766 {
  2586. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2587. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2588. }
  2589. if adminUserInfo.Org.Id != 10445 {
  2590. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2591. }
  2592. //北方营口医院
  2593. if adminUserInfo.Org.Id == 10445 {
  2594. //获取最后一条透析处方数据
  2595. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2596. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2597. } else {
  2598. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2599. }
  2600. //新化博翔
  2601. if adminUserInfo.Org.Id == 10447 {
  2602. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2603. }
  2604. //阳春
  2605. if adminUserInfo.Org.Id == 10485 {
  2606. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2607. }
  2608. if adminUserInfo.Org.Id == 10551 {
  2609. //获取最后一条透析处方数据
  2610. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2611. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2612. }
  2613. if adminUserInfo.Org.Id == 10580 {
  2614. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2615. }
  2616. if adminUserInfo.Org.Id == 10612 {
  2617. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2618. }
  2619. //孝康
  2620. if adminUserInfo.Org.Id == 10693 {
  2621. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2622. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2623. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2624. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2625. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2626. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2627. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2628. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2629. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2630. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2631. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2632. }
  2633. if adminUserInfo.Org.Id == 10721 {
  2634. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2635. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2636. }
  2637. if adminUserInfo.Org.Id == 10697 {
  2638. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2639. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2640. lastWeightAfter.LastAfterWeight = floatAfeter
  2641. }
  2642. if adminUserInfo.Org.Id == 10624 {
  2643. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2644. }
  2645. }
  2646. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10766 {
  2647. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2648. if adminUserInfo.Org.Id != 10702 {
  2649. if evaluation.SystolicBloodPressure == 0 {
  2650. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2651. if adminUserInfo.Org.Id == 10693 {
  2652. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2653. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2654. }
  2655. pre := models.PredialysisEvaluation{
  2656. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2657. }
  2658. fmt.Println("prew", pre)
  2659. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2661. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2662. redis := service.RedisClient()
  2663. redis.Set(key, "", time.Second)
  2664. redis.Set(keyOne, "", time.Second)
  2665. defer redis.Close()
  2666. fmt.Println(getNurseErr)
  2667. }
  2668. }
  2669. if adminUserInfo.Org.Id != 10702 {
  2670. if evaluation.DiastolicBloodPressure == 0 {
  2671. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2672. if adminUserInfo.Org.Id == 10693 {
  2673. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2674. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2675. }
  2676. pres := models.PredialysisEvaluation{
  2677. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2678. }
  2679. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2680. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2681. redis := service.RedisClient()
  2682. redis.Set(key, "", time.Second)
  2683. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2684. redis.Set(keyOne, "", time.Second)
  2685. defer redis.Close()
  2686. fmt.Println(getNurseErr)
  2687. }
  2688. }
  2689. if adminUserInfo.Org.Id != 10702 {
  2690. if evaluation.PulseFrequency == 0 {
  2691. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2692. if adminUserInfo.Org.Id == 10693 {
  2693. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2694. evaluation.PulseFrequency = pulseFrequency
  2695. }
  2696. press := models.PredialysisEvaluation{
  2697. PulseFrequency: evaluation.PulseFrequency,
  2698. }
  2699. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2701. redis := service.RedisClient()
  2702. redis.Set(key, "", time.Second)
  2703. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2704. redis.Set(keyOne, "", time.Second)
  2705. defer redis.Close()
  2706. fmt.Println(getNurseErr)
  2707. }
  2708. }
  2709. if evaluation.Temperature == 0 {
  2710. evaluation.Temperature = fmonitorRecords.Temperature
  2711. press := models.PredialysisEvaluation{
  2712. Temperature: evaluation.Temperature,
  2713. }
  2714. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2715. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2716. redis := service.RedisClient()
  2717. redis.Set(key, "", time.Second)
  2718. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2719. redis.Set(keyOne, "", time.Second)
  2720. defer redis.Close()
  2721. fmt.Println(getNurseErr)
  2722. }
  2723. }
  2724. if adminUserInfo.Org.Id == 9583 {
  2725. //获取透析处方的最后一条数据
  2726. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2727. if diaerr != nil {
  2728. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. }
  2732. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2733. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2734. }
  2735. }
  2736. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2737. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2738. }
  2739. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2740. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2741. }
  2742. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2743. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2744. }
  2745. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2746. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2747. }
  2748. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2749. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2750. }
  2751. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2752. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2753. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2754. }
  2755. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2756. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2757. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2758. }
  2759. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2760. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2761. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2762. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2763. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2764. }
  2765. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2766. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2767. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2768. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2769. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2770. }
  2771. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2772. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2773. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2774. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2775. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2776. }
  2777. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2778. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2779. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2780. }
  2781. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2782. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2783. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2784. }
  2785. if lastAssessmentAfterDislysis != nil {
  2786. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2787. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2788. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2789. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2790. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2791. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2792. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2793. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2794. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2795. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2796. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2797. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2798. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2799. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2800. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2801. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2802. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2803. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2804. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2805. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2806. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2807. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2808. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2809. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2810. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2811. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2812. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2813. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2814. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2815. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2816. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2817. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2818. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2819. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2820. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2821. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2822. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2823. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2824. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2825. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2826. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2827. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2828. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2829. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2830. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2831. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2832. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2833. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2834. if tempassessmentAfterDislysis.PatientId == 18695 {
  2835. tempassessmentAfterDislysis.ActualDisplacement = 0
  2836. }
  2837. if adminUserInfo.Org.Id != 10375 {
  2838. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2839. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2840. }
  2841. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2842. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2843. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2844. }
  2845. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2846. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2847. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2848. }
  2849. }
  2850. finish := models.XtDialysisFinish{
  2851. IsFinish: 1,
  2852. UserOrgId: adminUserInfo.Org.Id,
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Mtime: 0,
  2856. Module: 9,
  2857. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2858. Sourse: 1,
  2859. PatientId: tempassessmentAfterDislysis.PatientId,
  2860. }
  2861. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2862. if dialysisFinish.ID == 0 {
  2863. service.CreateDialysisFinish(finish)
  2864. }
  2865. //孝康
  2866. if adminUserInfo.Org.Id == 10693 {
  2867. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2868. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2869. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2870. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2871. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2872. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2873. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2874. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2875. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2876. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2877. }
  2878. if adminUserInfo.Org.Id == 10697 {
  2879. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2880. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2881. lastWeightAfter.LastAfterWeight = floatAfeter
  2882. }
  2883. if adminUserInfo.Org.Id == 10721 {
  2884. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2885. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2886. }
  2887. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2888. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2889. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2890. redis := service.RedisClient()
  2891. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2892. redis.Set(keyOne, "", time.Second)
  2893. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2894. redis.Set(keyTwo, "", time.Second)
  2895. defer redis.Close()
  2896. //清空key 值
  2897. redis.Set(key, "", time.Second)
  2898. if err != nil {
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2900. return
  2901. }
  2902. if dialysisOrder == nil {
  2903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2904. return
  2905. }
  2906. if dialysisOrder.Stage == 2 {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2908. return
  2909. }
  2910. if dialysisOrder.Stage == 1 {
  2911. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2912. finish := models.XtDialysisFinish{
  2913. IsFinish: 1,
  2914. UserOrgId: adminUserInfo.Org.Id,
  2915. Status: 1,
  2916. Ctime: time.Now().Unix(),
  2917. Mtime: 0,
  2918. Module: 8,
  2919. RecordDate: recordDate.Unix(),
  2920. Sourse: 1,
  2921. PatientId: id,
  2922. }
  2923. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2924. if dialysisFinish.ID == 0 {
  2925. service.CreateDialysisFinish(finish)
  2926. }
  2927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2928. redis := service.RedisClient()
  2929. defer redis.Close()
  2930. //清空key 值
  2931. redis.Set(key, "", time.Second)
  2932. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2933. redis.Set(keyOne, "", time.Second)
  2934. //结束时候透析次数加1
  2935. service.UpdateSolutionByPatientId(id)
  2936. //下机完自动消毒,针对长沙南雅
  2937. if dialysisOrder.Stage == 1 {
  2938. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2939. //根据床位号获取设备型号
  2940. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2941. //查询使用消毒最后一条消毒记录
  2942. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2943. fmt.Println("err", err)
  2944. if err == gorm.ErrRecordNotFound {
  2945. //查找排班
  2946. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2947. //查询改设备是否有消毒计划
  2948. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2949. //根据床位号获取设备id
  2950. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2951. //查询病人信息
  2952. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2953. var con = ""
  2954. if patients.IsInfectious == 0 {
  2955. con = ""
  2956. }
  2957. if patients.IsInfectious == 1 {
  2958. con = "无"
  2959. }
  2960. if patients.IsInfectious == 2 {
  2961. con = "有"
  2962. }
  2963. if errcode == nil {
  2964. var end_time int64
  2965. end_time = endDate.Unix() + plan.DisinfecTime*60
  2966. //新增消毒
  2967. information := models.DeviceInformation{
  2968. Date: dialysisOrder.DialysisDate,
  2969. Zone: dialysisOrder.ZoneId,
  2970. Class: dialysisOrder.SchedualType,
  2971. BedNumber: dialysisOrder.BedID,
  2972. PatientId: dialysisOrder.PatientId,
  2973. DialysisMode: scheduleByPatient.ModeId,
  2974. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2975. Disinfection: 1,
  2976. DialysisConcentration: 1,
  2977. DisinfectionStatus: 1,
  2978. Move: 1,
  2979. UserOrgId: dialysisOrder.UserOrgId,
  2980. DisinfectType: plan.Way,
  2981. DisinfectantType: plan.MachineDisinfectant,
  2982. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2983. Disinfectant: plan.Disinfectant,
  2984. Ctime: time.Now().Unix(),
  2985. Status: 1,
  2986. SignName: nurseID,
  2987. EquimentId: addmacher.ID,
  2988. DisinfectionResidue: 2,
  2989. Bed: addmacher.BedNumber,
  2990. StartTime: dialysisOrder.StartTime,
  2991. EndTime: dialysisOrder.EndTime,
  2992. Contagion: con,
  2993. WeightLoss: 0,
  2994. Hyperfiltratio: 0,
  2995. DialysisHour: "",
  2996. MachineRun: 1,
  2997. DisinfecStartime: endDate.Unix(),
  2998. DisinfecEndtime: end_time,
  2999. }
  3000. err := service.CreateInformationTwo(&information)
  3001. fmt.Println("报错", err)
  3002. }
  3003. }
  3004. }
  3005. }
  3006. dialysisOrder.Stage = 2
  3007. dialysisOrder.FinishNurse = nurseID
  3008. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  3009. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  3010. dialysisOrder.EndTime = endDate.Unix()
  3011. // 长沙南雅需求
  3012. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  3013. //获取最后1条监测的数据
  3014. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3015. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3016. var accumulatedBloodVolume float64
  3017. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  3018. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  3019. fmt.Println(err)
  3020. // 查询未执行的医嘱
  3021. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  3022. for _, item := range doctorAdvice {
  3023. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  3024. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  3025. redis := service.RedisClient()
  3026. //清空key 值
  3027. redis.Set(key, "", time.Second)
  3028. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  3029. redis.Set(keyTwo, "", time.Second)
  3030. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3031. redis.Set(keyThree, "", time.Second)
  3032. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  3033. theTime := toTime.Format("2006-01-02")
  3034. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3035. redis.Set(keyFour, "", time.Second)
  3036. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3037. redis.Set(keyFive, "", time.Second)
  3038. defer redis.Close()
  3039. }
  3040. }
  3041. go func() {
  3042. ssoDomain := beego.AppConfig.String("call_domain")
  3043. api := ssoDomain + "/index/downpatient"
  3044. values := make(url.Values)
  3045. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  3046. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3047. values.Set("patient_id", strconv.FormatInt(id, 10))
  3048. http.PostForm(api, values)
  3049. }()
  3050. if err == nil {
  3051. c.ServeSuccessJSON(map[string]interface{}{
  3052. "dialysisOrder": dialysisOrder,
  3053. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  3054. })
  3055. } else {
  3056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3057. }
  3058. }
  3059. //查找是否开启配置
  3060. //orderSetting, _ := service.GetDialysisOrderSetting(adminUserInfo.Org.Id)
  3061. ////开启下机扣减
  3062. //if orderSetting.IsOpen == 1 {
  3063. //
  3064. // //查询今日患者排班的模式
  3065. // db := service.XTWriteDB()
  3066. // // 开始外部循环的事务
  3067. // tx := db.Begin()
  3068. // // 在函数结束时处理事务回滚
  3069. // defer func() {
  3070. // if r := recover(); r != nil {
  3071. // tx.Rollback()
  3072. // }
  3073. // }()
  3074. //
  3075. // schedule, _ := service.GetDialysisOrderSchedule(id, recordDate.Unix(), adminUserInfo.Org.Id, tx)
  3076. //
  3077. // if schedule.ModeId == 1 {
  3078. // //扣减库存
  3079. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3080. //
  3081. // patient, _ := service.GetSfPatientById(tx, id)
  3082. // var over_count int64
  3083. // if schedule.ModeId == 1 {
  3084. // over_count = patient.HdCount
  3085. // }
  3086. // if schedule.ModeId == 2 {
  3087. // over_count = patient.HdfCount
  3088. // }
  3089. //
  3090. // if schedule.ModeId == 3 {
  3091. // over_count = patient.HdhpCount
  3092. // }
  3093. // if schedule.ModeId == 4 {
  3094. // over_count = patient.HpCount
  3095. // }
  3096. // if schedule.ModeId == 5 {
  3097. // over_count = patient.OtherCount
  3098. // }
  3099. // patientCountFlow := models.SfPatientCountFlow{
  3100. // PatientId: id,
  3101. // ModeId: schedule.ModeId,
  3102. // Count: 1,
  3103. // Status: 1,
  3104. // Ctime: time.Now().Unix(),
  3105. // Mtime: time.Now().Unix(),
  3106. // RecordDate: recordDate.Unix(),
  3107. // UserOrgId: adminUserInfo.Org.Id,
  3108. // Creater: adminUserInfo.AdminUser.Id,
  3109. // IsType: 1,
  3110. // OverCount: over_count,
  3111. // WarehouseOutId: 0,
  3112. // }
  3113. //
  3114. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3115. // }
  3116. //
  3117. // if schedule.ModeId == 2 {
  3118. //
  3119. // //扣减库存
  3120. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3121. //
  3122. // patient, _ := service.GetSfPatientById(tx, id)
  3123. // var over_count int64
  3124. // if schedule.ModeId == 1 {
  3125. // over_count = patient.HdCount
  3126. // }
  3127. // if schedule.ModeId == 2 {
  3128. // over_count = patient.HdfCount
  3129. // }
  3130. //
  3131. // if schedule.ModeId == 3 {
  3132. // over_count = patient.HdhpCount
  3133. // }
  3134. // if schedule.ModeId == 4 {
  3135. // over_count = patient.HpCount
  3136. // }
  3137. // if schedule.ModeId == 5 {
  3138. // over_count = patient.OtherCount
  3139. // }
  3140. // patientCountFlow := models.SfPatientCountFlow{
  3141. // PatientId: id,
  3142. // ModeId: schedule.ModeId,
  3143. // Count: 1,
  3144. // Status: 1,
  3145. // Ctime: time.Now().Unix(),
  3146. // Mtime: time.Now().Unix(),
  3147. // RecordDate: recordDate.Unix(),
  3148. // UserOrgId: adminUserInfo.Org.Id,
  3149. // Creater: adminUserInfo.AdminUser.Id,
  3150. // IsType: 2,
  3151. // OverCount: over_count,
  3152. // WarehouseOutId: 0,
  3153. // }
  3154. //
  3155. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3156. // }
  3157. //
  3158. // if schedule.ModeId == 3 {
  3159. //
  3160. // //扣减库存
  3161. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3162. //
  3163. // patient, _ := service.GetSfPatientById(tx, id)
  3164. // var over_count int64
  3165. // if schedule.ModeId == 1 {
  3166. // over_count = patient.HdCount
  3167. // }
  3168. // if schedule.ModeId == 2 {
  3169. // over_count = patient.HdfCount
  3170. // }
  3171. //
  3172. // if schedule.ModeId == 3 {
  3173. // over_count = patient.HdhpCount
  3174. // }
  3175. // if schedule.ModeId == 4 {
  3176. // over_count = patient.HpCount
  3177. // }
  3178. // if schedule.ModeId == 5 {
  3179. // over_count = patient.OtherCount
  3180. // }
  3181. // patientCountFlow := models.SfPatientCountFlow{
  3182. // PatientId: id,
  3183. // ModeId: schedule.ModeId,
  3184. // Count: 1,
  3185. // Status: 1,
  3186. // Ctime: time.Now().Unix(),
  3187. // Mtime: time.Now().Unix(),
  3188. // RecordDate: recordDate.Unix(),
  3189. // UserOrgId: adminUserInfo.Org.Id,
  3190. // Creater: adminUserInfo.AdminUser.Id,
  3191. // IsType: 3,
  3192. // OverCount: over_count,
  3193. // WarehouseOutId: 0,
  3194. // }
  3195. //
  3196. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3197. // }
  3198. // if schedule.ModeId == 4 {
  3199. //
  3200. // //扣减库存
  3201. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3202. //
  3203. // patient, _ := service.GetSfPatientById(tx, id)
  3204. // var over_count int64
  3205. // if schedule.ModeId == 1 {
  3206. // over_count = patient.HdCount
  3207. // }
  3208. // if schedule.ModeId == 2 {
  3209. // over_count = patient.HdfCount
  3210. // }
  3211. //
  3212. // if schedule.ModeId == 3 {
  3213. // over_count = patient.HdhpCount
  3214. // }
  3215. // if schedule.ModeId == 4 {
  3216. // over_count = patient.HpCount
  3217. // }
  3218. // if schedule.ModeId == 5 {
  3219. // over_count = patient.OtherCount
  3220. // }
  3221. // patientCountFlow := models.SfPatientCountFlow{
  3222. // PatientId: id,
  3223. // ModeId: schedule.ModeId,
  3224. // Count: 1,
  3225. // Status: 1,
  3226. // Ctime: time.Now().Unix(),
  3227. // Mtime: time.Now().Unix(),
  3228. // RecordDate: recordDate.Unix(),
  3229. // UserOrgId: adminUserInfo.Org.Id,
  3230. // Creater: adminUserInfo.AdminUser.Id,
  3231. // IsType: 4,
  3232. // OverCount: over_count,
  3233. // WarehouseOutId: 0,
  3234. // }
  3235. //
  3236. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3237. // }
  3238. // if schedule.ModeId != 1 && schedule.ModeId != 2 && schedule.ModeId != 3 && schedule.ModeId != 4 {
  3239. //
  3240. // //扣减库存
  3241. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3242. //
  3243. // patient, _ := service.GetSfPatientById(tx, id)
  3244. // var over_count int64
  3245. // if schedule.ModeId == 1 {
  3246. // over_count = patient.HdCount
  3247. // }
  3248. // if schedule.ModeId == 2 {
  3249. // over_count = patient.HdfCount
  3250. // }
  3251. //
  3252. // if schedule.ModeId == 3 {
  3253. // over_count = patient.HdhpCount
  3254. // }
  3255. // if schedule.ModeId == 4 {
  3256. // over_count = patient.HpCount
  3257. // }
  3258. // if schedule.ModeId == 5 {
  3259. // over_count = patient.OtherCount
  3260. // }
  3261. // patientCountFlow := models.SfPatientCountFlow{
  3262. // PatientId: id,
  3263. // ModeId: schedule.ModeId,
  3264. // Count: 1,
  3265. // Status: 1,
  3266. // Ctime: time.Now().Unix(),
  3267. // Mtime: time.Now().Unix(),
  3268. // RecordDate: recordDate.Unix(),
  3269. // UserOrgId: adminUserInfo.Org.Id,
  3270. // Creater: adminUserInfo.AdminUser.Id,
  3271. // IsType: 5,
  3272. // OverCount: over_count,
  3273. // WarehouseOutId: 0,
  3274. // }
  3275. //
  3276. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3277. // }
  3278. //
  3279. // tx.Commit()
  3280. // return
  3281. //}
  3282. }
  3283. func (c *DialysisAPIController) GetAllZone() {
  3284. adminUserInfo := c.GetMobileAdminUserInfo()
  3285. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3286. if err == nil {
  3287. c.ServeSuccessJSON(map[string]interface{}{
  3288. "zone": zone,
  3289. })
  3290. }
  3291. }
  3292. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3293. adminUserInfo := c.GetMobileAdminUserInfo()
  3294. page, _ := c.GetInt64("page", 1)
  3295. limit, _ := c.GetInt64("limit", 10)
  3296. schedulType, _ := c.GetInt64("schedul_type", 0)
  3297. startTime, _ := c.GetInt64("schedul_time", 0)
  3298. partitionType, _ := c.GetInt64("partition_type", 0)
  3299. keywords := c.GetString("keywords")
  3300. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3301. if err == nil {
  3302. c.ServeSuccessJSON(map[string]interface{}{
  3303. "schedule": dialysisSchedule,
  3304. })
  3305. }
  3306. return
  3307. }
  3308. // /m/api/dialysis/start [post]
  3309. // @param patient_id:int
  3310. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3311. // @param nurse:int 上机护士
  3312. // @param bed:int 床位号
  3313. func (this *DialysisAPIController) StartDialysis() {
  3314. patientID, _ := this.GetInt64("patient_id")
  3315. recordDateStr := this.GetString("record_date")
  3316. nurseID, _ := this.GetInt64("start_nurse")
  3317. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3318. blood_drawing, _ := this.GetInt64("blood_drawing")
  3319. schedual_type, _ := this.GetInt64("schedual_type")
  3320. bedID, _ := this.GetInt64("bed")
  3321. start_time := this.GetString("start_time")
  3322. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3323. change_nurse, _ := this.GetInt64("change_nurse")
  3324. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3325. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3326. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3327. puncture_needle := this.GetString("puncture_needle")
  3328. puncture_way := this.GetString("puncture_way")
  3329. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3330. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3331. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3332. zone_id, _ := this.GetInt64("zone_id")
  3333. elecsign := this.GetString("url")
  3334. nuclein_date_str := this.GetString("nuclein_date_str")
  3335. schedule_remark := this.GetString("schedule_remark")
  3336. order_remark := this.GetString("order_remark")
  3337. catheter_operation := this.GetString("catheter_operation")
  3338. blood_flow_volume := this.GetString("blood_flow_volume")
  3339. dialysis_strainer := this.GetString("dialysis_strainer")
  3340. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3342. return
  3343. }
  3344. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3345. if parseStartDateErr != nil {
  3346. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3348. return
  3349. }
  3350. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3351. if parseErr != nil {
  3352. this.ErrorLog("时间解析失败:%v", parseErr)
  3353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3354. return
  3355. }
  3356. adminUserInfo := this.GetMobileAdminUserInfo()
  3357. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3358. if getPatientErr != nil {
  3359. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3361. return
  3362. } else if patient == nil {
  3363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3364. return
  3365. }
  3366. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3367. if getNurseErr != nil {
  3368. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3370. return
  3371. } else if nurse == nil {
  3372. this.ErrorLog("护士不存在")
  3373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3374. return
  3375. }
  3376. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3377. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3378. if getDeviceNumberErr != nil {
  3379. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3381. return
  3382. } else if deviceNumber == nil {
  3383. this.ErrorLog("床位号不存在")
  3384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3385. return
  3386. }
  3387. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3388. if getRecordErr != nil {
  3389. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3391. return
  3392. } else if dialysisRecord != nil {
  3393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3394. return
  3395. }
  3396. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3397. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3398. timeLayout := "2006-01-02 15:04:05"
  3399. loc, _ := time.LoadLocation("Local")
  3400. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3401. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3402. schedulestartTime := theStartTime.Unix()
  3403. scheduleendTime := theEndTime.Unix()
  3404. var theNucleinDate int64
  3405. timeLayoutOne := "2006-01-02"
  3406. if len(nuclein_date_str) > 0 {
  3407. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3408. if err != nil {
  3409. utils.ErrorLog(err.Error())
  3410. }
  3411. theNucleinDate = theTime.Unix()
  3412. }
  3413. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3414. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3415. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3416. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3417. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3418. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3419. if record.ID == 0 {
  3420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3421. return
  3422. }
  3423. advices, _ := service.GetDialysisPrescriptionDoctorAdviceList(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3424. if len(advices) == 0 {
  3425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3426. return
  3427. }
  3428. }
  3429. //查询该床位是否有人用了
  3430. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3431. if err == gorm.ErrRecordNotFound { //空床位
  3432. // 修改了床位逻辑
  3433. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3434. if daySchedule.ID > 0 {
  3435. daySchedule.PartitionId = deviceNumber.ZoneID
  3436. daySchedule.BedId = bedID
  3437. daySchedule.ScheduleType = schedual_type
  3438. daySchedule.UpdatedTime = time.Now().Unix()
  3439. xtSchedule := models.Schedule{
  3440. PartitionId: deviceNumber.ZoneID,
  3441. BedId: bedID,
  3442. ScheduleType: schedual_type,
  3443. UpdatedTime: time.Now().Unix(),
  3444. }
  3445. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3446. if err != nil {
  3447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3448. return
  3449. }
  3450. }
  3451. } else if err == nil {
  3452. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3453. if order.ID > 0 { //该机位被其他人占用了
  3454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3455. return
  3456. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3457. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3458. if daySchedule.ID > 0 {
  3459. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3460. if err != nil {
  3461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3462. return
  3463. }
  3464. }
  3465. }
  3466. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3468. return
  3469. }
  3470. //else if order.ID == 0 { //该床位没被占用
  3471. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3472. // if daySchedule.ID > 0 {
  3473. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3474. // //daySchedule.BedId = bedID
  3475. // //daySchedule.ScheduleType = schedual_type
  3476. // //daySchedule.UpdatedTime = time.Now().Unix()
  3477. // //err := service.UpdateSchedule(&daySchedule)
  3478. // xtSchedule := models.Schedule{
  3479. // PartitionId: deviceNumber.ZoneID,
  3480. // BedId: bedID,
  3481. // ScheduleType: schedual_type,
  3482. // UpdatedTime: time.Now().Unix(),
  3483. // }
  3484. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3485. // if err != nil {
  3486. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3487. // return
  3488. // }
  3489. // }
  3490. //}
  3491. //}
  3492. } else if err != nil {
  3493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3494. return
  3495. }
  3496. // 查询信息规挡的设置天数
  3497. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3498. if infor.ID > 0 && infor.WeekDay > 0 {
  3499. var cha_time int64
  3500. timeNowStr := time.Now().Format("2006-01-02")
  3501. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3502. //今日的日期减去设置的日期
  3503. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3504. if cha_time >= recordDate.Unix() {
  3505. //查询审核是否允许
  3506. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3507. //申请状态不允许的情况 拒绝修改
  3508. if infor.ApplicationStatus != 1 {
  3509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3510. return
  3511. }
  3512. }
  3513. }
  3514. dialysisRecord = &models.DialysisOrder{
  3515. DialysisDate: recordDate.Unix(),
  3516. UserOrgId: adminUserInfo.Org.Id,
  3517. PatientId: patientID,
  3518. Stage: 1,
  3519. BedID: bedID,
  3520. StartNurse: nurseID,
  3521. Status: 1,
  3522. StartTime: startDate.Unix(),
  3523. CreatedTime: time.Now().Unix(),
  3524. UpdatedTime: time.Now().Unix(),
  3525. PunctureNurse: puncture_nurse,
  3526. Creator: adminUserInfo.AdminUser.Id,
  3527. Modifier: adminUserInfo.AdminUser.Id,
  3528. SchedualType: schedual_type,
  3529. WashpipeNurse: washpipe_nurse,
  3530. ChangeNurse: change_nurse,
  3531. DifficultPunctureNurse: difficult_puncture_nurse,
  3532. NewFistulaNurse: new_fistula_nurse,
  3533. ZoneId: zone_id,
  3534. QualityNurseId: quality_nurse_id,
  3535. PunctureNeedle: puncture_needle,
  3536. PunctureWay: puncture_way,
  3537. DialysisIrrigation: dialysis_irrigation,
  3538. DialysisDialyszers: dialysis_dialyszers,
  3539. BloodAccessId: blood_access_id,
  3540. Url: elecsign,
  3541. NucleinDate: theNucleinDate,
  3542. ScheduleRemark: schedule_remark,
  3543. OrderRemark: order_remark,
  3544. CatheterOperation: catheter_operation,
  3545. BloodFlowVolume: blood_flow_volume,
  3546. BloodDrawing: blood_drawing,
  3547. DialysisStrainer: dialysis_strainer,
  3548. }
  3549. //查询该床位是否有人用了
  3550. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3551. if errorscode == gorm.ErrRecordNotFound {
  3552. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3553. finish := models.XtDialysisFinish{
  3554. IsFinish: 1,
  3555. UserOrgId: adminUserInfo.Org.Id,
  3556. Status: 1,
  3557. Ctime: time.Now().Unix(),
  3558. Mtime: 0,
  3559. Module: 6,
  3560. RecordDate: schedulestartTime,
  3561. Sourse: 1,
  3562. PatientId: patientID,
  3563. }
  3564. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3565. if dialysisFinish.ID == 0 {
  3566. service.CreateDialysisFinish(finish)
  3567. }
  3568. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3569. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3570. //统计该患者总次数
  3571. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3572. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3573. }
  3574. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3575. //统计该患者总次数
  3576. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3577. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3578. }
  3579. redis := service.RedisClient()
  3580. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3581. redis.Set(key, "", time.Second)
  3582. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3583. //清空key 值
  3584. redis.Set(keyOne, "", time.Second)
  3585. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3586. //清空key 值
  3587. redis.Set(keyTwo, "", time.Second)
  3588. if createErr != nil {
  3589. this.ErrorLog("上机失败:%v", createErr)
  3590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3591. return
  3592. }
  3593. }
  3594. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3595. var tempdispose string
  3596. // 只针对中能建
  3597. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3598. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3599. }
  3600. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3601. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3602. }
  3603. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3604. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3605. //}
  3606. var ultrafiltration_rate float64
  3607. var ultrafiltration_rate_one string
  3608. var replacement_rate float64
  3609. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3610. //后期预增脱水量
  3611. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3612. if prescription.ID > 0 {
  3613. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3614. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3615. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3616. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3617. }
  3618. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 || adminUserInfo.Org.Id == 9478 {
  3619. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3620. }
  3621. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3622. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3623. }
  3624. //针对医师汇
  3625. if adminUserInfo.Org.Id == 10121 {
  3626. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3627. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3628. }
  3629. //针对通道
  3630. if adminUserInfo.Org.Id == 10234 {
  3631. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3632. }
  3633. //针对监利大垸医院
  3634. if template.TemplateId == 41 {
  3635. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3636. }
  3637. //针对肇庆三鹤血液透析中心
  3638. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3639. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3640. }
  3641. if adminUserInfo.Org.Id == 10469 {
  3642. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3643. }
  3644. if adminUserInfo.Org.Id == 10667 {
  3645. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3646. }
  3647. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3648. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3649. }
  3650. // 只针对方济医院
  3651. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3652. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3653. ultrafiltration_rate = value
  3654. }
  3655. //针对
  3656. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3657. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3658. ultrafiltration_rate = ultrafiltration_rate / 1000
  3659. }
  3660. if adminUserInfo.Org.Id == 10551 {
  3661. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3662. ultrafiltration_rate = ultrafiltration_rate / 1000
  3663. }
  3664. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3665. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3666. ultrafiltration_rate = ultrafiltration_rate / 1000
  3667. }
  3668. if adminUserInfo.Org.Id == 10580 {
  3669. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3670. ultrafiltration_rate = ultrafiltration_rate / 1000
  3671. }
  3672. if adminUserInfo.Org.Id == 10629 {
  3673. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3674. ultrafiltration_rate = ultrafiltration_rate / 1000
  3675. }
  3676. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3677. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3678. ultrafiltration_rate = ultrafiltration_rate / 1000
  3679. }
  3680. if adminUserInfo.Org.Id == 10751 {
  3681. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3682. ultrafiltration_rate = ultrafiltration_rate / 1000
  3683. }
  3684. if adminUserInfo.Org.Id == 10667 {
  3685. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3686. ultrafiltration_rate = ultrafiltration_rate / 1000
  3687. }
  3688. if adminUserInfo.Org.Id == 10693 {
  3689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3690. ultrafiltration_rate = ultrafiltration_rate
  3691. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3692. }
  3693. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3694. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3695. ultrafiltration_rate = ultrafiltration_rate
  3696. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3697. }
  3698. if adminUserInfo.Org.Id == 10206 {
  3699. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3700. ultrafiltration_rate = ultrafiltration_rate
  3701. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3702. }
  3703. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3704. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3705. ultrafiltration_rate = ultrafiltration_rate
  3706. }
  3707. if adminUserInfo.Org.Id == 10702 {
  3708. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3709. ultrafiltration_rate = ultrafiltration_rate / 1000
  3710. }
  3711. if adminUserInfo.Org.Id == 10752 {
  3712. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3713. ultrafiltration_rate = ultrafiltration_rate / 1000
  3714. }
  3715. if adminUserInfo.Org.Id == 10723 {
  3716. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3717. ultrafiltration_rate = ultrafiltration_rate / 1000
  3718. }
  3719. if adminUserInfo.Org.Id == 10721 {
  3720. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3721. ultrafiltration_rate = ultrafiltration_rate / 1000
  3722. }
  3723. if adminUserInfo.Org.Id == 10766 {
  3724. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3725. ultrafiltration_rate = ultrafiltration_rate / 1000
  3726. }
  3727. if adminUserInfo.Org.Id == 10757 {
  3728. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3729. ultrafiltration_rate = ultrafiltration_rate / 1000
  3730. }
  3731. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3732. if prescription.ModeId == 2 {
  3733. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3734. if totalMin == 0 {
  3735. totalMin = 240
  3736. }
  3737. if prescription.ReplacementTotal == 0 {
  3738. prescription.ReplacementTotal = 15
  3739. }
  3740. //乘10 除10是为了保留一位小数
  3741. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3742. }
  3743. }
  3744. if adminUserInfo.Org.Id == 10766 {
  3745. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  3746. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3747. if totalMin == 0 {
  3748. totalMin = 240
  3749. }
  3750. if prescription.DisplaceLiquiValue == 0 {
  3751. prescription.DisplaceLiquiValue = 15
  3752. }
  3753. //乘10 除10是为了保留一位小数
  3754. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3755. }
  3756. }
  3757. if adminUserInfo.Org.Id == 10752 {
  3758. if prescription.ModeId == 2 {
  3759. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3760. if totalMin == 0 {
  3761. totalMin = 240
  3762. }
  3763. if prescription.ReplacementTotal == 0 {
  3764. prescription.ReplacementTotal = 15
  3765. }
  3766. //乘10 除10是为了保留一位小数
  3767. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3768. }
  3769. }
  3770. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3771. if prescription.ModeId == 2 {
  3772. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3773. if totalMin == 0 {
  3774. totalMin = 240
  3775. }
  3776. if prescription.DisplaceLiquiValue == 0 {
  3777. prescription.ReplacementTotal = 32
  3778. }
  3779. //乘10 除10是为了保留一位小数
  3780. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3781. }
  3782. }
  3783. }
  3784. }
  3785. if adminUserInfo.Org.Id == 10172 {
  3786. if prescription.ID == 0 {
  3787. if prescription.ModeId == 2 {
  3788. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3789. if totalMin == 0 {
  3790. totalMin = 240
  3791. }
  3792. if prescription.ReplacementTotal == 0 {
  3793. prescription.ReplacementTotal = 15
  3794. }
  3795. //乘10 除10是为了保留一位小数
  3796. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3797. }
  3798. }
  3799. }
  3800. record := models.MonitoringRecord{
  3801. UserOrgId: adminUserInfo.Org.Id,
  3802. PatientId: patientID,
  3803. DialysisOrderId: dialysisRecord.ID,
  3804. MonitoringDate: schedulestartTime,
  3805. OperateTime: startDate.Unix(),
  3806. // MonitoringTime: recordTime,
  3807. MonitoringNurse: nurseID,
  3808. Dispose: tempdispose,
  3809. UltrafiltrationRate: ultrafiltration_rate,
  3810. UltrafiltrationVolume: 0,
  3811. Status: 1,
  3812. CreatedTime: time.Now().Unix(),
  3813. UpdatedTime: time.Now().Unix(),
  3814. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3815. ReplacementRate: replacement_rate,
  3816. }
  3817. //只针对广慈医院
  3818. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10757 || adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  3819. // 查询病人是否有透前评估数据
  3820. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3821. //如果有数据就插入
  3822. if errcode == nil {
  3823. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3824. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3825. record.BreathingRate = befor.BreathingRate
  3826. record.PulseFrequency = befor.PulseFrequency
  3827. record.Temperature = befor.Temperature
  3828. }
  3829. }
  3830. //孝昌
  3831. if adminUserInfo.Org.Id == 10693 {
  3832. // 查询病人是否有透前评估数据
  3833. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3834. //如果有数据就插入
  3835. if errcode == nil {
  3836. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3837. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3838. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3839. record.BreathingRate = befor.BreathingRate
  3840. }
  3841. }
  3842. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3843. if newdialysisRecord.ID > 0 {
  3844. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3845. record.Temperature = 36.5
  3846. record.ArterialPressure = -100
  3847. record.DialysateTemperature = 36.5
  3848. record.Conductivity = 14
  3849. record.BreathingRate = "20"
  3850. record.VenousPressure = 80
  3851. record.TransmembranePressure = 60
  3852. record.Dispose = catheter_operation
  3853. }
  3854. //针对新化博翔
  3855. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3856. record.BloodOxygenSaturation = "99"
  3857. record.Conductivity = 14
  3858. record.DialysateTemperature = 36.5
  3859. record.BreathingRate = "20"
  3860. }
  3861. //针对兰溪人民医院的需求
  3862. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3863. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3864. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3865. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3866. record.Temperature = befor.Temperature
  3867. record.PulseFrequency = befor.PulseFrequency
  3868. record.BreathingRate = befor.BreathingRate
  3869. }
  3870. //针对乐山友谊医院的需求
  3871. if adminUserInfo.Org.Id == 10677 {
  3872. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3873. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3874. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3875. record.Temperature = befor.Temperature
  3876. record.PulseFrequency = befor.PulseFrequency
  3877. record.BreathingRate = befor.BreathingRate
  3878. }
  3879. //新化博翔
  3880. if adminUserInfo.Org.Id == 10447 {
  3881. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3882. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3883. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3884. record.BreathingRate = befor.BreathingRate
  3885. }
  3886. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3887. record.PulseFrequency = 80
  3888. record.Temperature = 36.5
  3889. }
  3890. //诊断灵山圣康
  3891. if adminUserInfo.Org.Id == 10375 {
  3892. record.Conductivity = 13.8
  3893. record.DialysateTemperature = 37
  3894. record.DialysateFlow = 500
  3895. record.BloodFlowVolume = 200
  3896. record.BreathingRate = "18"
  3897. record.SodiumConcentration = 140
  3898. }
  3899. //江成肾病医院
  3900. if adminUserInfo.Org.Id == 10517 {
  3901. record.SodiumConcentration = 138
  3902. record.DialysateTemperature = 36.5
  3903. }
  3904. //濉溪杏康血液透析中心
  3905. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3906. record.BloodFlowVolume = prescription.BloodFlowVolume
  3907. }
  3908. //胶州少海医院
  3909. if adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 9478 {
  3910. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3911. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3912. record.BreathingRate = befor.BreathingRate
  3913. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3914. record.Temperature = befor.Temperature
  3915. record.PulseFrequency = befor.PulseFrequency
  3916. }
  3917. if adminUserInfo.Org.Id != 10683 {
  3918. err = service.CreateMonitor(&record)
  3919. }
  3920. //记录日志
  3921. byterequest, _ := json.Marshal(record)
  3922. monitorRecordLog := models.XtMonitorRecordLog{
  3923. RecordDate: record.MonitoringDate,
  3924. PatientId: record.PatientId,
  3925. Module: 1,
  3926. AdminUserId: adminUserInfo.AdminUser.Id,
  3927. Ctime: time.Now().Unix(),
  3928. Mtime: 0,
  3929. Status: 1,
  3930. UserOrgId: record.UserOrgId,
  3931. ErrLog: string(byterequest),
  3932. Source: "执行上机时新增监测",
  3933. }
  3934. service.CreateMonitorRecordLog(monitorRecordLog)
  3935. finish := models.XtDialysisFinish{
  3936. IsFinish: 1,
  3937. UserOrgId: adminUserInfo.Org.Id,
  3938. Status: 1,
  3939. Ctime: time.Now().Unix(),
  3940. Mtime: 0,
  3941. Module: 7,
  3942. RecordDate: schedulestartTime,
  3943. Sourse: 1,
  3944. PatientId: patientID,
  3945. }
  3946. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3947. if dialysisFinish.ID == 0 {
  3948. service.CreateDialysisFinish(finish)
  3949. }
  3950. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3951. redis := service.RedisClient()
  3952. //清空key 值
  3953. redis.Set(key, "", time.Second)
  3954. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3955. redis.Set(keyOne, "", time.Second)
  3956. defer redis.Close()
  3957. if err != nil {
  3958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3959. return
  3960. }
  3961. }
  3962. go func() {
  3963. ssoDomain := beego.AppConfig.String("call_domain")
  3964. api := ssoDomain + "/index/uppatient"
  3965. values := make(url.Values)
  3966. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3967. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3968. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3969. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3970. http.PostForm(api, values)
  3971. }()
  3972. this.ServeSuccessJSON(map[string]interface{}{
  3973. "dialysis_order": newdialysisRecord,
  3974. "monitor": record,
  3975. })
  3976. return
  3977. }
  3978. func (c *DialysisAPIController) PostSolution() {
  3979. id, _ := c.GetInt64("patient", 0)
  3980. recordDateStr := c.GetString("record_date")
  3981. if id <= 0 {
  3982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3983. return
  3984. }
  3985. adminUserInfo := c.GetMobileAdminUserInfo()
  3986. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3987. if patient.ID == 0 {
  3988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3989. return
  3990. }
  3991. if len(recordDateStr) == 0 {
  3992. recordDateStr = time.Now().Format("2006-01-02")
  3993. }
  3994. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3995. if parseDateErr != nil {
  3996. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3998. return
  3999. }
  4000. mode_id, _ := c.GetInt64("mode_id", 0)
  4001. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  4002. dialyzer, _ := c.GetInt64("dialyzer", 0)
  4003. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  4004. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  4005. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  4006. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  4007. replacement_way, _ := c.GetInt64("replacement_way", 0)
  4008. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  4009. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  4010. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  4011. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  4012. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  4013. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  4014. kalium, _ := c.GetFloat("kalium", 0)
  4015. sodium, _ := c.GetFloat("sodium", 0)
  4016. calcium, _ := c.GetFloat("calcium", 0)
  4017. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  4018. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  4019. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  4020. glucose, _ := c.GetFloat("glucose", 0)
  4021. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  4022. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  4023. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  4024. conductivity, _ := c.GetFloat("conductivity", 0)
  4025. remark := c.GetString("remark")
  4026. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  4027. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  4028. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  4029. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  4030. body_fluid, _ := c.GetInt64("body_fluid", 0)
  4031. special_medicine, _ := c.GetInt64("special_medicine", 0)
  4032. special_medicine_other := c.GetString("special_medicine_other")
  4033. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  4034. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  4035. blood_access, _ := c.GetInt64("blood_access", 0)
  4036. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  4037. body_fluid_other := c.GetString("body_fluid_other")
  4038. replacement_total, _ := c.GetFloat("replacement_total", 0)
  4039. niprocart, _ := c.GetInt64("niprocart", 0)
  4040. jms, _ := c.GetInt64("jms", 0)
  4041. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  4042. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  4043. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  4044. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  4045. filtryzer, _ := c.GetInt64("filtryzer", 0)
  4046. target_ktv, _ := c.GetFloat("target_ktv", 0)
  4047. dialyzers, _ := c.GetInt64("dialyzers", 0)
  4048. injector, _ := c.GetInt64("injector", 0)
  4049. bloodlines, _ := c.GetInt64("bloodlines", 0)
  4050. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  4051. safe_package, _ := c.GetInt64("package", 0)
  4052. a_liquid, _ := c.GetInt64("a_liquid", 0)
  4053. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  4054. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  4055. blood := c.GetString("blood")
  4056. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  4057. dialysis_irrigation := c.GetString("dialysis_irrigation")
  4058. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  4059. displace_speed := c.GetString("displace_speed")
  4060. illness, _ := c.GetInt64("illness")
  4061. amylaceum := c.GetString("amylaceum")
  4062. single_time := c.GetString("single_time")
  4063. single_water := c.GetString("single_water")
  4064. replacement_flow := c.GetString("replacement_flow")
  4065. plasma_separator := c.GetString("plasma_separator")
  4066. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  4067. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  4068. oxygen_flow := c.GetString("oxygen_flow")
  4069. oxygen_time := c.GetString("oxygen_time")
  4070. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  4071. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  4072. puncture_needle := c.GetString("puncture_needle")
  4073. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  4074. epo := c.GetString("epo")
  4075. epo_count, _ := c.GetFloat("epo_count", 0)
  4076. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  4077. pre_impulse := c.GetString("pre_impulse")
  4078. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  4079. admin_user_id, _ := c.GetInt64("admin_user_id")
  4080. is_water := c.GetString("is_water")
  4081. add_amount, _ := c.GetFloat("add_amount")
  4082. reduce_amount, _ := c.GetFloat("reduce_amount")
  4083. prescribing_number, _ := c.GetFloat("prescribing_number")
  4084. treatment_remark := c.GetString("treatment_remark")
  4085. prescription_sodium := c.GetString("prescription_sodium")
  4086. start_sodium := c.GetString("start_sodium")
  4087. sodium_curve := c.GetString("sodium_curve")
  4088. var is_war int64
  4089. if is_water == "是" {
  4090. is_war = 1
  4091. }
  4092. if is_water == "否" {
  4093. is_war = 2
  4094. }
  4095. if is_water == "请选择" {
  4096. is_war = 0
  4097. }
  4098. drhy_water := c.GetString("drhy_water")
  4099. dry_water_hour := c.GetString("dry_water_hour")
  4100. water_machine := c.GetString("water_machine")
  4101. dialysis_remark := c.GetString("dialysis_remark")
  4102. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4103. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4104. prescription_water, _ := c.GetFloat("prescription_water")
  4105. dialysis_strainer := c.GetString("dialysis_strainer")
  4106. chaptalization := c.GetString("chaptalization")
  4107. washing_time := c.GetString("washing_time")
  4108. warsh_count := c.GetString("warsh_count")
  4109. blood_access_part_id := c.GetString("blood_access_part_id")
  4110. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4111. dialyzate := c.GetString("dialyzate")
  4112. first_super := c.GetString("first_super")
  4113. is_sequential := c.GetString("is_sequential")
  4114. sterilization_water := c.GetString("sterilization_water")
  4115. five_glucose := c.GetString("five_glucose")
  4116. fifty_glucose := c.GetString("fifty_glucose")
  4117. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  4118. calcium_gluconate := c.GetString("calcium_gluconate")
  4119. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  4120. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  4121. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  4122. new_sty := c.GetString("new_sty")
  4123. var fisrt_sup int64
  4124. if first_super == "是" {
  4125. fisrt_sup = 1
  4126. }
  4127. if first_super == "否" {
  4128. fisrt_sup = 2
  4129. }
  4130. if first_super == "请选择" {
  4131. fisrt_sup = 0
  4132. }
  4133. var is_sequen int64
  4134. if is_sequential == "是" {
  4135. is_sequen = 1
  4136. }
  4137. if is_sequential == "否" {
  4138. is_sequen = 2
  4139. }
  4140. if is_sequential == "请选择" {
  4141. is_sequen = 0
  4142. }
  4143. conduct := c.GetString("conduct")
  4144. if mode_id > 0 {
  4145. var str string
  4146. //查找该机构用的是什么透析器
  4147. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4148. if filedConfig.ID > 0 {
  4149. str = dialyzerPerfusionApparatus
  4150. } else {
  4151. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4152. }
  4153. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4154. }
  4155. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4156. //
  4157. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4158. // if appRole.UserType == 3 {
  4159. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4160. // if getPermissionErr != nil {
  4161. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4162. // return
  4163. // } else if headNursePermission == nil {
  4164. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4165. // return
  4166. // }
  4167. // }
  4168. //}
  4169. // 查询信息规挡的设置天数
  4170. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4171. if infor.ID > 0 && infor.WeekDay > 0 {
  4172. var cha_time int64
  4173. timeNowStr := time.Now().Format("2006-01-02")
  4174. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4175. //今日的日期减去设置的日期
  4176. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4177. if cha_time >= recordDate.Unix() {
  4178. //查询审核是否允许
  4179. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4180. //申请状态不允许的情况 拒绝修改
  4181. if infor.ApplicationStatus != 1 {
  4182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4183. return
  4184. }
  4185. }
  4186. }
  4187. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4188. var dialysis_dialyszers_id int64
  4189. var dialysis_strainer_id int64
  4190. var dialysis_irrigation_id int64
  4191. if len(goodList) > 0 {
  4192. for _, item := range goodList {
  4193. if item.SpecificationName == dialysis_dialyszers {
  4194. dialysis_dialyszers_id = item.ID
  4195. }
  4196. if item.SpecificationName == dialysis_irrigation {
  4197. dialysis_irrigation_id = item.ID
  4198. }
  4199. if item.SpecificationName == dialysis_strainer {
  4200. dialysis_strainer_id = item.ID
  4201. }
  4202. }
  4203. }
  4204. prescription := models.DialysisPrescription{
  4205. UserOrgId: adminUserInfo.Org.Id,
  4206. PatientId: id,
  4207. RecordDate: recordDate.Unix(),
  4208. ModeId: mode_id,
  4209. DialysisDuration: dialysis_duration,
  4210. Dialyzer: dialyzer,
  4211. PerfusionApparatus: perfusion_apparatus,
  4212. BloodFlowVolume: blood_flow_volume,
  4213. DewaterAmount: dewater_amount,
  4214. DisplaceLiqui: displace_liqui,
  4215. ReplacementWay: replacement_way,
  4216. Anticoagulant: anticoagulant,
  4217. AnticoagulantShouji: anticoagulant_shouji,
  4218. AnticoagulantWeichi: anticoagulant_weichi,
  4219. AnticoagulantZongliang: anticoagulant_zongliang,
  4220. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4221. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4222. Kalium: kalium,
  4223. Sodium: sodium,
  4224. Calcium: calcium,
  4225. Bicarbonate: bicarbonate,
  4226. Glucose: glucose,
  4227. // DryWeight: dry_weight,
  4228. DialysateFlow: dialysate_flow,
  4229. DialysateTemperature: dialysate_temperature,
  4230. Conductivity: conductivity,
  4231. Remark: remark,
  4232. Status: 1,
  4233. CreatedTime: time.Now().Unix(),
  4234. UpdatedTime: time.Now().Unix(),
  4235. DialysisDurationMinute: dialysisDurationMinute,
  4236. DialysisDurationHour: dialysisDurationHour,
  4237. TargetUltrafiltration: targetUltrafiltration,
  4238. DialysateFormulation: dialysateFormulation,
  4239. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4240. BodyFluid: body_fluid,
  4241. SpecialMedicine: special_medicine,
  4242. SpecialMedicineOther: special_medicine_other,
  4243. DisplaceLiquiPart: displace_liqui_part,
  4244. DisplaceLiquiValue: displace_liqui_value,
  4245. BloodAccess: blood_access,
  4246. Ultrafiltration: ultrafiltration,
  4247. BodyFluidOther: body_fluid_other,
  4248. ReplacementTotal: replacement_total,
  4249. Niprocart: niprocart,
  4250. Jms: jms,
  4251. FistulaNeedleSet: fistula_needle_set,
  4252. FistulaNeedleSet16: fistula_needle_set_16,
  4253. Hemoperfusion: hemoperfusion,
  4254. DialyserSterilised: dialyser_sterilised,
  4255. Filtryzer: filtryzer,
  4256. TargetKtv: target_ktv,
  4257. Dialyzers: dialyzers,
  4258. Injector: injector,
  4259. Bloodlines: bloodlines,
  4260. TubingHemodialysis: tubing_hemodialysis,
  4261. Package: safe_package,
  4262. ALiquid: a_liquid,
  4263. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4264. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4265. Blood: blood,
  4266. DialysisDialyszers: dialysis_dialyszers,
  4267. DialysisIrrigation: dialysis_irrigation,
  4268. AntioxidantCommodityName: antioxidant_commodity_name,
  4269. DisplaceSpeed: displace_speed,
  4270. Illness: illness,
  4271. Amylaceum: amylaceum,
  4272. SingleWater: single_water,
  4273. SingleTime: single_time,
  4274. ReplacementFlow: replacement_flow,
  4275. PlasmaSeparator: plasma_separator,
  4276. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4277. OxygenUptake: oxygen_uptake,
  4278. OxygenTime: oxygen_time,
  4279. OxygenFlow: oxygen_flow,
  4280. HemodialysisPipelines: hemodialysis_pipelines,
  4281. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4282. PunctureNeedle: puncture_needle,
  4283. PunctureNeedleCount: puncture_needle_count,
  4284. Epo: epo,
  4285. EpoCount: epo_count,
  4286. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4287. PreImpulse: impulse,
  4288. AdminUserId: admin_user_id,
  4289. IsWater: is_war,
  4290. DrhyWater: drhy_water,
  4291. DryWaterHour: dry_water_hour,
  4292. WaterMachine: water_machine,
  4293. AddAmount: add_amount,
  4294. ReduceAmount: reduce_amount,
  4295. DialysisRemark: dialysis_remark,
  4296. PrescribingNumber: prescribing_number,
  4297. PrescriptionSodium: prescription_sodium,
  4298. StartSodium: start_sodium,
  4299. SodiumCurve: sodium_curve,
  4300. TreatmentRemark: treatment_remark,
  4301. DialysisFluidFlow: dialysis_fluid_flow,
  4302. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4303. PrescriptionWater: prescription_water,
  4304. DialysisStrainer: dialysis_strainer,
  4305. Chaptalization: chaptalization,
  4306. WashingTime: washing_time,
  4307. WarshCount: warsh_count,
  4308. BloodAccessPartId: blood_access_part_id,
  4309. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4310. Dialyzate: dialyzate,
  4311. DialysisDialyszersId: dialysis_dialyszers_id,
  4312. DialysisIrrigationId: dialysis_irrigation_id,
  4313. DialysisStrainerId: dialysis_strainer_id,
  4314. FirstSuper: fisrt_sup,
  4315. IsSequential: is_sequen,
  4316. Conduct: conduct,
  4317. SterilizationWater: sterilization_water,
  4318. FiveGlucose: five_glucose,
  4319. FiftyGlucose: fifty_glucose,
  4320. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4321. CalciumGluconate: calcium_gluconate,
  4322. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4323. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4324. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4325. NewSty: new_sty,
  4326. }
  4327. if prescription.ModeId != 13 {
  4328. prescription.SterilizationWater = ""
  4329. prescription.FiveGlucose = ""
  4330. prescription.FiftyGlucose = ""
  4331. prescription.MagnesiumSulfateInjection = ""
  4332. prescription.CalciumGluconate = ""
  4333. prescription.FivePotassiumChlorideInjection = ""
  4334. prescription.TenPotassiumChlorideInjection = ""
  4335. prescription.FiveSodiumBicarbonateInjection = ""
  4336. prescription.NewSty = ""
  4337. }
  4338. if adminUserInfo.Org.Id == 10721 {
  4339. if prescription.ModeId == 2 {
  4340. if prescription.ReplacementTotal == 0 {
  4341. prescription.ReplacementTotal = 15
  4342. }
  4343. }
  4344. }
  4345. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 9478 {
  4346. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  4347. if prescription.ReplacementTotal == 0 {
  4348. prescription.ReplacementTotal = 15
  4349. }
  4350. }
  4351. }
  4352. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4353. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4354. //
  4355. if appRole.UserType == 2 || appRole.UserType == 1 {
  4356. prescription_doctor = adminUserInfo.AdminUser.Id
  4357. prescription.PrescriptionDoctor = prescription_doctor
  4358. }
  4359. if dialysisPrescription.ID == 0 { //新增
  4360. prescription.Creater = adminUserInfo.AdminUser.Id
  4361. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4362. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4363. }
  4364. } else { //修改
  4365. if dialysisPrescription.Creater == 0 {
  4366. prescription.Creater = adminUserInfo.AdminUser.Id
  4367. } else {
  4368. prescription.Creater = dialysisPrescription.Creater
  4369. if adminUserInfo.Org.Id == 9882 {
  4370. if appRole.UserType == 2 || appRole.UserType == 1 {
  4371. prescription.Creater = adminUserInfo.AdminUser.Id
  4372. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4373. }
  4374. }
  4375. }
  4376. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4377. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4378. }
  4379. //if/**/
  4380. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4381. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4382. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4383. // if getPermissionErr != nil {
  4384. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4385. // return
  4386. // } else if headNursePermission == nil {
  4387. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4388. // return
  4389. // }
  4390. //}
  4391. //prescription.Creater = dialysisPrescription.Creater
  4392. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4393. prescription.Modifier = adminUserInfo.AdminUser.Id
  4394. prescription.ID = dialysisPrescription.ID
  4395. }
  4396. solution := models.DialysisSolution{
  4397. RegistrarsId: adminUserInfo.AdminUser.Id,
  4398. UserOrgId: adminUserInfo.Org.Id,
  4399. Doctor: prescription_doctor,
  4400. PatientId: id,
  4401. ModeId: mode_id,
  4402. DialysisDuration: dialysis_duration,
  4403. PerfusionApparatus: perfusion_apparatus,
  4404. BloodFlowVolume: blood_flow_volume,
  4405. Dewater: dewater_amount,
  4406. DisplaceLiqui: displace_liqui,
  4407. ReplacementWay: replacement_way,
  4408. Anticoagulant: anticoagulant,
  4409. AnticoagulantShouji: anticoagulant_shouji,
  4410. AnticoagulantWeichi: anticoagulant_weichi,
  4411. AnticoagulantZongliang: anticoagulant_zongliang,
  4412. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4413. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4414. Kalium: kalium,
  4415. Sodium: sodium,
  4416. Calcium: calcium,
  4417. Bicarbonate: bicarbonate,
  4418. Glucose: glucose,
  4419. // DryWeight: dry_weight,
  4420. DialysateFlow: dialysate_flow,
  4421. DialysateTemperature: dialysate_temperature,
  4422. Conductivity: conductivity,
  4423. Remark: remark,
  4424. Status: 1,
  4425. CreatedTime: time.Now().Unix(),
  4426. UpdatedTime: time.Now().Unix(),
  4427. DialysisDurationMinute: dialysisDurationMinute,
  4428. DialysisDurationHour: dialysisDurationHour,
  4429. TargetUltrafiltration: targetUltrafiltration,
  4430. DialysateFormulation: dialysateFormulation,
  4431. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4432. BodyFluid: body_fluid,
  4433. SpecialMedicine: special_medicine,
  4434. SpecialMedicineOther: special_medicine_other,
  4435. DisplaceLiquiPart: displace_liqui_part,
  4436. DisplaceLiquiValue: displace_liqui_value,
  4437. BloodAccess: blood_access,
  4438. Ultrafiltration: ultrafiltration,
  4439. BodyFluidOther: body_fluid_other,
  4440. ReplacementTotal: replacement_total,
  4441. TargetKtv: target_ktv,
  4442. DialysisDialyszers: dialysis_dialyszers,
  4443. DialysisIrrigation: dialysis_irrigation,
  4444. HemodialysisPipelines: hemodialysis_pipelines,
  4445. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4446. PunctureNeedle: puncture_needle,
  4447. PunctureNeedleCount: puncture_needle_count,
  4448. Epo: epo,
  4449. EpoCount: epo_count,
  4450. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4451. PreImpulse: impulse,
  4452. SolutionStatus: 1,
  4453. DialysisRemark: dialysis_remark,
  4454. PrescribingNumber: prescribing_number,
  4455. PrescriptionSodium: prescription_sodium,
  4456. StartSodium: start_sodium,
  4457. SodiumCurve: sodium_curve,
  4458. TreatmentRemark: treatment_remark,
  4459. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4460. DialysisFluidFlow: dialysis_fluid_flow,
  4461. PrescriptionWater: prescription_water,
  4462. DialysisStrainer: dialysis_strainer,
  4463. Chaptalization: chaptalization,
  4464. WashingTime: washing_time,
  4465. WarshCount: warsh_count,
  4466. BloodAccessPartId: blood_access_part_id,
  4467. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4468. Dialyzate: dialyzate,
  4469. DialysisDialyszersId: dialysis_dialyszers_id,
  4470. DialysisIrrigationId: dialysis_irrigation_id,
  4471. DialysisStrainerId: dialysis_strainer_id,
  4472. FirstSuper: fisrt_sup,
  4473. IsSequential: is_sequen,
  4474. Conduct: conduct,
  4475. SterilizationWater: sterilization_water,
  4476. FiveGlucose: five_glucose,
  4477. FiftyGlucose: fifty_glucose,
  4478. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4479. CalciumGluconate: calcium_gluconate,
  4480. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4481. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4482. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4483. NewSty: new_sty,
  4484. }
  4485. if prescription.ModeId != 13 {
  4486. prescription.SterilizationWater = ""
  4487. prescription.FiveGlucose = ""
  4488. prescription.FiftyGlucose = ""
  4489. prescription.MagnesiumSulfateInjection = ""
  4490. prescription.CalciumGluconate = ""
  4491. prescription.FivePotassiumChlorideInjection = ""
  4492. prescription.TenPotassiumChlorideInjection = ""
  4493. prescription.FiveSodiumBicarbonateInjection = ""
  4494. prescription.NewSty = ""
  4495. }
  4496. //针对河间咸的
  4497. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4498. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4499. solution.DisplaceLiquiPart = 0
  4500. solution.DisplaceLiquiValue = 0
  4501. }
  4502. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4503. prescription.DisplaceLiquiPart = 0
  4504. prescription.DisplaceLiquiValue = 0
  4505. }
  4506. }
  4507. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4508. if solution.PrescribingNumber == 0 {
  4509. solution.PrescribingNumber = 1
  4510. }
  4511. if prescription.PrescribingNumber == 0 {
  4512. prescription.PrescribingNumber = 1
  4513. }
  4514. if solution.PrescribingNumber == 0 && id == 14682 {
  4515. solution.PrescribingNumber = 2
  4516. }
  4517. if solution.PrescribingNumber == 0 && id == 18560 {
  4518. solution.PrescribingNumber = 2
  4519. }
  4520. if prescription.PrescribingNumber == 0 && id == 14682 {
  4521. prescription.PrescribingNumber = 2
  4522. }
  4523. if prescription.PrescribingNumber == 0 && id == 18560 {
  4524. prescription.PrescribingNumber = 2
  4525. }
  4526. }
  4527. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4528. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  4529. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4530. if len(monitorList) > 0 {
  4531. var ultrafiltration_rate float64
  4532. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4533. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4534. var replacement_rate float64
  4535. if adminUserInfo.Org.Id == 10721 {
  4536. //乘10 除10是为了保留一位小数
  4537. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4538. }
  4539. if adminUserInfo.Org.Id == 9478 {
  4540. //乘10 除10是为了保留一位小数
  4541. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4542. }
  4543. if adminUserInfo.Org.Id == 10766 {
  4544. //乘10 除10是为了保留一位小数
  4545. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4546. }
  4547. var firstOpeateTime = monitorList[0].OperateTime
  4548. for _, item := range monitorList {
  4549. //超滤率
  4550. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4551. //置换率
  4552. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4553. //超滤量
  4554. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4555. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4556. //置换量
  4557. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4558. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4559. }
  4560. }
  4561. }
  4562. //记录日志
  4563. byterequest, _ := json.Marshal(prescription)
  4564. prescriptionLog := models.XtDialysisPrescriptionLog{
  4565. UserOrgId: prescription.UserOrgId,
  4566. Ctime: time.Now().Unix(),
  4567. Mtime: 0,
  4568. ErrLog: string(byterequest),
  4569. AdminUserId: adminUserInfo.AdminUser.Id,
  4570. RecordDate: prescription.RecordDate,
  4571. PatientId: prescription.PatientId,
  4572. Source: "手机端新增长期处方",
  4573. Status: 1,
  4574. }
  4575. service.CreatePrescriptionLog(prescriptionLog)
  4576. finish := models.XtDialysisFinish{
  4577. IsFinish: 1,
  4578. UserOrgId: adminUserInfo.Org.Id,
  4579. Status: 1,
  4580. Ctime: time.Now().Unix(),
  4581. Mtime: 0,
  4582. Module: 1,
  4583. RecordDate: recordDate.Unix(),
  4584. Sourse: 1,
  4585. PatientId: id,
  4586. }
  4587. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4588. if dialysisFinish.ID == 0 {
  4589. service.CreateDialysisFinish(finish)
  4590. }
  4591. //获取最新1条
  4592. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4593. //更新状态
  4594. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4595. //长沙南雅医院,自动生成抗凝剂的临时处方
  4596. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4597. if prescribing_number == 0 {
  4598. prescribing_number = 1
  4599. }
  4600. advice := models.DoctorAdvice{
  4601. UserOrgId: adminUserInfo.Org.Id,
  4602. PatientId: id,
  4603. GroupNo: 0,
  4604. AdviceType: 2,
  4605. RecordDate: recordDate.Unix(),
  4606. AdviceDate: recordDate.Unix(),
  4607. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4608. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4609. AdviceDesc: "",
  4610. ReminderDate: 0,
  4611. SingleDose: prescription.AnticoagulantZongliang,
  4612. SingleDoseUnit: "iu",
  4613. DrugSpec: 0,
  4614. DrugSpecUnit: "",
  4615. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4616. PrescribingNumberUnit: "支",
  4617. DeliveryWay: "静脉注射",
  4618. ExecutionFrequency: "上机前",
  4619. AdviceDoctor: 0,
  4620. Status: 1,
  4621. CreatedTime: time.Now().Unix(),
  4622. UpdatedTime: time.Now().Unix(),
  4623. IsPrescription: 1,
  4624. ExecutionState: 2,
  4625. StopState: 2,
  4626. IsSettle: 2,
  4627. }
  4628. // 查询排班信息
  4629. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4630. if schedulePatient.ID > 0 {
  4631. if schedulePatient.ScheduleType == 1 {
  4632. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4633. }
  4634. if schedulePatient.ScheduleType == 2 {
  4635. advice.StartTime = recordDate.Unix() + 9*60*60
  4636. }
  4637. }
  4638. // 抗凝剂名称
  4639. switch anticoagulant {
  4640. case 1:
  4641. advice.AdviceName = "无肝素"
  4642. break
  4643. case 2:
  4644. advice.AdviceName = "普通肝素"
  4645. break
  4646. case 3:
  4647. advice.AdviceName = "低分子肝素"
  4648. break
  4649. case 4:
  4650. advice.AdviceName = "阿加曲班"
  4651. break
  4652. case 5:
  4653. advice.AdviceName = "枸橼酸钠"
  4654. break
  4655. case 6:
  4656. advice.AdviceName = "低分子肝素钙"
  4657. break
  4658. case 7:
  4659. advice.AdviceName = "低分子肝素钠"
  4660. break
  4661. case 8:
  4662. advice.AdviceName = "依诺肝素"
  4663. break
  4664. case 9:
  4665. advice.AdviceName = "达肝素"
  4666. break
  4667. case 10:
  4668. advice.AdviceName = "体外抗凝"
  4669. break
  4670. case 11:
  4671. advice.AdviceName = "那曲肝素"
  4672. break
  4673. case 12:
  4674. advice.AdviceName = "无抗凝剂"
  4675. break
  4676. }
  4677. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4678. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4679. advice.AdviceDoctor = appRole.AdminUserId
  4680. }
  4681. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4682. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4683. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4684. advice.AdviceName = "低分子肝素钠注射液"
  4685. // 修改患者临时医嘱里的抗凝剂医嘱
  4686. advice.ID = advicePrescription.ID
  4687. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4688. } else {
  4689. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4690. advice.AdviceName = "低分子肝素钠注射液"
  4691. service.CreateDoctorAdvice(&advice)
  4692. }
  4693. }
  4694. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4695. redis := service.RedisClient()
  4696. defer redis.Close()
  4697. //清空key 值
  4698. redis.Set(key, "", time.Second)
  4699. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4700. redis.Set(keyOne, "", time.Second)
  4701. }
  4702. //获取key,清空redis
  4703. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4704. redis := service.RedisClient()
  4705. defer redis.Close()
  4706. //清空key 值
  4707. redis.Set(key, "", time.Second)
  4708. //清空长期医嘱的key
  4709. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4710. redis.Set(soulution_key, "", time.Second)
  4711. //查询最近透析准备表里是否存在 透析器 灌流器
  4712. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4713. redis.Set(keyOne, "", time.Second)
  4714. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4715. redis.Set(keyTwo, "", time.Second)
  4716. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4717. redis.Set(keyThree, "", time.Second)
  4718. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4719. redis.Set(keyFour, "", time.Second)
  4720. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4721. //
  4722. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4723. //
  4724. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4725. //if len(mation)>0{
  4726. // for _, item := range splitStr {
  4727. // for _,it := range mation{
  4728. // if(item == it.SpecificationName){
  4729. //
  4730. // //查询最近一次的透析器
  4731. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4732. //
  4733. // if errcode == gorm.ErrRecordNotFound{
  4734. // //插入数据
  4735. // prepare := models.DialysisBeforePrepare{
  4736. // UserOrgId: adminUserInfo.Org.Id,
  4737. // PatientId: id,
  4738. // RecordDate: recordDate.Unix(),
  4739. // GoodTypeId: it.GoodTypeId,
  4740. // GoodId: it.ID,
  4741. // Count: 1,
  4742. // Ctime: time.Now().Unix(),
  4743. // Creater: adminUserInfo.AdminUser.Id,
  4744. // Status:1,
  4745. //
  4746. // }
  4747. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4748. // fmt.Println("",errcode)
  4749. // }
  4750. // }
  4751. // }
  4752. //
  4753. // }
  4754. //
  4755. // for _, item := range splitIrrigation {
  4756. // for _,it := range mation{
  4757. // if(item == it.SpecificationName){
  4758. // //查询最近一次的透析器
  4759. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4760. // if errcode == gorm.ErrRecordNotFound{
  4761. // //插入数据
  4762. // prepare := models.DialysisBeforePrepare{
  4763. // UserOrgId: adminUserInfo.Org.Id,
  4764. // PatientId: id,
  4765. // RecordDate: recordDate.Unix(),
  4766. // GoodTypeId: it.GoodTypeId,
  4767. // GoodId: it.ID,
  4768. // Count: 1,
  4769. // Ctime: time.Now().Unix(),
  4770. // Creater: adminUserInfo.AdminUser.Id,
  4771. // Status:1,
  4772. //
  4773. // }
  4774. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4775. // fmt.Println(errcode)
  4776. // }
  4777. // }
  4778. // }
  4779. // }
  4780. //}
  4781. c.ServeSuccessJSON(map[string]interface{}{
  4782. "solution": &solution,
  4783. "prescription": &prescription,
  4784. })
  4785. }
  4786. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4787. patient, _ := c.GetInt64("patient", 0)
  4788. adminUserInfo := c.GetMobileAdminUserInfo()
  4789. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4790. c.ServeSuccessJSON(map[string]interface{}{
  4791. "receiveTreatmentAsses": receiveTreatmentAsses,
  4792. })
  4793. }
  4794. func (this *DialysisAPIController) PostSignInfo() {
  4795. patientID, _ := this.GetInt64("patient_id")
  4796. recordDateStr := this.GetString("date")
  4797. if patientID <= 0 {
  4798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4799. return
  4800. }
  4801. if len(recordDateStr) == 0 {
  4802. recordDateStr = time.Now().Format("2006-01-02")
  4803. }
  4804. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4805. if parseDateErr != nil {
  4806. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4808. return
  4809. }
  4810. adminInfo := this.GetMobileAdminUserInfo()
  4811. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4812. if err != nil {
  4813. this.ErrorLog("签名失败:%v", err)
  4814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4815. return
  4816. }
  4817. this.ServeSuccessJSON(map[string]interface{}{
  4818. "doctor_id": adminInfo.AdminUser.Id,
  4819. })
  4820. }
  4821. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4822. patientID, _ := this.GetInt64("patient_id")
  4823. adminInfo := this.GetMobileAdminUserInfo()
  4824. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4825. this.ServeSuccessJSON(map[string]interface{}{
  4826. "monitor": record,
  4827. })
  4828. }
  4829. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4830. thisTime := time.Now()
  4831. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4832. timeLayout := "2006-01-02 15:04:05"
  4833. loc, _ := time.LoadLocation("Local")
  4834. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4835. theAssessmentDateTime := theStartTime.Unix()
  4836. patientID, _ := this.GetInt64("patient_id")
  4837. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4838. adminInfo := this.GetMobileAdminUserInfo()
  4839. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4840. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4841. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4842. var ultrafiltration_rate float64
  4843. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4844. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4845. fmt.Println(evaluation)
  4846. fmt.Println("prescription.ID", prescription.ID)
  4847. if prescription.ID > 0 {
  4848. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4849. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4850. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4851. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4852. record.UltrafiltrationRate = ultrafiltration_rate
  4853. }
  4854. //重庆塘坝卫生院
  4855. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4856. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4857. record.UltrafiltrationRate = ultrafiltration_rate
  4858. }
  4859. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4860. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4861. record.UltrafiltrationRate = ultrafiltration_rate
  4862. }
  4863. if adminInfo.Org.Id == 10510 {
  4864. record.UltrafiltrationRate = 0
  4865. }
  4866. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4867. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4868. record.UltrafiltrationRate = ultrafiltration_rate
  4869. }
  4870. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4871. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4872. record.UltrafiltrationRate = ultrafiltration_rate
  4873. }
  4874. // 只针对方济医院
  4875. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4876. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4877. ultrafiltration_rate = value
  4878. record.UltrafiltrationRate = ultrafiltration_rate
  4879. }
  4880. if template.TemplateId == 41 || template.TemplateId == 47 {
  4881. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4882. record.UltrafiltrationRate = ultrafiltration_rate
  4883. }
  4884. if template.TemplateId == 43 {
  4885. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4886. record.UltrafiltrationRate = ultrafiltration_rate
  4887. }
  4888. if template.TemplateId == 46 || template.TemplateId == 54 {
  4889. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4890. record.UltrafiltrationRate = ultrafiltration_rate
  4891. }
  4892. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4893. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4894. record.UltrafiltrationRate = ultrafiltration_rate
  4895. }
  4896. if adminInfo.Org.Id == 10469 {
  4897. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4898. record.UltrafiltrationRate = ultrafiltration_rate
  4899. }
  4900. if adminInfo.Org.Id == 10667 {
  4901. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4902. record.UltrafiltrationRate = ultrafiltration_rate
  4903. }
  4904. if adminInfo.Org.Id == 10471 {
  4905. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4906. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4907. }
  4908. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4909. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4910. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4911. }
  4912. if adminInfo.Org.Id == 10751 {
  4913. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4914. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4915. }
  4916. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4917. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4918. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4919. }
  4920. if adminInfo.Org.Id == 10721 {
  4921. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4922. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4923. }
  4924. if adminInfo.Org.Id == 10766 {
  4925. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4926. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4927. }
  4928. if adminInfo.Org.Id == 10757 {
  4929. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4930. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4931. }
  4932. if adminInfo.Org.Id == 10752 {
  4933. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4934. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4935. }
  4936. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4937. record.UltrafiltrationRate = 0
  4938. }
  4939. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4940. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4941. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4942. }
  4943. if adminInfo.Org.Id == 10206 {
  4944. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4945. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4946. }
  4947. //湘潭爱心美白石
  4948. if adminInfo.Org.Id == 9850 {
  4949. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4950. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4951. }
  4952. if adminInfo.Org.Id == 9919 {
  4953. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4954. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4955. }
  4956. //if template.TemplateId == 47 {
  4957. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4958. // record.UltrafiltrationRate = ultrafiltration_rate
  4959. //}
  4960. }
  4961. }
  4962. // record.UltrafiltrationRate = ultrafiltration_rate
  4963. record.UltrafiltrationVolume = 0
  4964. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  4965. if ultrafiltration_rate > 0 {
  4966. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4967. record.UltrafiltrationVolume = value
  4968. }
  4969. }
  4970. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4971. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4972. if adminInfo.Org.Id != 10735 {
  4973. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4974. record.UltrafiltrationVolume = ultrafiltration_volume
  4975. }
  4976. //胶州少海医院
  4977. if adminInfo.Org.Id == 10735 {
  4978. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4979. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4980. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4981. if lastMonitorRecordList.ID > 0 {
  4982. record.UltrafiltrationRate = ultrafiltration_rate_one
  4983. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4984. record.UltrafiltrationVolume = ultrafiltration_volume
  4985. } else {
  4986. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4987. record.UltrafiltrationVolume = ultrafiltration_volume
  4988. }
  4989. }
  4990. }
  4991. }
  4992. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4993. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4994. record.UltrafiltrationVolume = ultrafiltration_volume
  4995. }
  4996. //长沙南雅
  4997. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  4998. if ultrafiltration_rate > 0 {
  4999. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5000. record.UltrafiltrationVolume = ultrafiltration_volume
  5001. }
  5002. }
  5003. if adminInfo.Org.Id == 10471 {
  5004. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5005. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5006. }
  5007. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  5008. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5009. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5010. }
  5011. if adminInfo.Org.Id == 10751 {
  5012. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5013. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5014. }
  5015. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  5016. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5017. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5018. }
  5019. //长沙南雅累计血容量自动计算
  5020. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  5021. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  5022. //}
  5023. if template.TemplateId == 47 || template.TemplateId == 54 {
  5024. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5025. }
  5026. if adminInfo.Org.Id == 10510 {
  5027. record.UltrafiltrationVolume = 0
  5028. }
  5029. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10766 {
  5030. if ultrafiltration_rate > 0 {
  5031. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5032. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5033. }
  5034. }
  5035. //古镇乐生
  5036. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  5037. if ultrafiltration_rate > 0 {
  5038. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5039. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5040. }
  5041. }
  5042. if adminInfo.Org.Id == 9919 {
  5043. if ultrafiltration_rate > 0 {
  5044. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5045. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  5046. }
  5047. }
  5048. if adminInfo.Org.Id == 10206 {
  5049. if ultrafiltration_rate > 0 {
  5050. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5051. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5052. }
  5053. }
  5054. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10290 {
  5055. var replacement_rate float64
  5056. var displacement_quantity float64
  5057. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5058. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  5059. record.ReplacementRate = replacement_rate
  5060. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5061. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5062. record.DisplacementQuantity = displacement_quantity
  5063. }
  5064. if adminInfo.Org.Id == 10766 || adminInfo.Org.Id == 10164 {
  5065. var replacement_rate float64
  5066. var displacement_quantity float64
  5067. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5068. //replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5069. ////乘10 除10是为了保留一位小数
  5070. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5071. fmt.Println("replacement_rate", replacement_rate)
  5072. record.ReplacementRate = replacement_rate
  5073. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5074. record.DisplacementQuantity = displacement_quantity
  5075. //fmt.Println("totalMin", totalMin)
  5076. //fmt.Println("math.Floor(prescription", math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60))
  5077. //fmt.Println("replacement_rate", replacement_rate)
  5078. //fmt.Println("math.Floor", math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600))
  5079. //fmt.Println("displacement_quantity===================", displacement_quantity)
  5080. }
  5081. if adminInfo.Org.Id == 9478 {
  5082. var replacement_rate float64
  5083. var displacement_quantity float64
  5084. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5085. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5086. record.ReplacementRate = replacement_rate
  5087. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5088. record.DisplacementQuantity = displacement_quantity
  5089. }
  5090. if adminInfo.Org.Id == 10752 {
  5091. var replacement_rate float64
  5092. var displacement_quantity float64
  5093. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5094. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5095. record.ReplacementRate = replacement_rate
  5096. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5097. record.DisplacementQuantity = displacement_quantity
  5098. }
  5099. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5100. var replacement_rate float64
  5101. var displacement_quantity float64
  5102. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5103. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5104. record.ReplacementRate = replacement_rate
  5105. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5106. record.DisplacementQuantity = displacement_quantity
  5107. }
  5108. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  5109. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5110. record.UltrafiltrationVolume = ultrafiltration_volume
  5111. }
  5112. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  5113. var replacement_rate float64
  5114. var displacement_quantity float64
  5115. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5116. if totalMin == 0 {
  5117. totalMin = 240
  5118. }
  5119. if prescription.DisplaceLiquiValue == 0 {
  5120. prescription.ReplacementTotal = 32
  5121. }
  5122. //乘10 除10是为了保留一位小数
  5123. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5124. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5125. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5126. record.DisplacementQuantity = displacement_quantity
  5127. }
  5128. if adminInfo.Org.Id == 9850 {
  5129. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5130. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5131. }
  5132. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5133. fisrtMonitorRecordList, _ := service.GetFisrtMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5134. this.ServeSuccessJSON(map[string]interface{}{
  5135. "monitor": record,
  5136. "lastMonitorRecordList": lastMonitorRecordList,
  5137. "fisrtMonitorRecordList": fisrtMonitorRecordList,
  5138. })
  5139. }
  5140. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5141. record_id, _ := this.GetInt64("id")
  5142. nurseID, _ := this.GetInt64("start_nurse")
  5143. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5144. bedID, _ := this.GetInt64("bed")
  5145. start_time := this.GetString("start_time")
  5146. schedual_type, _ := this.GetInt64("schedual_type")
  5147. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  5148. change_nurse, _ := this.GetInt64("change_nurse")
  5149. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  5150. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  5151. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  5152. patient_id, _ := this.GetInt64("patient_id")
  5153. record_date, _ := this.GetInt64("record_date")
  5154. puncture_needle := this.GetString("puncture_needle")
  5155. puncture_way := this.GetString("puncture_way")
  5156. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  5157. dialysis_irrigation := this.GetString("dialysis_irrigation")
  5158. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  5159. nuclein_date_str := this.GetString("nuclein_date_str")
  5160. order_remark := this.GetString("order_remark")
  5161. schedule_remark := this.GetString("schedule_remark")
  5162. catheter_operation := this.GetString("catheter_operation")
  5163. blood_flow_volume := this.GetString("blood_flow_volume")
  5164. blood_drawing, _ := this.GetInt64("blood_drawing")
  5165. dialysis_strainer := this.GetString("dialysis_strainer")
  5166. if record_id == 0 {
  5167. this.ErrorLog("id:%v", record_id)
  5168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5169. return
  5170. }
  5171. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5172. if parseStartDateErr != nil {
  5173. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5175. return
  5176. }
  5177. adminUserInfo := this.GetMobileAdminUserInfo()
  5178. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5179. if getNurseErr != nil {
  5180. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5182. return
  5183. } else if nurse == nil {
  5184. this.ErrorLog("护士不存在")
  5185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5186. return
  5187. }
  5188. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5189. //if getNurseErr != nil {
  5190. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5191. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5192. // return
  5193. //} else if nurse == nil {
  5194. // this.ErrorLog("护士不存在")
  5195. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5196. // return
  5197. //}
  5198. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5199. if getDeviceNumberErr != nil {
  5200. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5202. return
  5203. } else if deviceNumber == nil {
  5204. this.ErrorLog("床位号不存在")
  5205. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5206. return
  5207. }
  5208. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5209. //
  5210. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5211. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5212. // if getPermissionErr != nil {
  5213. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5214. // return
  5215. // } else if headNursePermission == nil {
  5216. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5217. // return
  5218. // }
  5219. //}
  5220. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5221. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5222. timeLayout := "2006-01-02 15:04:05"
  5223. loc, _ := time.LoadLocation("Local")
  5224. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5225. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5226. schedulestartTime := theStartTime.Unix()
  5227. scheduleendTime := theEndTime.Unix()
  5228. var theNucleinDate int64
  5229. timeLayoutOne := "2006-01-02"
  5230. if len(nuclein_date_str) > 0 {
  5231. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5232. if err != nil {
  5233. utils.ErrorLog(err.Error())
  5234. }
  5235. theNucleinDate = theTime.Unix()
  5236. }
  5237. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5238. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5239. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5240. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5241. if err == gorm.ErrRecordNotFound { //空床位
  5242. // 修改了床位逻辑
  5243. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5244. if daySchedule.ID > 0 {
  5245. //daySchedule.BedId = bedID
  5246. //daySchedule.PartitionId = deviceNumber.ZoneID
  5247. //daySchedule.ScheduleType = schedual_type
  5248. //daySchedule.UpdatedTime = time.Now().Unix()
  5249. //err := service.UpdateSchedule(&daySchedule)
  5250. xtSchedule := models.Schedule{
  5251. PartitionId: deviceNumber.ZoneID,
  5252. BedId: bedID,
  5253. ScheduleType: schedual_type,
  5254. UpdatedTime: time.Now().Unix(),
  5255. }
  5256. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5257. if err != nil {
  5258. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5259. return
  5260. }
  5261. }
  5262. } else if err == nil {
  5263. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5264. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5265. if daySchedule.ID > 0 {
  5266. //daySchedule.BedId = bedID
  5267. //daySchedule.PartitionId = deviceNumber.ZoneID
  5268. //
  5269. //daySchedule.ScheduleType = schedual_type
  5270. //daySchedule.UpdatedTime = time.Now().Unix()
  5271. //err := service.UpdateSchedule(&daySchedule)
  5272. xtSchedule := models.Schedule{
  5273. PartitionId: deviceNumber.ZoneID,
  5274. BedId: bedID,
  5275. ScheduleType: schedual_type,
  5276. UpdatedTime: time.Now().Unix(),
  5277. }
  5278. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5279. if err != nil {
  5280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5281. return
  5282. }
  5283. }
  5284. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5286. return
  5287. }
  5288. } else if err != nil {
  5289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5290. return
  5291. }
  5292. }
  5293. dialysisRecord := &models.DialysisOrder{
  5294. ID: record_id,
  5295. UserOrgId: adminUserInfo.Org.Id,
  5296. BedID: bedID,
  5297. StartNurse: nurseID,
  5298. StartTime: startDate.Unix(),
  5299. PunctureNurse: puncture_nurse,
  5300. Creator: adminUserInfo.AdminUser.Id,
  5301. Modifier: adminUserInfo.AdminUser.Id,
  5302. WashpipeNurse: washpipe_nurse,
  5303. SchedualType: schedual_type,
  5304. ChangeNurse: change_nurse,
  5305. DifficultPunctureNurse: difficult_puncture_nurse,
  5306. NewFistulaNurse: new_fistula_nurse,
  5307. QualityNurseId: quality_nurse_id,
  5308. PunctureNeedle: puncture_needle,
  5309. PunctureWay: puncture_way,
  5310. DialysisDialyszers: dialysis_dialyszers,
  5311. DialysisIrrigation: dialysis_irrigation,
  5312. BloodAccessId: blood_access_id,
  5313. NucleinDate: theNucleinDate,
  5314. OrderRemark: order_remark,
  5315. ScheduleRemark: schedule_remark,
  5316. CatheterOperation: catheter_operation,
  5317. BloodFlowVolume: blood_flow_volume,
  5318. BloodDrawing: blood_drawing,
  5319. DialysisStrainer: dialysis_strainer,
  5320. }
  5321. _, prescription := service.FindDialysisPrescriptionByReordDate(patient_id, record_date, adminUserInfo.Org.Id)
  5322. if prescription.ID > 0 {
  5323. var endTime int64
  5324. endTime = dialysisRecord.StartTime + prescription.DialysisDurationHour*3600 + prescription.DialysisDurationMinute*60
  5325. dialysisRecord.EndTime = endTime
  5326. }
  5327. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10164 {
  5328. //查询第一条监测
  5329. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5330. service.UpdateFirstMoitorById(firstMonitor.ID, dialysisRecord.StartTime)
  5331. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5332. redis := service.RedisClient()
  5333. //清空key 值
  5334. redis.Set(key, "", time.Second)
  5335. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5336. redis.Set(keyOne, "", time.Second)
  5337. defer redis.Close()
  5338. }
  5339. //修改床位号需要重新消毒
  5340. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5341. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5342. //查询第一条监测
  5343. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5344. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5345. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5346. redis := service.RedisClient()
  5347. //清空key 值
  5348. redis.Set(key, "", time.Second)
  5349. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5350. redis.Set(keyOne, "", time.Second)
  5351. defer redis.Close()
  5352. }
  5353. // 查询信息规挡的设置天数
  5354. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5355. if infor.ID > 0 && infor.WeekDay > 0 {
  5356. var cha_time int64
  5357. timeNowStr := time.Now().Format("2006-01-02")
  5358. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5359. //今日的日期减去设置的日期
  5360. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5361. if cha_time >= record_date {
  5362. //查询审核是否允许
  5363. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5364. //申请状态不允许的情况 拒绝修改
  5365. if infor.ApplicationStatus != 1 {
  5366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5367. return
  5368. }
  5369. }
  5370. }
  5371. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5372. //修改床位后重新生成消毒计划
  5373. if adminUserInfo.Org.Id == 10340 {
  5374. //根据床位号获取设备型号
  5375. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5376. //查询使用消毒最后一条消毒记录
  5377. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5378. fmt.Println("err", err)
  5379. if err == gorm.ErrRecordNotFound {
  5380. //查找排班
  5381. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5382. //查询改设备是否有消毒计划
  5383. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5384. //根据床位号获取设备id
  5385. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5386. //查询病人信息
  5387. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5388. var con = ""
  5389. if patients.IsInfectious == 0 {
  5390. con = ""
  5391. }
  5392. if patients.IsInfectious == 1 {
  5393. con = "无"
  5394. }
  5395. if patients.IsInfectious == 2 {
  5396. con = "有"
  5397. }
  5398. if errcode == nil {
  5399. var end_time int64
  5400. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5401. //新增消毒
  5402. information := models.DeviceInformation{
  5403. Date: dialysisRecord.DialysisDate,
  5404. Zone: dialysisRecord.ZoneId,
  5405. Class: dialysisRecord.SchedualType,
  5406. BedNumber: dialysisRecord.BedID,
  5407. PatientId: dialysisRecord.PatientId,
  5408. DialysisMode: scheduleByPatient.ModeId,
  5409. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5410. Disinfection: 1,
  5411. DialysisConcentration: 1,
  5412. DisinfectionStatus: 1,
  5413. Move: 1,
  5414. UserOrgId: dialysisRecord.UserOrgId,
  5415. DisinfectType: plan.Way,
  5416. DisinfectantType: plan.MachineDisinfectant,
  5417. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5418. Disinfectant: plan.Disinfectant,
  5419. Ctime: time.Now().Unix(),
  5420. Status: 1,
  5421. SignName: nurseID,
  5422. EquimentId: addmacher.ID,
  5423. DisinfectionResidue: 2,
  5424. Bed: addmacher.BedNumber,
  5425. StartTime: dialysisRecord.StartTime,
  5426. EndTime: dialysisRecord.EndTime,
  5427. Contagion: con,
  5428. WeightLoss: 0,
  5429. Hyperfiltratio: 0,
  5430. DialysisHour: "",
  5431. MachineRun: 1,
  5432. DisinfecStartime: dialysisRecord.EndTime,
  5433. DisinfecEndtime: end_time,
  5434. }
  5435. err := service.CreateInformationTwo(&information)
  5436. fmt.Println("报错", err)
  5437. }
  5438. }
  5439. }
  5440. order, _ := service.GetLastPatientOrder(record_id)
  5441. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5442. redis := service.RedisClient()
  5443. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5444. redis.Set(key, "", time.Second)
  5445. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5446. //清空key 值
  5447. redis.Set(keyOne, "", time.Second)
  5448. scheduleDateStartOne := startDate.Format("2006-01-02")
  5449. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5450. redis.Set(keyTwo, "", time.Second)
  5451. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5452. redis.Set(keyThree, "", time.Second)
  5453. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5454. redis.Set(keyFour, "", time.Second)
  5455. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5456. redis.Set(keyFive, "", time.Second)
  5457. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5458. redis.Set(keySix, "", time.Second)
  5459. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5460. redis.Set(keySeven, "", time.Second)
  5461. if updateErr != nil {
  5462. this.ErrorLog("修改上机失败:%v", updateErr)
  5463. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5464. return
  5465. }
  5466. if updateErr == nil {
  5467. if tempDialysisRecord.Stage == 2 {
  5468. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5469. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5470. fmt.Println(value)
  5471. a, b := math.Modf(value)
  5472. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5473. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5474. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5475. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5476. redis := service.RedisClient()
  5477. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5478. redis.Set(key, "", time.Second)
  5479. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5480. redis.Set(keyOne, "", time.Second)
  5481. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5482. //清空key 值
  5483. redis.Set(keySix, "", time.Second)
  5484. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5485. redis.Set(keySeven, "", time.Second)
  5486. redis.Close()
  5487. if updateAssessmentErr != nil {
  5488. utils.ErrorLog("%v", updateAssessmentErr)
  5489. }
  5490. }
  5491. }
  5492. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5493. this.ServeSuccessJSON(map[string]interface{}{
  5494. "dialysis_order": dialysisRecords,
  5495. })
  5496. }
  5497. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5498. record_id, _ := c.GetInt64("id")
  5499. nurseID, _ := c.GetInt64("nurse")
  5500. end_time := c.GetString("end_time")
  5501. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5502. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5503. catheter := c.GetString("catheter")
  5504. cruor := c.GetString("cruor")
  5505. mission := c.GetString("mission")
  5506. condenser := c.GetString("condenser")
  5507. if record_id <= 0 || nurseID <= 0 {
  5508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5509. return
  5510. }
  5511. adminUserInfo := c.GetMobileAdminUserInfo()
  5512. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5513. if getNurseErr != nil {
  5514. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5516. return
  5517. } else if nurse == nil {
  5518. c.ErrorLog("护士不存在")
  5519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5520. return
  5521. }
  5522. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5523. if parseEndDateErr != nil {
  5524. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5526. return
  5527. }
  5528. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5529. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5530. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5531. // if getPermissionErr != nil {
  5532. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5533. // return
  5534. // } else if headNursePermission == nil {
  5535. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5536. // return
  5537. // }
  5538. //}
  5539. // 查询信息规挡的设置天数
  5540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5541. if infor.ID > 0 {
  5542. var cha_time int64
  5543. timeNowStr := time.Now().Format("2006-01-02")
  5544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5545. //今日的日期减去设置的日期
  5546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5547. if cha_time >= tempDialysisRecords.DialysisDate {
  5548. //查询审核是否允许
  5549. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5550. //申请状态不允许的情况 拒绝修改
  5551. if infor.ApplicationStatus != 1 {
  5552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5553. return
  5554. }
  5555. }
  5556. }
  5557. dialysisRecord := &models.DialysisOrder{
  5558. ID: record_id,
  5559. UserOrgId: adminUserInfo.Org.Id,
  5560. EndTime: endDate.Unix(),
  5561. FinishNurse: nurseID,
  5562. FinishModifier: adminUserInfo.AdminUser.Id,
  5563. PuncturePointHaematoma: puncture_point_haematoma,
  5564. BloodAccessInternalFistula: blood_access_internal_fistula,
  5565. Catheter: catheter,
  5566. Cruor: cruor,
  5567. Mission: mission,
  5568. Condenser: condenser,
  5569. }
  5570. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5571. redis := service.RedisClient()
  5572. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5573. //清空key 值
  5574. redis.Set(key, "", time.Second)
  5575. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5576. //清空key 值
  5577. redis.Set(keyOne, "", time.Second)
  5578. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5579. redis.Set(keySeven, "", time.Second)
  5580. redis.Close()
  5581. if updateErr != nil {
  5582. c.ErrorLog("修改下机失败:%v", updateErr)
  5583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5584. return
  5585. }
  5586. if updateErr == nil {
  5587. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5588. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5589. a, b := math.Modf(value)
  5590. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5591. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5592. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5593. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5594. redis := service.RedisClient()
  5595. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5596. redis.Set(keyTen, "", time.Second)
  5597. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5598. redis.Set(keyTwo, "", time.Second)
  5599. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5600. redis.Set(key, "", time.Second)
  5601. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5602. redis.Set(keyThree, "", time.Second)
  5603. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5604. redis.Set(keySeven, "", time.Second)
  5605. defer redis.Close()
  5606. if updateAssessmentErr != nil {
  5607. utils.ErrorLog("%v", updateAssessmentErr)
  5608. }
  5609. }
  5610. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5611. c.ServeSuccessJSON(map[string]interface{}{
  5612. "dialysis_order": dialysisRecords,
  5613. })
  5614. }
  5615. func (c *DialysisAPIController) GetLongAdvice() {
  5616. patient_id, _ := c.GetInt64("id")
  5617. adminUserInfo := c.GetMobileAdminUserInfo()
  5618. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5619. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5620. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5621. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5622. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5623. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5624. c.ServeSuccessJSON(map[string]interface{}{
  5625. "status": "1",
  5626. })
  5627. return
  5628. } else { //开启推送提醒
  5629. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5630. var advice_three []*models.DoctorAdvice
  5631. recordDateStr := time.Now().Format("2006-01-02")
  5632. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5633. nowtime := recordDate.Unix()
  5634. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5635. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5636. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5637. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5638. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5639. for _, advice := range advices {
  5640. if advice.FrequencyType == 3 {
  5641. t := time.Now()
  5642. week := int(t.Weekday())
  5643. fmt.Println(t.Weekday())
  5644. fmt.Println(week)
  5645. switch week {
  5646. case 1:
  5647. if strings.Index(advice.WeekDay, "周一") == -1 {
  5648. advice_three = append(advice_three, advice)
  5649. }
  5650. break
  5651. case 2:
  5652. if strings.Index(advice.WeekDay, "周二") == -1 {
  5653. advice_three = append(advice_three, advice)
  5654. }
  5655. break
  5656. case 3:
  5657. if strings.Index(advice.WeekDay, "周三") == -1 {
  5658. advice_three = append(advice_three, advice)
  5659. }
  5660. break
  5661. case 4:
  5662. if strings.Index(advice.WeekDay, "周四") == -1 {
  5663. advice_three = append(advice_three, advice)
  5664. }
  5665. break
  5666. case 5:
  5667. if strings.Index(advice.WeekDay, "周五") == -1 {
  5668. advice_three = append(advice_three, advice)
  5669. }
  5670. break
  5671. case 6:
  5672. if strings.Index(advice.WeekDay, "周六") == -1 {
  5673. advice_three = append(advice_three, advice)
  5674. }
  5675. break
  5676. case 0:
  5677. if strings.Index(advice.WeekDay, "周日") == -1 {
  5678. advice_three = append(advice_three, advice)
  5679. }
  5680. break
  5681. }
  5682. }
  5683. }
  5684. for _, advice := range advices_two {
  5685. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5686. now := p.Unix()
  5687. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5688. dayStr2 := "-" + dayStr
  5689. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5690. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5691. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5692. for _, ad := range advices {
  5693. advice_three = append(advice_three, ad)
  5694. }
  5695. }
  5696. if err == nil {
  5697. c.ServeSuccessJSON(map[string]interface{}{
  5698. "status": "2",
  5699. "advices": advices,
  5700. "advices_two": RemoveRepeatedElement(advice_three),
  5701. "is_open_remind": config.IsOpenRemind,
  5702. "his_config_open": hisConfig.IsOpen,
  5703. "is_advice_open": is_advice_open.IsAdviceOpen,
  5704. "prescription_open": prescription_open.IsOpen,
  5705. })
  5706. }
  5707. }
  5708. }
  5709. func (c *DialysisAPIController) GetLongAdviceOne() {
  5710. patient_id, _ := c.GetInt64("id")
  5711. startTime := c.GetString("schedule_date")
  5712. timeLayout := "2006-01-02"
  5713. loc, _ := time.LoadLocation("Local")
  5714. var theStartTime int64
  5715. if len(startTime) > 0 {
  5716. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5717. if err != nil {
  5718. utils.ErrorLog(err.Error())
  5719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5720. return
  5721. }
  5722. theStartTime = theTime.Unix()
  5723. }
  5724. adminUserInfo := c.GetMobileAdminUserInfo()
  5725. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5726. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5727. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5728. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5729. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5730. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5731. c.ServeSuccessJSON(map[string]interface{}{
  5732. "status": "1",
  5733. })
  5734. return
  5735. } else { //开启推送提醒
  5736. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5737. var advice_three []*models.DoctorAdvice
  5738. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5739. fmt.Println("theStartTime-----------------------", theStartTime)
  5740. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5741. for _, advice := range advices {
  5742. if advice.FrequencyType == 3 {
  5743. t := time.Now()
  5744. week := int(t.Weekday())
  5745. fmt.Println(t.Weekday())
  5746. fmt.Println(week)
  5747. switch week {
  5748. case 1:
  5749. if strings.Index(advice.WeekDay, "周一") == -1 {
  5750. advice_three = append(advice_three, advice)
  5751. }
  5752. break
  5753. case 2:
  5754. if strings.Index(advice.WeekDay, "周二") == -1 {
  5755. advice_three = append(advice_three, advice)
  5756. }
  5757. break
  5758. case 3:
  5759. if strings.Index(advice.WeekDay, "周三") == -1 {
  5760. advice_three = append(advice_three, advice)
  5761. }
  5762. break
  5763. case 4:
  5764. if strings.Index(advice.WeekDay, "周四") == -1 {
  5765. advice_three = append(advice_three, advice)
  5766. }
  5767. break
  5768. case 5:
  5769. if strings.Index(advice.WeekDay, "周五") == -1 {
  5770. advice_three = append(advice_three, advice)
  5771. }
  5772. break
  5773. case 6:
  5774. if strings.Index(advice.WeekDay, "周六") == -1 {
  5775. advice_three = append(advice_three, advice)
  5776. }
  5777. break
  5778. case 0:
  5779. if strings.Index(advice.WeekDay, "周日") == -1 {
  5780. advice_three = append(advice_three, advice)
  5781. }
  5782. break
  5783. }
  5784. }
  5785. }
  5786. for _, advice := range advices_two {
  5787. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5788. now := p.Unix()
  5789. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5790. dayStr2 := "-" + dayStr
  5791. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5792. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5793. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5794. fmt.Println("advices-==---------------", advices)
  5795. for _, ad := range advices {
  5796. advice_three = append(advice_three, ad)
  5797. }
  5798. }
  5799. if err == nil {
  5800. c.ServeSuccessJSON(map[string]interface{}{
  5801. "status": "2",
  5802. "advices": advices,
  5803. "advices_two": RemoveRepeatedElement(advice_three),
  5804. "is_open_remind": config.IsOpenRemind,
  5805. "his_config_open": hisConfig.IsOpen,
  5806. "is_advice_open": is_advice_open.IsAdviceOpen,
  5807. "prescription_open": prescription_open.IsOpen,
  5808. })
  5809. }
  5810. }
  5811. }
  5812. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5813. newArr = make([]*models.DoctorAdvice, 0)
  5814. for i := 0; i < len(arr); i++ {
  5815. repeat := false
  5816. for j := i + 1; j < len(arr); j++ {
  5817. if arr[i].ID == arr[j].ID {
  5818. repeat = true
  5819. break
  5820. }
  5821. }
  5822. if !repeat {
  5823. newArr = append(newArr, arr[i])
  5824. }
  5825. }
  5826. return
  5827. }
  5828. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5829. patient, _ := c.GetInt64("id", 0)
  5830. groupNo, _ := c.GetInt64("groupno", 0)
  5831. if patient <= 0 {
  5832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5833. return
  5834. }
  5835. adminUserInfo := c.GetMobileAdminUserInfo()
  5836. dataBody := make(map[string]interface{}, 0)
  5837. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5838. if err != nil {
  5839. utils.ErrorLog(err.Error())
  5840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5841. return
  5842. }
  5843. utils.ErrorLog("%v", dataBody)
  5844. timeLayout := "2006-01-02 15:04"
  5845. loc, _ := time.LoadLocation("Local")
  5846. timeLayout2 := "2006-01-02"
  5847. loc2, _ := time.LoadLocation("Local")
  5848. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5849. utils.ErrorLog("advice_type")
  5850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5851. return
  5852. }
  5853. adviceType := int64(2)
  5854. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5855. utils.ErrorLog("advice_date")
  5856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5857. return
  5858. }
  5859. adviceDate, _ := dataBody["advice_date"].(string)
  5860. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5861. AdviceDate := theTime.Unix()
  5862. RecordDate := theTime.Unix()
  5863. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5864. utils.ErrorLog("start_time")
  5865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5866. return
  5867. }
  5868. startTime, _ := dataBody["start_time"].(string)
  5869. if len(startTime) == 0 {
  5870. utils.ErrorLog("len(start_time) == 0")
  5871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5872. return
  5873. }
  5874. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5875. if err != nil {
  5876. utils.ErrorLog(err.Error())
  5877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5878. return
  5879. }
  5880. StartTime := theTime.Unix()
  5881. Remark := ""
  5882. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5883. remark, _ := dataBody["remark"].(string)
  5884. Remark = remark
  5885. }
  5886. var advices []*models.GroupAdvice
  5887. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5888. utils.ErrorLog("advices")
  5889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5890. return
  5891. }
  5892. adviceNames := dataBody["advices"].([]interface{})
  5893. for _, adviceNameMap := range adviceNames {
  5894. adviceNameM := adviceNameMap.(map[string]interface{})
  5895. var advice models.GroupAdvice
  5896. advice.Remark = Remark
  5897. advice.AdviceType = adviceType
  5898. advice.StartTime = StartTime
  5899. advice.AdviceDate = AdviceDate
  5900. advice.RecordDate = RecordDate
  5901. advice.Status = 1
  5902. advice.CreatedTime = time.Now().Unix()
  5903. advice.UpdatedTime = time.Now().Unix()
  5904. advice.StopState = 2
  5905. advice.ExecutionState = 2
  5906. advice.UserOrgId = adminUserInfo.Org.Id
  5907. advice.PatientId = patient
  5908. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5909. advice.IsSettle = 2
  5910. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5911. utils.ErrorLog("advice_name")
  5912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5913. return
  5914. }
  5915. adviceName, _ := adviceNameM["advice_name"].(string)
  5916. if len(adviceName) == 0 {
  5917. utils.ErrorLog("len(advice_name) == 0")
  5918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5919. return
  5920. }
  5921. advice.AdviceName = adviceName
  5922. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5923. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5924. advice.DrugSpec = drugSpec
  5925. }
  5926. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5927. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5928. advice.AdviceDesc = adviceDesc
  5929. }
  5930. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5931. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5932. advice.DrugSpecUnit = drugSpecUnit
  5933. }
  5934. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5935. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5936. // advice.SingleDose = singleDose
  5937. //}
  5938. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5939. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5940. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5941. }
  5942. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5943. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5944. advice.SingleDoseUnit = singleDoseUnit
  5945. }
  5946. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5947. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5948. // advice.PrescribingNumber = prescribingNumber
  5949. //}
  5950. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5951. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5952. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5953. }
  5954. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5955. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5956. advice.PrescribingNumberUnit = prescribingNumberUnit
  5957. }
  5958. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5959. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5960. advice.DeliveryWay = deliveryWay
  5961. }
  5962. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5963. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5964. advice.ExecutionFrequency = executionFrequency
  5965. }
  5966. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5967. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5968. advice.FrequencyType = frequency_type
  5969. }
  5970. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5971. day_count := int64(adviceNameM["day_count"].(float64))
  5972. advice.DayCount = day_count
  5973. }
  5974. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5975. week_day, _ := adviceNameM["week_day"].(string)
  5976. advice.WeekDay = week_day
  5977. }
  5978. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5979. way := int64(adviceNameM["way"].(float64))
  5980. advice.Way = way
  5981. }
  5982. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5983. drug_id := int64(adviceNameM["drug_id"].(float64))
  5984. advice.DrugId = drug_id
  5985. }
  5986. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5987. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5988. advice.DrugNameId = drug_name_id
  5989. }
  5990. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5991. remark, _ := adviceNameM["remark"].(string)
  5992. advice.Remark = remark
  5993. }
  5994. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5995. groupno := int64(adviceNameM["groupno"].(float64))
  5996. advice.GroupNo = groupno
  5997. }
  5998. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5999. template_id, _ := adviceNameM["template_id"].(string)
  6000. advice.TemplateId = template_id
  6001. }
  6002. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  6003. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  6004. advice.ExecutionFrequency = executionFrequency
  6005. }
  6006. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  6007. children := adviceNameM["child"].([]interface{})
  6008. if len(children) > 0 {
  6009. for _, childrenMap := range children {
  6010. childMap := childrenMap.(map[string]interface{})
  6011. var child models.GroupAdvice
  6012. child.Remark = Remark
  6013. child.AdviceType = adviceType
  6014. child.StartTime = StartTime
  6015. child.AdviceDate = AdviceDate
  6016. child.RecordDate = RecordDate
  6017. child.Status = 1
  6018. child.CreatedTime = time.Now().Unix()
  6019. child.UpdatedTime = time.Now().Unix()
  6020. child.StopState = 2
  6021. child.ExecutionState = 2
  6022. child.UserOrgId = adminUserInfo.Org.Id
  6023. child.PatientId = patient
  6024. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  6025. child.IsSettle = 1
  6026. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  6027. utils.ErrorLog("child advice_name")
  6028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6029. return
  6030. }
  6031. childAdviceName, _ := childMap["advice_name"].(string)
  6032. if len(childAdviceName) == 0 {
  6033. utils.ErrorLog("len(child advice_name) == 0")
  6034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6035. return
  6036. }
  6037. child.AdviceName = childAdviceName
  6038. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  6039. childAdviceDesc, _ := childMap["advice_desc"].(string)
  6040. child.AdviceDesc = childAdviceDesc
  6041. }
  6042. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  6043. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  6044. child.DrugSpec = childDrugSpec
  6045. }
  6046. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  6047. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  6048. child.DrugSpecUnit = childDrugSpecUnit
  6049. }
  6050. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  6051. child.SingleDose = childMap["single_dose"].(float64)
  6052. }
  6053. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  6054. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  6055. child.SingleDoseUnit = childSingleDoseUnit
  6056. }
  6057. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  6058. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  6059. }
  6060. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  6061. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  6062. child.PrescribingNumberUnit = childPrescribingNumberUnit
  6063. }
  6064. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  6065. groupno := int64(childMap["groupno"].(float64))
  6066. advice.GroupNo = groupno
  6067. }
  6068. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  6069. remark, _ := childMap["remark"].(string)
  6070. child.Remark = remark
  6071. }
  6072. child.DeliveryWay = advice.DeliveryWay
  6073. child.ExecutionFrequency = advice.ExecutionFrequency
  6074. advice.Children = append(advice.Children, &child)
  6075. }
  6076. }
  6077. }
  6078. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  6079. if temp_advice.ID == 0 {
  6080. advices = append(advices, &advice)
  6081. }
  6082. }
  6083. if len(advices) > 0 {
  6084. finish := models.XtDialysisFinish{
  6085. IsFinish: 1,
  6086. UserOrgId: adminUserInfo.Org.Id,
  6087. Status: 1,
  6088. Ctime: time.Now().Unix(),
  6089. Mtime: 0,
  6090. Module: 4,
  6091. RecordDate: AdviceDate,
  6092. Sourse: 1,
  6093. PatientId: patient,
  6094. }
  6095. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  6096. if dialysisFinish.ID == 0 {
  6097. service.CreateDialysisFinish(finish)
  6098. }
  6099. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  6100. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  6101. for _, item := range advices {
  6102. byterequest, _ := json.Marshal(item)
  6103. adviceLog := models.XtDoctorAdviceLog{
  6104. UserOrgId: adminUserInfo.Org.Id,
  6105. PatientId: patient,
  6106. AdminUserId: adminUserInfo.AdminUser.Id,
  6107. Module: 1,
  6108. ErrLog: string(byterequest),
  6109. Status: 1,
  6110. Ctime: time.Now().Unix(),
  6111. Mtime: 0,
  6112. Source: "手机端医嘱推送",
  6113. RecordDate: item.AdviceDate,
  6114. }
  6115. service.CreateDoctorAdviceLog(adviceLog)
  6116. }
  6117. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6118. redis := service.RedisClient()
  6119. //清空key 值
  6120. redis.Set(key, "", time.Second)
  6121. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6122. redis.Set(keyOne, "", time.Second)
  6123. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6124. defer redis.Close()
  6125. redis.Set(keyThree, "", time.Second)
  6126. if err != nil {
  6127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6128. return
  6129. }
  6130. c.ServeSuccessJSON(map[string]interface{}{
  6131. "msg": "ok",
  6132. "advices": list,
  6133. })
  6134. } else {
  6135. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  6136. for _, item := range advices {
  6137. byterequest, _ := json.Marshal(item)
  6138. adviceLog := models.XtDoctorAdviceLog{
  6139. UserOrgId: adminUserInfo.Org.Id,
  6140. PatientId: patient,
  6141. AdminUserId: adminUserInfo.AdminUser.Id,
  6142. Module: 1,
  6143. ErrLog: string(byterequest),
  6144. Status: 1,
  6145. Ctime: time.Now().Unix(),
  6146. Mtime: 0,
  6147. Source: "手机端医嘱推送",
  6148. RecordDate: item.AdviceDate,
  6149. }
  6150. service.CreateDoctorAdviceLog(adviceLog)
  6151. }
  6152. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6153. redis := service.RedisClient()
  6154. //清空key 值
  6155. redis.Set(key, "", time.Second)
  6156. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6157. redis.Set(keyOne, "", time.Second)
  6158. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6159. defer redis.Close()
  6160. redis.Set(keyThree, "", time.Second)
  6161. if err != nil {
  6162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6163. return
  6164. }
  6165. c.ServeSuccessJSON(map[string]interface{}{
  6166. "msg": "ok",
  6167. "advices": list,
  6168. })
  6169. }
  6170. } else {
  6171. c.ServeSuccessJSON(map[string]interface{}{
  6172. "msg": "ok",
  6173. })
  6174. }
  6175. return
  6176. }
  6177. func (c *DialysisAPIController) UploadDryWeight() {
  6178. patient_id, _ := c.GetInt64("id")
  6179. dry_weight, _ := c.GetFloat("dry_weight")
  6180. doctor_id, _ := c.GetInt64("doctor_id")
  6181. remark := c.GetString("remark")
  6182. adminUserInfo := c.GetMobileAdminUserInfo()
  6183. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  6184. if err == gorm.ErrRecordNotFound {
  6185. dryWeight := &models.SgjPatientDryweight{
  6186. PatientId: patient_id,
  6187. DryWeight: dry_weight,
  6188. Remakes: remark,
  6189. Ctime: time.Now().Unix(),
  6190. Mtime: time.Now().Unix(),
  6191. Creator: doctor_id,
  6192. Status: 1,
  6193. UserOrgId: adminUserInfo.Org.Id,
  6194. AdjustedValue: "/",
  6195. UserId: adminUserInfo.AdminUser.Id,
  6196. }
  6197. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6198. redis := service.RedisClient()
  6199. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6200. redis.Set(keyOne, "", time.Second)
  6201. loc, _ := time.LoadLocation("Local")
  6202. nowTime := time.Now()
  6203. nowDay := nowTime.Format("2006-01-02")
  6204. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6205. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6206. redis.Set(key, "", time.Second)
  6207. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6208. redis.Set(keyTwo, "", time.Second)
  6209. redis.Close()
  6210. if createErr == nil {
  6211. c.ServeSuccessJSON(map[string]interface{}{
  6212. "msg": "提交成功",
  6213. "weight": dryWeight,
  6214. })
  6215. }
  6216. } else {
  6217. dryWeight := &models.SgjPatientDryweight{
  6218. PatientId: patient_id,
  6219. DryWeight: dry_weight,
  6220. Remakes: remark,
  6221. Ctime: time.Now().Unix(),
  6222. Mtime: time.Now().Unix(),
  6223. Creator: doctor_id,
  6224. Status: 1,
  6225. UserOrgId: adminUserInfo.Org.Id,
  6226. AdjustedValue: "/",
  6227. UserId: adminUserInfo.AdminUser.Id,
  6228. }
  6229. var value float64
  6230. value = dry_weight - weightAdjust.DryWeight
  6231. if value < 0 {
  6232. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6233. } else if value == 0 {
  6234. dryWeight.AdjustedValue = "/"
  6235. } else if value > 0 {
  6236. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6237. }
  6238. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6239. //康桥
  6240. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6241. timeNowStr := time.Now().Format("2006-01-02")
  6242. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6243. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6244. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6245. if beforAssesment.ID > 0 {
  6246. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6247. var dewater_amount float64
  6248. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6249. if adminUserInfo.Org.Id != 10702 {
  6250. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6251. }
  6252. if adminUserInfo.Org.Id == 10702 {
  6253. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6254. }
  6255. //获取key,清空redis
  6256. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6257. redis := service.RedisClient()
  6258. //清空key 值
  6259. redis.Set(key, "", time.Second)
  6260. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6261. //清空key 值
  6262. redis.Set(keyOne, "", time.Second)
  6263. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6264. //清空key 值
  6265. redis.Set(keyTwo, "", time.Second)
  6266. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6267. redis.Set(keySix, "", time.Second)
  6268. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6269. redis.Set(keySeven, "", time.Second)
  6270. }
  6271. }
  6272. redis := service.RedisClient()
  6273. loc, _ := time.LoadLocation("Local")
  6274. nowTime := time.Now()
  6275. nowDay := nowTime.Format("2006-01-02")
  6276. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6277. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6278. redis.Set(keyOne, "", time.Second)
  6279. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6280. redis.Set(key, "", time.Second)
  6281. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6282. redis.Set(keyTwo, "", time.Second)
  6283. redis.Close()
  6284. if createErr == nil {
  6285. c.ServeSuccessJSON(map[string]interface{}{
  6286. "msg": "提交成功",
  6287. "weight": dryWeight,
  6288. })
  6289. }
  6290. }
  6291. }
  6292. func (c *DialysisAPIController) GetSolution() {
  6293. patient_id, _ := c.GetInt64("patient_id")
  6294. mode_id, _ := c.GetInt64("mode_id")
  6295. adminUserInfo := c.GetMobileAdminUserInfo()
  6296. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6297. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6298. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6299. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6300. if err != nil {
  6301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6302. return
  6303. }
  6304. c.ServeSuccessJSON(map[string]interface{}{
  6305. "solution": solution,
  6306. "prescription": prescription,
  6307. "system_prescription": system_prescription,
  6308. "dialysisPrescription": dialysisPrescription,
  6309. })
  6310. }
  6311. func (c *DialysisAPIController) GetSchedule() {
  6312. schedual_type, _ := c.GetInt64("schedual_type")
  6313. adminUserInfo := c.GetMobileAdminUserInfo()
  6314. scheduleTime, _ := c.GetInt64("record_date")
  6315. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6316. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6317. c.ServeSuccessJSON(map[string]interface{}{
  6318. "number": deviceNumber,
  6319. "list": list,
  6320. })
  6321. }
  6322. func (c *DialysisAPIController) GetPatientId() {
  6323. id, _ := c.GetInt64("id")
  6324. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6325. patientId, _ := service.GetPatientId(id)
  6326. //获取该患者的所有传染病
  6327. list, _ := service.GetPatientInfectious(id)
  6328. c.ServeSuccessJSON(map[string]interface{}{
  6329. "patient": patientId,
  6330. "infectioulist": list,
  6331. })
  6332. }
  6333. func (this *DialysisAPIController) GetDialysisSchedule() {
  6334. schedualDate := this.GetString("date")
  6335. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6336. if parseDateErr != nil {
  6337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6338. return
  6339. }
  6340. adminInfo := this.GetMobileAdminUserInfo()
  6341. orgID := adminInfo.Org.Id
  6342. redis := service.RedisClient()
  6343. defer redis.Close()
  6344. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6345. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6346. if len(scheduals) > 0 {
  6347. //缓存数据
  6348. scheduals_json, err := json.Marshal(scheduals)
  6349. if err == nil {
  6350. redis.Set(key, scheduals_json, time.Second*30)
  6351. }
  6352. }
  6353. this.ServeSuccessJSON(map[string]interface{}{
  6354. "scheduals": scheduals,
  6355. })
  6356. }
  6357. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6358. change_type, _ := this.GetInt64("type", 0)
  6359. record_date := this.GetString("record_time")
  6360. patient_id, _ := this.GetInt64("patient_id", 0)
  6361. timeLayout := "2006-01-02"
  6362. loc, _ := time.LoadLocation("Local")
  6363. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6364. record_time := theAdviceRecordTime.Unix()
  6365. adminUserInfo := this.GetMobileAdminUserInfo()
  6366. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6367. if err == nil {
  6368. if len(advices) == 0 {
  6369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6370. return
  6371. } else {
  6372. this.ServeSuccessJSON(map[string]interface{}{
  6373. "advices": advices,
  6374. "schedule": sch,
  6375. })
  6376. return
  6377. }
  6378. } else {
  6379. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6380. return
  6381. }
  6382. }
  6383. func (c *DialysisAPIController) CreateConsumables() {
  6384. record_date := c.GetString("record_time")
  6385. patient_id, _ := c.GetInt64("patient_id", 0)
  6386. active, _ := c.GetInt64("active")
  6387. adminUser := c.GetMobileAdminUserInfo()
  6388. timeLayout := "2006-01-02"
  6389. loc, _ := time.LoadLocation("Local")
  6390. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6391. record_time := theRecordTime.Unix()
  6392. // 查询信息规挡的设置天数
  6393. orgid := c.GetMobileAdminUserInfo().Org.Id
  6394. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6395. if infor.ID > 0 {
  6396. var cha_time int64
  6397. timeNowStr := time.Now().Format("2006-01-02")
  6398. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6399. //今日的日期减去设置的日期
  6400. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6401. if cha_time >= record_time {
  6402. //查询审核是否允许
  6403. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6404. //申请状态不允许的情况 拒绝修改
  6405. if infor.ApplicationStatus != 1 {
  6406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6407. return
  6408. }
  6409. }
  6410. }
  6411. dataBody := make(map[string]interface{}, 0)
  6412. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6413. if err != nil {
  6414. utils.ErrorLog(err.Error())
  6415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6416. return
  6417. }
  6418. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6419. var beforePrepares []*models.DialysisBeforePrepareGoods
  6420. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6421. var dialysisBefor []*models.DialysisBeforePrepare
  6422. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6423. goods, _ := dataBody["goods"].([]interface{})
  6424. if len(goods) > 0 {
  6425. for _, item := range goods {
  6426. items := item.(map[string]interface{})
  6427. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6428. utils.ErrorLog("good_id")
  6429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6430. return
  6431. }
  6432. good_id := int64(items["good_id"].(float64))
  6433. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6434. utils.ErrorLog("good_type_id")
  6435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6436. return
  6437. }
  6438. good_type_id := int64(items["good_type_id"].(float64))
  6439. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6440. utils.ErrorLog("count")
  6441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6442. return
  6443. }
  6444. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6445. commdity_code := items["commdity_code"].(string)
  6446. fmt.Println("commdity", commdity_code)
  6447. prepareGoods := &models.DialysisBeforePrepareGoods{
  6448. GoodTypeId: good_type_id,
  6449. GoodId: good_id,
  6450. Count: count,
  6451. StorehouseId: houseConfig.StorehouseOutInfo,
  6452. }
  6453. beforePrepares = append(beforePrepares, prepareGoods)
  6454. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6455. GoodTypeId: good_type_id,
  6456. GoodId: good_id,
  6457. Count: count,
  6458. StorehouseId: houseConfig.StorehouseOutInfo,
  6459. }
  6460. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6461. prepare := &models.DialysisBeforePrepare{
  6462. GoodTypeId: good_type_id,
  6463. GoodId: good_id,
  6464. Count: count,
  6465. PatientId: patient_id,
  6466. RecordDate: record_time,
  6467. UserOrgId: adminUser.Org.Id,
  6468. Status: 1,
  6469. Ctime: time.Now().Unix(),
  6470. Creater: adminUser.AdminUser.Id,
  6471. CommdityCode: commdity_code,
  6472. StorehouseId: houseConfig.StorehouseOutInfo,
  6473. }
  6474. dialysisBefor = append(dialysisBefor, prepare)
  6475. }
  6476. }
  6477. //查询是否有库存
  6478. for _, item := range dialysisBefor {
  6479. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6480. if err == gorm.ErrRecordNotFound {
  6481. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6482. c.ServeSuccessJSON(map[string]interface{}{
  6483. "message": "1",
  6484. "good_name": goodObj.GoodName,
  6485. "specification_name": goodObj.SpecificationName,
  6486. })
  6487. return
  6488. }
  6489. if err != nil {
  6490. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6491. c.ServeSuccessJSON(map[string]interface{}{
  6492. "message": "1",
  6493. "good_name": goodObj.GoodName,
  6494. "specification_name": goodObj.SpecificationName,
  6495. })
  6496. return
  6497. }
  6498. }
  6499. fmt.Println("active-----------------------", active)
  6500. fmt.Println("len(goods)-----------------------", len(goods))
  6501. //新增
  6502. if active == 1 && len(goods) > 0 {
  6503. for _, item := range dialysisBefor {
  6504. dialyPrepareOne := models.DialysisBeforePrepare{
  6505. GoodTypeId: item.GoodTypeId,
  6506. GoodId: item.GoodId,
  6507. PatientId: item.PatientId,
  6508. RecordDate: item.RecordDate,
  6509. UserOrgId: item.UserOrgId,
  6510. Count: item.Count,
  6511. Ctime: time.Now().Unix(),
  6512. Creater: item.Creater,
  6513. CommdityCode: item.CommdityCode,
  6514. Status: 1,
  6515. StorehouseId: houseConfig.StorehouseOutInfo,
  6516. }
  6517. //先清除再插入
  6518. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6519. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6520. //查询默认仓库
  6521. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6522. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6523. var total_count int64
  6524. for _, it := range stockList {
  6525. total_count += it.StockCount
  6526. }
  6527. //基础库插入数据
  6528. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6529. //更新库存
  6530. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6531. var flush_count int64
  6532. for _, it := range goodList {
  6533. flush_count += it.StockCount
  6534. }
  6535. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6536. }
  6537. if err == nil {
  6538. c.ServeSuccessJSON(map[string]interface{}{
  6539. "msg": "保存成功",
  6540. "message": "2",
  6541. })
  6542. return
  6543. } else {
  6544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6545. return
  6546. }
  6547. }
  6548. if len(beforePrepares) > 0 && active == 2 {
  6549. for _, item := range beforePrepares {
  6550. //1.查看该患者该耗材型号最后一次出库数量
  6551. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6552. //判断当前出库数量和最后一次出库数量的大小
  6553. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6554. if item.Count <= goodInfo.Count {
  6555. //退库
  6556. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6557. //查询今日出库数据
  6558. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6559. for _, it := range list {
  6560. prepare := models.DialysisBeforePrepare{
  6561. UserOrgId: it.OrgId,
  6562. PatientId: patient_id,
  6563. RecordDate: it.RecordTime,
  6564. GoodId: it.GoodId,
  6565. GoodTypeId: it.GoodTypeId,
  6566. Count: it.Count,
  6567. Ctime: time.Now().Unix(),
  6568. Creater: adminUser.AdminUser.Id,
  6569. Status: 1,
  6570. StorehouseId: houseConfig.StorehouseOutInfo,
  6571. }
  6572. //删除准备表数据
  6573. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6574. service.CreateDialysisBeforePrepareOne(&prepare)
  6575. }
  6576. }
  6577. var last_total int64
  6578. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6579. if item.Count >= goodInfo.Count {
  6580. //查询当前批次当前耗材最后一条出库数据
  6581. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6582. //计算当前出库和最后一次出库数据相差数据
  6583. last_total = item.Count - lastOutInfo.Count
  6584. //查询该批次剩余库存
  6585. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6586. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6587. if lastInfo.StockCount >= last_total {
  6588. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6589. //查询今日出库数据
  6590. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6591. for _, it := range list {
  6592. prepare := models.DialysisBeforePrepare{
  6593. UserOrgId: it.OrgId,
  6594. PatientId: patient_id,
  6595. RecordDate: it.RecordTime,
  6596. GoodId: it.GoodId,
  6597. GoodTypeId: it.GoodTypeId,
  6598. Count: it.Count,
  6599. Ctime: time.Now().Unix(),
  6600. Creater: adminUser.AdminUser.Id,
  6601. Status: 1,
  6602. StorehouseId: houseConfig.StorehouseOutInfo,
  6603. }
  6604. //删除准备表数据
  6605. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6606. service.CreateDialysisBeforePrepareOne(&prepare)
  6607. //查询默认仓库
  6608. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6609. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6610. var total_count int64
  6611. for _, it := range stockList {
  6612. total_count += it.StockCount
  6613. }
  6614. //基础库插入数据
  6615. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6616. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6617. var flush_count int64
  6618. for _, it := range goodList {
  6619. flush_count += it.StockCount
  6620. }
  6621. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6622. }
  6623. }
  6624. //如果库存不够,则出库到下一个批次
  6625. if lastInfo.StockCount < last_total {
  6626. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6627. //查询今日出库数据
  6628. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6629. for _, it := range list {
  6630. prepare := models.DialysisBeforePrepare{
  6631. UserOrgId: it.OrgId,
  6632. PatientId: patient_id,
  6633. RecordDate: it.RecordTime,
  6634. GoodId: it.GoodId,
  6635. GoodTypeId: it.GoodTypeId,
  6636. Count: it.Count,
  6637. Ctime: time.Now().Unix(),
  6638. Creater: adminUser.AdminUser.Id,
  6639. Status: 1,
  6640. StorehouseId: houseConfig.StorehouseOutInfo,
  6641. }
  6642. //删除准备表数据
  6643. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6644. service.CreateDialysisBeforePrepareOne(&prepare)
  6645. //查询默认仓库
  6646. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6647. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6648. var total_count int64
  6649. for _, it := range stockList {
  6650. total_count += it.StockCount
  6651. }
  6652. //基础库插入数据
  6653. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6654. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6655. var flush_count int64
  6656. for _, it := range goodList {
  6657. flush_count += it.StockCount
  6658. }
  6659. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6660. }
  6661. if err != nil {
  6662. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6663. c.ServeSuccessJSON(map[string]interface{}{
  6664. "message": "1",
  6665. "good_name": goodObj.GoodName,
  6666. "specification_name": goodObj.SpecificationName,
  6667. })
  6668. return
  6669. }
  6670. }
  6671. }
  6672. if err != nil {
  6673. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6674. c.ServeSuccessJSON(map[string]interface{}{
  6675. "message": "1",
  6676. "good_name": goodObj.GoodName,
  6677. "specification_name": goodObj.SpecificationName,
  6678. })
  6679. return
  6680. }
  6681. }
  6682. }
  6683. }
  6684. var errs error
  6685. if errs == nil {
  6686. c.ServeSuccessJSON(map[string]interface{}{
  6687. "msg": "提交成功",
  6688. "message": "2",
  6689. "good_name": "",
  6690. "specification_name": "",
  6691. })
  6692. return
  6693. } else {
  6694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6695. return
  6696. }
  6697. }
  6698. func (c *DialysisAPIController) CreateStockOutInfo() {
  6699. patient_id, _ := c.GetInt64("patient_id", 0)
  6700. record_date := c.GetString("record_time")
  6701. if patient_id <= 0 {
  6702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6703. return
  6704. }
  6705. adminInfo := c.GetMobileAdminUserInfo()
  6706. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6707. timeLayout := "2006-01-02"
  6708. loc, _ := time.LoadLocation("Local")
  6709. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6710. record_time := theRecordTime.Unix()
  6711. // 查询信息规挡的设置天数
  6712. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6713. if infor.ID > 0 && infor.WeekDay > 0 {
  6714. var cha_time int64
  6715. timeNowStr := time.Now().Format("2006-01-02")
  6716. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6717. //今日的日期减去设置的日期
  6718. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6719. if cha_time >= record_time {
  6720. //查询审核是否允许
  6721. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6722. //申请状态不允许的情况 拒绝修改
  6723. if infor.ApplicationStatus != 1 {
  6724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6725. return
  6726. }
  6727. }
  6728. }
  6729. //创建步骤表
  6730. finish := models.XtDialysisFinish{
  6731. IsFinish: 1,
  6732. UserOrgId: adminInfo.Org.Id,
  6733. Status: 1,
  6734. Ctime: time.Now().Unix(),
  6735. Mtime: 0,
  6736. Module: 11,
  6737. RecordDate: record_time,
  6738. Sourse: 1,
  6739. PatientId: patient_id,
  6740. }
  6741. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6742. if dialysisFinish.ID == 0 {
  6743. service.CreateDialysisFinish(finish)
  6744. }
  6745. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6746. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6747. //去重
  6748. consumables = RemoveRepeatedGood(consumables)
  6749. if adminInfo.Org.Id == 9919 {
  6750. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6751. //查询是否有库存
  6752. for _, item := range consumables {
  6753. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6754. if item.Count > warehouse.Count {
  6755. goodErrcode := models.XtGoodErrcode{
  6756. UserOrgId: item.UserOrgId,
  6757. Errcode: "自动出库库存不足",
  6758. GoodId: item.GoodId,
  6759. Status: 1,
  6760. Ctime: time.Now().Unix(),
  6761. Mtime: 0,
  6762. Count: 0,
  6763. StockCount: 0,
  6764. Creater: creator,
  6765. BatchNumberId: warehouse.ID,
  6766. WarehouseOutId: 0,
  6767. }
  6768. service.CreateGoodErrcode(goodErrcode)
  6769. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6770. c.ServeSuccessJSON(map[string]interface{}{
  6771. "message": "1",
  6772. "good_name": goodObj.GoodName,
  6773. "specification_name": goodObj.SpecificationName,
  6774. })
  6775. return
  6776. }
  6777. }
  6778. //查询是否有出库单
  6779. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6780. if err == gorm.ErrRecordNotFound {
  6781. //没有记录,则创建出库单
  6782. timeStr := time.Now().Format("2006-01-02")
  6783. timeArr := strings.Split(timeStr, "-")
  6784. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6785. total = total + 1
  6786. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6787. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6788. number = number + total
  6789. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6790. creater := adminInfo.AdminUser.Id
  6791. warehouseOut := models.WarehouseOut{
  6792. WarehouseOutOrderNumber: warehousing_out_order,
  6793. OperationTime: time.Now().Unix(),
  6794. OrgId: adminInfo.Org.Id,
  6795. Creater: creater,
  6796. Ctime: time.Now().Unix(),
  6797. Status: 1,
  6798. WarehouseOutTime: record_time,
  6799. Dealer: 0,
  6800. Manufacturer: 0,
  6801. Type: 1,
  6802. IsSys: 1,
  6803. StorehouseId: houseConfig.StorehouseOutInfo,
  6804. IsCheck: 1,
  6805. }
  6806. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6807. if err != nil {
  6808. goodErrcode := models.XtGoodErrcode{
  6809. UserOrgId: adminInfo.Org.Id,
  6810. Errcode: "创建出库单失败",
  6811. GoodId: 0,
  6812. Status: 1,
  6813. Ctime: time.Now().Unix(),
  6814. Mtime: 0,
  6815. Count: 0,
  6816. StockCount: 0,
  6817. Creater: creator,
  6818. BatchNumberId: 0,
  6819. WarehouseOutId: 0,
  6820. }
  6821. service.CreateGoodErrcode(goodErrcode)
  6822. utils.TraceLog("创建出库单失败 err = %v", err)
  6823. } else {
  6824. for _, item := range consumables {
  6825. //出库
  6826. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6827. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6828. if err == nil {
  6829. goodErrcode := models.XtGoodErrcode{
  6830. UserOrgId: adminInfo.Org.Id,
  6831. Errcode: "自动出库接口报错",
  6832. GoodId: 0,
  6833. Status: 1,
  6834. Ctime: time.Now().Unix(),
  6835. Mtime: 0,
  6836. Count: 0,
  6837. StockCount: 0,
  6838. Creater: creator,
  6839. BatchNumberId: 0,
  6840. WarehouseOutId: 0,
  6841. }
  6842. service.CreateGoodErrcode(goodErrcode)
  6843. utils.TraceLog("创建出库单失败 err = %v", err)
  6844. }
  6845. //查询
  6846. //出库数量相加
  6847. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6848. if errs != nil {
  6849. goodErrcode := models.XtGoodErrcode{
  6850. UserOrgId: item.UserOrgId,
  6851. Errcode: "创建剩余库存字段报错",
  6852. GoodId: item.GoodId,
  6853. Status: 1,
  6854. Ctime: time.Now().Unix(),
  6855. Mtime: 0,
  6856. Count: 0,
  6857. StockCount: 0,
  6858. Creater: creater,
  6859. BatchNumberId: 0,
  6860. WarehouseOutId: 0,
  6861. }
  6862. service.CreateGoodErrcode(goodErrcode)
  6863. }
  6864. }
  6865. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6866. if len(list) == 0 {
  6867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6868. return
  6869. }
  6870. for _, item := range list {
  6871. prepare := models.DialysisBeforePrepare{
  6872. UserOrgId: adminInfo.Org.Id,
  6873. PatientId: patient_id,
  6874. RecordDate: record_time,
  6875. GoodId: item.GoodId,
  6876. GoodTypeId: item.GoodTypeId,
  6877. Count: item.Count,
  6878. Creater: adminInfo.AdminUser.Id,
  6879. Status: 1,
  6880. Ctime: time.Now().Unix(),
  6881. StorehouseId: houseConfig.StorehouseOutInfo,
  6882. }
  6883. //清空准备表数据
  6884. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6885. if err != nil {
  6886. goodErrcode := models.XtGoodErrcode{
  6887. UserOrgId: item.OrgId,
  6888. Errcode: "自动出库清空准备表数据报错",
  6889. GoodId: item.GoodId,
  6890. Status: 1,
  6891. Ctime: time.Now().Unix(),
  6892. Mtime: 0,
  6893. Count: 0,
  6894. StockCount: 0,
  6895. Creater: creater,
  6896. BatchNumberId: 0,
  6897. WarehouseOutId: 0,
  6898. }
  6899. service.CreateGoodErrcode(goodErrcode)
  6900. }
  6901. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6902. if errs != nil {
  6903. goodErrcode := models.XtGoodErrcode{
  6904. UserOrgId: item.OrgId,
  6905. Errcode: "自动出库创建准备表数据报错",
  6906. GoodId: item.GoodId,
  6907. Status: 1,
  6908. Ctime: time.Now().Unix(),
  6909. Mtime: 0,
  6910. Count: 0,
  6911. StockCount: 0,
  6912. Creater: creater,
  6913. BatchNumberId: 0,
  6914. WarehouseOutId: 0,
  6915. }
  6916. service.CreateGoodErrcode(goodErrcode)
  6917. }
  6918. //查询默认仓库
  6919. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6920. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6921. var total_count int64
  6922. for _, it := range stockList {
  6923. total_count += it.StockCount
  6924. }
  6925. //基础库插入数据
  6926. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6927. if errcodes != nil {
  6928. goodErrcode := models.XtGoodErrcode{
  6929. UserOrgId: item.OrgId,
  6930. Errcode: "自动出库基础库插入数据",
  6931. GoodId: item.GoodId,
  6932. Status: 1,
  6933. Ctime: time.Now().Unix(),
  6934. Mtime: 0,
  6935. Count: 0,
  6936. StockCount: 0,
  6937. Creater: creater,
  6938. BatchNumberId: 0,
  6939. WarehouseOutId: 0,
  6940. }
  6941. service.CreateGoodErrcode(goodErrcode)
  6942. }
  6943. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6944. var flush_count int64
  6945. for _, it := range goodList {
  6946. flush_count += it.StockCount
  6947. }
  6948. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6949. if errsss != nil {
  6950. goodErrcode := models.XtGoodErrcode{
  6951. UserOrgId: item.OrgId,
  6952. Errcode: "自动出库剩余库存更新数据",
  6953. GoodId: item.GoodId,
  6954. Status: 1,
  6955. Ctime: time.Now().Unix(),
  6956. Mtime: 0,
  6957. Count: 0,
  6958. StockCount: 0,
  6959. Creater: creater,
  6960. BatchNumberId: 0,
  6961. WarehouseOutId: 0,
  6962. }
  6963. service.CreateGoodErrcode(goodErrcode)
  6964. }
  6965. }
  6966. }
  6967. //
  6968. } else if err == nil {
  6969. for _, item := range consumables {
  6970. //出库
  6971. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6972. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6973. if err != nil {
  6974. goodErrcode := models.XtGoodErrcode{
  6975. UserOrgId: adminInfo.Org.Id,
  6976. Errcode: "自动出库接口报错",
  6977. GoodId: 0,
  6978. Status: 1,
  6979. Ctime: time.Now().Unix(),
  6980. Mtime: 0,
  6981. Count: 0,
  6982. StockCount: 0,
  6983. Creater: creator,
  6984. BatchNumberId: 0,
  6985. WarehouseOutId: 0,
  6986. }
  6987. service.CreateGoodErrcode(goodErrcode)
  6988. }
  6989. //出库数量相加
  6990. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6991. if errss != nil {
  6992. goodErrcode := models.XtGoodErrcode{
  6993. UserOrgId: item.UserOrgId,
  6994. Errcode: "创建剩余库存字段报错",
  6995. GoodId: item.GoodId,
  6996. Status: 1,
  6997. Ctime: time.Now().Unix(),
  6998. Mtime: time.Now().Unix(),
  6999. Count: 0,
  7000. StockCount: 0,
  7001. Creater: item.Creater,
  7002. BatchNumberId: 0,
  7003. WarehouseOutId: 0,
  7004. }
  7005. service.CreateGoodErrcode(goodErrcode)
  7006. }
  7007. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7008. if len(list) == 0 {
  7009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7010. return
  7011. }
  7012. for _, item := range list {
  7013. prepare := models.DialysisBeforePrepare{
  7014. UserOrgId: adminInfo.Org.Id,
  7015. PatientId: patient_id,
  7016. RecordDate: record_time,
  7017. GoodId: item.GoodId,
  7018. GoodTypeId: item.GoodTypeId,
  7019. Count: item.Count,
  7020. Creater: adminInfo.AdminUser.Id,
  7021. Status: 1,
  7022. Ctime: time.Now().Unix(),
  7023. StorehouseId: houseConfig.StorehouseOutInfo,
  7024. }
  7025. //清空准备表数据
  7026. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7027. if errs != nil {
  7028. goodErrcode := models.XtGoodErrcode{
  7029. UserOrgId: adminInfo.Org.Id,
  7030. Errcode: "自动出库清空准备表数据报错",
  7031. GoodId: 0,
  7032. Status: 1,
  7033. Ctime: time.Now().Unix(),
  7034. Mtime: 0,
  7035. Count: 0,
  7036. StockCount: 0,
  7037. Creater: creator,
  7038. BatchNumberId: 0,
  7039. WarehouseOutId: 0,
  7040. }
  7041. service.CreateGoodErrcode(goodErrcode)
  7042. }
  7043. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7044. if errcodes != nil {
  7045. goodErrcode := models.XtGoodErrcode{
  7046. UserOrgId: adminInfo.Org.Id,
  7047. Errcode: "自动出库创建准备表数据报错",
  7048. GoodId: 0,
  7049. Status: 1,
  7050. Ctime: time.Now().Unix(),
  7051. Mtime: 0,
  7052. Count: 0,
  7053. StockCount: 0,
  7054. Creater: creator,
  7055. BatchNumberId: 0,
  7056. WarehouseOutId: 0,
  7057. }
  7058. service.CreateGoodErrcode(goodErrcode)
  7059. }
  7060. //查询默认仓库
  7061. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7062. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7063. var total_count int64
  7064. for _, it := range stockList {
  7065. total_count += it.StockCount
  7066. }
  7067. //基础库插入数据
  7068. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7069. if errcodes != nil {
  7070. goodErrcode := models.XtGoodErrcode{
  7071. UserOrgId: adminInfo.Org.Id,
  7072. Errcode: "自动出库基础库插入数据报错",
  7073. GoodId: 0,
  7074. Status: 1,
  7075. Ctime: time.Now().Unix(),
  7076. Mtime: 0,
  7077. Count: 0,
  7078. StockCount: 0,
  7079. Creater: creator,
  7080. BatchNumberId: 0,
  7081. WarehouseOutId: 0,
  7082. }
  7083. service.CreateGoodErrcode(goodErrcode)
  7084. }
  7085. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7086. var flush_count int64
  7087. for _, it := range goodList {
  7088. flush_count += it.StockCount
  7089. }
  7090. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7091. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7092. if errss != nil {
  7093. goodErrcode := models.XtGoodErrcode{
  7094. UserOrgId: item.OrgId,
  7095. Errcode: "自动出库剩余库存更新数据",
  7096. GoodId: item.GoodId,
  7097. Status: 1,
  7098. Ctime: time.Now().Unix(),
  7099. Mtime: 0,
  7100. Count: 0,
  7101. StockCount: 0,
  7102. Creater: creater,
  7103. BatchNumberId: 0,
  7104. WarehouseOutId: 0,
  7105. }
  7106. service.CreateGoodErrcode(goodErrcode)
  7107. }
  7108. }
  7109. }
  7110. }
  7111. c.ServeSuccessJSON(map[string]interface{}{
  7112. "msg": "提交成功",
  7113. "message": "2",
  7114. "good_name": "",
  7115. "specification_name": "",
  7116. })
  7117. return
  7118. }
  7119. if record.IsOpen == 1 {
  7120. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7121. //查询是否有库存
  7122. for _, item := range consumables {
  7123. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  7124. if item.Count > warehouse.Count {
  7125. goodErrcode := models.XtGoodErrcode{
  7126. UserOrgId: item.UserOrgId,
  7127. Errcode: "自动出库库存不足",
  7128. GoodId: item.GoodId,
  7129. Status: 1,
  7130. Ctime: time.Now().Unix(),
  7131. Mtime: 0,
  7132. Count: 0,
  7133. StockCount: 0,
  7134. Creater: creator,
  7135. BatchNumberId: warehouse.ID,
  7136. WarehouseOutId: 0,
  7137. }
  7138. service.CreateGoodErrcode(goodErrcode)
  7139. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7140. c.ServeSuccessJSON(map[string]interface{}{
  7141. "message": "1",
  7142. "good_name": goodObj.GoodName,
  7143. "specification_name": goodObj.SpecificationName,
  7144. })
  7145. return
  7146. }
  7147. }
  7148. //查询是否有出库单
  7149. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7150. if err == gorm.ErrRecordNotFound {
  7151. //没有记录,则创建出库单
  7152. timeStr := time.Now().Format("2006-01-02")
  7153. timeArr := strings.Split(timeStr, "-")
  7154. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7155. total = total + 1
  7156. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7157. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7158. number = number + total
  7159. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7160. creater := adminInfo.AdminUser.Id
  7161. warehouseOut := models.WarehouseOut{
  7162. WarehouseOutOrderNumber: warehousing_out_order,
  7163. OperationTime: time.Now().Unix(),
  7164. OrgId: adminInfo.Org.Id,
  7165. Creater: creater,
  7166. Ctime: time.Now().Unix(),
  7167. Status: 1,
  7168. WarehouseOutTime: record_time,
  7169. Dealer: 0,
  7170. Manufacturer: 0,
  7171. Type: 1,
  7172. IsSys: 1,
  7173. StorehouseId: houseConfig.StorehouseOutInfo,
  7174. IsCheck: 1,
  7175. }
  7176. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  7177. if err != nil {
  7178. goodErrcode := models.XtGoodErrcode{
  7179. UserOrgId: adminInfo.Org.Id,
  7180. Errcode: "创建出库单失败",
  7181. GoodId: 0,
  7182. Status: 1,
  7183. Ctime: time.Now().Unix(),
  7184. Mtime: 0,
  7185. Count: 0,
  7186. StockCount: 0,
  7187. Creater: creator,
  7188. BatchNumberId: 0,
  7189. WarehouseOutId: 0,
  7190. }
  7191. service.CreateGoodErrcode(goodErrcode)
  7192. utils.TraceLog("创建出库单失败 err = %v", err)
  7193. } else {
  7194. for _, item := range consumables {
  7195. //出库
  7196. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7197. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7198. if err == nil {
  7199. goodErrcode := models.XtGoodErrcode{
  7200. UserOrgId: adminInfo.Org.Id,
  7201. Errcode: "自动出库接口报错",
  7202. GoodId: 0,
  7203. Status: 1,
  7204. Ctime: time.Now().Unix(),
  7205. Mtime: 0,
  7206. Count: 0,
  7207. StockCount: 0,
  7208. Creater: creator,
  7209. BatchNumberId: 0,
  7210. WarehouseOutId: 0,
  7211. }
  7212. service.CreateGoodErrcode(goodErrcode)
  7213. utils.TraceLog("创建出库单失败 err = %v", err)
  7214. }
  7215. //查询
  7216. //出库数量相加
  7217. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7218. if errs != nil {
  7219. goodErrcode := models.XtGoodErrcode{
  7220. UserOrgId: item.UserOrgId,
  7221. Errcode: "创建剩余库存字段报错",
  7222. GoodId: item.GoodId,
  7223. Status: 1,
  7224. Ctime: time.Now().Unix(),
  7225. Mtime: 0,
  7226. Count: 0,
  7227. StockCount: 0,
  7228. Creater: creater,
  7229. BatchNumberId: 0,
  7230. WarehouseOutId: 0,
  7231. }
  7232. service.CreateGoodErrcode(goodErrcode)
  7233. }
  7234. }
  7235. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7236. if len(list) == 0 {
  7237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7238. return
  7239. }
  7240. for _, item := range list {
  7241. prepare := models.DialysisBeforePrepare{
  7242. UserOrgId: adminInfo.Org.Id,
  7243. PatientId: patient_id,
  7244. RecordDate: record_time,
  7245. GoodId: item.GoodId,
  7246. GoodTypeId: item.GoodTypeId,
  7247. Count: item.Count,
  7248. Creater: adminInfo.AdminUser.Id,
  7249. Status: 1,
  7250. Ctime: time.Now().Unix(),
  7251. StorehouseId: houseConfig.StorehouseOutInfo,
  7252. }
  7253. //清空准备表数据
  7254. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7255. if err != nil {
  7256. goodErrcode := models.XtGoodErrcode{
  7257. UserOrgId: item.OrgId,
  7258. Errcode: "自动出库清空准备表数据报错",
  7259. GoodId: item.GoodId,
  7260. Status: 1,
  7261. Ctime: time.Now().Unix(),
  7262. Mtime: 0,
  7263. Count: 0,
  7264. StockCount: 0,
  7265. Creater: creater,
  7266. BatchNumberId: 0,
  7267. WarehouseOutId: 0,
  7268. }
  7269. service.CreateGoodErrcode(goodErrcode)
  7270. }
  7271. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7272. if errs != nil {
  7273. goodErrcode := models.XtGoodErrcode{
  7274. UserOrgId: item.OrgId,
  7275. Errcode: "自动出库创建准备表数据报错",
  7276. GoodId: item.GoodId,
  7277. Status: 1,
  7278. Ctime: time.Now().Unix(),
  7279. Mtime: 0,
  7280. Count: 0,
  7281. StockCount: 0,
  7282. Creater: creater,
  7283. BatchNumberId: 0,
  7284. WarehouseOutId: 0,
  7285. }
  7286. service.CreateGoodErrcode(goodErrcode)
  7287. }
  7288. //查询默认仓库
  7289. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7290. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7291. var total_count int64
  7292. for _, it := range stockList {
  7293. total_count += it.StockCount
  7294. }
  7295. //基础库插入数据
  7296. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7297. if errcodes != nil {
  7298. goodErrcode := models.XtGoodErrcode{
  7299. UserOrgId: item.OrgId,
  7300. Errcode: "自动出库基础库插入数据",
  7301. GoodId: item.GoodId,
  7302. Status: 1,
  7303. Ctime: time.Now().Unix(),
  7304. Mtime: 0,
  7305. Count: 0,
  7306. StockCount: 0,
  7307. Creater: creater,
  7308. BatchNumberId: 0,
  7309. WarehouseOutId: 0,
  7310. }
  7311. service.CreateGoodErrcode(goodErrcode)
  7312. }
  7313. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7314. var flush_count int64
  7315. for _, it := range goodList {
  7316. flush_count += it.StockCount
  7317. }
  7318. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7319. if errsss != nil {
  7320. goodErrcode := models.XtGoodErrcode{
  7321. UserOrgId: item.OrgId,
  7322. Errcode: "自动出库剩余库存更新数据",
  7323. GoodId: item.GoodId,
  7324. Status: 1,
  7325. Ctime: time.Now().Unix(),
  7326. Mtime: 0,
  7327. Count: 0,
  7328. StockCount: 0,
  7329. Creater: creater,
  7330. BatchNumberId: 0,
  7331. WarehouseOutId: 0,
  7332. }
  7333. service.CreateGoodErrcode(goodErrcode)
  7334. }
  7335. }
  7336. }
  7337. //
  7338. } else if err == nil {
  7339. for _, item := range consumables {
  7340. //出库
  7341. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7342. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7343. if err != nil {
  7344. goodErrcode := models.XtGoodErrcode{
  7345. UserOrgId: adminInfo.Org.Id,
  7346. Errcode: "自动出库接口报错",
  7347. GoodId: 0,
  7348. Status: 1,
  7349. Ctime: time.Now().Unix(),
  7350. Mtime: 0,
  7351. Count: 0,
  7352. StockCount: 0,
  7353. Creater: creator,
  7354. BatchNumberId: 0,
  7355. WarehouseOutId: 0,
  7356. }
  7357. service.CreateGoodErrcode(goodErrcode)
  7358. }
  7359. //出库数量相加
  7360. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7361. if errss != nil {
  7362. goodErrcode := models.XtGoodErrcode{
  7363. UserOrgId: item.UserOrgId,
  7364. Errcode: "创建剩余库存字段报错",
  7365. GoodId: item.GoodId,
  7366. Status: 1,
  7367. Ctime: time.Now().Unix(),
  7368. Mtime: time.Now().Unix(),
  7369. Count: 0,
  7370. StockCount: 0,
  7371. Creater: item.Creater,
  7372. BatchNumberId: 0,
  7373. WarehouseOutId: 0,
  7374. }
  7375. service.CreateGoodErrcode(goodErrcode)
  7376. }
  7377. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7378. if len(list) == 0 {
  7379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7380. return
  7381. }
  7382. for _, item := range list {
  7383. prepare := models.DialysisBeforePrepare{
  7384. UserOrgId: adminInfo.Org.Id,
  7385. PatientId: patient_id,
  7386. RecordDate: record_time,
  7387. GoodId: item.GoodId,
  7388. GoodTypeId: item.GoodTypeId,
  7389. Count: item.Count,
  7390. Creater: adminInfo.AdminUser.Id,
  7391. Status: 1,
  7392. Ctime: time.Now().Unix(),
  7393. StorehouseId: houseConfig.StorehouseOutInfo,
  7394. }
  7395. //清空准备表数据
  7396. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7397. if errs != nil {
  7398. goodErrcode := models.XtGoodErrcode{
  7399. UserOrgId: adminInfo.Org.Id,
  7400. Errcode: "自动出库清空准备表数据报错",
  7401. GoodId: 0,
  7402. Status: 1,
  7403. Ctime: time.Now().Unix(),
  7404. Mtime: 0,
  7405. Count: 0,
  7406. StockCount: 0,
  7407. Creater: creator,
  7408. BatchNumberId: 0,
  7409. WarehouseOutId: 0,
  7410. }
  7411. service.CreateGoodErrcode(goodErrcode)
  7412. }
  7413. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7414. if errcodes != nil {
  7415. goodErrcode := models.XtGoodErrcode{
  7416. UserOrgId: adminInfo.Org.Id,
  7417. Errcode: "自动出库创建准备表数据报错",
  7418. GoodId: 0,
  7419. Status: 1,
  7420. Ctime: time.Now().Unix(),
  7421. Mtime: 0,
  7422. Count: 0,
  7423. StockCount: 0,
  7424. Creater: creator,
  7425. BatchNumberId: 0,
  7426. WarehouseOutId: 0,
  7427. }
  7428. service.CreateGoodErrcode(goodErrcode)
  7429. }
  7430. //查询默认仓库
  7431. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7432. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7433. var total_count int64
  7434. for _, it := range stockList {
  7435. total_count += it.StockCount
  7436. }
  7437. //基础库插入数据
  7438. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7439. if errcodes != nil {
  7440. goodErrcode := models.XtGoodErrcode{
  7441. UserOrgId: adminInfo.Org.Id,
  7442. Errcode: "自动出库基础库插入数据报错",
  7443. GoodId: 0,
  7444. Status: 1,
  7445. Ctime: time.Now().Unix(),
  7446. Mtime: 0,
  7447. Count: 0,
  7448. StockCount: 0,
  7449. Creater: creator,
  7450. BatchNumberId: 0,
  7451. WarehouseOutId: 0,
  7452. }
  7453. service.CreateGoodErrcode(goodErrcode)
  7454. }
  7455. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7456. var flush_count int64
  7457. for _, it := range goodList {
  7458. flush_count += it.StockCount
  7459. }
  7460. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7461. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7462. if errss != nil {
  7463. goodErrcode := models.XtGoodErrcode{
  7464. UserOrgId: item.OrgId,
  7465. Errcode: "自动出库剩余库存更新数据",
  7466. GoodId: item.GoodId,
  7467. Status: 1,
  7468. Ctime: time.Now().Unix(),
  7469. Mtime: 0,
  7470. Count: 0,
  7471. StockCount: 0,
  7472. Creater: creater,
  7473. BatchNumberId: 0,
  7474. WarehouseOutId: 0,
  7475. }
  7476. service.CreateGoodErrcode(goodErrcode)
  7477. }
  7478. }
  7479. }
  7480. }
  7481. c.ServeSuccessJSON(map[string]interface{}{
  7482. "msg": "提交成功",
  7483. "message": "2",
  7484. "good_name": "",
  7485. "specification_name": "",
  7486. })
  7487. return
  7488. } else {
  7489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7490. return
  7491. }
  7492. }
  7493. func (c *DialysisAPIController) EditConsumables() {
  7494. patient_id, _ := c.GetInt64("patient_id", 0)
  7495. record_date := c.GetString("record_time")
  7496. if patient_id <= 0 {
  7497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7498. return
  7499. }
  7500. adminInfo := c.GetMobileAdminUserInfo()
  7501. timeLayout := "2006-01-02"
  7502. loc, _ := time.LoadLocation("Local")
  7503. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7504. record_time := theRecordTime.Unix()
  7505. // 查询信息规挡的设置天数
  7506. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7507. if infor.ID > 0 && infor.WeekDay > 0 {
  7508. var cha_time int64
  7509. timeNowStr := time.Now().Format("2006-01-02")
  7510. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7511. //今日的日期减去设置的日期
  7512. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7513. if cha_time >= record_time {
  7514. //查询审核是否允许
  7515. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7516. //申请状态不允许的情况 拒绝修改
  7517. if infor.ApplicationStatus != 1 {
  7518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7519. return
  7520. }
  7521. }
  7522. }
  7523. dataBody := make(map[string]interface{}, 0)
  7524. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7525. if err != nil {
  7526. utils.ErrorLog(err.Error())
  7527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7528. return
  7529. }
  7530. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7531. var beforePrepares []*models.DialysisBeforePrepareGoods
  7532. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7533. var cancelbefor []*models.DialysisBeforePrepareGoods
  7534. var outbefor []*models.DialysisBeforePrepareGoods
  7535. //判断是否开启自动出库
  7536. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7537. if record.IsOpen == 1 {
  7538. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7539. goods, _ := dataBody["goods"].([]interface{})
  7540. if len(goods) > 0 {
  7541. for _, item := range goods {
  7542. items := item.(map[string]interface{})
  7543. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7544. utils.ErrorLog("good_id")
  7545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7546. return
  7547. }
  7548. good_id := int64(items["good_id"].(float64))
  7549. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7550. utils.ErrorLog("good_type_id")
  7551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7552. return
  7553. }
  7554. good_type_id := int64(items["good_type_id"].(float64))
  7555. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7556. utils.ErrorLog("count")
  7557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7558. return
  7559. }
  7560. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7561. commdity_code := items["commdity_code"].(string)
  7562. fmt.Println(commdity_code)
  7563. prepareGoods := &models.DialysisBeforePrepareGoods{
  7564. GoodTypeId: good_type_id,
  7565. GoodId: good_id,
  7566. Count: count,
  7567. StorehouseId: houseConfig.StorehouseOutInfo,
  7568. }
  7569. beforePrepares = append(beforePrepares, prepareGoods)
  7570. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7571. GoodTypeId: good_type_id,
  7572. GoodId: good_id,
  7573. Count: count,
  7574. StorehouseId: houseConfig.StorehouseOutInfo,
  7575. }
  7576. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7577. }
  7578. for _, item := range beforePrepares {
  7579. //1.查看该患者该耗材型号最后一次出库数量
  7580. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7581. //判断当前出库数量和最后一次出库数量的大小
  7582. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7583. if item.Count < goodInfo.Count {
  7584. cancelbefor = append(cancelbefor, item)
  7585. }
  7586. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7587. if item.Count > goodInfo.Count {
  7588. outbefor = append(outbefor, item)
  7589. }
  7590. //处理编辑耗材新增不了的问题
  7591. if goodInfo.Count == item.Count {
  7592. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7593. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7594. }
  7595. }
  7596. if len(cancelbefor) > 0 {
  7597. //退库
  7598. for _, item := range cancelbefor {
  7599. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7600. creater := adminInfo.AdminUser.Id
  7601. //查询该患者当天已经出库的耗材信息
  7602. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7603. var delete_count int64 = 0
  7604. delete_count = warehouseOutInfos.Count - item.Count
  7605. //增加库存数量
  7606. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7607. //减少实际出库库存数量
  7608. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7609. // 删除出库完成后,要增加对应批次的库存数量
  7610. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7611. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7612. //更新剩余库存
  7613. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7614. var flush_count int64
  7615. for _, it := range goodListOne {
  7616. flush_count += it.StockCount
  7617. }
  7618. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7619. //查询剩余库存
  7620. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7621. var sum_count int64
  7622. for _, item := range goodList {
  7623. sum_count += item.StockCount
  7624. }
  7625. // 在出库记录表里记录退库详情
  7626. warehouseOutInfo := &models.WarehouseOutInfo{
  7627. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7628. WarehouseOutId: warehouseOut.ID,
  7629. Status: 1,
  7630. Ctime: time.Now().Unix(),
  7631. OrgId: adminInfo.Org.Id,
  7632. Type: 1,
  7633. IsSys: 1,
  7634. SysRecordTime: record_time,
  7635. GoodTypeId: item.GoodTypeId,
  7636. GoodId: item.GoodId,
  7637. PatientId: patient_id,
  7638. ConsumableType: 2,
  7639. StorehouseId: houseConfig.StorehouseOutInfo,
  7640. IsCheck: 1,
  7641. OverCount: sum_count,
  7642. }
  7643. warehouseOutInfo.Count = item.Count
  7644. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7645. warehouseOutInfo.Price = stockInInfo.Price
  7646. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7647. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7648. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7649. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7650. warehouseOutInfo.Number = warehouseOutInfos.Number
  7651. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7652. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7653. //查找当天是否存在出库记录
  7654. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7655. if errcod == gorm.ErrRecordNotFound {
  7656. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7657. //插入详情明细表
  7658. stockFlow := models.VmStockFlow{
  7659. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7660. WarehouseOutId: warehouseOut.ID,
  7661. GoodId: item.GoodId,
  7662. Number: warehouseOutInfos.Number,
  7663. ProductDate: stockInInfo.ProductDate,
  7664. ExpireDate: stockInInfo.ExpiryDate,
  7665. Count: item.Count,
  7666. Price: stockInInfo.Price,
  7667. Status: 1,
  7668. Ctime: record_time,
  7669. UserOrgId: adminInfo.Org.Id,
  7670. Manufacturer: stockInInfo.Manufacturer,
  7671. Dealer: stockInInfo.Dealer,
  7672. LicenseNumber: stockInInfo.LicenseNumber,
  7673. IsEdit: 2,
  7674. Creator: creater,
  7675. SystemTime: record_time,
  7676. ConsumableType: 3,
  7677. WarehousingDetailId: 0,
  7678. IsSys: 1,
  7679. UpdateCreator: creater,
  7680. PatientId: patient_id,
  7681. StorehouseId: houseConfig.StorehouseOutInfo,
  7682. }
  7683. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7684. if errflow == gorm.ErrRecordNotFound {
  7685. //创建流水表
  7686. err := service.CreateStockFlowOne(stockFlow)
  7687. fmt.Println("err", err)
  7688. } else if errflow == nil {
  7689. //插入详情明细表
  7690. stockFlow := models.VmStockFlow{
  7691. ID: exsit.ID,
  7692. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7693. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7694. WarehouseOutId: warehouseOut.ID,
  7695. GoodId: item.GoodId,
  7696. Number: warehouseOutInfos.Number,
  7697. ProductDate: stockInInfo.ProductDate,
  7698. ExpireDate: stockInInfo.ExpiryDate,
  7699. Count: exsit.Count - delete_count,
  7700. Price: stockInInfo.Price,
  7701. Status: 1,
  7702. Ctime: record_time,
  7703. UserOrgId: adminInfo.Org.Id,
  7704. Manufacturer: stockInInfo.Manufacturer,
  7705. Dealer: stockInInfo.Dealer,
  7706. LicenseNumber: stockInInfo.LicenseNumber,
  7707. IsEdit: 2,
  7708. Creator: creater,
  7709. SystemTime: record_time,
  7710. ConsumableType: 3,
  7711. WarehousingDetailId: 0,
  7712. IsSys: 1,
  7713. UpdateCreator: creater,
  7714. PatientId: patient_id,
  7715. StorehouseId: houseConfig.StorehouseOutInfo,
  7716. }
  7717. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7718. }
  7719. } else if errcod == nil {
  7720. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7721. //查询剩余库存
  7722. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7723. var sum_count int64
  7724. for _, item := range goodList {
  7725. sum_count += item.StockCount
  7726. }
  7727. //创建退库单,生成退库数据
  7728. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7729. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7730. operation_time := time.Now().Unix()
  7731. creater := adminInfo.AdminUser.Id
  7732. //创建退库单
  7733. timeStr := time.Now().Format("2006-01-02")
  7734. timeArr := strings.Split(timeStr, "-")
  7735. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7736. total = total + 1
  7737. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7738. cancelStock := models.CancelStock{
  7739. OrderNumber: orderNumber,
  7740. OperaTime: operation_time,
  7741. OrgId: adminInfo.Org.Id,
  7742. Creater: creater,
  7743. Ctime: time.Now().Unix(),
  7744. Status: 1,
  7745. ReturnTime: record_time,
  7746. Type: 1,
  7747. StorehouseId: houseConfig.StorehouseOutInfo,
  7748. IsCheck: 1,
  7749. }
  7750. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7751. if msgerrkonde == gorm.ErrRecordNotFound {
  7752. service.AddSigleCancelStock(&cancelStock)
  7753. }
  7754. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7755. //查询是否有出库
  7756. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7757. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7758. deaerler, _ := service.GetDealerById(info.Dealer)
  7759. if info.ID > 0 {
  7760. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7761. cancelStockInfo := models.CancelStockInfo{
  7762. GoodId: item.GoodId,
  7763. CancelStockId: cancel.ID,
  7764. GoodTypeId: good.GoodTypeId,
  7765. Count: delete_count,
  7766. Price: info.Price,
  7767. Total: 0,
  7768. ProductDate: info.ProductDate,
  7769. ExpiryDate: info.ExpiryDate,
  7770. Ctime: time.Now().Unix(),
  7771. Status: 1,
  7772. OrgId: adminInfo.Org.Id,
  7773. OrderNumber: cancel.OrderNumber,
  7774. Type: 0,
  7775. Dealer: deaerler.DealerName,
  7776. Manufacturer: manufacturer.ManufacturerName,
  7777. Number: info.Number,
  7778. RegisterAccount: "",
  7779. Remark: "",
  7780. WarehouseInfoId: info.WarehouseInfotId,
  7781. PatientId: info.PatientId,
  7782. RecordDate: info.SysRecordTime,
  7783. StorehouseId: houseConfig.StorehouseOutInfo,
  7784. IsCheck: 1,
  7785. }
  7786. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7787. //退库数量增加
  7788. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7789. //查询剩余库存
  7790. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7791. var over_count int64
  7792. for _, it := range goodList {
  7793. over_count += it.StockCount
  7794. }
  7795. flow := models.VmStockFlow{
  7796. WarehousingId: info.WarehouseInfotId,
  7797. GoodId: item.GoodId,
  7798. Number: info.Number,
  7799. LicenseNumber: info.LicenseNumber,
  7800. Count: delete_count,
  7801. UserOrgId: adminInfo.Org.Id,
  7802. PatientId: patient_id,
  7803. SystemTime: info.SysRecordTime,
  7804. ConsumableType: 7,
  7805. IsSys: 0,
  7806. WarehousingOrder: "",
  7807. WarehouseOutId: info.WarehouseOutId,
  7808. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7809. IsEdit: 0,
  7810. CancelStockId: cancel.ID,
  7811. CancelOrderNumber: cancel.OrderNumber,
  7812. Manufacturer: manufacturer.ID,
  7813. Dealer: 0,
  7814. Creator: adminInfo.AdminUser.Id,
  7815. UpdateCreator: 0,
  7816. Status: 1,
  7817. Ctime: record_time,
  7818. Mtime: 0,
  7819. Price: info.Price,
  7820. WarehousingDetailId: info.WarehouseInfotId,
  7821. WarehouseOutDetailId: info.ID,
  7822. CancelOutDetailId: cancelInfo.ID,
  7823. ProductDate: info.ProductDate,
  7824. ExpireDate: info.ExpiryDate,
  7825. StorehouseId: houseConfig.StorehouseOutInfo,
  7826. OverCount: over_count,
  7827. }
  7828. service.CreateStockFlowOne(flow)
  7829. }
  7830. }
  7831. //更改自动出库的表格
  7832. details := models.BloodAutomaticReduceDetail{
  7833. WarehouseOutId: warehouseOutInfo.ID,
  7834. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7835. PatientId: patient_id,
  7836. Ctime: time.Now().Unix(),
  7837. Mtime: time.Now().Unix(),
  7838. Status: 1,
  7839. RecordTime: record_time,
  7840. OrgId: adminInfo.Org.Id,
  7841. GoodId: item.GoodId,
  7842. GoodTypeId: item.GoodTypeId,
  7843. Count: item.Count,
  7844. StorehouseId: houseConfig.StorehouseOutInfo,
  7845. }
  7846. //查询当天耗材是否已经存在数据
  7847. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7848. if errcode == gorm.ErrRecordNotFound {
  7849. service.CreateAutoReduceRecord(&details)
  7850. } else if errcode == nil {
  7851. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7852. service.CreateAutoReduceRecord(&details)
  7853. }
  7854. //查询默认仓库
  7855. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7856. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7857. var total_count int64
  7858. for _, it := range stockList {
  7859. total_count += it.StockCount
  7860. }
  7861. //基础库插入数据
  7862. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7863. }
  7864. }
  7865. if len(outbefor) > 0 {
  7866. //出库
  7867. for _, item := range outbefor {
  7868. var last_total int64
  7869. //1.查看该患者该耗材型号最后一次出库数量
  7870. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7871. //计算当前出库和最后一次出库数据相差数据
  7872. last_total = item.Count - goodInfoOne.Count
  7873. //查询该耗材的总库存
  7874. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7875. // 如果库存差大于剩余库存则提示库存不足
  7876. if last_total > wareinfo.StockCount {
  7877. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7878. c.ServeSuccessJSON(map[string]interface{}{
  7879. "message": "1",
  7880. "good_name": goodObj.GoodName,
  7881. "specification_name": goodObj.SpecificationName,
  7882. })
  7883. return
  7884. } else {
  7885. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7886. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7887. if err == gorm.ErrRecordNotFound {
  7888. //没有记录,则创建出库单
  7889. timeStr := time.Now().Format("2006-01-02")
  7890. timeArr := strings.Split(timeStr, "-")
  7891. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7892. total = total + 1
  7893. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7894. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7895. number = number + total
  7896. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7897. warehouseOut := models.WarehouseOut{
  7898. WarehouseOutOrderNumber: warehousing_out_order,
  7899. OperationTime: time.Now().Unix(),
  7900. OrgId: adminInfo.Org.Id,
  7901. Creater: adminInfo.AdminUser.Id,
  7902. Ctime: time.Now().Unix(),
  7903. Status: 1,
  7904. WarehouseOutTime: record_time,
  7905. Dealer: 0,
  7906. Manufacturer: 0,
  7907. Type: 1,
  7908. IsSys: 1,
  7909. StorehouseId: houseConfig.StorehouseOutInfo,
  7910. IsCheck: 1,
  7911. }
  7912. service.AddSigleWarehouseOutOne(&warehouseOut)
  7913. }
  7914. //出库
  7915. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7916. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7917. //1.查看该患者该耗材型号最后一次出库数量
  7918. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7919. prepare := models.DialysisBeforePrepare{
  7920. UserOrgId: adminInfo.Org.Id,
  7921. PatientId: patient_id,
  7922. RecordDate: record_time,
  7923. GoodId: item.GoodId,
  7924. GoodTypeId: item.GoodTypeId,
  7925. Count: item.Count - goodInfoTwo.Count,
  7926. Ctime: time.Now().Unix(),
  7927. Mtime: 0,
  7928. Creater: adminInfo.AdminUser.Id,
  7929. Modifier: adminInfo.AdminUser.Id,
  7930. Status: 1,
  7931. CommdityCode: "",
  7932. NewCount: 0,
  7933. ProjectId: 0,
  7934. StorehouseId: houseConfig.StorehouseOutInfo,
  7935. }
  7936. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7937. //增加出库数量
  7938. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7939. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7940. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7941. var total_count int64
  7942. for _, it := range stockList {
  7943. total_count += it.StockCount
  7944. }
  7945. //基础库插入数据
  7946. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7947. //剩余库存
  7948. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7949. var flush_count int64
  7950. for _, it := range goodList {
  7951. flush_count += it.StockCount
  7952. }
  7953. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7954. }
  7955. }
  7956. }
  7957. //查询今日出库数据
  7958. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7959. for _, it := range list {
  7960. prepare := models.DialysisBeforePrepare{
  7961. UserOrgId: it.OrgId,
  7962. PatientId: patient_id,
  7963. RecordDate: it.RecordTime,
  7964. GoodId: it.GoodId,
  7965. GoodTypeId: it.GoodTypeId,
  7966. Count: it.Count,
  7967. Ctime: time.Now().Unix(),
  7968. Creater: adminInfo.AdminUser.Id,
  7969. Status: 1,
  7970. StorehouseId: houseConfig.StorehouseOutInfo,
  7971. ProjectId: it.ProjectId,
  7972. }
  7973. //删除准备表数据
  7974. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7975. service.CreateDialysisBeforePrepareOne(&prepare)
  7976. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7977. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7978. var total_count int64
  7979. for _, it := range stockList {
  7980. total_count += it.StockCount
  7981. }
  7982. //基础库插入数据
  7983. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7984. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7985. var flush_count int64
  7986. for _, it := range goodList {
  7987. flush_count += it.StockCount
  7988. }
  7989. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7990. }
  7991. }
  7992. }
  7993. //更新自动出库的地方
  7994. var errs error
  7995. if errs == nil {
  7996. c.ServeSuccessJSON(map[string]interface{}{
  7997. "msg": "修改成功",
  7998. "message": "2",
  7999. "good_name": "",
  8000. "specification_name": "",
  8001. })
  8002. return
  8003. } else {
  8004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8005. return
  8006. }
  8007. }
  8008. }
  8009. func (c *DialysisAPIController) GetDialysisGoods() {
  8010. schedualDate := c.GetString("schedule_date")
  8011. schedule_type, _ := c.GetInt64("schedule_type")
  8012. partition_id, _ := c.GetInt64("partition_id")
  8013. page, _ := c.GetInt("page")
  8014. patient_id, _ := c.GetInt64("patient_id")
  8015. schedualEndDate := int64(0)
  8016. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  8017. if parseDateErr != nil && len(schedualDate) != 0 {
  8018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8019. return
  8020. }
  8021. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  8022. if parseDateErr != nil && len(schedualDate) != 0 {
  8023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8024. return
  8025. }
  8026. schedualEndDate = endDate.Unix()
  8027. adminUser := c.GetMobileAdminUserInfo()
  8028. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  8029. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  8030. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8031. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8032. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  8033. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  8034. //获取当天该病人的透析处方
  8035. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8036. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8037. if err == gorm.ErrRecordNotFound {
  8038. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8039. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8040. if patient_id != 0 {
  8041. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8042. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8043. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8044. //获取患者总的出库数据
  8045. item.LastAutomaticReduceDetail = goodUser
  8046. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8047. item.Project = project
  8048. for _, it := range item.AutomaticReduceDetail {
  8049. var total int64
  8050. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8051. for _, its := range auto {
  8052. total += its.Count
  8053. }
  8054. it.Count = total
  8055. }
  8056. }
  8057. }
  8058. c.ServeSuccessJSON(map[string]interface{}{
  8059. "dialysis_goods": dialysisGoods,
  8060. "good_type": goodTypes,
  8061. "total": total,
  8062. "prescribe": prescribe,
  8063. "good_info": good_info,
  8064. "warehouseOutList": warehouseOutList,
  8065. "config": config,
  8066. "outConfig": outConfig,
  8067. "settleConfig": settleConfig,
  8068. })
  8069. return
  8070. } else if err == nil {
  8071. //获取当天排班的每个患者的库存使用情况
  8072. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8073. //获取患者总的出库数据
  8074. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8075. if patient_id != 0 {
  8076. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8077. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8078. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8079. item.Project = project
  8080. item.LastAutomaticReduceDetail = goodUser
  8081. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8082. for _, it := range item.AutomaticReduceDetail {
  8083. var total int64
  8084. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8085. for _, its := range auto {
  8086. total += its.Count
  8087. }
  8088. it.Count = total
  8089. }
  8090. }
  8091. }
  8092. if err == nil {
  8093. c.ServeSuccessJSON(map[string]interface{}{
  8094. "dialysis_goods": dialysisGoods,
  8095. "good_type": goodTypes,
  8096. "total": total,
  8097. "prescribe": prescribe,
  8098. "good_info": good_info,
  8099. "project": project,
  8100. "warehouseOutList": warehouseOutList,
  8101. "config": config,
  8102. "outConfig": outConfig,
  8103. "settleConfig": settleConfig,
  8104. })
  8105. return
  8106. } else {
  8107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8108. return
  8109. }
  8110. } else if err != nil {
  8111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8112. return
  8113. }
  8114. }
  8115. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  8116. start_time := c.GetString("start_time")
  8117. end_time := c.GetString("end_time")
  8118. timeLayout := "2006-01-02"
  8119. loc, _ := time.LoadLocation("Local")
  8120. var theStartTime int64
  8121. if len(start_time) > 0 {
  8122. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8123. if err != nil {
  8124. utils.ErrorLog(err.Error())
  8125. }
  8126. theStartTime = theTime.Unix()
  8127. }
  8128. var theEndtTime int64
  8129. if len(end_time) > 0 {
  8130. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8131. if err != nil {
  8132. utils.ErrorLog(err.Error())
  8133. }
  8134. theEndtTime = theTime.Unix()
  8135. }
  8136. adminUser := c.GetMobileAdminUserInfo()
  8137. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  8138. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  8139. if err == nil {
  8140. c.ServeSuccessJSON(map[string]interface{}{
  8141. "stock_out": outInfo,
  8142. "stockCount": stockCount,
  8143. })
  8144. return
  8145. } else {
  8146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8147. return
  8148. }
  8149. }
  8150. func (c *DialysisAPIController) GetStockInGoodInfo() {
  8151. patient_id, _ := c.GetInt64("patient_id", 0)
  8152. record_time := c.GetString("record_time")
  8153. adminUser := c.GetMobileAdminUserInfo()
  8154. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  8155. if parseDateErr != nil && len(record_time) != 0 {
  8156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8157. return
  8158. }
  8159. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  8160. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8161. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  8162. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  8163. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8164. //获取今日患者的透析处方参数
  8165. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8166. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  8167. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8168. c.ServeSuccessJSON(map[string]interface{}{
  8169. "good_type": goodTypes,
  8170. "good_user": goodUser,
  8171. "good_info": good_info,
  8172. "last_good_user": lastGoodUserDetial,
  8173. "project": project,
  8174. "prescription": prescribe,
  8175. "outInfo": outInfo,
  8176. "configs": configs,
  8177. })
  8178. return
  8179. }
  8180. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  8181. patient_id, _ := c.GetInt64("patient_id", 0)
  8182. record_date := c.GetString("record_time")
  8183. timeLayout := "2006-01-02"
  8184. loc, _ := time.LoadLocation("Local")
  8185. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8186. record_time := theRecordTime.Unix()
  8187. adminInfo := c.GetMobileAdminUserInfo()
  8188. dataBody := make(map[string]interface{}, 0)
  8189. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8190. if err != nil {
  8191. utils.ErrorLog(err.Error())
  8192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8193. return
  8194. }
  8195. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8196. var beforePrepares []*models.DialysisBeforePrepareGoods
  8197. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8198. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8199. goods, _ := dataBody["goods"].([]interface{})
  8200. if len(goods) > 0 {
  8201. for _, item := range goods {
  8202. items := item.(map[string]interface{})
  8203. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8204. utils.ErrorLog("good_id")
  8205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8206. return
  8207. }
  8208. good_id := int64(items["good_id"].(float64))
  8209. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8210. utils.ErrorLog("good_type_id")
  8211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8212. return
  8213. }
  8214. good_type_id := int64(items["good_type_id"].(float64))
  8215. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8216. utils.ErrorLog("count")
  8217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8218. return
  8219. }
  8220. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8221. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8222. utils.ErrorLog("project_id")
  8223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8224. return
  8225. }
  8226. project_id := int64(items["project_id"].(float64))
  8227. new_count := int64(items["new_count"].(float64))
  8228. old_count := int64(items["old_count"].(float64))
  8229. prepare := &models.DialysisBeforePrepareGoods{
  8230. GoodId: good_id,
  8231. GoodTypeId: good_type_id,
  8232. Count: count,
  8233. ProjectId: project_id,
  8234. StorehouseId: houseConfig.StorehouseOutInfo,
  8235. NewCount: new_count,
  8236. OldCount: old_count,
  8237. }
  8238. beforePrepares = append(beforePrepares, prepare)
  8239. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8240. GoodId: good_id,
  8241. GoodTypeId: good_type_id,
  8242. Count: count,
  8243. ProjectId: project_id,
  8244. StorehouseId: houseConfig.StorehouseOutInfo,
  8245. NewCount: new_count,
  8246. OldCount: old_count,
  8247. }
  8248. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8249. }
  8250. }
  8251. }
  8252. //查询是否有库存
  8253. for _, item := range beforePrepares {
  8254. if item.NewCount > 0 {
  8255. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8256. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8257. if item.Count > warehouse.Count {
  8258. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8259. c.ServeSuccessJSON(map[string]interface{}{
  8260. "message": "1",
  8261. "good_name": goodObj.GoodName,
  8262. "specification_name": goodObj.SpecificationName,
  8263. })
  8264. return
  8265. }
  8266. }
  8267. }
  8268. // 查询信息规挡的设置天数
  8269. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8270. if infor.ID > 0 && infor.WeekDay > 0 {
  8271. var cha_time int64
  8272. timeNowStr := time.Now().Format("2006-01-02")
  8273. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8274. //今日的日期减去设置的日期
  8275. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8276. if cha_time >= record_time {
  8277. //查询审核是否允许
  8278. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8279. //申请状态不允许的情况 拒绝修改
  8280. if infor.ApplicationStatus != 1 {
  8281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8282. return
  8283. }
  8284. }
  8285. }
  8286. //出库逻辑
  8287. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8288. if err != nil {
  8289. utils.ErrorLog(err.Error())
  8290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8291. return
  8292. }
  8293. finish := models.XtDialysisFinish{
  8294. IsFinish: 1,
  8295. UserOrgId: adminInfo.Org.Id,
  8296. Status: 1,
  8297. Ctime: time.Now().Unix(),
  8298. Mtime: 0,
  8299. Module: 11,
  8300. RecordDate: record_time,
  8301. Sourse: 1,
  8302. PatientId: patient_id,
  8303. }
  8304. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8305. if dialysisFinish.ID == 0 {
  8306. service.CreateDialysisFinish(finish)
  8307. }
  8308. //查询当天出库的数据
  8309. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8310. for _, item := range list {
  8311. prepare := models.DialysisBeforePrepare{
  8312. UserOrgId: item.OrgId,
  8313. PatientId: item.PatientId,
  8314. RecordDate: item.RecordTime,
  8315. GoodId: item.GoodId,
  8316. GoodTypeId: item.GoodTypeId,
  8317. Count: item.Count,
  8318. Creater: adminInfo.AdminUser.Id,
  8319. Status: 1,
  8320. Ctime: time.Now().Unix(),
  8321. ProjectId: item.ProjectId,
  8322. StorehouseId: houseConfig.StorehouseOutInfo,
  8323. }
  8324. //清空准备表的数据
  8325. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8326. //插入准备表数据
  8327. service.CreateDialysisBeforePrepareOne(&prepare)
  8328. //查询默认仓库
  8329. //查询默认仓库
  8330. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8331. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8332. var total_count int64
  8333. for _, it := range stockList {
  8334. total_count += it.StockCount
  8335. }
  8336. //基础库插入数据
  8337. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8338. ////更新剩余库存
  8339. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8340. var flush_count int64
  8341. for _, it := range goodList {
  8342. flush_count += it.StockCount
  8343. }
  8344. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8345. if errs != nil {
  8346. goodErrcode := models.XtGoodErrcode{
  8347. UserOrgId: item.OrgId,
  8348. Errcode: "手动出库更新剩余出库失败",
  8349. GoodId: item.GoodId,
  8350. Status: 1,
  8351. Ctime: time.Now().Unix(),
  8352. Mtime: 0,
  8353. Count: 0,
  8354. StockCount: 0,
  8355. Creater: adminInfo.AdminUser.Id,
  8356. BatchNumberId: 0,
  8357. WarehouseOutId: 0,
  8358. }
  8359. service.CreateGoodErrcode(goodErrcode)
  8360. }
  8361. }
  8362. //更新自动出库的地方
  8363. var errs error
  8364. if errs == nil {
  8365. c.ServeSuccessJSON(map[string]interface{}{
  8366. "msg": "修改成功",
  8367. "message": "2",
  8368. "good_name": "",
  8369. "specification_name": "",
  8370. })
  8371. return
  8372. } else {
  8373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8374. return
  8375. }
  8376. }
  8377. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8378. newArr = make([]*models.DialysisBeforePrepare, 0)
  8379. for i := 0; i < len(arr); i++ {
  8380. repeat := false
  8381. for j := i + 1; j < len(arr); j++ {
  8382. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8383. repeat = true
  8384. break
  8385. }
  8386. }
  8387. if !repeat {
  8388. newArr = append(newArr, arr[i])
  8389. }
  8390. }
  8391. return
  8392. }
  8393. func (c *DialysisAPIController) GetAllDrug() {
  8394. patient_id, _ := c.GetInt64("patient_id", 0)
  8395. adminInfo := c.GetMobileAdminUserInfo()
  8396. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8397. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8398. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8399. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8400. c.ServeSuccessJSON(map[string]interface{}{
  8401. "base_drug_config": drugStockConfig,
  8402. "private_drug_config": privateDrugConfig,
  8403. "base_drug_list": drugList,
  8404. "private_drug_list": privateDrugList,
  8405. })
  8406. }
  8407. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8408. newArr = make([]*models.DialysisBeforePrepare, 0)
  8409. for i := 0; i < len(arr); i++ {
  8410. repeat := false
  8411. for j := i + 1; j < len(arr); j++ {
  8412. if arr[i].GoodId == arr[j].GoodId {
  8413. repeat = true
  8414. break
  8415. }
  8416. }
  8417. if !repeat {
  8418. newArr = append(newArr, arr[i])
  8419. }
  8420. }
  8421. return
  8422. }
  8423. func (c *DialysisAPIController) GetDepartment() {
  8424. adminInfo := c.GetMobileAdminUserInfo()
  8425. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8426. if err == nil {
  8427. c.ServeSuccessJSON(map[string]interface{}{
  8428. "departments": departments,
  8429. })
  8430. } else {
  8431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8432. return
  8433. }
  8434. }
  8435. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8436. types, _ := c.GetInt("type", 0)
  8437. start_time := c.GetString("start_time")
  8438. end_time := c.GetString("end_time")
  8439. orgId := c.GetMobileAdminUserInfo().Org.Id
  8440. timeLayout := "2006-01-02"
  8441. loc, _ := time.LoadLocation("Local")
  8442. var startTime int64
  8443. if len(start_time) > 0 {
  8444. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8445. if err != nil {
  8446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8447. return
  8448. }
  8449. startTime = theTime.Unix()
  8450. }
  8451. var endTime int64
  8452. if len(end_time) > 0 {
  8453. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8454. if err != nil {
  8455. utils.ErrorLog(err.Error())
  8456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8457. return
  8458. }
  8459. endTime = theTime.Unix()
  8460. }
  8461. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8462. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8463. if err != nil {
  8464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8465. } else {
  8466. c.ServeSuccessJSON(map[string]interface{}{
  8467. "list": list,
  8468. "type": types,
  8469. "stockTotal": stockTotal,
  8470. })
  8471. }
  8472. }
  8473. func (c *DialysisAPIController) GetPrescriptionList() {
  8474. start_time := c.GetString("start_time")
  8475. end_time := c.GetString("end_time")
  8476. schedule_type, _ := c.GetInt64("schedule_type")
  8477. partion_id, _ := c.GetInt64("partion_id")
  8478. orgId := c.GetMobileAdminUserInfo().Org.Id
  8479. timeLayout := "2006-01-02"
  8480. loc, _ := time.LoadLocation("Local")
  8481. var startTime int64
  8482. if len(start_time) > 0 {
  8483. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8484. if err != nil {
  8485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8486. return
  8487. }
  8488. startTime = theTime.Unix()
  8489. }
  8490. var endTime int64
  8491. if len(end_time) > 0 {
  8492. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8493. if err != nil {
  8494. utils.ErrorLog(err.Error())
  8495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8496. return
  8497. }
  8498. endTime = theTime.Unix()
  8499. }
  8500. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8501. fmt.Println("schedulelist22222222", schedulelist)
  8502. c.ServeSuccessJSON(map[string]interface{}{
  8503. "list": schedulelist,
  8504. })
  8505. return
  8506. }
  8507. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8508. ids := c.GetString("ids")
  8509. //patient_id, _ := c.GetInt64("patient_id")
  8510. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8511. idArray := strings.Split(ids, ",")
  8512. err := service.BatchDeleteMonitor(idArray)
  8513. fmt.Print("err", err)
  8514. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8515. //redis := service.RedisClient()
  8516. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8517. //redis.Set(key, "", time.Second)
  8518. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8519. //redis.Set(keyOne, "", time.Second)
  8520. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8521. //redis.Close()
  8522. c.ServeSuccessJSON(map[string]interface{}{
  8523. "msg": "批量删除成功",
  8524. })
  8525. return
  8526. }
  8527. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8528. id, _ := c.GetInt64("id")
  8529. timeLayout := "2006-01-02"
  8530. loc, _ := time.LoadLocation("Local")
  8531. //start_time := time.Now().Format("2006-01-02")
  8532. start_time := c.GetString("start_time")
  8533. end_time := c.GetString("end_time")
  8534. var startdateunix int64
  8535. if len(start_time) > 0 {
  8536. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8537. if err != nil {
  8538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8539. return
  8540. }
  8541. startdateunix = theTime.Unix()
  8542. }
  8543. var enddateunix int64
  8544. if len(end_time) > 0 {
  8545. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8546. if err != nil {
  8547. utils.ErrorLog(err.Error())
  8548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8549. return
  8550. }
  8551. enddateunix = theTime.Unix()
  8552. }
  8553. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8554. //nowTime := time.Now()
  8555. //endTime := nowTime.AddDate(-30, 0, 0)
  8556. //endTimes := endTime.Format("2006-01-02")
  8557. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8558. org_id := c.GetMobileAdminUserInfo().Org.Id
  8559. //if org_id == 10579 {
  8560. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8561. // c.ServeSuccessJSON(map[string]interface{}{
  8562. // "list": list,
  8563. // })
  8564. // return
  8565. //} else {
  8566. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8567. // c.ServeSuccessJSON(map[string]interface{}{
  8568. // "list": list,
  8569. // })
  8570. // return
  8571. //}
  8572. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8573. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8574. c.ServeSuccessJSON(map[string]interface{}{
  8575. "list": list,
  8576. })
  8577. return
  8578. } else {
  8579. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8580. c.ServeSuccessJSON(map[string]interface{}{
  8581. "list": list,
  8582. })
  8583. }
  8584. return
  8585. }
  8586. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8587. dataBody := make(map[string]interface{}, 0)
  8588. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8589. ids := c.GetString("ids")
  8590. idArray := strings.Split(ids, ",")
  8591. origin, _ := c.GetInt64("origin")
  8592. if origin == 1 {
  8593. err = service.BatchDeleteAdvice(idArray)
  8594. fmt.Print("err", err)
  8595. c.ServeSuccessJSON(map[string]interface{}{
  8596. "msg": "批量删除成功",
  8597. })
  8598. return
  8599. }
  8600. if origin == 2 {
  8601. service.BatchDeleteHisAdvice(idArray)
  8602. }
  8603. }
  8604. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8605. good_id, _ := c.GetInt64("good_id")
  8606. count, _ := c.GetInt64("count")
  8607. record_time, _ := c.GetInt64("record_time")
  8608. patient_id, _ := c.GetInt64("patient_id")
  8609. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8610. c.ServeSuccessJSON(map[string]interface{}{
  8611. "detail": detail,
  8612. })
  8613. return
  8614. }
  8615. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8616. good_id, _ := c.GetInt64("good_id")
  8617. record_time, _ := c.GetInt64("record_time")
  8618. patient_id, _ := c.GetInt64("patient_id")
  8619. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8620. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8621. fmt.Print("err", err)
  8622. c.ServeSuccessJSON(map[string]interface{}{
  8623. "msg": "批量删除成功",
  8624. })
  8625. return
  8626. }
  8627. func (c *DialysisAPIController) BatchAdviceCheck() {
  8628. ids := c.GetString("ids")
  8629. idArray := strings.Split(ids, ",")
  8630. creator, _ := c.GetInt64("creator")
  8631. origin, _ := c.GetInt64("origin")
  8632. if origin == 1 {
  8633. err := service.BatchAdviceCheck(idArray, creator)
  8634. fmt.Println(err)
  8635. list, _ := service.GetAdviceExecutionById(idArray)
  8636. c.ServeSuccessJSON(map[string]interface{}{
  8637. "list": list,
  8638. })
  8639. return
  8640. }
  8641. if origin == 2 {
  8642. service.BatchHisAdviceCheck(idArray, creator)
  8643. list, _ := service.GetHisAdviceExecutionById(idArray)
  8644. c.ServeSuccessJSON(map[string]interface{}{
  8645. "list": list,
  8646. })
  8647. return
  8648. }
  8649. }
  8650. func (c *DialysisAPIController) BatchAdviceExecution() {
  8651. ids := c.GetString("ids")
  8652. idArray := strings.Split(ids, ",")
  8653. executionTime := c.GetString("execution_time")
  8654. creator, _ := c.GetInt64("creator")
  8655. timeLayout := "2006-01-02 15:04:05"
  8656. loc, _ := time.LoadLocation("Local")
  8657. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8658. orgin, _ := c.GetInt64("origin")
  8659. if orgin == 1 {
  8660. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8661. list, _ := service.GetAdviceExecutionById(idArray)
  8662. fmt.Println(err)
  8663. c.ServeSuccessJSON(map[string]interface{}{
  8664. "list": list,
  8665. })
  8666. return
  8667. }
  8668. if orgin == 2 {
  8669. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8670. list, _ := service.GetHisAdviceExecutionById(idArray)
  8671. fmt.Println(err)
  8672. c.ServeSuccessJSON(map[string]interface{}{
  8673. "list": list,
  8674. })
  8675. return
  8676. }
  8677. }
  8678. func (c *DialysisAPIController) UpdateStockGoods() {
  8679. good_id, _ := c.GetInt64("good_id")
  8680. record_time, _ := c.GetInt64("record_time")
  8681. patient_id, _ := c.GetInt64("patient_id")
  8682. count, _ := c.GetInt64("count")
  8683. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8684. fmt.Print("err", err)
  8685. c.ServeSuccessJSON(map[string]interface{}{
  8686. "msg": "更新成功",
  8687. })
  8688. return
  8689. }
  8690. // 当前数据比上一次出库数据少
  8691. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8692. //查询该患者当天已经出库的耗材信息
  8693. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8694. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8695. for i := len(goods_yc) - 1; i >= 0; i-- {
  8696. goods_yc_temp := goods_yc[i]
  8697. for j := len(goods) - 1; j >= 0; j-- {
  8698. goods_temp := goods[j]
  8699. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8700. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8701. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8702. if goods_yc_temp.Count == goods_temp.Count {
  8703. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8704. goods = append(goods[:j], goods[j+1:]...)
  8705. break
  8706. }
  8707. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8708. if goods_yc_temp.Count > goods_temp.Count {
  8709. temp_count := goods_yc_temp.Count - goods_temp.Count
  8710. goods_yc[i].Count = temp_count
  8711. goods = append(goods[:j], goods[j+1:]...)
  8712. break
  8713. }
  8714. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8715. if goods_yc_temp.Count < goods_temp.Count {
  8716. temp_count := goods_temp.Count - goods_yc_temp.Count
  8717. goods[j].Count = temp_count
  8718. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8719. break
  8720. }
  8721. }
  8722. }
  8723. }
  8724. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8725. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8726. //退库
  8727. if len(goods_yc) > 0 {
  8728. for _, good_yc := range goods_yc {
  8729. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8730. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8731. }
  8732. }
  8733. return nil
  8734. }
  8735. // 耗材出库删除
  8736. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8737. // 先根据相关信息查询当天该耗材的出库信息
  8738. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8739. if err != nil {
  8740. return err
  8741. }
  8742. var delete_count int64 = 0
  8743. delete_count = warehouseOutInfos.Count - count
  8744. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8745. // 在出库记录表里记录退库详情
  8746. warehouseOutInfo := &models.WarehouseOutInfo{
  8747. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8748. WarehouseOutId: warehouseOut.ID,
  8749. Status: 1,
  8750. Ctime: time.Now().Unix(),
  8751. OrgId: orgID,
  8752. Type: 1,
  8753. IsSys: 1,
  8754. SysRecordTime: record_time,
  8755. GoodTypeId: good_yc.GoodTypeId,
  8756. GoodId: good_yc.GoodId,
  8757. PatientId: good_yc.PatientId,
  8758. ConsumableType: 2,
  8759. StorehouseId: houseConfig.StorehouseOutInfo,
  8760. IsCheck: 1,
  8761. }
  8762. warehouseOutInfo.Count = count
  8763. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8764. warehouseOutInfo.Price = stockInInfo.Price
  8765. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8766. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8767. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8768. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8769. warehouseOutInfo.Number = warehouseOutInfos.Number
  8770. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8771. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8772. //查找当天是否存在出库记录
  8773. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8774. if errcod == gorm.ErrRecordNotFound {
  8775. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8776. //插入详情明细表
  8777. stockFlow := models.VmStockFlow{
  8778. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8779. WarehouseOutId: warehouseOut.ID,
  8780. GoodId: good_yc.GoodId,
  8781. Number: warehouseOutInfos.Number,
  8782. ProductDate: stockInInfo.ProductDate,
  8783. ExpireDate: stockInInfo.ExpiryDate,
  8784. Count: count,
  8785. Price: stockInInfo.Price,
  8786. Status: 1,
  8787. Ctime: time.Now().Unix(),
  8788. UserOrgId: good_yc.OrgId,
  8789. Manufacturer: stockInInfo.Manufacturer,
  8790. Dealer: stockInInfo.Dealer,
  8791. LicenseNumber: stockInInfo.LicenseNumber,
  8792. IsEdit: 2,
  8793. Creator: creater,
  8794. SystemTime: record_time,
  8795. ConsumableType: 3,
  8796. WarehousingDetailId: 0,
  8797. IsSys: 1,
  8798. UpdateCreator: creater,
  8799. PatientId: patient_id,
  8800. StorehouseId: houseConfig.StorehouseOutInfo,
  8801. }
  8802. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8803. if errflow == gorm.ErrRecordNotFound {
  8804. //创建流水表
  8805. err := service.CreateStockFlowOne(stockFlow)
  8806. fmt.Println("err", err)
  8807. } else if errflow == nil {
  8808. //插入详情明细表
  8809. stockFlow := models.VmStockFlow{
  8810. ID: exsit.ID,
  8811. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8812. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8813. WarehouseOutId: warehouseOut.ID,
  8814. GoodId: good_yc.GoodId,
  8815. Number: warehouseOutInfos.Number,
  8816. ProductDate: stockInInfo.ProductDate,
  8817. ExpireDate: stockInInfo.ExpiryDate,
  8818. Count: exsit.Count - delete_count,
  8819. Price: stockInInfo.Price,
  8820. Status: 1,
  8821. Ctime: time.Now().Unix(),
  8822. UserOrgId: good_yc.OrgId,
  8823. Manufacturer: stockInInfo.Manufacturer,
  8824. Dealer: stockInInfo.Dealer,
  8825. LicenseNumber: stockInInfo.LicenseNumber,
  8826. IsEdit: 2,
  8827. Creator: creater,
  8828. SystemTime: record_time,
  8829. ConsumableType: 3,
  8830. WarehousingDetailId: 0,
  8831. IsSys: 1,
  8832. UpdateCreator: creater,
  8833. PatientId: patient_id,
  8834. StorehouseId: houseConfig.StorehouseOutInfo,
  8835. }
  8836. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8837. }
  8838. if errOne != nil {
  8839. return errOne
  8840. }
  8841. } else if errcod == nil {
  8842. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8843. //插入详情明细表
  8844. stockFlow := models.VmStockFlow{
  8845. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8846. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8847. WarehouseOutId: warehouseOut.ID,
  8848. GoodId: good_yc.GoodId,
  8849. Number: warehouseOutInfos.Number,
  8850. ProductDate: stockInInfo.ProductDate,
  8851. ExpireDate: stockInInfo.ExpiryDate,
  8852. Count: count,
  8853. Price: stockInInfo.Price,
  8854. Status: 1,
  8855. Ctime: time.Now().Unix(),
  8856. UserOrgId: good_yc.OrgId,
  8857. Manufacturer: stockInInfo.Manufacturer,
  8858. Dealer: stockInInfo.Dealer,
  8859. LicenseNumber: stockInInfo.LicenseNumber,
  8860. IsEdit: 2,
  8861. Creator: creater,
  8862. SystemTime: record_time,
  8863. ConsumableType: 3,
  8864. WarehousingDetailId: 0,
  8865. IsSys: 1,
  8866. UpdateCreator: creater,
  8867. PatientId: patient_id,
  8868. ReturnCount: delete_count,
  8869. StorehouseId: houseConfig.StorehouseOutInfo,
  8870. }
  8871. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8872. if errflows == gorm.ErrRecordNotFound {
  8873. //创建流水表
  8874. service.CreateStockFlowOne(stockFlow)
  8875. } else if errflows == nil {
  8876. stockFlow := models.VmStockFlow{
  8877. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8878. ID: exsit.ID,
  8879. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8880. WarehouseOutId: warehouseOut.ID,
  8881. GoodId: good_yc.GoodId,
  8882. Number: warehouseOutInfos.Number,
  8883. ProductDate: stockInInfo.ProductDate,
  8884. ExpireDate: stockInInfo.ExpiryDate,
  8885. Count: exsit.Count - delete_count,
  8886. Price: stockInInfo.Price,
  8887. Status: 1,
  8888. Ctime: time.Now().Unix(),
  8889. UserOrgId: good_yc.OrgId,
  8890. Manufacturer: stockInInfo.Manufacturer,
  8891. Dealer: stockInInfo.Dealer,
  8892. LicenseNumber: stockInInfo.LicenseNumber,
  8893. IsEdit: 2,
  8894. Creator: creater,
  8895. SystemTime: record_time,
  8896. ConsumableType: 3,
  8897. WarehousingDetailId: 0,
  8898. IsSys: 1,
  8899. UpdateCreator: creater,
  8900. PatientId: patient_id,
  8901. ReturnCount: delete_count,
  8902. StorehouseId: houseConfig.StorehouseOutInfo,
  8903. }
  8904. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8905. }
  8906. }
  8907. //更改自动出库的表格
  8908. details := models.BloodAutomaticReduceDetail{
  8909. WarehouseOutId: warehouseOutInfo.ID,
  8910. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8911. PatientId: patient_id,
  8912. Ctime: time.Now().Unix(),
  8913. Mtime: time.Now().Unix(),
  8914. Status: 1,
  8915. RecordTime: record_time,
  8916. OrgId: orgID,
  8917. GoodId: good_yc.GoodId,
  8918. GoodTypeId: good_yc.GoodTypeId,
  8919. Count: count,
  8920. StorehouseId: houseConfig.StorehouseOutInfo,
  8921. }
  8922. //查询当天耗材是否已经存在数据
  8923. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8924. if errcode == gorm.ErrRecordNotFound {
  8925. errTwo := service.CreateAutoReduceRecord(&details)
  8926. if errTwo != nil {
  8927. return errTwo
  8928. }
  8929. } else if errcode == nil {
  8930. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8931. service.CreateAutoReduceRecord(&details)
  8932. }
  8933. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8934. //增加出库库存数量
  8935. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8936. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8937. fmt.Println("errOne", errOne)
  8938. // 删除出库完成后,要增加对应批次的库存数量
  8939. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8940. if errThree != nil {
  8941. return errThree
  8942. }
  8943. if good_yc.Count == 0 {
  8944. return nil
  8945. } else {
  8946. return errors.New("退库和出库数据不匹配")
  8947. }
  8948. }
  8949. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8950. //查询该患者当天已经出库的耗材信息
  8951. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8952. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8953. for i := len(goods_yc) - 1; i >= 0; i-- {
  8954. goods_yc_temp := goods_yc[i]
  8955. for j := len(goods) - 1; j >= 0; j-- {
  8956. goods_temp := goods[j]
  8957. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8958. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8959. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8960. if goods_yc_temp.Count == goods_temp.Count {
  8961. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8962. goods = append(goods[:j], goods[j+1:]...)
  8963. break
  8964. }
  8965. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8966. if goods_yc_temp.Count > goods_temp.Count {
  8967. temp_count := goods_yc_temp.Count - goods_temp.Count
  8968. goods_yc[i].Count = temp_count
  8969. goods = append(goods[:j], goods[j+1:]...)
  8970. break
  8971. }
  8972. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8973. if goods_yc_temp.Count < goods_temp.Count {
  8974. temp_count := goods_temp.Count - goods_yc_temp.Count
  8975. goods[j].Count = temp_count
  8976. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8977. break
  8978. }
  8979. }
  8980. }
  8981. }
  8982. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8983. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8984. fmt.Println("剩余需要出库的", len(goods))
  8985. if len(goods) > 0 {
  8986. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8987. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8988. if err == gorm.ErrRecordNotFound {
  8989. //没有记录,则创建出库单
  8990. timeStr := time.Now().Format("2006-01-02")
  8991. timeArr := strings.Split(timeStr, "-")
  8992. total, _ := service.FindAllWarehouseOut(orgID)
  8993. total = total + 1
  8994. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8995. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8996. number = number + total
  8997. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8998. warehouseOut := models.WarehouseOut{
  8999. WarehouseOutOrderNumber: warehousing_out_order,
  9000. OperationTime: time.Now().Unix(),
  9001. OrgId: orgID,
  9002. Creater: creater,
  9003. Ctime: time.Now().Unix(),
  9004. Status: 1,
  9005. WarehouseOutTime: record_time,
  9006. Dealer: 0,
  9007. Manufacturer: 0,
  9008. Type: 1,
  9009. IsSys: 1,
  9010. StorehouseId: houseConfig.StorehouseOutInfo,
  9011. IsCheck: 1,
  9012. }
  9013. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  9014. if err != nil {
  9015. utils.TraceLog("创建出库单失败 err = %v", err)
  9016. return err
  9017. } else {
  9018. out = warehouseOut
  9019. }
  9020. }
  9021. for _, item := range goods {
  9022. var newCount int64 = 0
  9023. for _, it := range goodOne {
  9024. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  9025. newCount = it.Count
  9026. }
  9027. }
  9028. prepare := models.DialysisBeforePrepare{
  9029. GoodTypeId: item.GoodTypeId,
  9030. GoodId: item.GoodId,
  9031. Count: item.Count,
  9032. StorehouseId: houseConfig.StorehouseOutInfo,
  9033. }
  9034. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  9035. //增加出库数量
  9036. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  9037. }
  9038. }
  9039. if len(goods_yc) > 0 {
  9040. for _, good_yc := range goods_yc {
  9041. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  9042. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  9043. }
  9044. }
  9045. return nil
  9046. }
  9047. // 耗材出库删除
  9048. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  9049. // 先根据相关信息查询当天该耗材的出库信息
  9050. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  9051. if err != nil {
  9052. return err
  9053. }
  9054. var delete_count int64 = 0
  9055. for _, ware := range warehouseOutInfos {
  9056. // 判断当前出库的数据和删除出库数量
  9057. if good_yc.Count <= ware.Count {
  9058. delete_count = good_yc.Count
  9059. } else {
  9060. delete_count = ware.Count
  9061. }
  9062. warehouseOutInfo := &models.WarehouseOutInfo{
  9063. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9064. WarehouseOutId: warehouseOut.ID,
  9065. Status: 1,
  9066. Ctime: time.Now().Unix(),
  9067. Remark: "",
  9068. OrgId: orgID,
  9069. Type: 1,
  9070. Manufacturer: 0,
  9071. Dealer: 0,
  9072. IsSys: 0,
  9073. SysRecordTime: record_time,
  9074. GoodTypeId: good_yc.GoodTypeId,
  9075. GoodId: good_yc.GoodId,
  9076. StorehouseId: warehouseOut.StorehouseId,
  9077. IsCheck: 1,
  9078. }
  9079. warehouseOutInfo.Count = delete_count
  9080. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9081. warehouseOutInfo.Price = stockInInfo.Price
  9082. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9083. if errOne != nil {
  9084. return errOne
  9085. }
  9086. // 删除出库完成后,要改变流水库存(有疑问)
  9087. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  9088. fmt.Println("errOne", errOne)
  9089. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  9090. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9091. //扣减出库数量
  9092. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  9093. if errThree != nil {
  9094. return errThree
  9095. }
  9096. }
  9097. if good_yc.Count == 0 {
  9098. return nil
  9099. } else {
  9100. return errors.New("退库和出库数据不匹配")
  9101. }
  9102. }
  9103. func (this *DialysisAPIController) GetMobileScheduleList() {
  9104. limit, _ := this.GetInt64("limit")
  9105. page, _ := this.GetInt64("page")
  9106. type_options_visible, _ := this.GetInt64("type_options_visible")
  9107. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  9108. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  9109. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  9110. }
  9111. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  9112. newArr = make([]*models.HisPrescriptionProject, 0)
  9113. for i := 0; i < len(arr); i++ {
  9114. repeat := false
  9115. for j := i + 1; j < len(arr); j++ {
  9116. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  9117. repeat = true
  9118. break
  9119. }
  9120. }
  9121. if !repeat {
  9122. newArr = append(newArr, arr[i])
  9123. }
  9124. }
  9125. return
  9126. }
  9127. func (this *DialysisAPIController) GetRoleList() {
  9128. admin_user_id, _ := this.GetInt64("admin_user_id")
  9129. orgid := this.GetMobileAdminUserInfo().Org.Id
  9130. list, err := service.GetRoleList(orgid, admin_user_id)
  9131. fmt.Println(err)
  9132. this.ServeSuccessJSON(map[string]interface{}{
  9133. "list": list,
  9134. })
  9135. return
  9136. }
  9137. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  9138. // 先根据相关信息查询当天该耗材的出库信息
  9139. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  9140. if err != nil {
  9141. return err
  9142. }
  9143. var delete_count int64 = 0
  9144. delete_count = warehouseOutInfos.Count - count
  9145. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9146. // 删除出库完成后,要增加对应批次的库存数量
  9147. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  9148. if errThree != nil {
  9149. return errThree
  9150. }
  9151. //增加退库数量
  9152. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  9153. //扣减出库数量
  9154. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  9155. //查询剩余库存
  9156. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  9157. var sum_count int64
  9158. for _, item := range goodList {
  9159. sum_count += item.StockCount
  9160. }
  9161. // 在出库记录表里记录退库详情
  9162. warehouseOutInfo := &models.WarehouseOutInfo{
  9163. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9164. WarehouseOutId: warehouseOut.ID,
  9165. Status: 1,
  9166. Ctime: time.Now().Unix(),
  9167. OrgId: orgID,
  9168. Type: 1,
  9169. IsSys: 1,
  9170. SysRecordTime: record_time,
  9171. GoodTypeId: good_yc.GoodTypeId,
  9172. GoodId: good_yc.GoodId,
  9173. PatientId: good_yc.PatientId,
  9174. ConsumableType: 2,
  9175. StorehouseId: houseConfig.StorehouseOutInfo,
  9176. IsCheck: 1,
  9177. OverCount: sum_count,
  9178. }
  9179. warehouseOutInfo.Count = count
  9180. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9181. warehouseOutInfo.Price = stockInInfo.Price
  9182. warehouseOutInfo.Dealer = stockInInfo.Dealer
  9183. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  9184. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  9185. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  9186. warehouseOutInfo.Number = warehouseOutInfos.Number
  9187. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  9188. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  9189. //查找当天是否存在出库记录
  9190. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9191. if errcod == gorm.ErrRecordNotFound {
  9192. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9193. //插入详情明细表
  9194. if errOne != nil {
  9195. return errOne
  9196. }
  9197. //插入详情明细表
  9198. stockFlow := models.VmStockFlow{
  9199. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9200. WarehouseOutId: warehouseOut.ID,
  9201. GoodId: good_yc.GoodId,
  9202. Number: warehouseOutInfos.Number,
  9203. ProductDate: stockInInfo.ProductDate,
  9204. ExpireDate: stockInInfo.ExpiryDate,
  9205. Count: count,
  9206. Price: stockInInfo.Price,
  9207. Status: 1,
  9208. Ctime: record_time,
  9209. UserOrgId: good_yc.OrgId,
  9210. Manufacturer: stockInInfo.Manufacturer,
  9211. Dealer: stockInInfo.Dealer,
  9212. LicenseNumber: stockInInfo.LicenseNumber,
  9213. IsEdit: 2,
  9214. Creator: creater,
  9215. SystemTime: record_time,
  9216. ConsumableType: 3,
  9217. WarehousingDetailId: 0,
  9218. IsSys: 1,
  9219. UpdateCreator: creater,
  9220. PatientId: patient_id,
  9221. StorehouseId: houseConfig.StorehouseOutInfo,
  9222. OverCount: sum_count,
  9223. ProjectId: good_yc.ProjectId,
  9224. }
  9225. err := service.CreateStockFlowOne(stockFlow)
  9226. fmt.Println("err", err)
  9227. } else if errcod == nil {
  9228. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9229. }
  9230. //创建退库单
  9231. operation_time := time.Now().Unix()
  9232. //创建退库单
  9233. timeStr := time.Now().Format("2006-01-02")
  9234. timeArr := strings.Split(timeStr, "-")
  9235. total, _ := service.FindAllCancelStockTotal(orgID)
  9236. total = total + 1
  9237. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9238. cancelStock := models.CancelStock{
  9239. OrderNumber: orderNumber,
  9240. OperaTime: operation_time,
  9241. OrgId: orgID,
  9242. Creater: warehouseOut.Creater,
  9243. Ctime: time.Now().Unix(),
  9244. Status: 1,
  9245. ReturnTime: record_time,
  9246. Type: 1,
  9247. StorehouseId: stockInInfo.StorehouseId,
  9248. IsCheck: 1,
  9249. }
  9250. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9251. if msgerrkonde == gorm.ErrRecordNotFound {
  9252. service.AddSigleCancelStock(&cancelStock)
  9253. }
  9254. cancel, _ := service.GetLastCancelStockById(orgID)
  9255. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9256. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9257. cancelStockInfo := models.CancelStockInfo{
  9258. GoodId: stockInInfo.GoodId,
  9259. CancelStockId: cancel.ID,
  9260. GoodTypeId: stockInInfo.GoodTypeId,
  9261. Count: delete_count,
  9262. Price: stockInInfo.PackingPrice,
  9263. Total: 0,
  9264. ProductDate: stockInInfo.ProductDate,
  9265. ExpiryDate: stockInInfo.ExpiryDate,
  9266. Ctime: record_time,
  9267. Status: 1,
  9268. OrgId: orgID,
  9269. OrderNumber: cancel.OrderNumber,
  9270. Type: 0,
  9271. Dealer: deaerler.DealerName,
  9272. Manufacturer: manufacturer.ManufacturerName,
  9273. Number: stockInInfo.Number,
  9274. RegisterAccount: "",
  9275. Remark: "",
  9276. WarehouseInfoId: stockInInfo.ID,
  9277. PatientId: patient_id,
  9278. RecordDate: record_time,
  9279. StorehouseId: stockInInfo.StorehouseId,
  9280. IsCheck: 1,
  9281. }
  9282. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9283. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9284. flow := models.VmStockFlow{
  9285. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9286. GoodId: good_yc.GoodId,
  9287. Number: warehouseOutInfos.Number,
  9288. LicenseNumber: stockInInfo.LicenseNumber,
  9289. Count: delete_count,
  9290. UserOrgId: orgID,
  9291. PatientId: patient_id,
  9292. SystemTime: record_time,
  9293. ConsumableType: 7,
  9294. IsSys: 0,
  9295. WarehousingOrder: "",
  9296. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9297. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9298. IsEdit: 0,
  9299. CancelStockId: cancel.ID,
  9300. CancelOrderNumber: cancel.OrderNumber,
  9301. Manufacturer: manufacturer.ID,
  9302. Dealer: 0,
  9303. Creator: warehouseOut.Creater,
  9304. UpdateCreator: 0,
  9305. Status: 1,
  9306. Ctime: record_time,
  9307. Mtime: 0,
  9308. Price: stockInInfo.Price,
  9309. WarehousingDetailId: stockInInfo.ID,
  9310. WarehouseOutDetailId: warehouseOutInfos.ID,
  9311. CancelOutDetailId: cancelInfo.ID,
  9312. ProductDate: stockInInfo.ProductDate,
  9313. ExpireDate: stockInInfo.ExpiryDate,
  9314. StorehouseId: houseConfig.StorehouseOutInfo,
  9315. OverCount: sum_count,
  9316. }
  9317. service.CreateStockFlowOne(flow)
  9318. //更改自动出库的表格
  9319. details := models.BloodAutomaticReduceDetail{
  9320. WarehouseOutId: warehouseOutInfo.ID,
  9321. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9322. PatientId: patient_id,
  9323. Ctime: time.Now().Unix(),
  9324. Mtime: time.Now().Unix(),
  9325. Status: 1,
  9326. RecordTime: record_time,
  9327. OrgId: orgID,
  9328. GoodId: good_yc.GoodId,
  9329. GoodTypeId: good_yc.GoodTypeId,
  9330. Count: count,
  9331. StorehouseId: houseConfig.StorehouseOutInfo,
  9332. }
  9333. //查询当天耗材是否已经存在数据
  9334. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9335. if errcode == gorm.ErrRecordNotFound {
  9336. errTwo := service.CreateAutoReduceRecord(&details)
  9337. if errTwo != nil {
  9338. return errTwo
  9339. }
  9340. } else if errcode == nil {
  9341. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9342. service.CreateAutoReduceRecord(&details)
  9343. }
  9344. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9345. //增加出库库存数量
  9346. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9347. if good_yc.Count == 0 {
  9348. return nil
  9349. } else {
  9350. return errors.New("退库和出库数据不匹配")
  9351. }
  9352. }
  9353. func (this *DialysisAPIController) SavePatientSign() {
  9354. adminUserInfo := this.GetMobileAdminUserInfo()
  9355. patient_id, _ := this.GetInt64("patient_id")
  9356. dialysis_date, _ := this.GetInt64("dialysis_date")
  9357. orgid := adminUserInfo.Org.Id
  9358. var esdata models.DialysisOrder
  9359. var err error
  9360. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9362. return
  9363. }
  9364. esdata.Hash = esdata.Hash
  9365. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9366. order := models.DialysisOrder{
  9367. Hash: esdata.Hash,
  9368. Url: esdata.Url,
  9369. }
  9370. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9371. redis := service.RedisClient()
  9372. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9373. redis.Set(key, "", time.Second)
  9374. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9375. //清空key 值
  9376. redis.Set(keyOne, "", time.Second)
  9377. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9378. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9379. //redis.Set(keyTwo, "", time.Second)
  9380. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9381. redis.Set(keyThree, "", time.Second)
  9382. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9383. redis.Set(keyFour, "", time.Second)
  9384. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9385. redis.Set(keyFive, "", time.Second)
  9386. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9387. redis.Set(keySix, "", time.Second)
  9388. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9389. redis.Set(keySeven, "", time.Second)
  9390. if err != nil {
  9391. fmt.Println(err)
  9392. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9393. return
  9394. }
  9395. this.ServeSuccessJSON(map[string]interface{}{
  9396. "electronic_signature": esdata,
  9397. })
  9398. }
  9399. func (this *DialysisAPIController) GetPatientSign() {
  9400. patient_id, _ := this.GetInt64("patient_id")
  9401. dialysis_date, _ := this.GetInt64("dialysis_date")
  9402. adminUserInfo := this.GetMobileAdminUserInfo()
  9403. orgId := adminUserInfo.Org.Id
  9404. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9405. if err != nil {
  9406. fmt.Println(err)
  9407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9408. return
  9409. }
  9410. this.ServeSuccessJSON(map[string]interface{}{
  9411. "dialysisOrder": dialysisOrder,
  9412. })
  9413. }
  9414. func (this *DialysisAPIController) GetScheduleByPatient() {
  9415. patient_id, _ := this.GetInt64("patient_id")
  9416. schedule_date, _ := this.GetInt64("schedule_date")
  9417. orgid := this.GetMobileAdminUserInfo().Org.Id
  9418. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9419. this.ServeSuccessJSON(map[string]interface{}{
  9420. "schedule": schedule,
  9421. })
  9422. }
  9423. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9424. org_id := this.GetMobileAdminUserInfo().Org.Id
  9425. patient_id, _ := this.GetInt64("patient_id")
  9426. schedule_date, _ := this.GetInt64("schedule_date")
  9427. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9428. this.ServeSuccessJSON(map[string]interface{}{
  9429. "order": order,
  9430. })
  9431. }
  9432. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9433. org_id := this.GetMobileAdminUserInfo().Org.Id
  9434. schedule_date := this.GetString("schedule_date")
  9435. schedule_type, _ := this.GetInt64("schedule_type")
  9436. timeLayout := "2006-01-02"
  9437. loc, _ := time.LoadLocation("Local")
  9438. var startdateunix int64
  9439. if len(schedule_date) > 0 {
  9440. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9441. if err != nil {
  9442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9443. return
  9444. }
  9445. startdateunix = theTime.Unix()
  9446. }
  9447. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9448. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9449. devices, _ := service.GetAllDevicetByListSix(org_id)
  9450. for key, item := range scheduals {
  9451. // 床位信息
  9452. for _, device := range devices {
  9453. if item.BedId == device.ID {
  9454. scheduals[key].DeviceNumber = device
  9455. break
  9456. }
  9457. }
  9458. }
  9459. this.ServeSuccessJSON(map[string]interface{}{
  9460. "list": list,
  9461. "scheduals": scheduals,
  9462. })
  9463. }
  9464. func (this *DialysisAPIController) SavePatientPicture() {
  9465. patient_id, _ := this.GetInt64("patient_id")
  9466. dialysis_date, _ := this.GetInt64("schedule_date")
  9467. avatar := this.GetString("avatar")
  9468. fmt.Println("patient_id", patient_id)
  9469. orgId := this.GetMobileAdminUserInfo().Org.Id
  9470. order := models.DialysisOrder{
  9471. Url: avatar,
  9472. }
  9473. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9474. redis := service.RedisClient()
  9475. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9476. redis.Set(key, "", time.Second)
  9477. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9478. //清空key 值
  9479. redis.Set(keyOne, "", time.Second)
  9480. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9481. redis.Set(keyThree, "", time.Second)
  9482. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9483. redis.Set(keyFour, "", time.Second)
  9484. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9485. redis.Set(keyFive, "", time.Second)
  9486. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9487. redis.Set(keySix, "", time.Second)
  9488. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9489. redis.Set(keySeven, "", time.Second)
  9490. if err != nil {
  9491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9492. return
  9493. }
  9494. this.ServeSuccessJSON(map[string]interface{}{
  9495. "order": order,
  9496. })
  9497. }
  9498. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9499. ids := this.GetString("ids")
  9500. idSplit := strings.Split(ids, ",")
  9501. orgId := this.GetMobileAdminUserInfo().Org.Id
  9502. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9503. execution_time := this.GetString("exce_time")
  9504. timeLayout2 := "2006-01-02 15:04:05"
  9505. loc, _ := time.LoadLocation("Local")
  9506. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9507. if errs != nil {
  9508. utils.ErrorLog(errs.Error())
  9509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9510. return
  9511. }
  9512. //his客户
  9513. if config.IsOpen == 1 {
  9514. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9515. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9516. for _, item := range list {
  9517. for _, it := range adviceList {
  9518. if item.DrugId == it.DrugId {
  9519. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9520. }
  9521. }
  9522. }
  9523. for _, item := range list {
  9524. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9525. var sum_out_count int64
  9526. for _, itemThree := range item.ChildDoctorAdvice {
  9527. var prescribing_number int64
  9528. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9529. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9530. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9531. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9532. }
  9533. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9534. prescribing_number = parseIntPrescribingNumber
  9535. }
  9536. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9537. prescribing_number = parseIntPrescribingNumber
  9538. }
  9539. sum_out_count += prescribing_number
  9540. }
  9541. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9542. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9543. //库存不足
  9544. if sum_out_count > drugStockOut.FlushCount {
  9545. this.ServeSuccessJSON(map[string]interface{}{
  9546. "msg": "2",
  9547. "drug": medical,
  9548. "ids": ids,
  9549. })
  9550. return
  9551. }
  9552. }
  9553. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9554. //执行医嘱
  9555. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9556. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9557. for _, item := range advices {
  9558. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9559. redis := service.RedisClient()
  9560. //清空key 值
  9561. redis.Set(key, "", time.Second)
  9562. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9563. redis.Set(keyTwo, "", time.Second)
  9564. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9565. redis.Set(keyThree, "", time.Second)
  9566. recordDate := theTime.Format("2006-01-02")
  9567. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9568. redis.Set(keyFour, "", time.Second)
  9569. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9570. redis.Set(keyFive, "", time.Second)
  9571. defer redis.Close()
  9572. }
  9573. if errs == nil {
  9574. //药品管理信息
  9575. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9576. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9577. if drugStockConfig.IsOpen == 1 {
  9578. for _, item := range advices {
  9579. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9580. config, _ := service.GetDrugOpenConfigOne(orgId)
  9581. if config.IsOpen != 1 {
  9582. //查询该药品是否有库存
  9583. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9584. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9585. if medical.IsUse == 2 {
  9586. if config.IsOpen != 1 {
  9587. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9588. service.HisDrugsDelivery(orgId, creater, &advice)
  9589. if orgId == 3877 || orgId == 10265 {
  9590. //查询该药品是否有出库记录
  9591. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9592. if len(flowMap) == 0 {
  9593. errs := service.UpdateHisAdviceById(advice.ID)
  9594. if errs != nil {
  9595. drugError := models.XtDrugError{
  9596. UserOrgId: orgId,
  9597. DrugId: item.DrugId,
  9598. RecordDate: item.AdviceDate,
  9599. PatientId: item.PatientId,
  9600. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9601. Status: 1,
  9602. Ctime: time.Now().Unix(),
  9603. Mtime: 0,
  9604. SumCount: 0,
  9605. Prescribingnumber: advice.PrescribingNumber,
  9606. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9607. }
  9608. service.CreateDrugError(drugError)
  9609. }
  9610. this.ServeSuccessJSON(map[string]interface{}{
  9611. "msg": "2",
  9612. "drug": medical,
  9613. "ids": ids,
  9614. })
  9615. return
  9616. }
  9617. }
  9618. }
  9619. if pharmacyConfig.IsOpen != 1 {
  9620. service.HisDrugsDelivery(orgId, creater, &advice)
  9621. if orgId == 3877 || orgId == 10265 {
  9622. //查询该药品是否有出库记录
  9623. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9624. if len(flowMap) == 0 {
  9625. errs := service.UpdateHisAdviceById(advice.ID)
  9626. if errs != nil {
  9627. drugError := models.XtDrugError{
  9628. UserOrgId: orgId,
  9629. DrugId: item.DrugId,
  9630. RecordDate: item.AdviceDate,
  9631. PatientId: item.PatientId,
  9632. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9633. Status: 1,
  9634. Ctime: time.Now().Unix(),
  9635. Mtime: 0,
  9636. SumCount: 0,
  9637. Prescribingnumber: advice.PrescribingNumber,
  9638. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9639. }
  9640. service.CreateDrugError(drugError)
  9641. }
  9642. this.ServeSuccessJSON(map[string]interface{}{
  9643. "msg": "2",
  9644. "drug": medical,
  9645. "ids": ids,
  9646. })
  9647. return
  9648. }
  9649. }
  9650. }
  9651. //更新字典里面的库存
  9652. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9653. var sum_count int64
  9654. for _, its := range stockInfo {
  9655. if its.MaxUnit == medical.MaxUnit {
  9656. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9657. }
  9658. sum_count += its.StockMaxNumber + its.StockMinNumber
  9659. }
  9660. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9661. //剩余库存
  9662. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9663. }
  9664. }
  9665. }
  9666. }
  9667. }
  9668. this.ServeSuccessJSON(map[string]interface{}{
  9669. "msg": "1",
  9670. "ids": ids,
  9671. })
  9672. return
  9673. } else {
  9674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9675. }
  9676. }
  9677. //血透客户
  9678. if config.IsOpen == 2 || config.IsOpen == 0 {
  9679. //药品管理信息
  9680. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9681. if drugStockConfig.IsOpen == 1 {
  9682. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9683. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9684. for _, item := range list {
  9685. for _, it := range adviceList {
  9686. if item.DrugId == it.DrugId {
  9687. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9688. }
  9689. }
  9690. }
  9691. for _, item := range list {
  9692. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9693. var sum_out_count int64
  9694. for _, itemThree := range item.ChildDoctorAdvice {
  9695. var prescribing_number int64
  9696. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9697. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9698. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9699. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9700. }
  9701. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9702. prescribing_number = parseIntPrescribingNumber
  9703. }
  9704. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9705. prescribing_number = parseIntPrescribingNumber
  9706. }
  9707. sum_out_count += prescribing_number
  9708. }
  9709. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9710. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9711. //库存不足
  9712. if sum_out_count > drugStockOut.FlushCount {
  9713. this.ServeSuccessJSON(map[string]interface{}{
  9714. "msg": "2",
  9715. "drug": medical,
  9716. "ids": ids,
  9717. })
  9718. return
  9719. }
  9720. }
  9721. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9722. //执行医嘱
  9723. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9724. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9725. for _, item := range advices {
  9726. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9727. redis := service.RedisClient()
  9728. //清空key 值
  9729. redis.Set(key, "", time.Second)
  9730. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9731. redis.Set(keyTwo, "", time.Second)
  9732. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9733. redis.Set(keyThree, "", time.Second)
  9734. recordDate := theTime.Format("2006-01-02")
  9735. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9736. redis.Set(keyFour, "", time.Second)
  9737. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9738. redis.Set(keyFive, "", time.Second)
  9739. defer redis.Close()
  9740. }
  9741. if errs == nil {
  9742. for _, item := range advices {
  9743. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9744. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9745. //查询是否出库按钮开启
  9746. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9747. if adviceSetting.IsAdviceOpen == 1 {
  9748. //查询是否出库按钮开启
  9749. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9750. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9751. if prescriptionConfig.IsOpen == 1 {
  9752. if medical.IsUse == 2 {
  9753. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9754. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9755. }
  9756. if pharmacyConfig.IsOpen != 1 {
  9757. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9758. }
  9759. //更新字典里面的库存
  9760. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9761. var sum_count int64
  9762. for _, its := range stockInfo {
  9763. if its.MaxUnit == medical.MaxUnit {
  9764. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9765. }
  9766. sum_count += its.StockMaxNumber + its.StockMinNumber
  9767. }
  9768. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9769. //剩余库存
  9770. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9771. }
  9772. }
  9773. } else {
  9774. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9775. if medical.IsUse == 2 {
  9776. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9777. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9778. }
  9779. if pharmacyConfig.IsOpen != 1 {
  9780. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9781. }
  9782. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9783. var sum_count int64
  9784. for _, its := range stockInfo {
  9785. if its.MaxUnit == medical.MaxUnit {
  9786. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9787. }
  9788. sum_count += its.StockMaxNumber + its.StockMinNumber
  9789. }
  9790. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9791. //剩余库存
  9792. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9793. }
  9794. }
  9795. }
  9796. }
  9797. this.ServeSuccessJSON(map[string]interface{}{
  9798. "msg": "1",
  9799. "ids": ids,
  9800. })
  9801. return
  9802. } else {
  9803. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9804. //执行医嘱
  9805. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9806. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9807. for _, item := range advices {
  9808. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9809. redis := service.RedisClient()
  9810. //清空key 值
  9811. redis.Set(key, "", time.Second)
  9812. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9813. redis.Set(keyTwo, "", time.Second)
  9814. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9815. redis.Set(keyThree, "", time.Second)
  9816. recordDate := theTime.Format("2006-01-02")
  9817. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9818. redis.Set(keyFour, "", time.Second)
  9819. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9820. redis.Set(keyFive, "", time.Second)
  9821. defer redis.Close()
  9822. }
  9823. this.ServeSuccessJSON(map[string]interface{}{
  9824. "msg": "1",
  9825. "ids": ids,
  9826. })
  9827. return
  9828. }
  9829. }
  9830. }
  9831. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9832. ids := this.GetString("ids")
  9833. idSplit := strings.Split(ids, ",")
  9834. orgId := this.GetMobileAdminUserInfo().Org.Id
  9835. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9836. if config.IsOpen == 1 {
  9837. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9838. this.ServeSuccessJSON(map[string]interface{}{
  9839. "msg": "1",
  9840. "ids": ids,
  9841. })
  9842. return
  9843. }
  9844. if config.IsOpen == 0 || config.IsOpen == 2 {
  9845. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9846. this.ServeSuccessJSON(map[string]interface{}{
  9847. "msg": "1",
  9848. "ids": ids,
  9849. })
  9850. return
  9851. }
  9852. }
  9853. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9854. ids := this.GetString("ids")
  9855. idSplit := strings.Split(ids, ",")
  9856. orgId := this.GetMobileAdminUserInfo().Org.Id
  9857. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9858. //his
  9859. if config.IsOpen == 1 {
  9860. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9861. theTime := time.Now()
  9862. advices := models.HisDoctorAdviceThirty{
  9863. CheckTime: theTime.Unix(),
  9864. Checker: checker,
  9865. UpdatedTime: time.Now().Unix(),
  9866. }
  9867. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9868. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9869. for _, item := range list {
  9870. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9871. redis := service.RedisClient()
  9872. //清空key 值
  9873. redis.Set(key, "", time.Second)
  9874. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9875. redis.Set(keyTwo, "", time.Second)
  9876. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9877. redis.Set(keyThree, "", time.Second)
  9878. recordDate := theTime.Format("2006-01-02")
  9879. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9880. redis.Set(keyFour, "", time.Second)
  9881. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9882. redis.Set(keyFive, "", time.Second)
  9883. defer redis.Close()
  9884. }
  9885. this.ServeSuccessJSON(map[string]interface{}{
  9886. "msg": "1",
  9887. "ids": ids,
  9888. })
  9889. return
  9890. }
  9891. //血透
  9892. if config.IsOpen == 0 || config.IsOpen == 2 {
  9893. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9894. theTime := time.Now()
  9895. advices := models.DoctorAdvice{
  9896. CheckTime: theTime.Unix(),
  9897. Checker: checker,
  9898. UpdatedTime: time.Now().Unix(),
  9899. }
  9900. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9901. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9902. for _, item := range list {
  9903. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9904. redis := service.RedisClient()
  9905. //清空key 值
  9906. redis.Set(key, "", time.Second)
  9907. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9908. redis.Set(keyTwo, "", time.Second)
  9909. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9910. redis.Set(keyThree, "", time.Second)
  9911. recordDate := theTime.Format("2006-01-02")
  9912. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9913. redis.Set(keyFour, "", time.Second)
  9914. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9915. redis.Set(keyFive, "", time.Second)
  9916. defer redis.Close()
  9917. }
  9918. this.ServeSuccessJSON(map[string]interface{}{
  9919. "msg": "1",
  9920. "ids": ids,
  9921. })
  9922. return
  9923. }
  9924. }
  9925. func (this *DialysisAPIController) CheckSchedule() {
  9926. patientID, _ := this.GetInt64("patient_id")
  9927. recordDateStr := this.GetString("record_date")
  9928. nurseID, _ := this.GetInt64("start_nurse")
  9929. schedual_type, _ := this.GetInt64("schedual_type")
  9930. bedID, _ := this.GetInt64("bed")
  9931. start_time := this.GetString("start_time")
  9932. fmt.Println("patientID", patientID)
  9933. fmt.Println("recordDateStr", recordDateStr)
  9934. fmt.Println("nurseID", nurseID)
  9935. fmt.Println("schedual_type------", schedual_type)
  9936. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9937. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9938. return
  9939. }
  9940. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9941. if parseStartDateErr != nil {
  9942. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9944. return
  9945. }
  9946. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9947. if parseErr != nil {
  9948. this.ErrorLog("时间解析失败:%v", parseErr)
  9949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9950. return
  9951. }
  9952. adminUserInfo := this.GetMobileAdminUserInfo()
  9953. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9954. if getPatientErr != nil {
  9955. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9957. return
  9958. } else if patient == nil {
  9959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9960. return
  9961. }
  9962. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9963. if getNurseErr != nil {
  9964. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9966. return
  9967. } else if nurse == nil {
  9968. this.ErrorLog("护士不存在")
  9969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9970. return
  9971. }
  9972. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9973. if getDeviceNumberErr != nil {
  9974. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9976. return
  9977. } else if deviceNumber == nil {
  9978. this.ErrorLog("床位号不存在")
  9979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9980. return
  9981. }
  9982. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9983. if getRecordErr != nil {
  9984. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9986. return
  9987. } else if dialysisRecord != nil {
  9988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9989. return
  9990. }
  9991. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9992. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9993. timeLayout := "2006-01-02 15:04:05"
  9994. loc, _ := time.LoadLocation("Local")
  9995. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9996. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9997. schedulestartTime := theStartTime.Unix()
  9998. scheduleendTime := theEndTime.Unix()
  9999. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  10000. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  10001. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10002. //查询该床位是否有人用了
  10003. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10004. if err == nil {
  10005. if schedule.ID == 0 {
  10006. this.ServeSuccessJSON(map[string]interface{}{
  10007. "status": 0,
  10008. "msg": "请求失败",
  10009. })
  10010. } else {
  10011. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  10012. if order.ID > 0 { //该机位被其他人占用了
  10013. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  10014. return
  10015. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  10016. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  10017. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  10018. this.ServeSuccessJSON(map[string]interface{}{
  10019. "status": 1,
  10020. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  10021. })
  10022. return
  10023. } else {
  10024. this.ServeSuccessJSON(map[string]interface{}{
  10025. "status": 0,
  10026. "msg": "",
  10027. })
  10028. }
  10029. }
  10030. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  10031. this.ServeSuccessJSON(map[string]interface{}{
  10032. "status": 2,
  10033. "msg": "当前机位已有患者在使用,请重新选择!",
  10034. })
  10035. }
  10036. }
  10037. } else {
  10038. this.ServeSuccessJSON(map[string]interface{}{
  10039. "status": 0,
  10040. "msg": "",
  10041. })
  10042. }
  10043. }
  10044. func (this *DialysisAPIController) GetNewDoctorListToday() {
  10045. orgId := this.GetMobileAdminUserInfo().Org.Id
  10046. schedule_type, _ := this.GetInt64("schedule_type")
  10047. partion_type, _ := this.GetInt64("partion_type")
  10048. start_time := this.GetString("start_time")
  10049. timeLayout := "2006-01-02"
  10050. loc, _ := time.LoadLocation("Local")
  10051. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10052. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  10053. _, config := service.FindXTHisRecordByOrgId(orgId)
  10054. appId := this.GetMobileAdminUserInfo().App.Id
  10055. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  10056. if err == nil {
  10057. this.ServeSuccessJSON(map[string]interface{}{
  10058. "list": list,
  10059. "config": config,
  10060. "doctorList": doctorList,
  10061. })
  10062. return
  10063. } else {
  10064. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10065. return
  10066. }
  10067. }
  10068. func (this *DialysisAPIController) SaveMobileInformation() {
  10069. patient_id, _ := this.GetInt64("patient_id")
  10070. record_date, _ := this.GetInt64("record_date")
  10071. startTime := this.GetString("start_time")
  10072. module, _ := this.GetInt64("module")
  10073. remark := this.GetString("remark")
  10074. timeLayout := "2006-01-02 15:04"
  10075. loc, _ := time.LoadLocation("Local")
  10076. if len(startTime) == 0 {
  10077. utils.ErrorLog("len(start_time) == 0")
  10078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10079. return
  10080. }
  10081. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  10082. if err != nil {
  10083. utils.ErrorLog(err.Error())
  10084. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10085. return
  10086. }
  10087. StartTime := theTime.Unix()
  10088. fmt.Println("startime-------------", StartTime)
  10089. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  10090. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  10091. information := models.XtDialysisInformation{
  10092. Module: module,
  10093. PatientId: patient_id,
  10094. RecordDate: record_date,
  10095. ApplicationDate: StartTime,
  10096. Creater: creater,
  10097. ApplicationStatus: 2,
  10098. Checker: 0,
  10099. CheckTime: 0,
  10100. Remark: remark,
  10101. UserOrgId: user_org_id,
  10102. Ctime: time.Now().Unix(),
  10103. Status: 1,
  10104. Mtime: 0,
  10105. }
  10106. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  10107. if infor.ID == 0 {
  10108. service.SaveDialysisInformation(information)
  10109. }
  10110. if infor.ID > 0 {
  10111. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  10112. }
  10113. this.ServeSuccessJSON(map[string]interface{}{
  10114. "information": information,
  10115. })
  10116. return
  10117. }
  10118. func (this *DialysisAPIController) GetMobileInformation() {
  10119. limit, _ := this.GetInt64("limit")
  10120. page, _ := this.GetInt64("page")
  10121. orgid := this.GetMobileAdminUserInfo().Org.Id
  10122. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  10123. appid := this.GetMobileAdminUserInfo().App.Id
  10124. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10125. patients, _ := service.GetAllpatientThirty(orgid)
  10126. this.ServeSuccessJSON(map[string]interface{}{
  10127. "information": information,
  10128. "total": total,
  10129. "doclist": doclist,
  10130. "patients": patients,
  10131. })
  10132. return
  10133. }
  10134. func (this *DialysisAPIController) GetMobileInformationOne() {
  10135. limit, _ := this.GetInt64("limit")
  10136. page, _ := this.GetInt64("page")
  10137. orgid := this.GetMobileAdminUserInfo().Org.Id
  10138. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  10139. appid := this.GetMobileAdminUserInfo().App.Id
  10140. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10141. patients, _ := service.GetAllpatientThirty(orgid)
  10142. this.ServeSuccessJSON(map[string]interface{}{
  10143. "information": information,
  10144. "total": total,
  10145. "doclist": doclist,
  10146. "patients": patients,
  10147. })
  10148. return
  10149. }
  10150. func (this *DialysisAPIController) CheckMobileInformation() {
  10151. id, _ := this.GetInt64("id")
  10152. application_status, _ := this.GetInt64("application_status")
  10153. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  10154. checktime := time.Now().Unix()
  10155. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  10156. if err == nil {
  10157. this.ServeSuccessJSON(map[string]interface{}{
  10158. "msg": "ok",
  10159. })
  10160. return
  10161. }
  10162. }
  10163. func (c *DialysisAPIController) GetControlMonitorList() {
  10164. partition, _ := c.GetInt64("partition")
  10165. monitorDate := c.GetString("date")
  10166. patient_id, _ := c.GetInt64("patient_id")
  10167. pat_type, _ := c.GetInt64("pat_type")
  10168. timeLayout := "2006-01-02"
  10169. loc, _ := time.LoadLocation("Local")
  10170. var theStartTime int64
  10171. if len(monitorDate) > 0 {
  10172. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  10173. if err != nil {
  10174. theStartTime = 0
  10175. }
  10176. theStartTime = theTime.Unix()
  10177. }
  10178. adminInfo := c.GetMobileAdminUserInfo()
  10179. orgID := adminInfo.Org.Id
  10180. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  10181. if err != nil {
  10182. c.ErrorLog("获取排班信息失败:%v", err)
  10183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10184. } else {
  10185. if len(monitor) > 0 {
  10186. //获取所有床位
  10187. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  10188. //获取所有分区
  10189. zoneList, _ := service.GetAllZoneByList(orgID)
  10190. //获取透析处方
  10191. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  10192. //获取透前评估
  10193. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10194. //获取上机
  10195. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10196. //获取透后
  10197. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10198. //获取透后监测
  10199. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10200. //获取所有的患者
  10201. patients, _ := service.GetAllPatientListByListOne(orgID)
  10202. //获取所有透析模式
  10203. treatments, _ := service.GetAllTreatModeByList(orgID)
  10204. //获取所有医嘱
  10205. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10206. //获取双人核对
  10207. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10208. //治疗小结
  10209. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10210. //待消毒
  10211. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10212. for key, item := range monitor {
  10213. // 获取床位信息
  10214. for _, it := range numberList {
  10215. if item.BedId == it.ID {
  10216. monitor[key].DeviceNumber = it
  10217. break
  10218. }
  10219. }
  10220. //获取分区信息
  10221. for _, it := range zoneList {
  10222. if item.PartitionId == it.ID {
  10223. monitor[key].DeviceZone = it
  10224. }
  10225. }
  10226. for _, prescription := range prescriptions {
  10227. if item.PatientId == prescription.PatientId {
  10228. monitor[key].Prescription = prescription
  10229. break
  10230. }
  10231. }
  10232. for _, it := range checkList {
  10233. if item.PatientId == it.PatientId {
  10234. monitor[key].DoubleCheck = it
  10235. break
  10236. }
  10237. }
  10238. for _, it := range summaryList {
  10239. if item.PatientId == it.PatientId {
  10240. monitor[key].TreatmentSummaryForList = it
  10241. break
  10242. }
  10243. }
  10244. // 透前评估
  10245. for _, assessmentBefore := range assessmentBefores {
  10246. if item.PatientId == assessmentBefore.PatientId {
  10247. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10248. break
  10249. }
  10250. }
  10251. // 透析上下机
  10252. for _, dialysisOrder := range dialysisOrders {
  10253. if item.PatientId == dialysisOrder.PatientId {
  10254. monitor[key].DialysisOrder = dialysisOrder
  10255. break
  10256. }
  10257. }
  10258. // 治疗小节
  10259. for _, afterDislysis := range AssessmentAfterDislysis {
  10260. if item.PatientId == afterDislysis.PatientId {
  10261. monitor[key].AssessmentAfterDislysis = afterDislysis
  10262. break
  10263. }
  10264. }
  10265. for _, it := range monitorlist {
  10266. if item.PatientId == it.PatientId {
  10267. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10268. }
  10269. }
  10270. for _, it := range adviceList {
  10271. if item.PatientId == it.PatientId {
  10272. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10273. }
  10274. }
  10275. for _, patient := range patients {
  10276. if item.PatientId == patient.ID {
  10277. monitor[key].MonitorPatients = patient
  10278. break
  10279. }
  10280. }
  10281. for _, treatment := range treatments {
  10282. if item.ModeId == treatment.ID {
  10283. monitor[key].TreatmentMode = treatment
  10284. break
  10285. }
  10286. }
  10287. for _, infor := range informationList {
  10288. if item.PatientId == infor.PatientId {
  10289. monitor[key].NewDeviceInformation = infor
  10290. break
  10291. }
  10292. }
  10293. }
  10294. }
  10295. }
  10296. patients, err := service.GetAllpatientFourty(orgID)
  10297. var mds []*models.NewMonitorDialysisScheduleList
  10298. if pat_type == 0 {
  10299. for _, item := range monitor {
  10300. mds = append(mds, item)
  10301. }
  10302. }
  10303. //待医嘱核对
  10304. if pat_type == 1 {
  10305. for _, item := range monitor {
  10306. if len(item.AdviceList) > 0 {
  10307. mds = append(mds, item)
  10308. }
  10309. }
  10310. }
  10311. //待开小结
  10312. if pat_type == 2 {
  10313. for _, item := range monitor {
  10314. if item.TreatmentSummaryForList == nil {
  10315. mds = append(mds, item)
  10316. }
  10317. }
  10318. }
  10319. //待下机
  10320. if pat_type == 3 {
  10321. for _, item := range monitor {
  10322. if item.DialysisOrder != nil {
  10323. if item.DialysisOrder.ID > 0 {
  10324. mds = append(mds, item)
  10325. }
  10326. }
  10327. }
  10328. }
  10329. //待消毒
  10330. if pat_type == 4 {
  10331. for _, item := range monitor {
  10332. if item.NewDeviceInformation == nil {
  10333. mds = append(mds, item)
  10334. }
  10335. }
  10336. }
  10337. //待双人核对
  10338. if pat_type == 5 {
  10339. for _, item := range monitor {
  10340. if item.DoubleCheck == nil {
  10341. mds = append(mds, item)
  10342. }
  10343. }
  10344. }
  10345. //医嘱未执行
  10346. if pat_type == 6 {
  10347. for _, item := range monitor {
  10348. if len(item.AdviceList) > 0 {
  10349. mds = append(mds, item)
  10350. }
  10351. }
  10352. }
  10353. //患者未签名
  10354. if pat_type == 7 {
  10355. for _, item := range monitor {
  10356. if item.DialysisOrder != nil {
  10357. if item.DialysisOrder.ID > 0 {
  10358. mds = append(mds, item)
  10359. }
  10360. }
  10361. }
  10362. }
  10363. //目标超滤于实际超滤不同
  10364. if pat_type == 8 {
  10365. for _, item := range monitor {
  10366. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10367. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10368. mds = append(mds, item)
  10369. }
  10370. }
  10371. }
  10372. }
  10373. //血压少于5次
  10374. if pat_type == 9 {
  10375. for _, item := range monitor {
  10376. if len(item.MonitoringRecord) < 5 {
  10377. mds = append(mds, item)
  10378. }
  10379. }
  10380. }
  10381. if pat_type == 13 {
  10382. for _, item := range monitor {
  10383. if len(item.MonitoringRecord) < 3 {
  10384. mds = append(mds, item)
  10385. }
  10386. }
  10387. }
  10388. if pat_type == 10 {
  10389. for _, item := range monitor {
  10390. if len(item.MonitoringRecord) == 0 {
  10391. mds = append(mds, item)
  10392. }
  10393. }
  10394. }
  10395. if pat_type == 11 {
  10396. for _, item := range monitor {
  10397. if len(item.MonitoringRecord) > 0 {
  10398. mds = append(mds, item)
  10399. }
  10400. }
  10401. }
  10402. if pat_type == 12 {
  10403. for _, item := range monitor {
  10404. if len(item.MonitoringRecord) > 0 {
  10405. mds = append(mds, item)
  10406. }
  10407. }
  10408. }
  10409. if err == nil {
  10410. c.ServeSuccessJSON(map[string]interface{}{
  10411. "monitor": mds,
  10412. "patients": patients,
  10413. })
  10414. } else {
  10415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10416. }
  10417. }
  10418. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10419. admin_user_id, _ := c.GetInt64("admin_user_id")
  10420. timeStr := time.Now().Format("2006-01-02")
  10421. timeLayout := "2006-01-02 15:04:05"
  10422. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10423. timenow := timeStringToTime.Unix()
  10424. orgId := c.GetMobileAdminUserInfo().Org.Id
  10425. //查询当前护士的患者
  10426. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10427. var patientIds []int64
  10428. for _, item := range orderList {
  10429. patientIds = append(patientIds, item.PatientId)
  10430. }
  10431. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10432. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10433. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10434. //药品管理信息
  10435. _, drugStockConfig := service.FindHisConfig(orgId)
  10436. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10437. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10438. c.ServeSuccessJSON(map[string]interface{}{
  10439. "adviceList": adviceList,
  10440. "hisAdviceList": hisAdviceList,
  10441. "projectList": projectList,
  10442. "drugStockConfig": drugStockConfig,
  10443. "patientList": patientList,
  10444. "projectConfig": projectConfig,
  10445. })
  10446. }
  10447. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10448. patient_id, _ := c.GetInt64("patient_id")
  10449. org_id := c.GetMobileAdminUserInfo().Org.Id
  10450. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10451. c.ServeSuccessJSON(map[string]interface{}{
  10452. "recrods": recrods,
  10453. })
  10454. }
  10455. func (c *DialysisAPIController) ExMobileChangeSch() {
  10456. id_one, _ := c.GetInt64("id_one")
  10457. id_two, _ := c.GetInt64("id_two")
  10458. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10459. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10460. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10461. //if order2.ID > 0 {
  10462. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10463. // return
  10464. //}
  10465. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10466. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10467. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10468. if count > 0 {
  10469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10470. return
  10471. }
  10472. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10473. if count1 > 0 {
  10474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10475. return
  10476. }
  10477. }
  10478. err := service.UpdateScheduleThree(sch, sch_two)
  10479. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10480. if order.ID > 0 {
  10481. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10482. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10483. redis := service.RedisClient()
  10484. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10485. redis.Set(key, "", time.Second)
  10486. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10487. //清空key 值
  10488. redis.Set(keyOne, "", time.Second)
  10489. }
  10490. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10491. if orderOne.ID > 0 {
  10492. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10493. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10494. redis := service.RedisClient()
  10495. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10496. redis.Set(key, "", time.Second)
  10497. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10498. //清空key 值
  10499. redis.Set(keyOne, "", time.Second)
  10500. }
  10501. if err == nil {
  10502. //去除当天患者排班中重复数据,保留最后一条数据
  10503. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10504. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10505. c.ServeSuccessJSON(map[string]interface{}{
  10506. "msg": "交换成功",
  10507. })
  10508. } else {
  10509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10510. return
  10511. }
  10512. }
  10513. func (c *DialysisAPIController) MobileCoverSch() {
  10514. id_one, _ := c.GetInt64("id_one")
  10515. id_two, _ := c.GetInt64("id_two")
  10516. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10517. //针对凤凰医院
  10518. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10519. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10520. if len(advice) > 0 {
  10521. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10522. }
  10523. }
  10524. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10525. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10526. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10527. if len(hisAdvice) > 0 {
  10528. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10529. }
  10530. if len(project) > 0 {
  10531. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10532. }
  10533. }
  10534. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10535. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10536. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10537. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10538. if count > 0 {
  10539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10540. return
  10541. }
  10542. }
  10543. var new_sch models.Schedule
  10544. new_sch = sch
  10545. new_sch.BedId = sch_two.BedId
  10546. new_sch.ScheduleDate = sch_two.ScheduleDate
  10547. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10548. new_sch.PartitionId = sch_two.PartitionId
  10549. new_sch.ScheduleType = sch_two.ScheduleType
  10550. new_sch.ID = 0
  10551. //删除原来的排班
  10552. err := service.SaveSchTwo(sch, sch_two)
  10553. //生成新的排班
  10554. if err == nil {
  10555. err2 := service.SaveSch(&new_sch)
  10556. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10557. if order.ID > 0 {
  10558. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10559. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10560. redis := service.RedisClient()
  10561. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10562. redis.Set(key, "", time.Second)
  10563. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10564. //清空key 值
  10565. redis.Set(keyOne, "", time.Second)
  10566. }
  10567. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10568. if orderOne.ID > 0 {
  10569. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10570. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10571. redis := service.RedisClient()
  10572. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10573. redis.Set(key, "", time.Second)
  10574. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10575. //清空key 值
  10576. redis.Set(keyOne, "", time.Second)
  10577. }
  10578. if err2 == nil {
  10579. //去除当天患者排班中重复数据,保留最后一条数据
  10580. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10581. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10582. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10583. c.ServeSuccessJSON(map[string]interface{}{
  10584. "msg": "覆盖成功",
  10585. "new_sch": new_sch,
  10586. })
  10587. } else {
  10588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10589. return
  10590. }
  10591. } else {
  10592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10593. return
  10594. }
  10595. }
  10596. func (c *DialysisAPIController) BatchCheckAdvice() {
  10597. patient_id, _ := c.GetInt64("patient_id")
  10598. advice_date, _ := c.GetInt64("advice_date")
  10599. org_id := c.GetMobileAdminUserInfo().Org.Id
  10600. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10601. //查询是his系统还是血透系统
  10602. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10603. //his客户
  10604. if configs.IsOpen == 1 {
  10605. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10606. for _, item := range adviceList {
  10607. service.BatchCheckHisAdvice(item.ID, creater)
  10608. }
  10609. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10610. for _, item := range projectList {
  10611. service.BatchCheckProject(item.ID, creater)
  10612. }
  10613. c.ServeSuccessJSON(map[string]interface{}{
  10614. "adviceList": adviceList,
  10615. "projectList": projectList,
  10616. })
  10617. }
  10618. if configs.IsOpen != 1 {
  10619. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10620. for _, item := range adviceList {
  10621. service.BatchAdviceList(item.ID, creater)
  10622. }
  10623. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10624. for _, item := range projectList {
  10625. service.BatchCheckProject(item.ID, creater)
  10626. }
  10627. c.ServeSuccessJSON(map[string]interface{}{
  10628. "adviceList": adviceList,
  10629. "projectList": projectList,
  10630. })
  10631. }
  10632. return
  10633. }
  10634. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10635. org_id := c.GetMobileAdminUserInfo().Org.Id
  10636. drugList, _ := service.GetAllDrugList(org_id)
  10637. c.ServeSuccessJSON(map[string]interface{}{
  10638. "drugList": drugList,
  10639. })
  10640. }
  10641. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10642. org_id := c.GetMobileAdminUserInfo().Org.Id
  10643. dataBody := make(map[string]interface{}, 0)
  10644. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10645. if err != nil {
  10646. utils.ErrorLog(err.Error())
  10647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10648. return
  10649. }
  10650. timeLayout := "2006-01-02"
  10651. loc, _ := time.LoadLocation("Local")
  10652. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10653. utils.ErrorLog("advice_type")
  10654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10655. return
  10656. }
  10657. adviceType := int64(dataBody["advice_type"].(float64))
  10658. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10659. utils.ErrorLog("start_time")
  10660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10661. return
  10662. }
  10663. startTime2, _ := dataBody["start_time"].(string)
  10664. time_arr := strings.Split(startTime2, " ")
  10665. if len(time_arr) > 0 {
  10666. startTime2 = time_arr[0]
  10667. }
  10668. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10669. utils.ErrorLog("advice_date")
  10670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10671. return
  10672. }
  10673. advice_date, _ := dataBody["advice_date"].(string)
  10674. var advicedateunix int64
  10675. if len(advice_date) > 0 {
  10676. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10677. if err != nil {
  10678. fmt.Println(err)
  10679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10680. return
  10681. }
  10682. advicedateunix = theTime.Unix()
  10683. }
  10684. adviceDate := startTime2
  10685. if len(adviceDate) == 0 {
  10686. utils.ErrorLog("len(adviceDate) == 0")
  10687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10688. return
  10689. }
  10690. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10691. if err != nil {
  10692. utils.ErrorLog(err.Error())
  10693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10694. return
  10695. }
  10696. AdviceDate := advicedateunix
  10697. RecordDate := advicedateunix
  10698. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10699. utils.ErrorLog("start_time")
  10700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10701. return
  10702. }
  10703. startTime, _ := dataBody["start_time"].(string)
  10704. if len(startTime) == 0 {
  10705. utils.ErrorLog("len(start_time) == 0")
  10706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10707. return
  10708. }
  10709. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10710. if err != nil {
  10711. utils.ErrorLog(err.Error())
  10712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10713. return
  10714. }
  10715. StartTime := theTime.Unix()
  10716. advice_name, _ := dataBody["advice_name"].(string)
  10717. advice_desc, _ := dataBody["advice_desc"].(string)
  10718. delivery_way, _ := dataBody["delivery_way"].(string)
  10719. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10720. frequency_type := int64(dataBody["frequency_type"].(float64))
  10721. frequency_week, _ := dataBody["frequency_week"].(string)
  10722. prescribing_number := dataBody["prescribing_number"].(float64)
  10723. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10724. remark := dataBody["remark"].(string)
  10725. single_dose := dataBody["single_dose"].(float64)
  10726. single_dose_unit := dataBody["single_dose_unit"].(string)
  10727. patient_id := int64(dataBody["patient_id"].(float64))
  10728. day_count := int64(dataBody["day_count"].(float64))
  10729. groupNo := int64(dataBody["group_no"].(float64))
  10730. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10731. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10732. if groupNo <= 0 {
  10733. group := service.GetMaxAdviceGroupID(org_id)
  10734. groupNo = group + 1
  10735. }
  10736. var template_id = ""
  10737. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10738. template_id = "M" + adviceLastId
  10739. advice := models.DoctorAdvice{
  10740. UserOrgId: org_id,
  10741. PatientId: patient_id,
  10742. AdviceType: adviceType,
  10743. AdviceDate: AdviceDate,
  10744. StartTime: StartTime,
  10745. AdviceName: advice_name,
  10746. AdviceDesc: advice_desc,
  10747. ReminderDate: 0,
  10748. SingleDose: single_dose,
  10749. SingleDoseUnit: single_dose_unit,
  10750. DrugSpec: 0,
  10751. DrugSpecUnit: "",
  10752. PrescribingNumber: prescribing_number,
  10753. PrescribingNumberUnit: prescribing_number_unit,
  10754. DeliveryWay: delivery_way,
  10755. ExecutionFrequency: execution_frequency,
  10756. AdviceDoctor: advice_doctor,
  10757. Status: 1,
  10758. CreatedTime: time.Now().Unix(),
  10759. UpdatedTime: 0,
  10760. AdviceAffirm: "",
  10761. Remark: remark,
  10762. StopTime: 0,
  10763. StopReason: "",
  10764. StopDoctor: 0,
  10765. StopState: 2,
  10766. ParentId: 0,
  10767. ExecutionTime: 0,
  10768. ExecutionStaff: 0,
  10769. ExecutionState: 0,
  10770. Checker: 0,
  10771. RecordDate: RecordDate,
  10772. DialysisOrderId: 0,
  10773. CheckTime: 0,
  10774. CheckState: 0,
  10775. AdviceId: 0,
  10776. RemindType: 0,
  10777. FrequencyType: frequency_type,
  10778. DayCount: day_count,
  10779. WeekDay: frequency_week,
  10780. ChildDoctorAdvice: nil,
  10781. TemplateId: template_id,
  10782. Modifier: 0,
  10783. IsCheck: 0,
  10784. Way: 0,
  10785. DrugId: 0,
  10786. DrugNameId: 0,
  10787. IsMedicine: 0,
  10788. PushStartTime: 0,
  10789. IsSettle: 0,
  10790. IsPrescription: 0,
  10791. GroupNo: groupNo,
  10792. }
  10793. service.CreateMobileAdivce(advice)
  10794. c.ServeSuccessJSON(map[string]interface{}{
  10795. "msg": "保存成功!",
  10796. })
  10797. }
  10798. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10799. patient_id, _ := c.GetInt64("patient_id")
  10800. org_id := c.GetMobileAdminUserInfo().Org.Id
  10801. app_id := c.GetMobileAdminUserInfo().App.Id
  10802. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10803. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10804. c.ServeSuccessJSON(map[string]interface{}{
  10805. "adviceList": adviceList,
  10806. "adminRoles": adminRoles,
  10807. })
  10808. }
  10809. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10810. org_id := c.GetMobileAdminUserInfo().Org.Id
  10811. dataBody := make(map[string]interface{}, 0)
  10812. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10813. if err != nil {
  10814. utils.ErrorLog(err.Error())
  10815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10816. return
  10817. }
  10818. timeLayout := "2006-01-02"
  10819. loc, _ := time.LoadLocation("Local")
  10820. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10821. utils.ErrorLog("start_time")
  10822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10823. return
  10824. }
  10825. startTime2, _ := dataBody["start_time"].(string)
  10826. time_arr := strings.Split(startTime2, " ")
  10827. if len(time_arr) > 0 {
  10828. startTime2 = time_arr[0]
  10829. }
  10830. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10831. utils.ErrorLog("advice_date")
  10832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10833. return
  10834. }
  10835. advice_date, _ := dataBody["advice_date"].(string)
  10836. var advicedateunix int64
  10837. if len(advice_date) > 0 {
  10838. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10839. if err != nil {
  10840. fmt.Println(err)
  10841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10842. return
  10843. }
  10844. advicedateunix = theTime.Unix()
  10845. }
  10846. adviceDate := startTime2
  10847. if len(adviceDate) == 0 {
  10848. utils.ErrorLog("len(adviceDate) == 0")
  10849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10850. return
  10851. }
  10852. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10853. if err != nil {
  10854. utils.ErrorLog(err.Error())
  10855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10856. return
  10857. }
  10858. AdviceDate := advicedateunix
  10859. RecordDate := advicedateunix
  10860. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10861. utils.ErrorLog("start_time")
  10862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10863. return
  10864. }
  10865. startTime, _ := dataBody["start_time"].(string)
  10866. if len(startTime) == 0 {
  10867. utils.ErrorLog("len(start_time) == 0")
  10868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10869. return
  10870. }
  10871. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10872. if err != nil {
  10873. utils.ErrorLog(err.Error())
  10874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10875. return
  10876. }
  10877. StartTime := theTime.Unix()
  10878. advice_name, _ := dataBody["advice_name"].(string)
  10879. advice_desc, _ := dataBody["advice_desc"].(string)
  10880. delivery_way, _ := dataBody["delivery_way"].(string)
  10881. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10882. prescribing_number := dataBody["prescribing_number"].(float64)
  10883. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10884. remark := dataBody["remark"].(string)
  10885. single_dose := dataBody["single_dose"].(float64)
  10886. single_dose_unit := dataBody["single_dose_unit"].(string)
  10887. patient_id := int64(dataBody["patient_id"].(float64))
  10888. groupNo := int64(dataBody["group_no"].(float64))
  10889. parent_id := int64(dataBody["parent_id"].(float64))
  10890. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10891. advice := models.XtDoctorAdviceOne{
  10892. UserOrgId: org_id,
  10893. PatientId: patient_id,
  10894. AdviceType: 1,
  10895. AdviceDate: AdviceDate,
  10896. StartTime: StartTime,
  10897. AdviceName: advice_name,
  10898. AdviceDesc: advice_desc,
  10899. ReminderDate: 0,
  10900. SingleDose: single_dose,
  10901. SingleDoseUnit: single_dose_unit,
  10902. PrescribingNumber: prescribing_number,
  10903. PrescribingNumberUnit: prescribing_number_unit,
  10904. DeliveryWay: delivery_way,
  10905. ExecutionFrequency: execution_frequency,
  10906. AdviceDoctor: advice_doctor,
  10907. Status: 1,
  10908. CreatedTime: time.Now().Unix(),
  10909. UpdatedTime: time.Now().Unix(),
  10910. AdviceAffirm: "",
  10911. Remark: remark,
  10912. StopTime: 0,
  10913. StopReason: "",
  10914. StopDoctor: 0,
  10915. StopState: 2,
  10916. ParentId: parent_id,
  10917. ExecutionTime: 0,
  10918. ExecutionStaff: 0,
  10919. ExecutionState: 0,
  10920. Checker: 0,
  10921. RecordDate: RecordDate,
  10922. DialysisOrderId: 0,
  10923. CheckTime: 0,
  10924. CheckState: 0,
  10925. DrugSpec: 0,
  10926. DrugSpecUnit: "",
  10927. Groupno: groupNo,
  10928. RemindType: 0,
  10929. FrequencyType: 0,
  10930. DayCount: 0,
  10931. WeekDay: "",
  10932. TemplateId: "",
  10933. Modifier: 0,
  10934. }
  10935. service.CreateMobileAdivceOne(advice)
  10936. c.ServeSuccessJSON(map[string]interface{}{
  10937. "msg": "保存成功!",
  10938. })
  10939. }
  10940. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10941. id, _ := c.GetInt64("id")
  10942. service.DeleteSelfAdviceSubAdvice(id)
  10943. c.ServeSuccessJSON(map[string]interface{}{
  10944. "msg": "保存成功!",
  10945. })
  10946. }
  10947. func (c *DialysisAPIController) GetEditAdviceAction() {
  10948. id, _ := c.GetInt64("id")
  10949. org_id := c.GetMobileAdminUserInfo().Org.Id
  10950. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10951. drugList, _ := service.GetAllDrugList(org_id)
  10952. c.ServeSuccessJSON(map[string]interface{}{
  10953. "advice": advice,
  10954. "drugList": drugList,
  10955. })
  10956. }
  10957. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10958. dataBody := make(map[string]interface{}, 0)
  10959. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10960. if err != nil {
  10961. utils.ErrorLog(err.Error())
  10962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10963. return
  10964. }
  10965. timeLayout := "2006-01-02"
  10966. loc, _ := time.LoadLocation("Local")
  10967. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10968. utils.ErrorLog("start_time")
  10969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10970. return
  10971. }
  10972. startTime2, _ := dataBody["start_time"].(string)
  10973. time_arr := strings.Split(startTime2, " ")
  10974. if len(time_arr) > 0 {
  10975. startTime2 = time_arr[0]
  10976. }
  10977. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10978. utils.ErrorLog("advice_date")
  10979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10980. return
  10981. }
  10982. advice_date, _ := dataBody["advice_date"].(string)
  10983. var advicedateunix int64
  10984. if len(advice_date) > 0 {
  10985. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10986. if err != nil {
  10987. fmt.Println(err)
  10988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10989. return
  10990. }
  10991. advicedateunix = theTime.Unix()
  10992. }
  10993. adviceDate := startTime2
  10994. if len(adviceDate) == 0 {
  10995. utils.ErrorLog("len(adviceDate) == 0")
  10996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10997. return
  10998. }
  10999. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11000. if err != nil {
  11001. utils.ErrorLog(err.Error())
  11002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11003. return
  11004. }
  11005. AdviceDate := advicedateunix
  11006. RecordDate := advicedateunix
  11007. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11008. utils.ErrorLog("start_time")
  11009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11010. return
  11011. }
  11012. startTime, _ := dataBody["start_time"].(string)
  11013. if len(startTime) == 0 {
  11014. utils.ErrorLog("len(start_time) == 0")
  11015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11016. return
  11017. }
  11018. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11019. if err != nil {
  11020. utils.ErrorLog(err.Error())
  11021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11022. return
  11023. }
  11024. StartTime := theTime.Unix()
  11025. advice_name, _ := dataBody["advice_name"].(string)
  11026. advice_desc, _ := dataBody["advice_desc"].(string)
  11027. delivery_way, _ := dataBody["delivery_way"].(string)
  11028. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11029. prescribing_number := dataBody["prescribing_number"].(float64)
  11030. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11031. remark := dataBody["remark"].(string)
  11032. single_dose := dataBody["single_dose"].(float64)
  11033. single_dose_unit := dataBody["single_dose_unit"].(string)
  11034. id := int64(dataBody["id"].(float64))
  11035. frequency_type := int64(dataBody["frequency_type"].(float64))
  11036. frequency_week, _ := dataBody["frequency_week"].(string)
  11037. day_count := int64(dataBody["day_count"].(float64))
  11038. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11039. advice := models.XtDoctorAdviceOne{
  11040. AdviceDate: AdviceDate,
  11041. StartTime: StartTime,
  11042. AdviceName: advice_name,
  11043. AdviceDesc: advice_desc,
  11044. SingleDose: single_dose,
  11045. SingleDoseUnit: single_dose_unit,
  11046. PrescribingNumber: prescribing_number,
  11047. PrescribingNumberUnit: prescribing_number_unit,
  11048. DeliveryWay: delivery_way,
  11049. ExecutionFrequency: execution_frequency,
  11050. AdviceDoctor: advice_doctor,
  11051. Remark: remark,
  11052. RecordDate: RecordDate,
  11053. FrequencyType: frequency_type,
  11054. DayCount: day_count,
  11055. WeekDay: frequency_week,
  11056. }
  11057. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  11058. c.ServeSuccessJSON(map[string]interface{}{
  11059. "advice": advice,
  11060. })
  11061. }
  11062. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  11063. dataBody := make(map[string]interface{}, 0)
  11064. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11065. if err != nil {
  11066. utils.ErrorLog(err.Error())
  11067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11068. return
  11069. }
  11070. timeLayout := "2006-01-02"
  11071. loc, _ := time.LoadLocation("Local")
  11072. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11073. utils.ErrorLog("start_time")
  11074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11075. return
  11076. }
  11077. startTime2, _ := dataBody["start_time"].(string)
  11078. time_arr := strings.Split(startTime2, " ")
  11079. if len(time_arr) > 0 {
  11080. startTime2 = time_arr[0]
  11081. }
  11082. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11083. utils.ErrorLog("advice_date")
  11084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11085. return
  11086. }
  11087. advice_date, _ := dataBody["advice_date"].(string)
  11088. var advicedateunix int64
  11089. if len(advice_date) > 0 {
  11090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11091. if err != nil {
  11092. fmt.Println(err)
  11093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11094. return
  11095. }
  11096. advicedateunix = theTime.Unix()
  11097. }
  11098. adviceDate := startTime2
  11099. if len(adviceDate) == 0 {
  11100. utils.ErrorLog("len(adviceDate) == 0")
  11101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11102. return
  11103. }
  11104. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11105. if err != nil {
  11106. utils.ErrorLog(err.Error())
  11107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11108. return
  11109. }
  11110. AdviceDate := advicedateunix
  11111. RecordDate := advicedateunix
  11112. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11113. utils.ErrorLog("start_time")
  11114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11115. return
  11116. }
  11117. startTime, _ := dataBody["start_time"].(string)
  11118. if len(startTime) == 0 {
  11119. utils.ErrorLog("len(start_time) == 0")
  11120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11121. return
  11122. }
  11123. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11124. if err != nil {
  11125. utils.ErrorLog(err.Error())
  11126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11127. return
  11128. }
  11129. StartTime := theTime.Unix()
  11130. advice_name, _ := dataBody["advice_name"].(string)
  11131. advice_desc, _ := dataBody["advice_desc"].(string)
  11132. delivery_way, _ := dataBody["delivery_way"].(string)
  11133. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11134. prescribing_number := dataBody["prescribing_number"].(float64)
  11135. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11136. remark := dataBody["remark"].(string)
  11137. single_dose := dataBody["single_dose"].(float64)
  11138. single_dose_unit := dataBody["single_dose_unit"].(string)
  11139. id := int64(dataBody["id"].(float64))
  11140. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11141. advice := models.XtDoctorAdviceOne{
  11142. AdviceDate: AdviceDate,
  11143. StartTime: StartTime,
  11144. AdviceName: advice_name,
  11145. AdviceDesc: advice_desc,
  11146. SingleDose: single_dose,
  11147. SingleDoseUnit: single_dose_unit,
  11148. PrescribingNumber: prescribing_number,
  11149. PrescribingNumberUnit: prescribing_number_unit,
  11150. DeliveryWay: delivery_way,
  11151. ExecutionFrequency: execution_frequency,
  11152. AdviceDoctor: advice_doctor,
  11153. Remark: remark,
  11154. RecordDate: RecordDate,
  11155. }
  11156. service.UpdateMobileDoctorAdviceById(id, advice)
  11157. c.ServeSuccessJSON(map[string]interface{}{
  11158. "advice": advice,
  11159. })
  11160. }
  11161. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  11162. dataBody := make(map[string]interface{}, 0)
  11163. timeLayout := "2006-01-02"
  11164. loc, _ := time.LoadLocation("Local")
  11165. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11166. if err != nil {
  11167. utils.ErrorLog(err.Error())
  11168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11169. return
  11170. }
  11171. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11172. utils.ErrorLog("start_time")
  11173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11174. return
  11175. }
  11176. startTime2, _ := dataBody["start_time"].(string)
  11177. time_arr := strings.Split(startTime2, " ")
  11178. if len(time_arr) > 0 {
  11179. startTime2 = time_arr[0]
  11180. }
  11181. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11182. utils.ErrorLog("advice_date")
  11183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11184. return
  11185. }
  11186. advice_date, _ := dataBody["advice_date"].(string)
  11187. var advicedateunix int64
  11188. if len(advice_date) > 0 {
  11189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11190. if err != nil {
  11191. fmt.Println(err)
  11192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11193. return
  11194. }
  11195. advicedateunix = theTime.Unix()
  11196. }
  11197. adviceDate := startTime2
  11198. if len(adviceDate) == 0 {
  11199. utils.ErrorLog("len(adviceDate) == 0")
  11200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11201. return
  11202. }
  11203. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11204. if err != nil {
  11205. utils.ErrorLog(err.Error())
  11206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11207. return
  11208. }
  11209. RecordDate := advicedateunix
  11210. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11211. utils.ErrorLog("start_time")
  11212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11213. return
  11214. }
  11215. startTime, _ := dataBody["start_time"].(string)
  11216. if len(startTime) == 0 {
  11217. utils.ErrorLog("len(start_time) == 0")
  11218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11219. return
  11220. }
  11221. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11222. if err != nil {
  11223. utils.ErrorLog(err.Error())
  11224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11225. return
  11226. }
  11227. StartTime := theTime.Unix()
  11228. patient_id := int64(dataBody["patient_id"].(float64))
  11229. group_no := int64(dataBody["group_no"].(float64))
  11230. org_id := c.GetMobileAdminUserInfo().Org.Id
  11231. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11232. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11233. utils.ErrorLog("advices")
  11234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11235. return
  11236. }
  11237. adviceNames := dataBody["advices"].([]interface{})
  11238. var advices []*models.GroupAdvice
  11239. for _, adviceNameMap := range adviceNames {
  11240. var advice models.GroupAdvice
  11241. adviceNameM := adviceNameMap.(map[string]interface{})
  11242. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11243. utils.ErrorLog("advice_name")
  11244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11245. return
  11246. }
  11247. adviceName, _ := adviceNameM["advice_name"].(string)
  11248. if len(adviceName) == 0 {
  11249. utils.ErrorLog("len(advice_name) == 0")
  11250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11251. return
  11252. }
  11253. advice.AdviceName = adviceName
  11254. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11255. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11256. advice.DrugSpec = drugSpec
  11257. }
  11258. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11259. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11260. advice.AdviceDesc = adviceDesc
  11261. }
  11262. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11263. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11264. advice.DrugSpecUnit = drugSpecUnit
  11265. }
  11266. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11267. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11268. advice.SingleDose = singleDose
  11269. }
  11270. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11271. singleDose := adviceNameM["single_dose"].(float64)
  11272. advice.SingleDose = singleDose
  11273. }
  11274. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11275. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11276. advice.SingleDoseUnit = singleDoseUnit
  11277. }
  11278. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11279. tmp := adviceNameM["single_dose_unit"].(float64)
  11280. singleDoseUnit := service.TypeConversion(tmp)
  11281. advice.SingleDoseUnit = singleDoseUnit
  11282. }
  11283. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11284. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11285. advice.PrescribingNumber = prescribingNumber
  11286. }
  11287. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11288. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11289. advice.PrescribingNumber = prescribingNumber
  11290. }
  11291. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11292. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11293. advice.PrescribingNumberUnit = prescribingNumberUnit
  11294. }
  11295. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11296. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11297. advice.DeliveryWay = deliveryWay
  11298. }
  11299. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11300. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11301. advice.ExecutionFrequency = executionFrequency
  11302. }
  11303. remark, _ := adviceNameM["remark"].(string)
  11304. advice.Remark = remark
  11305. advice.AdviceType = 1
  11306. advice.StartTime = StartTime
  11307. advice.RecordDate = RecordDate
  11308. advice.PatientId = patient_id
  11309. advice.UserOrgId = org_id
  11310. advice.AdviceDoctor = advice_doctor
  11311. advice.StopState = 2
  11312. advices = append(advices, &advice)
  11313. }
  11314. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11315. c.ServeSuccessJSON(map[string]interface{}{
  11316. "advice": newAdvices,
  11317. })
  11318. }
  11319. func (c *DialysisAPIController) StopLongAdvice() {
  11320. stop_time := c.GetString("execution_time")
  11321. id, _ := c.GetInt64("id")
  11322. if len(stop_time) <= 0 {
  11323. utils.ErrorLog("stop_time")
  11324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11325. return
  11326. }
  11327. timeLayout2 := "2006-01-02 15:04:05"
  11328. loc, _ := time.LoadLocation("Local")
  11329. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11330. if errs != nil {
  11331. utils.ErrorLog(errs.Error())
  11332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11333. return
  11334. }
  11335. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11336. c.ServeSuccessJSON(map[string]interface{}{
  11337. "advice": advice,
  11338. })
  11339. }
  11340. func (c *DialysisAPIController) BatchAdviceCheckList() {
  11341. dataBody := make(map[string]interface{}, 0)
  11342. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11343. if err != nil {
  11344. utils.ErrorLog(err.Error())
  11345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11346. return
  11347. }
  11348. orgId := c.GetMobileAdminUserInfo().Org.Id
  11349. patient_id := int64(dataBody["patient_id"].(float64))
  11350. record_date := int64(dataBody["record_date"].(float64))
  11351. checker := int64(dataBody["checker"].(float64))
  11352. check_time := dataBody["check_time"].(string)
  11353. checkTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", check_time)
  11354. if parseStartDateErr != nil {
  11355. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11357. return
  11358. }
  11359. var advice_id []int64
  11360. var his_advice_id []int64
  11361. var project_id []int64
  11362. var team_list []int64
  11363. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11364. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11365. if len(newAdviceList) > 0 {
  11366. for _, item := range newAdviceList {
  11367. items := item.(map[string]interface{})
  11368. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11369. utils.ErrorLog("id")
  11370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11371. return
  11372. }
  11373. id := int64(items["id"].(float64))
  11374. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11375. utils.ErrorLog("origin")
  11376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11377. return
  11378. }
  11379. origin := int64(items["origin"].(float64))
  11380. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11381. utils.ErrorLog("team_id")
  11382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11383. return
  11384. }
  11385. team_id := int64(items["team_id"].(float64))
  11386. if team_id == 0 {
  11387. //临时医嘱
  11388. if origin == 1 {
  11389. service.BatchAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11390. advice_id = append(advice_id, id)
  11391. }
  11392. //his医嘱
  11393. if origin == 2 {
  11394. service.BatchHisAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11395. his_advice_id = append(his_advice_id, id)
  11396. }
  11397. //his医嘱
  11398. if origin == 3 {
  11399. service.BatchHisPrescriptionProject(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11400. project_id = append(project_id, id)
  11401. }
  11402. }
  11403. if team_id > 0 {
  11404. service.BatchCheckPrescriptionProject(patient_id, record_date, team_id, orgId, checker, checkTime.Unix())
  11405. team_list = append(team_list, team_id)
  11406. }
  11407. }
  11408. }
  11409. }
  11410. advice, _ := service.GetBatchAdviceList(advice_id)
  11411. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11412. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11413. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11414. c.ServeSuccessJSON(map[string]interface{}{
  11415. "advice": advice,
  11416. "hisadvice": hisadvice,
  11417. "hisproject": hisproject,
  11418. "teamlist": teamlist,
  11419. })
  11420. return
  11421. }
  11422. func (c *DialysisAPIController) BatchAdviceExeCutionList() {
  11423. dataBody := make(map[string]interface{}, 0)
  11424. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11425. if err != nil {
  11426. utils.ErrorLog(err.Error())
  11427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11428. return
  11429. }
  11430. orgId := c.GetMobileAdminUserInfo().Org.Id
  11431. patient_id := int64(dataBody["patient_id"].(float64))
  11432. record_date := int64(dataBody["record_date"].(float64))
  11433. execution_staff := int64(dataBody["execution_staff"].(float64))
  11434. execution_time := dataBody["execution_time"].(string)
  11435. executionTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  11436. if parseStartDateErr != nil {
  11437. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11439. return
  11440. }
  11441. var advice_id []int64
  11442. var his_advice_id []int64
  11443. var project_id []int64
  11444. var team_list []int64
  11445. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11446. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11447. if len(newAdviceList) > 0 {
  11448. for _, item := range newAdviceList {
  11449. items := item.(map[string]interface{})
  11450. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11451. utils.ErrorLog("id")
  11452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11453. return
  11454. }
  11455. id := int64(items["id"].(float64))
  11456. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11457. utils.ErrorLog("origin")
  11458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11459. return
  11460. }
  11461. origin := int64(items["origin"].(float64))
  11462. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11463. utils.ErrorLog("team_id")
  11464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11465. return
  11466. }
  11467. team_id := int64(items["team_id"].(float64))
  11468. if team_id == 0 {
  11469. //临时医嘱
  11470. if origin == 1 {
  11471. service.BatchExecutionAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11472. advice_id = append(advice_id, id)
  11473. }
  11474. //his医嘱
  11475. if origin == 2 {
  11476. service.BatchExecutionHisAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11477. his_advice_id = append(his_advice_id, id)
  11478. }
  11479. //his医嘱
  11480. if origin == 3 {
  11481. service.BatchExecutionHisPrescriptionProject(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11482. project_id = append(project_id, id)
  11483. }
  11484. }
  11485. if team_id > 0 {
  11486. service.BatchExecutionPrescriptionProject(patient_id, record_date, team_id, orgId, execution_staff, executionTime.Unix())
  11487. team_list = append(team_list, team_id)
  11488. }
  11489. }
  11490. }
  11491. }
  11492. advice, _ := service.GetBatchAdviceList(advice_id)
  11493. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11494. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11495. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11496. c.ServeSuccessJSON(map[string]interface{}{
  11497. "advice": advice,
  11498. "hisadvice": hisadvice,
  11499. "hisproject": hisproject,
  11500. "teamlist": teamlist,
  11501. })
  11502. return
  11503. }