dialysis_api_controller.go 382KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "math"
  13. "net/http"
  14. "net/url"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  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 stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. returnData := map[string]interface{}{
  503. "patient": patient,
  504. "schedual": schedual,
  505. "prescription": dialysisPrescribe,
  506. "solution": dialysisSolution,
  507. "last_prescription": lastDialysisPrescribe,
  508. "receiver_treatment_access": receiverTreatmentAccess,
  509. "predialysis_evaluation": predialysisEvaluation,
  510. "doctor_advices": doctorAdvices,
  511. "double_check": doubleCheck,
  512. "assessment_after_dislysis": assessmentAfterDislysis,
  513. "treatment_summary": treatmentSummary,
  514. "monitor_records": monitorRecords,
  515. "dialysis_order": dialysisOrder,
  516. "operators": operators,
  517. "last_predialysis_evaluation": lastPredialysisEvaluation,
  518. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  519. "last_monitor_record": lastMonitorRecord,
  520. "config": gobalConfig,
  521. "dry_weight": lastDryWeightDislysis,
  522. "system_prescription": systemDialysisPrescribe,
  523. "his_advices": his_advices,
  524. "is_open_config": is_open_config,
  525. "stockType": stockType,
  526. "prepare": prepare,
  527. "lastAssessment": lastAssessment,
  528. "prescribeOne": prescribeOne,
  529. "is_project_open_config": is_project_open_config,
  530. "project": projects,
  531. "team_projects": team_projects,
  532. "is_advice_open": is_advice_open,
  533. "prescription_open": prescriptionConfig.IsOpen,
  534. "lastOrder": lastOrder,
  535. "remind_lists": remind_lists,
  536. "lastDialysisPrescription": lastDialysisPrescription,
  537. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  538. "dryWeightList": dryWeightList,
  539. }
  540. this.ServeSuccessJSON(returnData)
  541. }
  542. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  543. adminInfo := c.GetMobileAdminUserInfo()
  544. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  545. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  546. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  547. returnData := map[string]interface{}{
  548. "admin_users": adminUsers,
  549. "devices": devices,
  550. "device_numbers": device_numbers,
  551. }
  552. c.ServeSuccessJSON(returnData)
  553. }
  554. func (c *DialysisAPIController) PostAtreatmentInfo() {
  555. id, _ := c.GetInt64("patient", 0)
  556. recordDateStr := c.GetString("record_date")
  557. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  558. summaryContent := c.GetString("summaryContent")
  559. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  560. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  561. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  562. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  563. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  564. nursingRecord := c.GetString("nursing_record")
  565. fmt.Println("护理记录", nursingRecord)
  566. specialRecord := c.GetString("special_record")
  567. fmt.Println("特殊记录", specialRecord)
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  570. checkStaffId = adminUserInfo.AdminUser.Id
  571. deboardNurseId = adminUserInfo.AdminUser.Id
  572. treatDoctor = adminUserInfo.AdminUser.Id
  573. if id <= 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  578. if patient.ID == 0 {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  580. return
  581. }
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. summary := models.TreatmentSummary{
  592. UserOrgId: adminUserInfo.Org.Id,
  593. PatientId: id,
  594. AssessmentDate: recordDate.Unix(),
  595. Mission: propagandaAndEducationContent,
  596. DialysisSummary: summaryContent,
  597. SjNurse: changeMedicalNurseId,
  598. ZlNurse: treatNurseId,
  599. HdNurse: checkStaffId,
  600. XjNurse: deboardNurseId,
  601. ZlDoctor: treatDoctor,
  602. CreatedTime: time.Now().Unix(),
  603. Status: 1,
  604. NursingRecord: nursingRecord,
  605. SpecialRecord: specialRecord,
  606. }
  607. // 查询信息规挡的设置天数
  608. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  609. if infor.ID > 0 && infor.WeekDay > 0 {
  610. var cha_time int64
  611. timeNowStr := time.Now().Format("2006-01-02")
  612. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  613. //今日的日期减去设置的日期
  614. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  615. if cha_time >= recordDate.Unix() {
  616. //查询审核是否允许
  617. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  618. //申请状态不允许的情况 拒绝修改
  619. if infor.ApplicationStatus != 1 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  621. return
  622. }
  623. }
  624. }
  625. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  626. if treatmentSummary.ID == 0 { //新增
  627. summary.Creater = adminUserInfo.AdminUser.Id
  628. service.AddSigleSummaryRecord(&summary)
  629. finish := models.XtDialysisFinish{
  630. IsFinish: 1,
  631. UserOrgId: adminUserInfo.Org.Id,
  632. Status: 1,
  633. Ctime: time.Now().Unix(),
  634. Mtime: 0,
  635. Module: 10,
  636. RecordDate: recordDate.Unix(),
  637. Sourse: 1,
  638. PatientId: id,
  639. }
  640. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  641. if dialysisFinish.ID == 0 {
  642. service.CreateDialysisFinish(finish)
  643. }
  644. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  645. redis := service.RedisClient()
  646. //清空key 值
  647. redis.Set(key, "", time.Second)
  648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  649. redis.Set(keyOne, "", time.Second)
  650. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  651. redis.Set(keyThree, "", time.Second)
  652. defer redis.Close()
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "summary": summary,
  655. })
  656. } else { //修改
  657. summary.Creater = treatmentSummary.Creater
  658. summary.CreatedTime = treatmentSummary.CreatedTime
  659. summary.Modifier = adminUserInfo.AdminUser.Id
  660. summary.ID = treatmentSummary.ID
  661. service.UpdateSummeRecord(&summary)
  662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  663. redis := service.RedisClient()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  667. redis.Set(keyOne, "", time.Second)
  668. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  669. redis.Set(keyThree, "", time.Second)
  670. defer redis.Close()
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "summary": summary,
  673. })
  674. }
  675. }
  676. func (c *DialysisAPIController) PostDoubleCheck() {
  677. id, _ := c.GetInt64("patient", 0)
  678. recordDateStr := c.GetString("record_date")
  679. checkTimeStr := c.GetString("check_time")
  680. firstCheckTimeStr := c.GetString("first_check_time")
  681. creater, _ := c.GetInt64("creater", 0)
  682. modifier, _ := c.GetInt64("modifier", 0)
  683. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  684. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  685. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  686. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  687. dialysis_item_desc := c.GetString("dialysis_item_desc")
  688. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  689. vascular_access_desc := c.GetString("vascular_access_desc")
  690. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  691. collator, _ := c.GetInt64("collator", 0)
  692. employee_number := c.GetString("employee_number")
  693. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  694. needle_batch_number := c.GetString("needle_batch_number")
  695. if id <= 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetMobileAdminUserInfo()
  700. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  701. if patient.ID == 0 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  703. return
  704. }
  705. if len(recordDateStr) == 0 {
  706. recordDateStr = time.Now().Format("2006-01-02")
  707. }
  708. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  709. if parseDateErr != nil {
  710. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. var checkDate int64
  715. if len(checkTimeStr) == 0 {
  716. checkDate = 0
  717. } else {
  718. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  719. checkDate = checkDateUnix.Unix()
  720. }
  721. var firstCheckDate int64
  722. if len(firstCheckTimeStr) == 0 {
  723. firstCheckDate = 0
  724. } else {
  725. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  726. firstCheckDate = firstCheckDateUnix.Unix()
  727. }
  728. //if adminUserInfo.Org.Id == 10340 {
  729. //
  730. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  731. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  732. // if check.ID == 0 {
  733. // if employee_number != list.JobNumber {
  734. // c.ServeSuccessJSON(map[string]interface{}{
  735. // "doubleCheck": check,
  736. // "msg": "2",
  737. // })
  738. // return
  739. // }
  740. // }
  741. // if check.ID > 0 {
  742. // if employee_number != list.JobNumber {
  743. // c.ServeSuccessJSON(map[string]interface{}{
  744. // "doubleCheck": check,
  745. // "msg": "2",
  746. // })
  747. // return
  748. // }
  749. // }
  750. //
  751. //}
  752. doubleCheck := models.DoubleCheck{
  753. UserOrgId: adminUserInfo.Org.Id,
  754. PatientId: id,
  755. DialysisItemCheck: dialysis_item_check,
  756. DialysisParameterCheck: dialysis_parameter_check,
  757. VascularAccessVerification: vascular_access_verification,
  758. PipelineConnectionCheck: pipeline_connection_check,
  759. DialysisItemDesc: dialysis_item_desc,
  760. DialysisParameterDesc: dialysis_parameter_desc,
  761. VascularAccessDesc: vascular_access_desc,
  762. PipelineConnectionDesc: pipeline_connection_desc,
  763. Collator: collator,
  764. Status: 1,
  765. CreatedTime: time.Now().Unix(),
  766. CheckDate: recordDate.Unix(),
  767. UpdatedTime: time.Now().Unix(),
  768. EmployeeNumber: employee_number,
  769. DialyzerBatchNumber: dialyzer_batch_number,
  770. NeedleBatchNumber: needle_batch_number,
  771. }
  772. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  773. if check.ID == 0 { //新增
  774. doubleCheck.FirstCheckTime = firstCheckDate
  775. doubleCheck.CheckTime = checkDate
  776. doubleCheck.Creater = creater
  777. doubleCheck.Modifier = modifier
  778. if adminUserInfo.Org.Id == 10340 {
  779. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  780. doubleCheck.Creater = order.StartNurse
  781. }
  782. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  783. //查询未核对的医嘱
  784. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  785. for _, advice := range doctorList {
  786. if advice.ExecutionStaff == modifier {
  787. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  789. return
  790. }
  791. }
  792. }
  793. // 查询信息规挡的设置天数
  794. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  795. if infor.ID > 0 && infor.WeekDay > 0 {
  796. var cha_time int64
  797. timeNowStr := time.Now().Format("2006-01-02")
  798. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  799. //今日的日期减去设置的日期
  800. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  801. if cha_time >= recordDate.Unix() {
  802. //查询审核是否允许
  803. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  804. //申请状态不允许的情况 拒绝修改
  805. if infor.ApplicationStatus != 1 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  807. return
  808. }
  809. }
  810. }
  811. err := service.AddSigleDoubleCheck(&doubleCheck)
  812. finish := models.XtDialysisFinish{
  813. IsFinish: 1,
  814. UserOrgId: adminUserInfo.Org.Id,
  815. Status: 1,
  816. Ctime: time.Now().Unix(),
  817. Mtime: 0,
  818. Module: 5,
  819. RecordDate: recordDate.Unix(),
  820. Sourse: 1,
  821. PatientId: id,
  822. }
  823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  824. if dialysisFinish.ID == 0 {
  825. service.CreateDialysisFinish(finish)
  826. }
  827. //针对长沙南雅
  828. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  829. //查询未核对的医嘱
  830. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  831. if len(doctorList) > 0 && modifier > 0 {
  832. for _, advice := range doctorList {
  833. service.UpdateDoctorAdviceList(advice.ID, modifier)
  834. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  835. redis := service.RedisClient()
  836. //清空key 值
  837. redis.Set(key, "", time.Second)
  838. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  839. redis.Set(keyTwo, "", time.Second)
  840. theTime := time.Now()
  841. recordDate := theTime.Format("2006-01-02")
  842. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  843. redis.Set(keyFour, "", time.Second)
  844. defer redis.Close()
  845. }
  846. }
  847. }
  848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  849. redis := service.RedisClient()
  850. //清空key 值
  851. redis.Set(key, "", time.Second)
  852. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  853. redis.Set(keyOne, "", time.Second)
  854. defer redis.Close()
  855. if err == nil {
  856. c.ServeSuccessJSON(map[string]interface{}{
  857. "doubleCheck": &doubleCheck,
  858. })
  859. }
  860. } else { //修改
  861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  862. if infor.ID > 0 {
  863. var cha_time int64
  864. timeNowStr := time.Now().Format("2006-01-02")
  865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  866. //今日的日期减去设置的日期
  867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  868. if cha_time >= recordDate.Unix() {
  869. //查询审核是否允许
  870. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  871. //申请状态不允许的情况 拒绝修改
  872. if infor.ApplicationStatus != 1 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  874. return
  875. }
  876. }
  877. }
  878. doubleCheck.FirstCheckTime = firstCheckDate
  879. doubleCheck.CheckTime = checkDate
  880. doubleCheck.Creater = creater
  881. doubleCheck.Modifier = modifier
  882. doubleCheck.CreatedTime = check.CreatedTime
  883. doubleCheck.ID = check.ID
  884. doubleCheck.EmployeeNumber = employee_number
  885. doubleCheck.NeedleBatchNumber = needle_batch_number
  886. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  887. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  888. //查询未核对的医嘱
  889. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  890. for _, advice := range doctorList {
  891. if advice.ExecutionStaff == modifier {
  892. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  893. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  894. return
  895. }
  896. }
  897. }
  898. err := service.UpdateDoubleCheck(&doubleCheck)
  899. //针对长沙南雅
  900. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  901. //查询未核对的医嘱
  902. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  903. if len(doctorList) > 0 && modifier > 0 {
  904. for _, advice := range doctorList {
  905. service.UpdateDoctorAdviceList(advice.ID, modifier)
  906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  907. redis := service.RedisClient()
  908. //清空key 值
  909. redis.Set(key, "", time.Second)
  910. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  911. redis.Set(keyTwo, "", time.Second)
  912. theTime := time.Now()
  913. recordDate := theTime.Format("2006-01-02")
  914. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  915. redis.Set(keyFour, "", time.Second)
  916. defer redis.Close()
  917. }
  918. }
  919. }
  920. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  925. redis.Set(keyOne, "", time.Second)
  926. defer redis.Close()
  927. if err == nil {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "doubleCheck": &doubleCheck,
  930. "msg": "1",
  931. })
  932. }
  933. }
  934. }
  935. func (c *DialysisAPIController) PostAcceptsAssessment() {
  936. id, _ := c.GetInt64("patient", 0)
  937. recordDateStr := c.GetString("record_date")
  938. way, _ := c.GetInt64("way", 0)
  939. consciousness, _ := c.GetInt64("consciousness", 0)
  940. appetite, _ := c.GetInt64("appetite", 0)
  941. condition, _ := c.GetInt64("condition", 0)
  942. posture, _ := c.GetInt64("posture")
  943. sick_condition, _ := c.GetInt64("sick_condition", 0)
  944. danger_level, _ := c.GetInt64("danger_level", 0)
  945. intake, _ := c.GetInt64("intake", 0)
  946. nutrition, _ := c.GetInt64("nutrition", 0)
  947. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  948. psychological_assessment_other := c.GetString("psychological_assessment_other")
  949. score := c.GetString("score")
  950. sick_condition_other := c.GetString("sick_condition_other")
  951. //precaution, _ := c.GetInt64("precaution", 0)
  952. precaution := c.GetString("precaution")
  953. precaution_other := c.GetString("precaution_other")
  954. psychological_other := c.GetString("psychological_other")
  955. admission_number := c.GetString("admission_number")
  956. tumble, _ := c.GetInt64("tumble")
  957. diacrisis := c.GetString("diacrisis")
  958. his_department := c.GetString("his_department")
  959. his_bed := c.GetString("his_bed")
  960. if id <= 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. adminUserInfo := c.GetMobileAdminUserInfo()
  965. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  966. if patient.ID == 0 {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  968. return
  969. }
  970. //now := time.Now()
  971. //year, month, day := now.Date()
  972. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  973. //todayTimeStamp := today_time.Unix()
  974. if len(recordDateStr) == 0 {
  975. recordDateStr = time.Now().Format("2006-01-02")
  976. }
  977. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  978. if parseDateErr != nil {
  979. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. // 查询信息规挡的设置天数
  984. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  985. if infor.ID > 0 && infor.WeekDay > 0 {
  986. var cha_time int64
  987. timeNowStr := time.Now().Format("2006-01-02")
  988. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  989. //今日的日期减去设置的日期
  990. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  991. if cha_time >= recordDate.Unix() {
  992. //查询审核是否允许
  993. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  994. //申请状态不允许的情况 拒绝修改
  995. if infor.ApplicationStatus != 1 {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  997. return
  998. }
  999. }
  1000. }
  1001. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1002. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1003. UserOrgId: adminUserInfo.Org.Id,
  1004. PatientId: id,
  1005. RecordDate: recordDate.Unix(),
  1006. Way: way,
  1007. Consciousness: consciousness,
  1008. Appetite: appetite,
  1009. Condition: condition,
  1010. SickCondition: sick_condition,
  1011. DangerLevel: danger_level,
  1012. Intake: intake,
  1013. Nutrition: nutrition,
  1014. PsychologicalAssessment: psychological_assessment,
  1015. PsychologicalAssessmentOther: psychological_assessment_other,
  1016. SickConditionOther: sick_condition_other,
  1017. Posture: posture,
  1018. CreatedTime: time.Now().Unix(),
  1019. UpdateTime: time.Now().Unix(),
  1020. Status: 1,
  1021. Score: score,
  1022. Precaution: precaution,
  1023. PrecautionOther: precaution_other,
  1024. PsychologicalOther: psychological_other,
  1025. AdmissionNumber: admission_number,
  1026. Tumble: tumble,
  1027. Diacrisis: diacrisis,
  1028. HisBed: his_bed,
  1029. HisDepartment: his_department,
  1030. }
  1031. if receiveTreatment.ID == 0 { //新增
  1032. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1033. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1034. finish := models.XtDialysisFinish{
  1035. IsFinish: 1,
  1036. UserOrgId: adminUserInfo.Org.Id,
  1037. Status: 1,
  1038. Ctime: time.Now().Unix(),
  1039. Mtime: 0,
  1040. Module: 2,
  1041. RecordDate: recordDate.Unix(),
  1042. Sourse: 1,
  1043. PatientId: id,
  1044. }
  1045. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1046. if dialysisFinish.ID == 0 {
  1047. service.CreateDialysisFinish(finish)
  1048. }
  1049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1050. redis := service.RedisClient()
  1051. defer redis.Close()
  1052. //清空key 值
  1053. redis.Set(key, "", time.Second)
  1054. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1055. redis.Set(keyOne, "", time.Second)
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "receiveTreatmentAsses": receiveTreatmentAsses,
  1059. })
  1060. }
  1061. } else { //修改
  1062. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1063. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1064. // if getPermissionErr != nil {
  1065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. // return
  1067. // } else if headNursePermission == nil {
  1068. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1069. // return
  1070. // }
  1071. //}
  1072. // 查询信息规挡的设置天数
  1073. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1074. if infor.ID > 0 && infor.WeekDay > 0 {
  1075. var cha_time int64
  1076. timeNowStr := time.Now().Format("2006-01-02")
  1077. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1078. //今日的日期减去设置的日期
  1079. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1080. if cha_time >= recordDate.Unix() {
  1081. //查询审核是否允许
  1082. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1083. //申请状态不允许的情况 拒绝修改
  1084. if infor.ApplicationStatus != 1 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1086. return
  1087. }
  1088. }
  1089. }
  1090. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1091. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1092. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1093. receiveTreatmentAsses.ID = receiveTreatment.ID
  1094. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1096. redis := service.RedisClient()
  1097. defer redis.Close()
  1098. //清空key 值
  1099. redis.Set(key, "", time.Second)
  1100. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1101. redis.Set(keyOne, "", time.Second)
  1102. if err == nil {
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "receiveTreatmentAsses": receiveTreatmentAsses,
  1105. })
  1106. }
  1107. }
  1108. }
  1109. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1110. id, _ := c.GetInt64("patient", 0)
  1111. recordDateStr := c.GetString("record_date")
  1112. weightAfter, _ := c.GetFloat("weight_after", 0)
  1113. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1114. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1115. fmt.Println("weight_loss", weightReduce)
  1116. temperature, _ := c.GetFloat("temperature", 0)
  1117. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1118. breathing_rate := c.GetString("breathing_rate")
  1119. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1120. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1121. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1122. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1123. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1124. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1125. cruor := c.GetString("cruor")
  1126. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1127. internalFistula := c.GetString("internal_fistula")
  1128. catheter := c.GetString("catheter")
  1129. complications := c.GetString("complication")
  1130. remark := c.GetString("remark")
  1131. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1132. dialysis_intakes := c.GetString("dialysis_intakes")
  1133. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1134. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1135. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1136. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1137. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1138. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1139. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1140. patientGose, _ := c.GetInt64("patient_gose", 0)
  1141. inpatientDepartment := c.GetString("inpatient_department")
  1142. observationContent := c.GetString("observation_content")
  1143. observationContentOther := c.GetString("observation_content_other")
  1144. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1145. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1146. in_advance_reason := c.GetString("in_advance_reason")
  1147. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1148. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1149. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1150. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1151. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1152. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1153. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1154. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1155. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1156. is_eat, _ := c.GetInt64("is_eat", 0)
  1157. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1158. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1159. channels, _ := c.GetInt64("channel", 0)
  1160. return_blood, _ := c.GetInt64("return_blood", 0)
  1161. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1162. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1163. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1164. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1165. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1166. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1167. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1168. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1169. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1170. setting_pressure := c.GetString("setting_pressure")
  1171. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1172. diastolic_pressure := c.GetString("diastolic_pressure")
  1173. other_complication := c.GetString("other_complication")
  1174. ktv := c.GetString("ktv")
  1175. urr := c.GetString("urr")
  1176. hypertenison, _ := c.GetInt64("hypertenison")
  1177. hypopiesia, _ := c.GetInt64("hypopiesia")
  1178. leave_office_method, _ := c.GetInt64("leave_office_method")
  1179. lapse, _ := c.GetInt64("lapse")
  1180. consciousness, _ := c.GetInt64("consciousness")
  1181. fallrisk, _ := c.GetInt64("fallrisk")
  1182. machine_run := c.GetString("machine_run")
  1183. after_urea := c.GetString("after_urea")
  1184. pip_coagulation := c.GetString("pip_coagulation")
  1185. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1186. transfusion_volume := c.GetString("transfusion_volume")
  1187. last_after_weight := c.GetString("last_after_weight")
  1188. if id <= 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1190. return
  1191. }
  1192. adminUserInfo := c.GetMobileAdminUserInfo()
  1193. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1194. if patient.ID == 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1196. return
  1197. }
  1198. if len(recordDateStr) == 0 {
  1199. recordDateStr = time.Now().Format("2006-01-02")
  1200. }
  1201. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1202. fmt.Println("parseDateErr", parseDateErr)
  1203. if parseDateErr != nil {
  1204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. //now := time.Now()
  1209. //year, month, day := now.Date()
  1210. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1211. //todayTimeStamp := today_time.Unix()
  1212. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1213. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1214. UserOrgId: adminUserInfo.Org.Id,
  1215. PatientId: id,
  1216. AssessmentDate: recordDate.Unix(),
  1217. Temperature: temperature,
  1218. PulseFrequency: pulse_frequency,
  1219. BreathingRate: breathing_rate,
  1220. SystolicBloodPressure: systolic_blood_pressure,
  1221. DiastolicBloodPressure: diastolic_blood_pressure,
  1222. ActualUltrafiltration: actual_ultrafiltration,
  1223. ActualDisplacement: actual_displacement,
  1224. ActualTreatmentHour: actualtreatHour,
  1225. ActualTreatmentMinute: actualtreatmin,
  1226. WeightAfter: weightAfter,
  1227. AdditionalWeight: additionalWeight,
  1228. WeightLoss: weightReduce,
  1229. Cruor: cruor,
  1230. SymptomAfterDialysis: symptomsAfterDialysi,
  1231. InternalFistula: internalFistula,
  1232. Catheter: catheter,
  1233. Complication: complications,
  1234. DialysisIntakes: dialysateVolume,
  1235. CreatedTime: time.Now().Unix(),
  1236. UpdatedTime: time.Now().Unix(),
  1237. Status: 1,
  1238. Remark: remark,
  1239. BloodAccessPartId: blood_access_part_id,
  1240. BloodAccessPartOperaId: blood_access_part_opera_id,
  1241. DialysisIntakesUnit: dialysis_intakes_unit,
  1242. PuncturePointOozingBlood: puncturePointOozingBlood,
  1243. PuncturePointHaematoma: puncturePointHaematoma,
  1244. InternalFistulaTremorAc: internalFistulaTremorAc,
  1245. PatientGose: patientGose,
  1246. InpatientDepartment: inpatientDepartment,
  1247. ObservationContent: observationContent,
  1248. ObservationContentOther: observationContentOther,
  1249. DialysisProcess: dialysis_process,
  1250. InAdvanceMinute: in_advance_minute,
  1251. InAdvanceReason: in_advance_reason,
  1252. HemostasisMinute: hemostasis_minute,
  1253. HemostasisOpera: hemostasis_opera,
  1254. TremorNoise: tremor_noise,
  1255. DisequilibriumSyndrome: disequilibrium_syndrome,
  1256. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1257. ArterialTube: arterial_tube,
  1258. IntravenousTube: intravenous_tube,
  1259. Dialyzer: dialyzer,
  1260. InAdvanceReasonOther: in_advance_reason_other,
  1261. IsEat: is_eat,
  1262. CvcA: cvc_a,
  1263. CvcV: cvc_v,
  1264. Channel: channels,
  1265. ReturnBlood: return_blood,
  1266. RehydrationVolume: rehydration_volume,
  1267. DialysisDuring: dialysis_during,
  1268. StrokeVolume: stroke_volume,
  1269. BloodFlow: blood_flow,
  1270. SealingFluidDispose: sealing_fluid_dispose,
  1271. SealingFluidSpecial: sealing_fluid_special,
  1272. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1273. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1274. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1275. SettingPressure: setting_pressure,
  1276. DiastolicPressure: diastolic_pressure,
  1277. OtherComplication: other_complication,
  1278. Ktv: ktv,
  1279. Urr: urr,
  1280. Hypopiesia: hypopiesia,
  1281. Hypertenison: hypertenison,
  1282. Lapse: lapse,
  1283. LeaveOfficeMethod: leave_office_method,
  1284. Consciousness: consciousness,
  1285. Fallrisk: fallrisk,
  1286. MachineRun: machine_run,
  1287. AfterUrea: after_urea,
  1288. PipCoagulation: pip_coagulation,
  1289. AccumulatedBloodVolume: accumulated_blood_volume,
  1290. TransfusionVolume: transfusion_volume,
  1291. LastAfterWeight: last_after_weight,
  1292. }
  1293. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1294. // 查询信息规挡的设置天数
  1295. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1296. if infor.ID > 0 && infor.WeekDay > 0 {
  1297. var cha_time int64
  1298. timeNowStr := time.Now().Format("2006-01-02")
  1299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1300. //今日的日期减去设置的日期
  1301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1302. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1303. if cha_time >= recordDate.Unix() {
  1304. //查询审核是否允许
  1305. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1306. //申请状态不允许的情况 拒绝修改
  1307. if infor.ApplicationStatus != 1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1309. return
  1310. }
  1311. }
  1312. }
  1313. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1314. if assessmentAfter.ID == 0 { //新增
  1315. if appRole.UserType == 2 || appRole.UserType == 1 {
  1316. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1317. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1318. } else {
  1319. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1320. }
  1321. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1322. //记录日志
  1323. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1324. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1325. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1326. PatientId: assessmentAfterDislysis.PatientId,
  1327. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1328. Status: 1,
  1329. ErrLog: string(byterequest),
  1330. AdminUserId: adminUserInfo.AdminUser.Id,
  1331. Ctime: 0,
  1332. Mtime: 0,
  1333. Source: "手机端保存透后评估",
  1334. }
  1335. service.CreateAfterDialysisLog(afterDialysisLog)
  1336. finish := models.XtDialysisFinish{
  1337. IsFinish: 1,
  1338. UserOrgId: adminUserInfo.Org.Id,
  1339. Status: 1,
  1340. Ctime: time.Now().Unix(),
  1341. Mtime: 0,
  1342. Module: 9,
  1343. RecordDate: recordDate.Unix(),
  1344. Sourse: 1,
  1345. PatientId: id,
  1346. }
  1347. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1348. if dialysisFinish.ID == 0 {
  1349. service.CreateDialysisFinish(finish)
  1350. }
  1351. redis := service.RedisClient()
  1352. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1353. redis.Set(keyTwo, "", time.Second)
  1354. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1355. //清空key 值
  1356. redis.Set(key, "", time.Second)
  1357. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1358. redis.Set(keyOne, "", time.Second)
  1359. defer redis.Close()
  1360. if err == nil {
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "assessmentAfterDislysis": assessmentAfterDislysis,
  1363. })
  1364. }
  1365. return
  1366. } else { //修改
  1367. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1368. if infor.ID > 0 && infor.WeekDay > 0 {
  1369. var cha_time int64
  1370. timeNowStr := time.Now().Format("2006-01-02")
  1371. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1372. //今日的日期减去设置的日期
  1373. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1374. if cha_time >= recordDate.Unix() {
  1375. //查询审核是否允许
  1376. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1377. //申请状态不允许的情况 拒绝修改
  1378. if infor.ApplicationStatus != 1 {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1380. return
  1381. }
  1382. }
  1383. }
  1384. if appRole.UserType == 2 || appRole.UserType == 1 {
  1385. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1386. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1387. } else {
  1388. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1389. if assessmentAfterDislysis.Creater == 0 {
  1390. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1391. }
  1392. }
  1393. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1394. assessmentAfterDislysis.ID = assessmentAfter.ID
  1395. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1396. //记录日志
  1397. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1398. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1399. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1400. PatientId: assessmentAfterDislysis.PatientId,
  1401. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1402. Status: 1,
  1403. ErrLog: string(byterequest),
  1404. AdminUserId: adminUserInfo.AdminUser.Id,
  1405. Ctime: time.Now().Unix(),
  1406. Mtime: 0,
  1407. Source: "手机端修改保存透后评估",
  1408. }
  1409. service.CreateAfterDialysisLog(afterDialysisLog)
  1410. redis := service.RedisClient()
  1411. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1412. redis.Set(keyTwo, "", time.Second)
  1413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1414. //清空key 值
  1415. redis.Set(key, "", time.Second)
  1416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1417. redis.Set(keyOne, "", time.Second)
  1418. if err == nil {
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "assessmentAfterDislysis": assessmentAfterDislysis,
  1421. })
  1422. return
  1423. }
  1424. }
  1425. return
  1426. }
  1427. func (c *DialysisAPIController) PostDialysisPrescription() {
  1428. id, _ := c.GetInt64("patient", 0)
  1429. recordDateStr := c.GetString("record_date")
  1430. if id <= 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adminUserInfo := c.GetMobileAdminUserInfo()
  1435. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1436. if patient.ID == 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1438. return
  1439. }
  1440. if len(recordDateStr) == 0 {
  1441. recordDateStr = time.Now().Format("2006-01-02")
  1442. }
  1443. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1444. if parseDateErr != nil {
  1445. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. mode_id, _ := c.GetInt64("mode_id", 0)
  1450. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1451. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1452. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1453. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1454. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1455. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1456. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1457. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1458. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1459. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1460. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1461. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1462. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1463. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1464. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1465. kalium, _ := c.GetFloat("kalium", 0)
  1466. sodium, _ := c.GetFloat("sodium", 0)
  1467. calcium, _ := c.GetFloat("calcium", 0)
  1468. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1469. glucose, _ := c.GetFloat("glucose", 0)
  1470. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1471. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1472. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1473. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1474. conductivity, _ := c.GetFloat("conductivity", 0)
  1475. remark := c.GetString("remark")
  1476. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1477. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1478. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1479. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1480. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1481. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1482. special_medicine_other := c.GetString("special_medicine_other")
  1483. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1484. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1485. blood_access, _ := c.GetInt64("blood_access", 0)
  1486. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1487. body_fluid_other := c.GetString("body_fluid_other")
  1488. niprocart, _ := c.GetInt64("niprocart", 0)
  1489. jms, _ := c.GetInt64("jms", 0)
  1490. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1491. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1492. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1493. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1494. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1495. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1496. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1497. injector, _ := c.GetInt64("injector", 0)
  1498. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1499. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1500. safe_package, _ := c.GetInt64("package", 0)
  1501. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1502. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1503. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1504. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1505. blood := c.GetString("blood")
  1506. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1507. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1508. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1509. displace_speed := c.GetString("displace_speed")
  1510. illness, _ := c.GetInt64("illness")
  1511. amylaceum := c.GetString("amylaceum")
  1512. single_time := c.GetString("single_time")
  1513. single_water := c.GetString("single_water")
  1514. replacement_flow := c.GetString("replacement_flow")
  1515. plasma_separator := c.GetString("plasma_separator")
  1516. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1517. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1518. oxygen_flow := c.GetString("oxygen_flow")
  1519. oxygen_time := c.GetString("oxygen_time")
  1520. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1521. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1522. puncture_needle := c.GetString("puncture_needle")
  1523. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1524. epo := c.GetString("epo")
  1525. epo_count, _ := c.GetFloat("epo_count", 0)
  1526. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1527. admin_user_id, _ := c.GetInt64("admin_user_id")
  1528. is_water := c.GetString("is_water")
  1529. var is_war int64
  1530. if is_water == "是" {
  1531. is_war = 1
  1532. }
  1533. if is_water == "否" {
  1534. is_war = 2
  1535. }
  1536. if is_water == "请选择" {
  1537. is_war = 0
  1538. }
  1539. drhy_water := c.GetString("drhy_water")
  1540. dry_water_hour := c.GetString("dry_water_hour")
  1541. water_machine := c.GetString("water_machine")
  1542. add_amount, _ := c.GetFloat("add_amount")
  1543. reduce_amount, _ := c.GetFloat("reduce_amount")
  1544. dialysis_remark := c.GetString("dialysis_remark")
  1545. prescribing_number, _ := c.GetFloat("prescribing_number")
  1546. prescription_sodium := c.GetString("prescription_sodium")
  1547. start_sodium := c.GetString("start_sodium")
  1548. sodium_curve := c.GetString("sodium_curve")
  1549. treatment_remark := c.GetString("treatment_remark")
  1550. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1551. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1552. prescription_water, _ := c.GetFloat("prescription_water")
  1553. dialysis_strainer := c.GetString("dialysis_strainer")
  1554. chaptalization := c.GetString("chaptalization")
  1555. washing_time := c.GetString("washing_time")
  1556. warsh_count := c.GetString("warsh_count")
  1557. blood_access_part_id := c.GetString("blood_access_part_id")
  1558. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1559. dialyzate := c.GetString("dialyzate")
  1560. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1561. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1562. //
  1563. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1564. // if appRole.UserType == 3 {
  1565. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1566. // if getPermissionErr != nil {
  1567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1568. // return
  1569. // } else if headNursePermission == nil {
  1570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1571. // return
  1572. // }
  1573. // }
  1574. //}
  1575. // 查询信息规挡的设置天数
  1576. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1577. if infor.ID > 0 && infor.WeekDay > 0 {
  1578. var cha_time int64
  1579. timeNowStr := time.Now().Format("2006-01-02")
  1580. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1581. //今日的日期减去设置的日期
  1582. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1583. if cha_time >= recordDate.Unix() {
  1584. //查询审核是否允许
  1585. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1586. //申请状态不允许的情况 拒绝修改
  1587. if infor.ApplicationStatus != 1 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1589. return
  1590. }
  1591. }
  1592. }
  1593. if mode_id > 0 {
  1594. var str string
  1595. //查找该机构用的是什么透析器
  1596. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1597. if filedConfig.ID > 0 {
  1598. str = dialyzerPerfusionApparatus
  1599. } else {
  1600. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1601. }
  1602. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1603. }
  1604. //TODO 需要根据角色去判断
  1605. prescription := models.DialysisPrescription{
  1606. UserOrgId: adminUserInfo.Org.Id,
  1607. PatientId: id,
  1608. RecordDate: recordDate.Unix(),
  1609. ModeId: mode_id,
  1610. DialysisDuration: dialysis_duration,
  1611. Dialyzer: dialyzer,
  1612. PerfusionApparatus: perfusion_apparatus,
  1613. BloodFlowVolume: blood_flow_volume,
  1614. DewaterAmount: dewater_amount,
  1615. DisplaceLiqui: displace_liqui,
  1616. ReplacementWay: replacement_way,
  1617. Anticoagulant: anticoagulant,
  1618. AnticoagulantShouji: anticoagulant_shouji,
  1619. AnticoagulantWeichi: anticoagulant_weichi,
  1620. AnticoagulantZongliang: anticoagulant_zongliang,
  1621. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1622. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1623. Kalium: kalium,
  1624. Sodium: sodium,
  1625. Calcium: calcium,
  1626. Bicarbonate: bicarbonate,
  1627. Glucose: glucose,
  1628. // DryWeight: dry_weight,
  1629. DialysateFlow: dialysate_flow,
  1630. DialysateTemperature: dialysate_temperature,
  1631. // PrescriptionDoctor: prescription_doctor,
  1632. ReplacementTotal: replacement_total,
  1633. Conductivity: conductivity,
  1634. Remark: remark,
  1635. Status: 1,
  1636. CreatedTime: time.Now().Unix(),
  1637. UpdatedTime: time.Now().Unix(),
  1638. DialysisDurationMinute: dialysisDurationMinute,
  1639. DialysisDurationHour: dialysisDurationHour,
  1640. TargetUltrafiltration: targetUltrafiltration,
  1641. DialysateFormulation: dialysateFormulation,
  1642. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1643. BodyFluid: body_fluid,
  1644. SpecialMedicine: special_medicine,
  1645. SpecialMedicineOther: special_medicine_other,
  1646. DisplaceLiquiPart: displace_liqui_part,
  1647. DisplaceLiquiValue: displace_liqui_value,
  1648. BloodAccess: blood_access,
  1649. Ultrafiltration: ultrafiltration,
  1650. BodyFluidOther: body_fluid_other,
  1651. Niprocart: niprocart,
  1652. Jms: jms,
  1653. FistulaNeedleSet: fistula_needle_set,
  1654. FistulaNeedleSet16: fistula_needle_set_16,
  1655. Hemoperfusion: hemoperfusion,
  1656. DialyserSterilised: dialyser_sterilised,
  1657. Filtryzer: filtryzer,
  1658. Dialyzers: dialyzers,
  1659. Injector: injector,
  1660. Bloodlines: bloodlines,
  1661. TubingHemodialysis: tubing_hemodialysis,
  1662. Package: safe_package,
  1663. ALiquid: a_liquid,
  1664. TargetKtv: target_ktv,
  1665. PreImpulse: pre_impulse,
  1666. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1667. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1668. Blood: blood,
  1669. DialysisDialyszers: dialysis_dialyszers,
  1670. DialysisIrrigation: dialysis_irrigation,
  1671. AntioxidantCommodityName: antioxidant_commodity_name,
  1672. DisplaceSpeed: displace_speed,
  1673. Illness: illness,
  1674. Amylaceum: amylaceum,
  1675. SingleTime: single_time,
  1676. SingleWater: single_water,
  1677. ReplacementFlow: replacement_flow,
  1678. PlasmaSeparator: plasma_separator,
  1679. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1680. OxygenUptake: oxygen_uptake,
  1681. OxygenFlow: oxygen_flow,
  1682. OxygenTime: oxygen_time,
  1683. HemodialysisPipelines: hemodialysis_pipelines,
  1684. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1685. PunctureNeedle: puncture_needle,
  1686. PunctureNeedleCount: puncture_needle_count,
  1687. Epo: epo,
  1688. EpoCount: epo_count,
  1689. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1690. AdminUserId: admin_user_id,
  1691. IsWater: is_war,
  1692. DrhyWater: drhy_water,
  1693. DryWaterHour: dry_water_hour,
  1694. WaterMachine: water_machine,
  1695. AddAmount: add_amount,
  1696. ReduceAmount: reduce_amount,
  1697. DialysisRemark: dialysis_remark,
  1698. PrescribingNumber: prescribing_number,
  1699. StartSodium: start_sodium,
  1700. SodiumCurve: sodium_curve,
  1701. TreatmentRemark: treatment_remark,
  1702. PrescriptionSodium: prescription_sodium,
  1703. DialysisFluidFlow: dialysis_fluid_flow,
  1704. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1705. PrescriptionWater: prescription_water,
  1706. DialysisStrainer: dialysis_strainer,
  1707. Chaptalization: chaptalization,
  1708. WashingTime: washing_time,
  1709. WarshCount: warsh_count,
  1710. BloodAccessPartId: blood_access_part_id,
  1711. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1712. Dialyzate: dialyzate,
  1713. }
  1714. //查询最近透析准备表里是否存在 透析器 灌流器
  1715. //
  1716. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1717. //
  1718. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1719. //
  1720. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1721. //if len(mation)>0{
  1722. // for _, item := range splitStr {
  1723. // for _,it := range mation{
  1724. // if(item == it.SpecificationName){
  1725. //
  1726. // //查询最近一次的透析器
  1727. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1728. //
  1729. // if errcode == gorm.ErrRecordNotFound{
  1730. // //插入数据
  1731. // prepare := models.DialysisBeforePrepare{
  1732. // UserOrgId: adminUserInfo.Org.Id,
  1733. // PatientId: id,
  1734. // RecordDate: recordDate.Unix(),
  1735. // GoodTypeId: it.GoodTypeId,
  1736. // GoodId: it.ID,
  1737. // Count: 1,
  1738. // Ctime: time.Now().Unix(),
  1739. // Creater: adminUserInfo.AdminUser.Id,
  1740. // Status:1,
  1741. //
  1742. // }
  1743. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1744. // fmt.Println("",errcode)
  1745. // }
  1746. // }
  1747. // }
  1748. //
  1749. // }
  1750. //
  1751. // for _, item := range splitIrrigation {
  1752. // for _,it := range mation{
  1753. // if(item == it.SpecificationName){
  1754. // //查询最近一次的透析器
  1755. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1756. // if errcode == gorm.ErrRecordNotFound{
  1757. // //插入数据
  1758. // prepare := models.DialysisBeforePrepare{
  1759. // UserOrgId: adminUserInfo.Org.Id,
  1760. // PatientId: id,
  1761. // RecordDate: recordDate.Unix(),
  1762. // GoodTypeId: it.GoodTypeId,
  1763. // GoodId: it.ID,
  1764. // Count: 1,
  1765. // Ctime: time.Now().Unix(),
  1766. // Creater: adminUserInfo.AdminUser.Id,
  1767. // Status:1,
  1768. //
  1769. // }
  1770. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1771. // fmt.Println(errcode)
  1772. // }
  1773. // }
  1774. // }
  1775. // }
  1776. //}
  1777. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1778. if dialysisPrescription.ID == 0 { //新增
  1779. if appRole.UserType == 2 || appRole.UserType == 1 {
  1780. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1781. }
  1782. prescription.Creater = adminUserInfo.AdminUser.Id
  1783. //针对河间咸得
  1784. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1785. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1786. prescription.DisplaceLiquiPart = 0
  1787. prescription.DisplaceLiquiValue = 0
  1788. }
  1789. }
  1790. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1791. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1792. }
  1793. err := service.AddSigleRecord(&prescription)
  1794. //记录日志
  1795. byterequest, _ := json.Marshal(prescription)
  1796. prescriptionLog := models.XtDialysisPrescriptionLog{
  1797. UserOrgId: prescription.UserOrgId,
  1798. Ctime: time.Now().Unix(),
  1799. Mtime: 0,
  1800. ErrLog: string(byterequest),
  1801. AdminUserId: adminUserInfo.AdminUser.Id,
  1802. RecordDate: prescription.RecordDate,
  1803. PatientId: prescription.PatientId,
  1804. Source: "手机端新增保存处方",
  1805. Status: 1,
  1806. }
  1807. service.CreatePrescriptionLog(prescriptionLog)
  1808. finish := models.XtDialysisFinish{
  1809. IsFinish: 1,
  1810. UserOrgId: adminUserInfo.Org.Id,
  1811. Status: 1,
  1812. Ctime: time.Now().Unix(),
  1813. Mtime: 0,
  1814. Module: 1,
  1815. RecordDate: recordDate.Unix(),
  1816. Sourse: 1,
  1817. PatientId: id,
  1818. }
  1819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1820. if dialysisFinish.ID == 0 {
  1821. service.CreateDialysisFinish(finish)
  1822. }
  1823. //长沙南雅医院,自动生成抗凝剂的临时处方
  1824. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1825. if prescribing_number == 0 {
  1826. prescribing_number = 1
  1827. }
  1828. if prescribing_number == 0 && id == 14682 {
  1829. prescribing_number = 2
  1830. }
  1831. if prescribing_number == 0 && id == 18560 {
  1832. prescribing_number = 2
  1833. }
  1834. advice := models.DoctorAdvice{
  1835. UserOrgId: adminUserInfo.Org.Id,
  1836. PatientId: id,
  1837. GroupNo: 0,
  1838. AdviceType: 2,
  1839. RecordDate: recordDate.Unix(),
  1840. AdviceDate: recordDate.Unix(),
  1841. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1842. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1843. AdviceDesc: "",
  1844. ReminderDate: 0,
  1845. SingleDose: anticoagulant_zongliang,
  1846. SingleDoseUnit: "iu",
  1847. DrugSpec: 0,
  1848. DrugSpecUnit: "",
  1849. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1850. PrescribingNumberUnit: "支",
  1851. DeliveryWay: "静脉注射",
  1852. ExecutionFrequency: "上机前",
  1853. AdviceDoctor: 0,
  1854. Status: 1,
  1855. CreatedTime: time.Now().Unix(),
  1856. UpdatedTime: time.Now().Unix(),
  1857. IsPrescription: 1,
  1858. ExecutionState: 2,
  1859. StopState: 2,
  1860. IsSettle: 2,
  1861. }
  1862. // 查询排班信息
  1863. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1864. if schedulePatient.ID > 0 {
  1865. if schedulePatient.ScheduleType == 1 {
  1866. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1867. }
  1868. if schedulePatient.ScheduleType == 2 {
  1869. advice.StartTime = recordDate.Unix() + 10*60*60
  1870. }
  1871. }
  1872. // 抗凝剂名称
  1873. switch anticoagulant {
  1874. case 1:
  1875. advice.AdviceName = "无肝素"
  1876. break
  1877. case 2:
  1878. advice.AdviceName = "普通肝素"
  1879. break
  1880. case 3:
  1881. advice.AdviceName = "低分子肝素"
  1882. break
  1883. case 4:
  1884. advice.AdviceName = "阿加曲班"
  1885. break
  1886. case 5:
  1887. advice.AdviceName = "枸橼酸钠"
  1888. break
  1889. case 6:
  1890. advice.AdviceName = "低分子肝素钙"
  1891. break
  1892. case 7:
  1893. advice.AdviceName = "低分子肝素钠"
  1894. break
  1895. case 8:
  1896. advice.AdviceName = "依诺肝素"
  1897. break
  1898. case 9:
  1899. advice.AdviceName = "达肝素"
  1900. break
  1901. case 10:
  1902. advice.AdviceName = "体外抗凝"
  1903. break
  1904. case 11:
  1905. advice.AdviceName = "那曲肝素"
  1906. break
  1907. case 12:
  1908. advice.AdviceName = "无抗凝剂"
  1909. break
  1910. }
  1911. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1912. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1913. advice.AdviceDoctor = appRole.AdminUserId
  1914. }
  1915. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1916. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1917. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1918. advice.AdviceName = "低分子肝素钠注射液"
  1919. // 修改患者临时医嘱里的抗凝剂医嘱
  1920. advice.ID = advicePrescription.ID
  1921. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1922. } else {
  1923. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1924. advice.AdviceName = "低分子肝素钠注射液"
  1925. // 新增患者临时医嘱里的抗凝剂医嘱
  1926. service.CreateDoctorAdvice(&advice)
  1927. }
  1928. }
  1929. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1930. redis := service.RedisClient()
  1931. defer redis.Close()
  1932. //清空key 值
  1933. redis.Set(key, "", time.Second)
  1934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1935. redis.Set(keyOne, "", time.Second)
  1936. }
  1937. //获取key,清空redis
  1938. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1939. redis := service.RedisClient()
  1940. //清空key 值
  1941. redis.Set(key, "", time.Second)
  1942. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1943. //清空key 值
  1944. redis.Set(keyOne, "", time.Second)
  1945. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1946. //清空key 值
  1947. redis.Set(keyTwo, "", time.Second)
  1948. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1949. redis.Set(keySix, "", time.Second)
  1950. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1951. redis.Set(keySeven, "", time.Second)
  1952. if err == nil {
  1953. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1954. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1955. //清空key 值
  1956. redis.Set(keyThree, "", time.Second)
  1957. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1958. //清空key 值
  1959. redis.Set(keyFour, "", time.Second)
  1960. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1961. redis.Set(keyFive, "", time.Second)
  1962. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1963. redis.Set(keySix, "", time.Second)
  1964. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1965. redis.Set(keySeven, "", time.Second)
  1966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1967. //清空key 值
  1968. redis.Set(keyOne, "", time.Second)
  1969. if updateErr != nil {
  1970. utils.ErrorLog("%v", updateErr)
  1971. }
  1972. defer redis.Close()
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "prescription": prescription,
  1975. })
  1976. }
  1977. } else { //修改
  1978. //if mode_id > 0 {
  1979. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1980. //}
  1981. //if template.TemplateId == 1 {
  1982. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1983. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1984. // if getPermissionErr != nil {
  1985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1986. // return
  1987. // } else if headNursePermission == nil {
  1988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1989. // return
  1990. // }
  1991. // }
  1992. //}
  1993. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1994. prescription.Modifier = adminUserInfo.AdminUser.Id
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. prescription_doctor := adminUserInfo.AdminUser.Id
  1997. prescription.PrescriptionDoctor = prescription_doctor
  1998. } else {
  1999. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2000. }
  2001. if dialysisPrescription.Creater == 0 { //体重称
  2002. prescription.Creater = adminUserInfo.AdminUser.Id
  2003. } else {
  2004. prescription.Creater = dialysisPrescription.Creater
  2005. if adminUserInfo.Org.Id == 9882 {
  2006. if appRole.UserType == 2 || appRole.UserType == 1 {
  2007. prescription_doctor := adminUserInfo.AdminUser.Id
  2008. prescription.PrescriptionDoctor = prescription_doctor
  2009. prescription.Creater = prescription_doctor
  2010. }
  2011. }
  2012. }
  2013. prescription.ID = dialysisPrescription.ID
  2014. service.UpDateDialysisPrescription(&prescription)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(prescription)
  2017. prescriptionLog := models.XtDialysisPrescriptionLog{
  2018. UserOrgId: prescription.UserOrgId,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. ErrLog: string(byterequest),
  2022. AdminUserId: adminUserInfo.AdminUser.Id,
  2023. RecordDate: prescription.RecordDate,
  2024. PatientId: prescription.PatientId,
  2025. Source: "手机端修改处方",
  2026. Status: 1,
  2027. }
  2028. service.CreatePrescriptionLog(prescriptionLog)
  2029. finish := models.XtDialysisFinish{
  2030. IsFinish: 1,
  2031. UserOrgId: adminUserInfo.Org.Id,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Module: 1,
  2036. RecordDate: recordDate.Unix(),
  2037. Sourse: 1,
  2038. PatientId: id,
  2039. }
  2040. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2041. if dialysisFinish.ID == 0 {
  2042. service.CreateDialysisFinish(finish)
  2043. }
  2044. //修改处方
  2045. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2046. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2047. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2048. if advicePrescription.ID > 0 {
  2049. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2051. redis := service.RedisClient()
  2052. defer redis.Close()
  2053. //清空key 值
  2054. redis.Set(key, "", time.Second)
  2055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2056. redis.Set(keyOne, "", time.Second)
  2057. }
  2058. }
  2059. //获取key,清空redis
  2060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2061. redis := service.RedisClient()
  2062. //清空key 值
  2063. redis.Set(key, "", time.Second)
  2064. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2065. //清空key 值
  2066. redis.Set(keyOne, "", time.Second)
  2067. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2068. redis.Set(keySix, "", time.Second)
  2069. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2070. redis.Set(keySeven, "", time.Second)
  2071. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2072. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2073. //清空key 值
  2074. redis.Set(keyTwoOne, "", time.Second)
  2075. defer redis.Close()
  2076. if updateErr != nil {
  2077. utils.ErrorLog("%v", updateErr)
  2078. }
  2079. c.ServeSuccessJSON(map[string]interface{}{
  2080. "prescription": prescription,
  2081. })
  2082. }
  2083. }
  2084. func (c *DialysisAPIController) Finish() {
  2085. id, _ := c.GetInt64("patient", 0)
  2086. recordDateStr := c.GetString("record_date")
  2087. nurseID, _ := c.GetInt64("nurse")
  2088. end_time := c.GetString("end_time")
  2089. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2090. internal_fistula := c.GetString("blood_access_internal_fistula")
  2091. catheter := c.GetString("catheter")
  2092. cruor := c.GetString("cruor")
  2093. mission := c.GetString("mission")
  2094. condenser := c.GetString("condenser")
  2095. if id <= 0 || nurseID <= 0 {
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2097. return
  2098. }
  2099. adminUserInfo := c.GetMobileAdminUserInfo()
  2100. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2101. if patient.ID == 0 {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2103. return
  2104. }
  2105. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2106. if getNurseErr != nil {
  2107. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2109. return
  2110. } else if nurse == nil {
  2111. c.ErrorLog("护士不存在")
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. if len(recordDateStr) == 0 {
  2116. recordDateStr = time.Now().Format("2006-01-02")
  2117. }
  2118. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2119. if parseDateErr != nil {
  2120. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2122. return
  2123. }
  2124. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2125. if parseEndDateErr != nil {
  2126. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. // 查询信息规挡的设置天数
  2131. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2132. if infor.ID > 0 && infor.WeekDay > 0 {
  2133. var cha_time int64
  2134. timeNowStr := time.Now().Format("2006-01-02")
  2135. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2136. //今日的日期减去设置的日期
  2137. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2138. if cha_time >= recordDate.Unix() {
  2139. //查询审核是否允许
  2140. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2141. //申请状态不允许的情况 拒绝修改
  2142. if infor.ApplicationStatus != 1 {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2144. return
  2145. }
  2146. }
  2147. }
  2148. //now := time.Now()
  2149. //year, month, day := now.Date()
  2150. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2151. //todayTimeStamp := today_time.Unix()
  2152. // 获取当天的第一条透析纪录
  2153. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2154. if getMonitorRecordsErr != nil {
  2155. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. return
  2158. }
  2159. // 获取当前的最后一条透析纪录
  2160. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2161. if getMonitorRecordsErr != nil {
  2162. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2164. return
  2165. }
  2166. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2167. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2168. if getAADErr != nil {
  2169. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2174. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2175. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2176. if assessmentAfterDislysis != nil {
  2177. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2178. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2179. } else {
  2180. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2181. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2182. tempassessmentAfterDislysis.Status = 1
  2183. tempassessmentAfterDislysis.PatientId = id
  2184. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2185. }
  2186. //长沙南雅
  2187. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2188. //获取最后一条透析处方数据
  2189. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2190. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2191. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2192. }
  2193. if dialysisOrder.Stage == 1 {
  2194. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2195. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2196. fmt.Println(value)
  2197. a, b := math.Modf(value)
  2198. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2199. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2200. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2201. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2202. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2203. }
  2204. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2205. //var num1 int64
  2206. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2207. //fmt.Println(num1)
  2208. //sub := float64(num1 / 3600)
  2209. //fmt.Println(sub)
  2210. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2211. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2212. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2213. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2214. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2215. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2216. if adminUserInfo.Org.Id != 10375 {
  2217. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2218. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2219. }
  2220. if adminUserInfo.Org.Id != 10445 {
  2221. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2222. }
  2223. //北方营口医院
  2224. if adminUserInfo.Org.Id == 10445 {
  2225. //获取最后一条透析处方数据
  2226. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2227. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2228. } else {
  2229. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2230. }
  2231. //新化博翔
  2232. if adminUserInfo.Org.Id == 10447 {
  2233. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2234. }
  2235. //阳春
  2236. if adminUserInfo.Org.Id == 10485 {
  2237. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2238. }
  2239. if adminUserInfo.Org.Id == 10551 {
  2240. //获取最后一条透析处方数据
  2241. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2242. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2243. }
  2244. if adminUserInfo.Org.Id == 10580 {
  2245. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2246. }
  2247. if adminUserInfo.Org.Id == 10612 {
  2248. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2249. }
  2250. }
  2251. 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 {
  2252. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2253. if evaluation.SystolicBloodPressure == 0 {
  2254. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2255. pre := models.PredialysisEvaluation{
  2256. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2257. }
  2258. fmt.Println("prew", pre)
  2259. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2260. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2261. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2262. redis := service.RedisClient()
  2263. redis.Set(key, "", time.Second)
  2264. redis.Set(keyOne, "", time.Second)
  2265. defer redis.Close()
  2266. fmt.Println(getNurseErr)
  2267. }
  2268. if evaluation.DiastolicBloodPressure == 0 {
  2269. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2270. pres := models.PredialysisEvaluation{
  2271. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2272. }
  2273. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2274. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2275. redis := service.RedisClient()
  2276. redis.Set(key, "", time.Second)
  2277. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2278. redis.Set(keyOne, "", time.Second)
  2279. defer redis.Close()
  2280. fmt.Println(getNurseErr)
  2281. }
  2282. if evaluation.PulseFrequency == 0 {
  2283. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2284. press := models.PredialysisEvaluation{
  2285. PulseFrequency: evaluation.PulseFrequency,
  2286. }
  2287. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2288. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2289. redis := service.RedisClient()
  2290. redis.Set(key, "", time.Second)
  2291. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2292. redis.Set(keyOne, "", time.Second)
  2293. defer redis.Close()
  2294. fmt.Println(getNurseErr)
  2295. }
  2296. if evaluation.Temperature == 0 {
  2297. evaluation.Temperature = fmonitorRecords.Temperature
  2298. press := models.PredialysisEvaluation{
  2299. Temperature: evaluation.Temperature,
  2300. }
  2301. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2302. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2303. redis := service.RedisClient()
  2304. redis.Set(key, "", time.Second)
  2305. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2306. redis.Set(keyOne, "", time.Second)
  2307. defer redis.Close()
  2308. fmt.Println(getNurseErr)
  2309. }
  2310. }
  2311. if adminUserInfo.Org.Id == 9583 {
  2312. //获取透析处方的最后一条数据
  2313. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2314. if diaerr != nil {
  2315. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2317. return
  2318. }
  2319. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2320. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2321. }
  2322. }
  2323. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2324. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2325. }
  2326. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2327. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2328. }
  2329. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2330. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2331. }
  2332. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2333. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2334. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2335. }
  2336. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2337. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2338. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2339. }
  2340. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2341. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2342. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2343. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2344. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2345. }
  2346. if lastAssessmentAfterDislysis != nil {
  2347. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2348. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2349. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2350. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2351. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2352. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2353. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2354. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2355. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2356. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2357. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2358. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2359. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2360. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2361. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2362. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2363. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2364. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2365. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2366. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2367. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2368. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2369. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2370. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2371. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2372. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2373. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2374. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2375. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2376. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2377. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2378. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2379. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2380. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2381. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2382. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2383. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2384. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2385. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2386. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2387. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2388. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2389. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2390. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2391. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2392. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2393. if tempassessmentAfterDislysis.PatientId == 18695 {
  2394. tempassessmentAfterDislysis.ActualDisplacement = 0
  2395. }
  2396. if adminUserInfo.Org.Id != 10375 {
  2397. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2398. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2399. }
  2400. }
  2401. finish := models.XtDialysisFinish{
  2402. IsFinish: 1,
  2403. UserOrgId: adminUserInfo.Org.Id,
  2404. Status: 1,
  2405. Ctime: time.Now().Unix(),
  2406. Mtime: 0,
  2407. Module: 9,
  2408. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2409. Sourse: 1,
  2410. PatientId: tempassessmentAfterDislysis.PatientId,
  2411. }
  2412. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2413. if dialysisFinish.ID == 0 {
  2414. service.CreateDialysisFinish(finish)
  2415. }
  2416. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2417. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2418. redis := service.RedisClient()
  2419. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2420. redis.Set(keyOne, "", time.Second)
  2421. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2422. redis.Set(keyTwo, "", time.Second)
  2423. defer redis.Close()
  2424. //清空key 值
  2425. redis.Set(key, "", time.Second)
  2426. if err != nil {
  2427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2428. return
  2429. }
  2430. if dialysisOrder == nil {
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2432. return
  2433. }
  2434. if dialysisOrder.Stage == 2 {
  2435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2436. return
  2437. }
  2438. if dialysisOrder.Stage == 1 {
  2439. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2440. finish := models.XtDialysisFinish{
  2441. IsFinish: 1,
  2442. UserOrgId: adminUserInfo.Org.Id,
  2443. Status: 1,
  2444. Ctime: time.Now().Unix(),
  2445. Mtime: 0,
  2446. Module: 8,
  2447. RecordDate: recordDate.Unix(),
  2448. Sourse: 1,
  2449. PatientId: id,
  2450. }
  2451. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2452. if dialysisFinish.ID == 0 {
  2453. service.CreateDialysisFinish(finish)
  2454. }
  2455. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2456. redis := service.RedisClient()
  2457. defer redis.Close()
  2458. //清空key 值
  2459. redis.Set(key, "", time.Second)
  2460. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2461. redis.Set(keyOne, "", time.Second)
  2462. //结束时候透析次数加1
  2463. service.UpdateSolutionByPatientId(id)
  2464. //下机完自动消毒,针对长沙南雅
  2465. if dialysisOrder.Stage == 1 {
  2466. 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 {
  2467. //根据床位号获取设备型号
  2468. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2469. //查询使用消毒最后一条消毒记录
  2470. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2471. fmt.Println("err", err)
  2472. if err == gorm.ErrRecordNotFound {
  2473. //查找排班
  2474. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2475. //查询改设备是否有消毒计划
  2476. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2477. //根据床位号获取设备id
  2478. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2479. //查询病人信息
  2480. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2481. var con = ""
  2482. if patients.IsInfectious == 0 {
  2483. con = ""
  2484. }
  2485. if patients.IsInfectious == 1 {
  2486. con = "无"
  2487. }
  2488. if patients.IsInfectious == 2 {
  2489. con = "有"
  2490. }
  2491. if errcode == nil {
  2492. var end_time int64
  2493. end_time = endDate.Unix() + plan.DisinfecTime*60
  2494. //新增消毒
  2495. information := models.DeviceInformation{
  2496. Date: dialysisOrder.DialysisDate,
  2497. Zone: dialysisOrder.ZoneId,
  2498. Class: dialysisOrder.SchedualType,
  2499. BedNumber: dialysisOrder.BedID,
  2500. PatientId: dialysisOrder.PatientId,
  2501. DialysisMode: scheduleByPatient.ModeId,
  2502. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2503. Disinfection: 1,
  2504. DialysisConcentration: 1,
  2505. DisinfectionStatus: 1,
  2506. Move: 1,
  2507. UserOrgId: dialysisOrder.UserOrgId,
  2508. DisinfectType: plan.Way,
  2509. DisinfectantType: plan.MachineDisinfectant,
  2510. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2511. Disinfectant: plan.Disinfectant,
  2512. Ctime: time.Now().Unix(),
  2513. Status: 1,
  2514. SignName: nurseID,
  2515. EquimentId: addmacher.ID,
  2516. DisinfectionResidue: 2,
  2517. Bed: addmacher.BedNumber,
  2518. StartTime: dialysisOrder.StartTime,
  2519. EndTime: dialysisOrder.EndTime,
  2520. Contagion: con,
  2521. WeightLoss: 0,
  2522. Hyperfiltratio: 0,
  2523. DialysisHour: "",
  2524. MachineRun: 1,
  2525. DisinfecStartime: endDate.Unix(),
  2526. DisinfecEndtime: end_time,
  2527. }
  2528. err := service.CreateInformationTwo(&information)
  2529. fmt.Println("报错", err)
  2530. }
  2531. }
  2532. }
  2533. }
  2534. dialysisOrder.Stage = 2
  2535. dialysisOrder.FinishNurse = nurseID
  2536. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2537. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2538. dialysisOrder.EndTime = endDate.Unix()
  2539. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2540. // 长沙南雅需求
  2541. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2542. //获取最后1条监测的数据
  2543. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2544. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2545. var accumulatedBloodVolume float64
  2546. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2547. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2548. fmt.Println(err)
  2549. // 查询未执行的医嘱
  2550. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2551. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2552. for _, item := range doctorAdvice {
  2553. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2554. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2555. redis := service.RedisClient()
  2556. //清空key 值
  2557. redis.Set(key, "", time.Second)
  2558. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2559. redis.Set(keyTwo, "", time.Second)
  2560. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2561. redis.Set(keyThree, "", time.Second)
  2562. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2563. theTime := toTime.Format("2006-01-02")
  2564. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2565. redis.Set(keyFour, "", time.Second)
  2566. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2567. redis.Set(keyFive, "", time.Second)
  2568. defer redis.Close()
  2569. }
  2570. }
  2571. go func() {
  2572. ssoDomain := beego.AppConfig.String("call_domain")
  2573. api := ssoDomain + "/index/downpatient"
  2574. values := make(url.Values)
  2575. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2576. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2577. values.Set("patient_id", strconv.FormatInt(id, 10))
  2578. http.PostForm(api, values)
  2579. }()
  2580. if err == nil {
  2581. c.ServeSuccessJSON(map[string]interface{}{
  2582. "dialysisOrder": dialysisOrder,
  2583. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2584. })
  2585. } else {
  2586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2587. }
  2588. }
  2589. }
  2590. func (c *DialysisAPIController) GetAllZone() {
  2591. adminUserInfo := c.GetMobileAdminUserInfo()
  2592. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2593. if err == nil {
  2594. c.ServeSuccessJSON(map[string]interface{}{
  2595. "zone": zone,
  2596. })
  2597. }
  2598. }
  2599. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2600. adminUserInfo := c.GetMobileAdminUserInfo()
  2601. page, _ := c.GetInt64("page", 1)
  2602. limit, _ := c.GetInt64("limit", 10)
  2603. schedulType, _ := c.GetInt64("schedul_type", 0)
  2604. startTime, _ := c.GetInt64("schedul_time", 0)
  2605. partitionType, _ := c.GetInt64("partition_type", 0)
  2606. keywords := c.GetString("keywords")
  2607. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2608. if err == nil {
  2609. c.ServeSuccessJSON(map[string]interface{}{
  2610. "schedule": dialysisSchedule,
  2611. })
  2612. }
  2613. return
  2614. }
  2615. // /m/api/dialysis/start [post]
  2616. // @param patient_id:int
  2617. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2618. // @param nurse:int 上机护士
  2619. // @param bed:int 床位号
  2620. func (this *DialysisAPIController) StartDialysis() {
  2621. patientID, _ := this.GetInt64("patient_id")
  2622. recordDateStr := this.GetString("record_date")
  2623. nurseID, _ := this.GetInt64("start_nurse")
  2624. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2625. blood_drawing, _ := this.GetInt64("blood_drawing")
  2626. schedual_type, _ := this.GetInt64("schedual_type")
  2627. bedID, _ := this.GetInt64("bed")
  2628. start_time := this.GetString("start_time")
  2629. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2630. change_nurse, _ := this.GetInt64("change_nurse")
  2631. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2632. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2633. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2634. puncture_needle := this.GetString("puncture_needle")
  2635. puncture_way := this.GetString("puncture_way")
  2636. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2637. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2638. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2639. zone_id, _ := this.GetInt64("zone_id")
  2640. elecsign := this.GetString("url")
  2641. nuclein_date_str := this.GetString("nuclein_date_str")
  2642. schedule_remark := this.GetString("schedule_remark")
  2643. order_remark := this.GetString("order_remark")
  2644. catheter_operation := this.GetString("catheter_operation")
  2645. blood_flow_volume := this.GetString("blood_flow_volume")
  2646. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2648. return
  2649. }
  2650. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2651. if parseStartDateErr != nil {
  2652. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2654. return
  2655. }
  2656. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2657. if parseErr != nil {
  2658. this.ErrorLog("时间解析失败:%v", parseErr)
  2659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2660. return
  2661. }
  2662. adminUserInfo := this.GetMobileAdminUserInfo()
  2663. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2664. if getPatientErr != nil {
  2665. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2667. return
  2668. } else if patient == nil {
  2669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2670. return
  2671. }
  2672. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2673. if getNurseErr != nil {
  2674. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2676. return
  2677. } else if nurse == nil {
  2678. this.ErrorLog("护士不存在")
  2679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2680. return
  2681. }
  2682. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2683. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2684. if getDeviceNumberErr != nil {
  2685. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2686. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2687. return
  2688. } else if deviceNumber == nil {
  2689. this.ErrorLog("床位号不存在")
  2690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2691. return
  2692. }
  2693. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2694. if getRecordErr != nil {
  2695. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2697. return
  2698. } else if dialysisRecord != nil {
  2699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2700. return
  2701. }
  2702. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2703. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2704. timeLayout := "2006-01-02 15:04:05"
  2705. loc, _ := time.LoadLocation("Local")
  2706. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2707. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2708. schedulestartTime := theStartTime.Unix()
  2709. scheduleendTime := theEndTime.Unix()
  2710. var theNucleinDate int64
  2711. timeLayoutOne := "2006-01-02"
  2712. if len(nuclein_date_str) > 0 {
  2713. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2714. if err != nil {
  2715. utils.ErrorLog(err.Error())
  2716. }
  2717. theNucleinDate = theTime.Unix()
  2718. }
  2719. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2720. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2721. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2722. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2723. //查询该床位是否有人用了
  2724. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2725. if err == gorm.ErrRecordNotFound { //空床位
  2726. // 修改了床位逻辑
  2727. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2728. if daySchedule.ID > 0 {
  2729. daySchedule.PartitionId = deviceNumber.ZoneID
  2730. daySchedule.BedId = bedID
  2731. daySchedule.ScheduleType = schedual_type
  2732. daySchedule.UpdatedTime = time.Now().Unix()
  2733. xtSchedule := models.Schedule{
  2734. PartitionId: deviceNumber.ZoneID,
  2735. BedId: bedID,
  2736. ScheduleType: schedual_type,
  2737. UpdatedTime: time.Now().Unix(),
  2738. }
  2739. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2740. if err != nil {
  2741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2742. return
  2743. }
  2744. }
  2745. } else if err == nil {
  2746. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2747. if order.ID > 0 { //该机位被其他人占用了
  2748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2749. return
  2750. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2751. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2752. if daySchedule.ID > 0 {
  2753. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2754. if err != nil {
  2755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2756. return
  2757. }
  2758. }
  2759. }
  2760. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2762. return
  2763. }
  2764. //else if order.ID == 0 { //该床位没被占用
  2765. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2766. // if daySchedule.ID > 0 {
  2767. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2768. // //daySchedule.BedId = bedID
  2769. // //daySchedule.ScheduleType = schedual_type
  2770. // //daySchedule.UpdatedTime = time.Now().Unix()
  2771. // //err := service.UpdateSchedule(&daySchedule)
  2772. // xtSchedule := models.Schedule{
  2773. // PartitionId: deviceNumber.ZoneID,
  2774. // BedId: bedID,
  2775. // ScheduleType: schedual_type,
  2776. // UpdatedTime: time.Now().Unix(),
  2777. // }
  2778. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2779. // if err != nil {
  2780. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2781. // return
  2782. // }
  2783. // }
  2784. //}
  2785. //}
  2786. } else if err != nil {
  2787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2788. return
  2789. }
  2790. // 查询信息规挡的设置天数
  2791. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2792. if infor.ID > 0 && infor.WeekDay > 0 {
  2793. var cha_time int64
  2794. timeNowStr := time.Now().Format("2006-01-02")
  2795. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2796. //今日的日期减去设置的日期
  2797. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2798. if cha_time >= recordDate.Unix() {
  2799. //查询审核是否允许
  2800. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2801. //申请状态不允许的情况 拒绝修改
  2802. if infor.ApplicationStatus != 1 {
  2803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2804. return
  2805. }
  2806. }
  2807. }
  2808. dialysisRecord = &models.DialysisOrder{
  2809. DialysisDate: recordDate.Unix(),
  2810. UserOrgId: adminUserInfo.Org.Id,
  2811. PatientId: patientID,
  2812. Stage: 1,
  2813. BedID: bedID,
  2814. StartNurse: nurseID,
  2815. Status: 1,
  2816. StartTime: startDate.Unix(),
  2817. CreatedTime: time.Now().Unix(),
  2818. UpdatedTime: time.Now().Unix(),
  2819. PunctureNurse: puncture_nurse,
  2820. Creator: adminUserInfo.AdminUser.Id,
  2821. Modifier: adminUserInfo.AdminUser.Id,
  2822. SchedualType: schedual_type,
  2823. WashpipeNurse: washpipe_nurse,
  2824. ChangeNurse: change_nurse,
  2825. DifficultPunctureNurse: difficult_puncture_nurse,
  2826. NewFistulaNurse: new_fistula_nurse,
  2827. ZoneId: zone_id,
  2828. QualityNurseId: quality_nurse_id,
  2829. PunctureNeedle: puncture_needle,
  2830. PunctureWay: puncture_way,
  2831. DialysisIrrigation: dialysis_irrigation,
  2832. DialysisDialyszers: dialysis_dialyszers,
  2833. BloodAccessId: blood_access_id,
  2834. Url: elecsign,
  2835. NucleinDate: theNucleinDate,
  2836. ScheduleRemark: schedule_remark,
  2837. OrderRemark: order_remark,
  2838. CatheterOperation: catheter_operation,
  2839. BloodFlowVolume: blood_flow_volume,
  2840. }
  2841. //查询该床位是否有人用了
  2842. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2843. if errorscode == gorm.ErrRecordNotFound {
  2844. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2845. finish := models.XtDialysisFinish{
  2846. IsFinish: 1,
  2847. UserOrgId: adminUserInfo.Org.Id,
  2848. Status: 1,
  2849. Ctime: time.Now().Unix(),
  2850. Mtime: 0,
  2851. Module: 6,
  2852. RecordDate: schedulestartTime,
  2853. Sourse: 1,
  2854. PatientId: patientID,
  2855. }
  2856. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2857. if dialysisFinish.ID == 0 {
  2858. service.CreateDialysisFinish(finish)
  2859. }
  2860. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2861. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2862. //统计该患者总次数
  2863. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2864. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2865. }
  2866. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2867. //统计该患者总次数
  2868. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2869. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2870. }
  2871. redis := service.RedisClient()
  2872. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2873. redis.Set(key, "", time.Second)
  2874. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2875. //清空key 值
  2876. redis.Set(keyOne, "", time.Second)
  2877. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2878. //清空key 值
  2879. redis.Set(keyTwo, "", time.Second)
  2880. if createErr != nil {
  2881. this.ErrorLog("上机失败:%v", createErr)
  2882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2883. return
  2884. }
  2885. }
  2886. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2887. var tempdispose string
  2888. // 只针对中能建
  2889. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2890. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2891. }
  2892. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2893. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2894. }
  2895. var ultrafiltration_rate float64
  2896. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2897. //后期预增脱水量
  2898. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2899. if prescription.ID > 0 {
  2900. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2901. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2902. 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
  2903. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2904. }
  2905. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2906. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2907. }
  2908. //针对医师汇
  2909. if adminUserInfo.Org.Id == 10121 {
  2910. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2911. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2912. }
  2913. //针对通道
  2914. if adminUserInfo.Org.Id == 10234 {
  2915. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2916. }
  2917. //针对监利大垸医院
  2918. if template.TemplateId == 41 {
  2919. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2920. }
  2921. //针对肇庆三鹤血液透析中心
  2922. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2923. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2924. }
  2925. if adminUserInfo.Org.Id == 10469 {
  2926. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2927. }
  2928. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2929. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2930. }
  2931. // 只针对方济医院
  2932. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2933. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2934. ultrafiltration_rate = value
  2935. }
  2936. //针对
  2937. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2938. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2939. ultrafiltration_rate = ultrafiltration_rate / 1000
  2940. }
  2941. if adminUserInfo.Org.Id == 10551 {
  2942. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2943. ultrafiltration_rate = ultrafiltration_rate / 1000
  2944. }
  2945. if adminUserInfo.Org.Id == 10612 {
  2946. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2947. ultrafiltration_rate = ultrafiltration_rate / 1000
  2948. }
  2949. if adminUserInfo.Org.Id == 10580 {
  2950. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2951. ultrafiltration_rate = ultrafiltration_rate / 1000
  2952. }
  2953. if adminUserInfo.Org.Id == 10629 {
  2954. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2955. ultrafiltration_rate = ultrafiltration_rate / 1000
  2956. }
  2957. }
  2958. }
  2959. record := models.MonitoringRecord{
  2960. UserOrgId: adminUserInfo.Org.Id,
  2961. PatientId: patientID,
  2962. DialysisOrderId: dialysisRecord.ID,
  2963. MonitoringDate: schedulestartTime,
  2964. OperateTime: startDate.Unix(),
  2965. // MonitoringTime: recordTime,
  2966. MonitoringNurse: nurseID,
  2967. Dispose: tempdispose,
  2968. UltrafiltrationRate: ultrafiltration_rate,
  2969. UltrafiltrationVolume: 0,
  2970. Status: 1,
  2971. CreatedTime: time.Now().Unix(),
  2972. UpdatedTime: time.Now().Unix(),
  2973. }
  2974. //只针对广慈医院
  2975. 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 {
  2976. // 查询病人是否有透前评估数据
  2977. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2978. //如果有数据就插入
  2979. if errcode == nil {
  2980. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2981. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2982. record.BreathingRate = befor.BreathingRate
  2983. record.PulseFrequency = befor.PulseFrequency
  2984. record.Temperature = befor.Temperature
  2985. }
  2986. }
  2987. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2988. if newdialysisRecord.ID > 0 {
  2989. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2990. record.Temperature = 36.5
  2991. record.ArterialPressure = -100
  2992. record.DialysateTemperature = 36.5
  2993. record.Conductivity = 14
  2994. record.BreathingRate = "20"
  2995. record.VenousPressure = 80
  2996. record.TransmembranePressure = 60
  2997. record.Dispose = catheter_operation
  2998. }
  2999. //针对新化博翔
  3000. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3001. record.BloodOxygenSaturation = "99"
  3002. record.Conductivity = 14
  3003. record.DialysateTemperature = 36.5
  3004. record.BreathingRate = "20"
  3005. }
  3006. //针对兰溪人民医院的需求
  3007. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  3008. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3009. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3010. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3011. record.Temperature = befor.Temperature
  3012. record.PulseFrequency = befor.PulseFrequency
  3013. record.BreathingRate = befor.BreathingRate
  3014. }
  3015. //新化博翔
  3016. if adminUserInfo.Org.Id == 10447 {
  3017. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3018. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3019. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3020. record.BreathingRate = befor.BreathingRate
  3021. }
  3022. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3023. record.PulseFrequency = 80
  3024. record.Temperature = 36.5
  3025. }
  3026. //诊断灵山圣康
  3027. if adminUserInfo.Org.Id == 10375 {
  3028. record.Conductivity = 13.8
  3029. record.DialysateTemperature = 37
  3030. record.DialysateFlow = 500
  3031. record.BloodFlowVolume = 200
  3032. record.BreathingRate = "18"
  3033. record.SodiumConcentration = 140
  3034. }
  3035. //江成肾病医院
  3036. if adminUserInfo.Org.Id == 10517 {
  3037. record.SodiumConcentration = 138
  3038. record.DialysateTemperature = 36.5
  3039. }
  3040. err := service.CreateMonitor(&record)
  3041. //记录日志
  3042. byterequest, _ := json.Marshal(record)
  3043. monitorRecordLog := models.XtMonitorRecordLog{
  3044. RecordDate: record.MonitoringDate,
  3045. PatientId: record.PatientId,
  3046. Module: 1,
  3047. AdminUserId: adminUserInfo.AdminUser.Id,
  3048. Ctime: time.Now().Unix(),
  3049. Mtime: 0,
  3050. Status: 1,
  3051. UserOrgId: record.UserOrgId,
  3052. ErrLog: string(byterequest),
  3053. Source: "执行上机时新增监测",
  3054. }
  3055. service.CreateMonitorRecordLog(monitorRecordLog)
  3056. finish := models.XtDialysisFinish{
  3057. IsFinish: 1,
  3058. UserOrgId: adminUserInfo.Org.Id,
  3059. Status: 1,
  3060. Ctime: time.Now().Unix(),
  3061. Mtime: 0,
  3062. Module: 7,
  3063. RecordDate: schedulestartTime,
  3064. Sourse: 1,
  3065. PatientId: patientID,
  3066. }
  3067. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3068. if dialysisFinish.ID == 0 {
  3069. service.CreateDialysisFinish(finish)
  3070. }
  3071. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3072. redis := service.RedisClient()
  3073. //清空key 值
  3074. redis.Set(key, "", time.Second)
  3075. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3076. redis.Set(keyOne, "", time.Second)
  3077. defer redis.Close()
  3078. if err != nil {
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3080. return
  3081. }
  3082. }
  3083. go func() {
  3084. ssoDomain := beego.AppConfig.String("call_domain")
  3085. api := ssoDomain + "/index/uppatient"
  3086. values := make(url.Values)
  3087. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3088. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3089. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3090. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3091. http.PostForm(api, values)
  3092. }()
  3093. this.ServeSuccessJSON(map[string]interface{}{
  3094. "dialysis_order": newdialysisRecord,
  3095. "monitor": record,
  3096. })
  3097. return
  3098. }
  3099. func (c *DialysisAPIController) PostSolution() {
  3100. id, _ := c.GetInt64("patient", 0)
  3101. recordDateStr := c.GetString("record_date")
  3102. if id <= 0 {
  3103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3104. return
  3105. }
  3106. adminUserInfo := c.GetMobileAdminUserInfo()
  3107. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3108. if patient.ID == 0 {
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3110. return
  3111. }
  3112. if len(recordDateStr) == 0 {
  3113. recordDateStr = time.Now().Format("2006-01-02")
  3114. }
  3115. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3116. if parseDateErr != nil {
  3117. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3119. return
  3120. }
  3121. mode_id, _ := c.GetInt64("mode_id", 0)
  3122. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3123. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3124. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3125. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3126. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3127. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3128. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3129. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3130. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3131. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3132. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3133. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3134. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3135. kalium, _ := c.GetFloat("kalium", 0)
  3136. sodium, _ := c.GetFloat("sodium", 0)
  3137. calcium, _ := c.GetFloat("calcium", 0)
  3138. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3139. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3140. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3141. glucose, _ := c.GetFloat("glucose", 0)
  3142. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3143. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3144. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3145. conductivity, _ := c.GetFloat("conductivity", 0)
  3146. remark := c.GetString("remark")
  3147. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3148. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3149. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3150. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3151. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3152. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3153. special_medicine_other := c.GetString("special_medicine_other")
  3154. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3155. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3156. blood_access, _ := c.GetInt64("blood_access", 0)
  3157. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3158. body_fluid_other := c.GetString("body_fluid_other")
  3159. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3160. niprocart, _ := c.GetInt64("niprocart", 0)
  3161. jms, _ := c.GetInt64("jms", 0)
  3162. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3163. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3164. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3165. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3166. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3167. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3168. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3169. injector, _ := c.GetInt64("injector", 0)
  3170. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3171. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3172. safe_package, _ := c.GetInt64("package", 0)
  3173. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3174. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3175. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3176. blood := c.GetString("blood")
  3177. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3178. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3179. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3180. displace_speed := c.GetString("displace_speed")
  3181. illness, _ := c.GetInt64("illness")
  3182. amylaceum := c.GetString("amylaceum")
  3183. single_time := c.GetString("single_time")
  3184. single_water := c.GetString("single_water")
  3185. replacement_flow := c.GetString("replacement_flow")
  3186. plasma_separator := c.GetString("plasma_separator")
  3187. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3188. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3189. oxygen_flow := c.GetString("oxygen_flow")
  3190. oxygen_time := c.GetString("oxygen_time")
  3191. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3192. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3193. puncture_needle := c.GetString("puncture_needle")
  3194. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3195. epo := c.GetString("epo")
  3196. epo_count, _ := c.GetFloat("epo_count", 0)
  3197. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3198. pre_impulse := c.GetString("pre_impulse")
  3199. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3200. admin_user_id, _ := c.GetInt64("admin_user_id")
  3201. is_water := c.GetString("is_water")
  3202. add_amount, _ := c.GetFloat("add_amount")
  3203. reduce_amount, _ := c.GetFloat("reduce_amount")
  3204. prescribing_number, _ := c.GetFloat("prescribing_number")
  3205. treatment_remark := c.GetString("treatment_remark")
  3206. prescription_sodium := c.GetString("prescription_sodium")
  3207. start_sodium := c.GetString("start_sodium")
  3208. sodium_curve := c.GetString("sodium_curve")
  3209. var is_war int64
  3210. if is_water == "是" {
  3211. is_war = 1
  3212. }
  3213. if is_water == "否" {
  3214. is_war = 2
  3215. }
  3216. if is_water == "请选择" {
  3217. is_war = 0
  3218. }
  3219. drhy_water := c.GetString("drhy_water")
  3220. dry_water_hour := c.GetString("dry_water_hour")
  3221. water_machine := c.GetString("water_machine")
  3222. dialysis_remark := c.GetString("dialysis_remark")
  3223. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3224. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3225. prescription_water, _ := c.GetFloat("prescription_water")
  3226. dialysis_strainer := c.GetString("dialysis_strainer")
  3227. chaptalization := c.GetString("chaptalization")
  3228. washing_time := c.GetString("washing_time")
  3229. warsh_count := c.GetString("warsh_count")
  3230. blood_access_part_id := c.GetString("blood_access_part_id")
  3231. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3232. dialyzate := c.GetString("dialyzate")
  3233. if mode_id > 0 {
  3234. var str string
  3235. //查找该机构用的是什么透析器
  3236. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3237. if filedConfig.ID > 0 {
  3238. str = dialyzerPerfusionApparatus
  3239. } else {
  3240. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3241. }
  3242. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3243. }
  3244. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3245. //
  3246. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3247. // if appRole.UserType == 3 {
  3248. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3249. // if getPermissionErr != nil {
  3250. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3251. // return
  3252. // } else if headNursePermission == nil {
  3253. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3254. // return
  3255. // }
  3256. // }
  3257. //}
  3258. // 查询信息规挡的设置天数
  3259. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3260. if infor.ID > 0 && infor.WeekDay > 0 {
  3261. var cha_time int64
  3262. timeNowStr := time.Now().Format("2006-01-02")
  3263. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3264. //今日的日期减去设置的日期
  3265. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3266. if cha_time >= recordDate.Unix() {
  3267. //查询审核是否允许
  3268. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3269. //申请状态不允许的情况 拒绝修改
  3270. if infor.ApplicationStatus != 1 {
  3271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3272. return
  3273. }
  3274. }
  3275. }
  3276. prescription := models.DialysisPrescription{
  3277. UserOrgId: adminUserInfo.Org.Id,
  3278. PatientId: id,
  3279. RecordDate: recordDate.Unix(),
  3280. ModeId: mode_id,
  3281. DialysisDuration: dialysis_duration,
  3282. Dialyzer: dialyzer,
  3283. PerfusionApparatus: perfusion_apparatus,
  3284. BloodFlowVolume: blood_flow_volume,
  3285. DewaterAmount: dewater_amount,
  3286. DisplaceLiqui: displace_liqui,
  3287. ReplacementWay: replacement_way,
  3288. Anticoagulant: anticoagulant,
  3289. AnticoagulantShouji: anticoagulant_shouji,
  3290. AnticoagulantWeichi: anticoagulant_weichi,
  3291. AnticoagulantZongliang: anticoagulant_zongliang,
  3292. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3293. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3294. Kalium: kalium,
  3295. Sodium: sodium,
  3296. Calcium: calcium,
  3297. Bicarbonate: bicarbonate,
  3298. Glucose: glucose,
  3299. // DryWeight: dry_weight,
  3300. DialysateFlow: dialysate_flow,
  3301. DialysateTemperature: dialysate_temperature,
  3302. Conductivity: conductivity,
  3303. Remark: remark,
  3304. Status: 1,
  3305. CreatedTime: time.Now().Unix(),
  3306. UpdatedTime: time.Now().Unix(),
  3307. DialysisDurationMinute: dialysisDurationMinute,
  3308. DialysisDurationHour: dialysisDurationHour,
  3309. TargetUltrafiltration: targetUltrafiltration,
  3310. DialysateFormulation: dialysateFormulation,
  3311. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3312. BodyFluid: body_fluid,
  3313. SpecialMedicine: special_medicine,
  3314. SpecialMedicineOther: special_medicine_other,
  3315. DisplaceLiquiPart: displace_liqui_part,
  3316. DisplaceLiquiValue: displace_liqui_value,
  3317. BloodAccess: blood_access,
  3318. Ultrafiltration: ultrafiltration,
  3319. BodyFluidOther: body_fluid_other,
  3320. ReplacementTotal: replacement_total,
  3321. Niprocart: niprocart,
  3322. Jms: jms,
  3323. FistulaNeedleSet: fistula_needle_set,
  3324. FistulaNeedleSet16: fistula_needle_set_16,
  3325. Hemoperfusion: hemoperfusion,
  3326. DialyserSterilised: dialyser_sterilised,
  3327. Filtryzer: filtryzer,
  3328. TargetKtv: target_ktv,
  3329. Dialyzers: dialyzers,
  3330. Injector: injector,
  3331. Bloodlines: bloodlines,
  3332. TubingHemodialysis: tubing_hemodialysis,
  3333. Package: safe_package,
  3334. ALiquid: a_liquid,
  3335. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3336. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3337. Blood: blood,
  3338. DialysisDialyszers: dialysis_dialyszers,
  3339. DialysisIrrigation: dialysis_irrigation,
  3340. AntioxidantCommodityName: antioxidant_commodity_name,
  3341. DisplaceSpeed: displace_speed,
  3342. Illness: illness,
  3343. Amylaceum: amylaceum,
  3344. SingleWater: single_water,
  3345. SingleTime: single_time,
  3346. ReplacementFlow: replacement_flow,
  3347. PlasmaSeparator: plasma_separator,
  3348. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3349. OxygenUptake: oxygen_uptake,
  3350. OxygenTime: oxygen_time,
  3351. OxygenFlow: oxygen_flow,
  3352. HemodialysisPipelines: hemodialysis_pipelines,
  3353. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3354. PunctureNeedle: puncture_needle,
  3355. PunctureNeedleCount: puncture_needle_count,
  3356. Epo: epo,
  3357. EpoCount: epo_count,
  3358. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3359. PreImpulse: impulse,
  3360. AdminUserId: admin_user_id,
  3361. IsWater: is_war,
  3362. DrhyWater: drhy_water,
  3363. DryWaterHour: dry_water_hour,
  3364. WaterMachine: water_machine,
  3365. AddAmount: add_amount,
  3366. ReduceAmount: reduce_amount,
  3367. DialysisRemark: dialysis_remark,
  3368. PrescribingNumber: prescribing_number,
  3369. PrescriptionSodium: prescription_sodium,
  3370. StartSodium: start_sodium,
  3371. SodiumCurve: sodium_curve,
  3372. TreatmentRemark: treatment_remark,
  3373. DialysisFluidFlow: dialysis_fluid_flow,
  3374. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3375. PrescriptionWater: prescription_water,
  3376. DialysisStrainer: dialysis_strainer,
  3377. Chaptalization: chaptalization,
  3378. WashingTime: washing_time,
  3379. WarshCount: warsh_count,
  3380. BloodAccessPartId: blood_access_part_id,
  3381. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3382. Dialyzate: dialyzate,
  3383. }
  3384. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3385. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3386. //
  3387. if appRole.UserType == 2 || appRole.UserType == 1 {
  3388. prescription_doctor = adminUserInfo.AdminUser.Id
  3389. prescription.PrescriptionDoctor = prescription_doctor
  3390. }
  3391. if dialysisPrescription.ID == 0 { //新增
  3392. prescription.Creater = adminUserInfo.AdminUser.Id
  3393. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3394. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3395. }
  3396. } else { //修改
  3397. if dialysisPrescription.Creater == 0 {
  3398. prescription.Creater = adminUserInfo.AdminUser.Id
  3399. } else {
  3400. prescription.Creater = dialysisPrescription.Creater
  3401. if adminUserInfo.Org.Id == 9882 {
  3402. if appRole.UserType == 2 || appRole.UserType == 1 {
  3403. prescription.Creater = adminUserInfo.AdminUser.Id
  3404. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3405. }
  3406. }
  3407. }
  3408. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3409. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3410. }
  3411. //if/**/
  3412. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3413. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3414. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3415. // if getPermissionErr != nil {
  3416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3417. // return
  3418. // } else if headNursePermission == nil {
  3419. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3420. // return
  3421. // }
  3422. //}
  3423. //prescription.Creater = dialysisPrescription.Creater
  3424. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3425. prescription.Modifier = adminUserInfo.AdminUser.Id
  3426. prescription.ID = dialysisPrescription.ID
  3427. }
  3428. solution := models.DialysisSolution{
  3429. RegistrarsId: adminUserInfo.AdminUser.Id,
  3430. UserOrgId: adminUserInfo.Org.Id,
  3431. Doctor: prescription_doctor,
  3432. PatientId: id,
  3433. ModeId: mode_id,
  3434. DialysisDuration: dialysis_duration,
  3435. PerfusionApparatus: perfusion_apparatus,
  3436. BloodFlowVolume: blood_flow_volume,
  3437. Dewater: dewater_amount,
  3438. DisplaceLiqui: displace_liqui,
  3439. ReplacementWay: replacement_way,
  3440. Anticoagulant: anticoagulant,
  3441. AnticoagulantShouji: anticoagulant_shouji,
  3442. AnticoagulantWeichi: anticoagulant_weichi,
  3443. AnticoagulantZongliang: anticoagulant_zongliang,
  3444. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3445. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3446. Kalium: kalium,
  3447. Sodium: sodium,
  3448. Calcium: calcium,
  3449. Bicarbonate: bicarbonate,
  3450. Glucose: glucose,
  3451. // DryWeight: dry_weight,
  3452. DialysateFlow: dialysate_flow,
  3453. DialysateTemperature: dialysate_temperature,
  3454. Conductivity: conductivity,
  3455. Remark: remark,
  3456. Status: 1,
  3457. CreatedTime: time.Now().Unix(),
  3458. UpdatedTime: time.Now().Unix(),
  3459. DialysisDurationMinute: dialysisDurationMinute,
  3460. DialysisDurationHour: dialysisDurationHour,
  3461. TargetUltrafiltration: targetUltrafiltration,
  3462. DialysateFormulation: dialysateFormulation,
  3463. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3464. BodyFluid: body_fluid,
  3465. SpecialMedicine: special_medicine,
  3466. SpecialMedicineOther: special_medicine_other,
  3467. DisplaceLiquiPart: displace_liqui_part,
  3468. DisplaceLiquiValue: displace_liqui_value,
  3469. BloodAccess: blood_access,
  3470. Ultrafiltration: ultrafiltration,
  3471. BodyFluidOther: body_fluid_other,
  3472. ReplacementTotal: replacement_total,
  3473. TargetKtv: target_ktv,
  3474. DialysisDialyszers: dialysis_dialyszers,
  3475. DialysisIrrigation: dialysis_irrigation,
  3476. HemodialysisPipelines: hemodialysis_pipelines,
  3477. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3478. PunctureNeedle: puncture_needle,
  3479. PunctureNeedleCount: puncture_needle_count,
  3480. Epo: epo,
  3481. EpoCount: epo_count,
  3482. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3483. PreImpulse: impulse,
  3484. SolutionStatus: 1,
  3485. DialysisRemark: dialysis_remark,
  3486. PrescribingNumber: prescribing_number,
  3487. PrescriptionSodium: prescription_sodium,
  3488. StartSodium: start_sodium,
  3489. SodiumCurve: sodium_curve,
  3490. TreatmentRemark: treatment_remark,
  3491. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3492. DialysisFluidFlow: dialysis_fluid_flow,
  3493. PrescriptionWater: prescription_water,
  3494. DialysisStrainer: dialysis_strainer,
  3495. Chaptalization: chaptalization,
  3496. WashingTime: washing_time,
  3497. WarshCount: warsh_count,
  3498. BloodAccessPartId: blood_access_part_id,
  3499. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3500. Dialyzate: dialyzate,
  3501. }
  3502. //针对河间咸的
  3503. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3504. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3505. solution.DisplaceLiquiPart = 0
  3506. solution.DisplaceLiquiValue = 0
  3507. }
  3508. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3509. prescription.DisplaceLiquiPart = 0
  3510. prescription.DisplaceLiquiValue = 0
  3511. }
  3512. }
  3513. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3514. if solution.PrescribingNumber == 0 {
  3515. solution.PrescribingNumber = 1
  3516. }
  3517. if prescription.PrescribingNumber == 0 {
  3518. prescription.PrescribingNumber = 1
  3519. }
  3520. if solution.PrescribingNumber == 0 && id == 14682 {
  3521. solution.PrescribingNumber = 2
  3522. }
  3523. if solution.PrescribingNumber == 0 && id == 18560 {
  3524. solution.PrescribingNumber = 2
  3525. }
  3526. if prescription.PrescribingNumber == 0 && id == 14682 {
  3527. prescription.PrescribingNumber = 2
  3528. }
  3529. if prescription.PrescribingNumber == 0 && id == 18560 {
  3530. prescription.PrescribingNumber = 2
  3531. }
  3532. }
  3533. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3534. //记录日志
  3535. byterequest, _ := json.Marshal(prescription)
  3536. prescriptionLog := models.XtDialysisPrescriptionLog{
  3537. UserOrgId: prescription.UserOrgId,
  3538. Ctime: time.Now().Unix(),
  3539. Mtime: 0,
  3540. ErrLog: string(byterequest),
  3541. AdminUserId: adminUserInfo.AdminUser.Id,
  3542. RecordDate: prescription.RecordDate,
  3543. PatientId: prescription.PatientId,
  3544. Source: "手机端新增长期处方",
  3545. Status: 1,
  3546. }
  3547. service.CreatePrescriptionLog(prescriptionLog)
  3548. finish := models.XtDialysisFinish{
  3549. IsFinish: 1,
  3550. UserOrgId: adminUserInfo.Org.Id,
  3551. Status: 1,
  3552. Ctime: time.Now().Unix(),
  3553. Mtime: 0,
  3554. Module: 1,
  3555. RecordDate: recordDate.Unix(),
  3556. Sourse: 1,
  3557. PatientId: id,
  3558. }
  3559. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3560. if dialysisFinish.ID == 0 {
  3561. service.CreateDialysisFinish(finish)
  3562. }
  3563. //获取最新1条
  3564. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3565. //更新状态
  3566. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3567. //长沙南雅医院,自动生成抗凝剂的临时处方
  3568. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3569. if prescribing_number == 0 {
  3570. prescribing_number = 1
  3571. }
  3572. advice := models.DoctorAdvice{
  3573. UserOrgId: adminUserInfo.Org.Id,
  3574. PatientId: id,
  3575. GroupNo: 0,
  3576. AdviceType: 2,
  3577. RecordDate: recordDate.Unix(),
  3578. AdviceDate: recordDate.Unix(),
  3579. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3580. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3581. AdviceDesc: "",
  3582. ReminderDate: 0,
  3583. SingleDose: prescription.AnticoagulantZongliang,
  3584. SingleDoseUnit: "iu",
  3585. DrugSpec: 0,
  3586. DrugSpecUnit: "",
  3587. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3588. PrescribingNumberUnit: "支",
  3589. DeliveryWay: "静脉注射",
  3590. ExecutionFrequency: "上机前",
  3591. AdviceDoctor: 0,
  3592. Status: 1,
  3593. CreatedTime: time.Now().Unix(),
  3594. UpdatedTime: time.Now().Unix(),
  3595. IsPrescription: 1,
  3596. ExecutionState: 2,
  3597. StopState: 2,
  3598. IsSettle: 2,
  3599. }
  3600. // 查询排班信息
  3601. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3602. if schedulePatient.ID > 0 {
  3603. if schedulePatient.ScheduleType == 1 {
  3604. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3605. }
  3606. if schedulePatient.ScheduleType == 2 {
  3607. advice.StartTime = recordDate.Unix() + 10*60*60
  3608. }
  3609. }
  3610. // 抗凝剂名称
  3611. switch anticoagulant {
  3612. case 1:
  3613. advice.AdviceName = "无肝素"
  3614. break
  3615. case 2:
  3616. advice.AdviceName = "普通肝素"
  3617. break
  3618. case 3:
  3619. advice.AdviceName = "低分子肝素"
  3620. break
  3621. case 4:
  3622. advice.AdviceName = "阿加曲班"
  3623. break
  3624. case 5:
  3625. advice.AdviceName = "枸橼酸钠"
  3626. break
  3627. case 6:
  3628. advice.AdviceName = "低分子肝素钙"
  3629. break
  3630. case 7:
  3631. advice.AdviceName = "低分子肝素钠"
  3632. break
  3633. case 8:
  3634. advice.AdviceName = "依诺肝素"
  3635. break
  3636. case 9:
  3637. advice.AdviceName = "达肝素"
  3638. break
  3639. case 10:
  3640. advice.AdviceName = "体外抗凝"
  3641. break
  3642. case 11:
  3643. advice.AdviceName = "那曲肝素"
  3644. break
  3645. case 12:
  3646. advice.AdviceName = "无抗凝剂"
  3647. break
  3648. }
  3649. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3650. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3651. advice.AdviceDoctor = appRole.AdminUserId
  3652. }
  3653. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3654. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3655. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3656. advice.AdviceName = "低分子肝素钠注射液"
  3657. // 修改患者临时医嘱里的抗凝剂医嘱
  3658. advice.ID = advicePrescription.ID
  3659. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3660. } else {
  3661. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3662. advice.AdviceName = "低分子肝素钠注射液"
  3663. service.CreateDoctorAdvice(&advice)
  3664. }
  3665. }
  3666. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3667. redis := service.RedisClient()
  3668. defer redis.Close()
  3669. //清空key 值
  3670. redis.Set(key, "", time.Second)
  3671. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3672. redis.Set(keyOne, "", time.Second)
  3673. }
  3674. //获取key,清空redis
  3675. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3676. redis := service.RedisClient()
  3677. defer redis.Close()
  3678. //清空key 值
  3679. redis.Set(key, "", time.Second)
  3680. //清空长期医嘱的key
  3681. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3682. redis.Set(soulution_key, "", time.Second)
  3683. //查询最近透析准备表里是否存在 透析器 灌流器
  3684. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3685. redis.Set(keyOne, "", time.Second)
  3686. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3687. redis.Set(keyTwo, "", time.Second)
  3688. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3689. redis.Set(keyThree, "", time.Second)
  3690. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3691. redis.Set(keyFour, "", time.Second)
  3692. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3693. //
  3694. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3695. //
  3696. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3697. //if len(mation)>0{
  3698. // for _, item := range splitStr {
  3699. // for _,it := range mation{
  3700. // if(item == it.SpecificationName){
  3701. //
  3702. // //查询最近一次的透析器
  3703. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3704. //
  3705. // if errcode == gorm.ErrRecordNotFound{
  3706. // //插入数据
  3707. // prepare := models.DialysisBeforePrepare{
  3708. // UserOrgId: adminUserInfo.Org.Id,
  3709. // PatientId: id,
  3710. // RecordDate: recordDate.Unix(),
  3711. // GoodTypeId: it.GoodTypeId,
  3712. // GoodId: it.ID,
  3713. // Count: 1,
  3714. // Ctime: time.Now().Unix(),
  3715. // Creater: adminUserInfo.AdminUser.Id,
  3716. // Status:1,
  3717. //
  3718. // }
  3719. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3720. // fmt.Println("",errcode)
  3721. // }
  3722. // }
  3723. // }
  3724. //
  3725. // }
  3726. //
  3727. // for _, item := range splitIrrigation {
  3728. // for _,it := range mation{
  3729. // if(item == it.SpecificationName){
  3730. // //查询最近一次的透析器
  3731. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3732. // if errcode == gorm.ErrRecordNotFound{
  3733. // //插入数据
  3734. // prepare := models.DialysisBeforePrepare{
  3735. // UserOrgId: adminUserInfo.Org.Id,
  3736. // PatientId: id,
  3737. // RecordDate: recordDate.Unix(),
  3738. // GoodTypeId: it.GoodTypeId,
  3739. // GoodId: it.ID,
  3740. // Count: 1,
  3741. // Ctime: time.Now().Unix(),
  3742. // Creater: adminUserInfo.AdminUser.Id,
  3743. // Status:1,
  3744. //
  3745. // }
  3746. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3747. // fmt.Println(errcode)
  3748. // }
  3749. // }
  3750. // }
  3751. // }
  3752. //}
  3753. c.ServeSuccessJSON(map[string]interface{}{
  3754. "solution": &solution,
  3755. "prescription": &prescription,
  3756. })
  3757. }
  3758. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3759. patient, _ := c.GetInt64("patient", 0)
  3760. adminUserInfo := c.GetMobileAdminUserInfo()
  3761. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3762. c.ServeSuccessJSON(map[string]interface{}{
  3763. "receiveTreatmentAsses": receiveTreatmentAsses,
  3764. })
  3765. }
  3766. func (this *DialysisAPIController) PostSignInfo() {
  3767. patientID, _ := this.GetInt64("patient_id")
  3768. recordDateStr := this.GetString("date")
  3769. if patientID <= 0 {
  3770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3771. return
  3772. }
  3773. if len(recordDateStr) == 0 {
  3774. recordDateStr = time.Now().Format("2006-01-02")
  3775. }
  3776. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3777. if parseDateErr != nil {
  3778. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3780. return
  3781. }
  3782. adminInfo := this.GetMobileAdminUserInfo()
  3783. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3784. if err != nil {
  3785. this.ErrorLog("签名失败:%v", err)
  3786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3787. return
  3788. }
  3789. this.ServeSuccessJSON(map[string]interface{}{
  3790. "doctor_id": adminInfo.AdminUser.Id,
  3791. })
  3792. }
  3793. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3794. patientID, _ := this.GetInt64("patient_id")
  3795. adminInfo := this.GetMobileAdminUserInfo()
  3796. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3797. this.ServeSuccessJSON(map[string]interface{}{
  3798. "monitor": record,
  3799. })
  3800. }
  3801. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3802. thisTime := time.Now()
  3803. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3804. timeLayout := "2006-01-02 15:04:05"
  3805. loc, _ := time.LoadLocation("Local")
  3806. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3807. theAssessmentDateTime := theStartTime.Unix()
  3808. patientID, _ := this.GetInt64("patient_id")
  3809. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3810. adminInfo := this.GetMobileAdminUserInfo()
  3811. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3812. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3813. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3814. var ultrafiltration_rate float64
  3815. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3816. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3817. fmt.Println(evaluation)
  3818. fmt.Println("prescription.ID", prescription.ID)
  3819. if prescription.ID > 0 {
  3820. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3821. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3822. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3823. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3824. record.UltrafiltrationRate = ultrafiltration_rate
  3825. }
  3826. if adminInfo.Org.Id == 10597 {
  3827. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3828. record.UltrafiltrationRate = ultrafiltration_rate
  3829. }
  3830. if adminInfo.Org.Id == 10510 {
  3831. record.UltrafiltrationRate = 0
  3832. }
  3833. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3834. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3835. record.UltrafiltrationRate = ultrafiltration_rate
  3836. }
  3837. if template.TemplateId == 20 || template.TemplateId == 22 {
  3838. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3839. record.UltrafiltrationRate = ultrafiltration_rate
  3840. }
  3841. // 只针对方济医院
  3842. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3843. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3844. ultrafiltration_rate = value
  3845. record.UltrafiltrationRate = ultrafiltration_rate
  3846. }
  3847. if template.TemplateId == 41 || template.TemplateId == 47 {
  3848. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3849. record.UltrafiltrationRate = ultrafiltration_rate
  3850. }
  3851. if template.TemplateId == 43 {
  3852. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3853. record.UltrafiltrationRate = ultrafiltration_rate
  3854. }
  3855. if template.TemplateId == 46 || template.TemplateId == 54 {
  3856. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3857. record.UltrafiltrationRate = ultrafiltration_rate
  3858. }
  3859. 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 {
  3860. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3861. record.UltrafiltrationRate = ultrafiltration_rate
  3862. }
  3863. if adminInfo.Org.Id == 10469 {
  3864. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3865. record.UltrafiltrationRate = ultrafiltration_rate
  3866. }
  3867. if adminInfo.Org.Id == 10471 {
  3868. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3869. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3870. }
  3871. if adminInfo.Org.Id == 10460 {
  3872. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3873. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3874. }
  3875. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  3876. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3877. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3878. }
  3879. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3880. record.UltrafiltrationRate = 0
  3881. }
  3882. //if template.TemplateId == 47 {
  3883. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3884. // record.UltrafiltrationRate = ultrafiltration_rate
  3885. //}
  3886. }
  3887. }
  3888. // record.UltrafiltrationRate = ultrafiltration_rate
  3889. record.UltrafiltrationVolume = 0
  3890. 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
  3891. if ultrafiltration_rate > 0 {
  3892. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3893. record.UltrafiltrationVolume = value
  3894. }
  3895. }
  3896. 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
  3897. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3898. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3899. record.UltrafiltrationVolume = ultrafiltration_volume
  3900. }
  3901. }
  3902. if adminInfo.Org.Id == 10597 {
  3903. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3904. record.UltrafiltrationVolume = ultrafiltration_volume
  3905. }
  3906. //长沙南雅
  3907. 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 {
  3908. if ultrafiltration_rate > 0 {
  3909. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3910. record.UltrafiltrationVolume = ultrafiltration_volume
  3911. }
  3912. }
  3913. if adminInfo.Org.Id == 10471 {
  3914. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3915. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3916. }
  3917. if adminInfo.Org.Id == 10460 {
  3918. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3919. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3920. }
  3921. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3922. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3923. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3924. }
  3925. //长沙南雅累计血容量自动计算
  3926. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3927. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3928. //}
  3929. if template.TemplateId == 47 || template.TemplateId == 54 {
  3930. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3931. }
  3932. if adminInfo.Org.Id == 10510 {
  3933. record.UltrafiltrationVolume = 0
  3934. }
  3935. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3936. this.ServeSuccessJSON(map[string]interface{}{
  3937. "monitor": record,
  3938. "lastMonitorRecordList": lastMonitorRecordList,
  3939. })
  3940. }
  3941. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3942. record_id, _ := this.GetInt64("id")
  3943. nurseID, _ := this.GetInt64("start_nurse")
  3944. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3945. bedID, _ := this.GetInt64("bed")
  3946. start_time := this.GetString("start_time")
  3947. schedual_type, _ := this.GetInt64("schedual_type")
  3948. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3949. change_nurse, _ := this.GetInt64("change_nurse")
  3950. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3951. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3952. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3953. fmt.Println("quality_nurse_id", quality_nurse_id)
  3954. patient_id, _ := this.GetInt64("patient_id")
  3955. record_date, _ := this.GetInt64("record_date")
  3956. puncture_needle := this.GetString("puncture_needle")
  3957. puncture_way := this.GetString("puncture_way")
  3958. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3959. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3960. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3961. nuclein_date_str := this.GetString("nuclein_date_str")
  3962. order_remark := this.GetString("order_remark")
  3963. schedule_remark := this.GetString("schedule_remark")
  3964. catheter_operation := this.GetString("catheter_operation")
  3965. blood_flow_volume := this.GetString("blood_flow_volume")
  3966. if record_id == 0 {
  3967. this.ErrorLog("id:%v", record_id)
  3968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3969. return
  3970. }
  3971. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3972. if parseStartDateErr != nil {
  3973. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3975. return
  3976. }
  3977. adminUserInfo := this.GetMobileAdminUserInfo()
  3978. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3979. if getNurseErr != nil {
  3980. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3981. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3982. return
  3983. } else if nurse == nil {
  3984. this.ErrorLog("护士不存在")
  3985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3986. return
  3987. }
  3988. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3989. //if getNurseErr != nil {
  3990. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3991. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3992. // return
  3993. //} else if nurse == nil {
  3994. // this.ErrorLog("护士不存在")
  3995. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3996. // return
  3997. //}
  3998. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3999. if getDeviceNumberErr != nil {
  4000. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4002. return
  4003. } else if deviceNumber == nil {
  4004. this.ErrorLog("床位号不存在")
  4005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4006. return
  4007. }
  4008. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4009. //
  4010. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4011. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4012. // if getPermissionErr != nil {
  4013. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4014. // return
  4015. // } else if headNursePermission == nil {
  4016. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4017. // return
  4018. // }
  4019. //}
  4020. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4021. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4022. timeLayout := "2006-01-02 15:04:05"
  4023. loc, _ := time.LoadLocation("Local")
  4024. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4025. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4026. schedulestartTime := theStartTime.Unix()
  4027. scheduleendTime := theEndTime.Unix()
  4028. var theNucleinDate int64
  4029. timeLayoutOne := "2006-01-02"
  4030. if len(nuclein_date_str) > 0 {
  4031. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4032. if err != nil {
  4033. utils.ErrorLog(err.Error())
  4034. }
  4035. theNucleinDate = theTime.Unix()
  4036. }
  4037. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4038. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4039. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4040. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4041. if err == gorm.ErrRecordNotFound { //空床位
  4042. // 修改了床位逻辑
  4043. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4044. if daySchedule.ID > 0 {
  4045. //daySchedule.BedId = bedID
  4046. //daySchedule.PartitionId = deviceNumber.ZoneID
  4047. //daySchedule.ScheduleType = schedual_type
  4048. //daySchedule.UpdatedTime = time.Now().Unix()
  4049. //err := service.UpdateSchedule(&daySchedule)
  4050. xtSchedule := models.Schedule{
  4051. PartitionId: deviceNumber.ZoneID,
  4052. BedId: bedID,
  4053. ScheduleType: schedual_type,
  4054. UpdatedTime: time.Now().Unix(),
  4055. }
  4056. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4057. if err != nil {
  4058. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4059. return
  4060. }
  4061. }
  4062. } else if err == nil {
  4063. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4064. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4065. if daySchedule.ID > 0 {
  4066. //daySchedule.BedId = bedID
  4067. //daySchedule.PartitionId = deviceNumber.ZoneID
  4068. //
  4069. //daySchedule.ScheduleType = schedual_type
  4070. //daySchedule.UpdatedTime = time.Now().Unix()
  4071. //err := service.UpdateSchedule(&daySchedule)
  4072. xtSchedule := models.Schedule{
  4073. PartitionId: deviceNumber.ZoneID,
  4074. BedId: bedID,
  4075. ScheduleType: schedual_type,
  4076. UpdatedTime: time.Now().Unix(),
  4077. }
  4078. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4079. if err != nil {
  4080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4081. return
  4082. }
  4083. }
  4084. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4086. return
  4087. }
  4088. } else if err != nil {
  4089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4090. return
  4091. }
  4092. }
  4093. dialysisRecord := &models.DialysisOrder{
  4094. ID: record_id,
  4095. UserOrgId: adminUserInfo.Org.Id,
  4096. BedID: bedID,
  4097. StartNurse: nurseID,
  4098. StartTime: startDate.Unix(),
  4099. PunctureNurse: puncture_nurse,
  4100. Creator: adminUserInfo.AdminUser.Id,
  4101. Modifier: adminUserInfo.AdminUser.Id,
  4102. WashpipeNurse: washpipe_nurse,
  4103. SchedualType: schedual_type,
  4104. ChangeNurse: change_nurse,
  4105. DifficultPunctureNurse: difficult_puncture_nurse,
  4106. NewFistulaNurse: new_fistula_nurse,
  4107. QualityNurseId: quality_nurse_id,
  4108. PunctureNeedle: puncture_needle,
  4109. PunctureWay: puncture_way,
  4110. DialysisDialyszers: dialysis_dialyszers,
  4111. DialysisIrrigation: dialysis_irrigation,
  4112. BloodAccessId: blood_access_id,
  4113. NucleinDate: theNucleinDate,
  4114. OrderRemark: order_remark,
  4115. ScheduleRemark: schedule_remark,
  4116. CatheterOperation: catheter_operation,
  4117. BloodFlowVolume: blood_flow_volume,
  4118. }
  4119. //修改床位号需要重新消毒
  4120. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4121. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4122. //查询第一条监测
  4123. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4124. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4125. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4126. redis := service.RedisClient()
  4127. //清空key 值
  4128. redis.Set(key, "", time.Second)
  4129. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4130. redis.Set(keyOne, "", time.Second)
  4131. defer redis.Close()
  4132. }
  4133. // 查询信息规挡的设置天数
  4134. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4135. if infor.ID > 0 && infor.WeekDay > 0 {
  4136. var cha_time int64
  4137. timeNowStr := time.Now().Format("2006-01-02")
  4138. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4139. //今日的日期减去设置的日期
  4140. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4141. if cha_time >= record_date {
  4142. //查询审核是否允许
  4143. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4144. //申请状态不允许的情况 拒绝修改
  4145. if infor.ApplicationStatus != 1 {
  4146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4147. return
  4148. }
  4149. }
  4150. }
  4151. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4152. order, _ := service.GetLastPatientOrder(record_id)
  4153. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4154. redis := service.RedisClient()
  4155. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4156. redis.Set(key, "", time.Second)
  4157. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4158. //清空key 值
  4159. redis.Set(keyOne, "", time.Second)
  4160. scheduleDateStartOne := startDate.Format("2006-01-02")
  4161. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4162. redis.Set(keyTwo, "", time.Second)
  4163. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4164. redis.Set(keyThree, "", time.Second)
  4165. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4166. redis.Set(keyFour, "", time.Second)
  4167. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4168. redis.Set(keyFive, "", time.Second)
  4169. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4170. redis.Set(keySix, "", time.Second)
  4171. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4172. redis.Set(keySeven, "", time.Second)
  4173. if updateErr != nil {
  4174. this.ErrorLog("修改上机失败:%v", updateErr)
  4175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4176. return
  4177. }
  4178. if updateErr == nil {
  4179. if tempDialysisRecord.Stage == 2 {
  4180. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4181. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4182. fmt.Println(value)
  4183. a, b := math.Modf(value)
  4184. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4185. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4186. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4187. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4188. redis := service.RedisClient()
  4189. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4190. redis.Set(key, "", time.Second)
  4191. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4192. redis.Set(keyOne, "", time.Second)
  4193. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4194. //清空key 值
  4195. redis.Set(keySix, "", time.Second)
  4196. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4197. redis.Set(keySeven, "", time.Second)
  4198. redis.Close()
  4199. if updateAssessmentErr != nil {
  4200. utils.ErrorLog("%v", updateAssessmentErr)
  4201. }
  4202. }
  4203. }
  4204. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4205. this.ServeSuccessJSON(map[string]interface{}{
  4206. "dialysis_order": dialysisRecords,
  4207. })
  4208. }
  4209. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4210. record_id, _ := c.GetInt64("id")
  4211. nurseID, _ := c.GetInt64("nurse")
  4212. end_time := c.GetString("end_time")
  4213. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4214. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4215. catheter := c.GetString("catheter")
  4216. cruor := c.GetString("cruor")
  4217. mission := c.GetString("mission")
  4218. condenser := c.GetString("condenser")
  4219. if record_id <= 0 || nurseID <= 0 {
  4220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4221. return
  4222. }
  4223. adminUserInfo := c.GetMobileAdminUserInfo()
  4224. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4225. if getNurseErr != nil {
  4226. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4228. return
  4229. } else if nurse == nil {
  4230. c.ErrorLog("护士不存在")
  4231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4232. return
  4233. }
  4234. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4235. if parseEndDateErr != nil {
  4236. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4238. return
  4239. }
  4240. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4241. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4242. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4243. // if getPermissionErr != nil {
  4244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4245. // return
  4246. // } else if headNursePermission == nil {
  4247. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4248. // return
  4249. // }
  4250. //}
  4251. // 查询信息规挡的设置天数
  4252. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4253. if infor.ID > 0 {
  4254. var cha_time int64
  4255. timeNowStr := time.Now().Format("2006-01-02")
  4256. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4257. //今日的日期减去设置的日期
  4258. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4259. if cha_time >= tempDialysisRecords.DialysisDate {
  4260. //查询审核是否允许
  4261. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4262. //申请状态不允许的情况 拒绝修改
  4263. if infor.ApplicationStatus != 1 {
  4264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4265. return
  4266. }
  4267. }
  4268. }
  4269. dialysisRecord := &models.DialysisOrder{
  4270. ID: record_id,
  4271. UserOrgId: adminUserInfo.Org.Id,
  4272. EndTime: endDate.Unix(),
  4273. FinishNurse: nurseID,
  4274. FinishModifier: adminUserInfo.AdminUser.Id,
  4275. PuncturePointHaematoma: puncture_point_haematoma,
  4276. BloodAccessInternalFistula: blood_access_internal_fistula,
  4277. Catheter: catheter,
  4278. Cruor: cruor,
  4279. Mission: mission,
  4280. Condenser: condenser,
  4281. }
  4282. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4283. redis := service.RedisClient()
  4284. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4285. //清空key 值
  4286. redis.Set(key, "", time.Second)
  4287. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4288. //清空key 值
  4289. redis.Set(keyOne, "", time.Second)
  4290. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4291. redis.Set(keySeven, "", time.Second)
  4292. redis.Close()
  4293. if updateErr != nil {
  4294. c.ErrorLog("修改下机失败:%v", updateErr)
  4295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4296. return
  4297. }
  4298. if updateErr == nil {
  4299. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4300. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4301. a, b := math.Modf(value)
  4302. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4303. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4304. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4305. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4306. redis := service.RedisClient()
  4307. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4308. redis.Set(keyTen, "", time.Second)
  4309. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4310. redis.Set(keyTwo, "", time.Second)
  4311. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4312. redis.Set(key, "", time.Second)
  4313. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4314. redis.Set(keyThree, "", time.Second)
  4315. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4316. redis.Set(keySeven, "", time.Second)
  4317. defer redis.Close()
  4318. if updateAssessmentErr != nil {
  4319. utils.ErrorLog("%v", updateAssessmentErr)
  4320. }
  4321. }
  4322. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4323. c.ServeSuccessJSON(map[string]interface{}{
  4324. "dialysis_order": dialysisRecords,
  4325. })
  4326. }
  4327. func (c *DialysisAPIController) GetLongAdvice() {
  4328. patient_id, _ := c.GetInt64("id")
  4329. adminUserInfo := c.GetMobileAdminUserInfo()
  4330. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4331. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4332. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4333. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4334. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4335. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4336. c.ServeSuccessJSON(map[string]interface{}{
  4337. "status": "1",
  4338. })
  4339. return
  4340. } else { //开启推送提醒
  4341. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4342. var advice_three []*models.DoctorAdvice
  4343. recordDateStr := time.Now().Format("2006-01-02")
  4344. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4345. nowtime := recordDate.Unix()
  4346. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4347. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4348. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4349. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4350. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4351. for _, advice := range advices {
  4352. if advice.FrequencyType == 3 {
  4353. t := time.Now()
  4354. week := int(t.Weekday())
  4355. fmt.Println(t.Weekday())
  4356. fmt.Println(week)
  4357. switch week {
  4358. case 1:
  4359. if strings.Index(advice.WeekDay, "周一") == -1 {
  4360. advice_three = append(advice_three, advice)
  4361. }
  4362. break
  4363. case 2:
  4364. if strings.Index(advice.WeekDay, "周二") == -1 {
  4365. advice_three = append(advice_three, advice)
  4366. }
  4367. break
  4368. case 3:
  4369. if strings.Index(advice.WeekDay, "周三") == -1 {
  4370. advice_three = append(advice_three, advice)
  4371. }
  4372. break
  4373. case 4:
  4374. if strings.Index(advice.WeekDay, "周四") == -1 {
  4375. advice_three = append(advice_three, advice)
  4376. }
  4377. break
  4378. case 5:
  4379. if strings.Index(advice.WeekDay, "周五") == -1 {
  4380. advice_three = append(advice_three, advice)
  4381. }
  4382. break
  4383. case 6:
  4384. if strings.Index(advice.WeekDay, "周六") == -1 {
  4385. advice_three = append(advice_three, advice)
  4386. }
  4387. break
  4388. case 0:
  4389. if strings.Index(advice.WeekDay, "周日") == -1 {
  4390. advice_three = append(advice_three, advice)
  4391. }
  4392. break
  4393. }
  4394. }
  4395. }
  4396. for _, advice := range advices_two {
  4397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4398. now := p.Unix()
  4399. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4400. dayStr2 := "-" + dayStr
  4401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4403. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4404. for _, ad := range advices {
  4405. advice_three = append(advice_three, ad)
  4406. }
  4407. }
  4408. if err == nil {
  4409. c.ServeSuccessJSON(map[string]interface{}{
  4410. "status": "2",
  4411. "advices": advices,
  4412. "advices_two": RemoveRepeatedElement(advice_three),
  4413. "is_open_remind": config.IsOpenRemind,
  4414. "his_config_open": hisConfig.IsOpen,
  4415. "is_advice_open": is_advice_open.IsAdviceOpen,
  4416. "prescription_open": prescription_open.IsOpen,
  4417. })
  4418. }
  4419. }
  4420. }
  4421. func (c *DialysisAPIController) GetLongAdviceOne() {
  4422. patient_id, _ := c.GetInt64("id")
  4423. startTime := c.GetString("schedule_date")
  4424. timeLayout := "2006-01-02"
  4425. loc, _ := time.LoadLocation("Local")
  4426. var theStartTime int64
  4427. if len(startTime) > 0 {
  4428. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4429. if err != nil {
  4430. utils.ErrorLog(err.Error())
  4431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4432. return
  4433. }
  4434. theStartTime = theTime.Unix()
  4435. }
  4436. adminUserInfo := c.GetMobileAdminUserInfo()
  4437. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4438. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4439. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4440. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4441. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4442. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4443. c.ServeSuccessJSON(map[string]interface{}{
  4444. "status": "1",
  4445. })
  4446. return
  4447. } else { //开启推送提醒
  4448. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4449. var advice_three []*models.DoctorAdvice
  4450. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4451. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4452. for _, advice := range advices {
  4453. if advice.FrequencyType == 3 {
  4454. t := time.Now()
  4455. week := int(t.Weekday())
  4456. fmt.Println(t.Weekday())
  4457. fmt.Println(week)
  4458. switch week {
  4459. case 1:
  4460. if strings.Index(advice.WeekDay, "周一") == -1 {
  4461. advice_three = append(advice_three, advice)
  4462. }
  4463. break
  4464. case 2:
  4465. if strings.Index(advice.WeekDay, "周二") == -1 {
  4466. advice_three = append(advice_three, advice)
  4467. }
  4468. break
  4469. case 3:
  4470. if strings.Index(advice.WeekDay, "周三") == -1 {
  4471. advice_three = append(advice_three, advice)
  4472. }
  4473. break
  4474. case 4:
  4475. if strings.Index(advice.WeekDay, "周四") == -1 {
  4476. advice_three = append(advice_three, advice)
  4477. }
  4478. break
  4479. case 5:
  4480. if strings.Index(advice.WeekDay, "周五") == -1 {
  4481. advice_three = append(advice_three, advice)
  4482. }
  4483. break
  4484. case 6:
  4485. if strings.Index(advice.WeekDay, "周六") == -1 {
  4486. advice_three = append(advice_three, advice)
  4487. }
  4488. break
  4489. case 0:
  4490. if strings.Index(advice.WeekDay, "周日") == -1 {
  4491. advice_three = append(advice_three, advice)
  4492. }
  4493. break
  4494. }
  4495. }
  4496. }
  4497. for _, advice := range advices_two {
  4498. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4499. now := p.Unix()
  4500. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4501. dayStr2 := "-" + dayStr
  4502. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4503. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4504. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4505. for _, ad := range advices {
  4506. advice_three = append(advice_three, ad)
  4507. }
  4508. }
  4509. if err == nil {
  4510. c.ServeSuccessJSON(map[string]interface{}{
  4511. "status": "2",
  4512. "advices": advices,
  4513. "advices_two": RemoveRepeatedElement(advice_three),
  4514. "is_open_remind": config.IsOpenRemind,
  4515. "his_config_open": hisConfig.IsOpen,
  4516. "is_advice_open": is_advice_open.IsAdviceOpen,
  4517. "prescription_open": prescription_open.IsOpen,
  4518. })
  4519. }
  4520. }
  4521. }
  4522. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4523. newArr = make([]*models.DoctorAdvice, 0)
  4524. for i := 0; i < len(arr); i++ {
  4525. repeat := false
  4526. for j := i + 1; j < len(arr); j++ {
  4527. if arr[i].ID == arr[j].ID {
  4528. repeat = true
  4529. break
  4530. }
  4531. }
  4532. if !repeat {
  4533. newArr = append(newArr, arr[i])
  4534. }
  4535. }
  4536. return
  4537. }
  4538. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4539. patient, _ := c.GetInt64("id", 0)
  4540. groupNo, _ := c.GetInt64("groupno", 0)
  4541. if patient <= 0 {
  4542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4543. return
  4544. }
  4545. adminUserInfo := c.GetMobileAdminUserInfo()
  4546. dataBody := make(map[string]interface{}, 0)
  4547. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4548. if err != nil {
  4549. utils.ErrorLog(err.Error())
  4550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4551. return
  4552. }
  4553. utils.ErrorLog("%v", dataBody)
  4554. timeLayout := "2006-01-02 15:04"
  4555. loc, _ := time.LoadLocation("Local")
  4556. timeLayout2 := "2006-01-02"
  4557. loc2, _ := time.LoadLocation("Local")
  4558. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4559. utils.ErrorLog("advice_type")
  4560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4561. return
  4562. }
  4563. adviceType := int64(2)
  4564. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4565. utils.ErrorLog("advice_date")
  4566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4567. return
  4568. }
  4569. adviceDate, _ := dataBody["advice_date"].(string)
  4570. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4571. AdviceDate := theTime.Unix()
  4572. RecordDate := theTime.Unix()
  4573. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4574. utils.ErrorLog("start_time")
  4575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4576. return
  4577. }
  4578. startTime, _ := dataBody["start_time"].(string)
  4579. if len(startTime) == 0 {
  4580. utils.ErrorLog("len(start_time) == 0")
  4581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4582. return
  4583. }
  4584. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4585. if err != nil {
  4586. utils.ErrorLog(err.Error())
  4587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4588. return
  4589. }
  4590. StartTime := theTime.Unix()
  4591. Remark := ""
  4592. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4593. remark, _ := dataBody["remark"].(string)
  4594. Remark = remark
  4595. }
  4596. var advices []*models.GroupAdvice
  4597. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4598. utils.ErrorLog("advices")
  4599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4600. return
  4601. }
  4602. adviceNames := dataBody["advices"].([]interface{})
  4603. for _, adviceNameMap := range adviceNames {
  4604. adviceNameM := adviceNameMap.(map[string]interface{})
  4605. var advice models.GroupAdvice
  4606. advice.Remark = Remark
  4607. advice.AdviceType = adviceType
  4608. advice.StartTime = StartTime
  4609. advice.AdviceDate = AdviceDate
  4610. advice.RecordDate = RecordDate
  4611. advice.Status = 1
  4612. advice.CreatedTime = time.Now().Unix()
  4613. advice.UpdatedTime = time.Now().Unix()
  4614. advice.StopState = 2
  4615. advice.ExecutionState = 2
  4616. advice.UserOrgId = adminUserInfo.Org.Id
  4617. advice.PatientId = patient
  4618. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4619. advice.IsSettle = 2
  4620. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4621. utils.ErrorLog("advice_name")
  4622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4623. return
  4624. }
  4625. adviceName, _ := adviceNameM["advice_name"].(string)
  4626. if len(adviceName) == 0 {
  4627. utils.ErrorLog("len(advice_name) == 0")
  4628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4629. return
  4630. }
  4631. advice.AdviceName = adviceName
  4632. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4633. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4634. advice.DrugSpec = drugSpec
  4635. }
  4636. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4637. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4638. advice.AdviceDesc = adviceDesc
  4639. }
  4640. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4641. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4642. advice.DrugSpecUnit = drugSpecUnit
  4643. }
  4644. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4645. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4646. // advice.SingleDose = singleDose
  4647. //}
  4648. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4649. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4650. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4651. }
  4652. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4653. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4654. advice.SingleDoseUnit = singleDoseUnit
  4655. }
  4656. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4657. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4658. // advice.PrescribingNumber = prescribingNumber
  4659. //}
  4660. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4661. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4662. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4663. }
  4664. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4665. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4666. advice.PrescribingNumberUnit = prescribingNumberUnit
  4667. }
  4668. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4669. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4670. advice.DeliveryWay = deliveryWay
  4671. }
  4672. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4673. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4674. advice.ExecutionFrequency = executionFrequency
  4675. }
  4676. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4677. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4678. advice.FrequencyType = frequency_type
  4679. }
  4680. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4681. day_count := int64(adviceNameM["day_count"].(float64))
  4682. advice.DayCount = day_count
  4683. }
  4684. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4685. week_day, _ := adviceNameM["week_day"].(string)
  4686. advice.WeekDay = week_day
  4687. }
  4688. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4689. way := int64(adviceNameM["way"].(float64))
  4690. advice.Way = way
  4691. }
  4692. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4693. drug_id := int64(adviceNameM["drug_id"].(float64))
  4694. advice.DrugId = drug_id
  4695. }
  4696. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4697. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4698. advice.DrugNameId = drug_name_id
  4699. }
  4700. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4701. remark, _ := adviceNameM["remark"].(string)
  4702. advice.Remark = remark
  4703. }
  4704. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4705. groupno := int64(adviceNameM["groupno"].(float64))
  4706. advice.GroupNo = groupno
  4707. }
  4708. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4709. template_id, _ := adviceNameM["template_id"].(string)
  4710. advice.TemplateId = template_id
  4711. }
  4712. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4713. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4714. advice.ExecutionFrequency = executionFrequency
  4715. }
  4716. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4717. children := adviceNameM["child"].([]interface{})
  4718. if len(children) > 0 {
  4719. for _, childrenMap := range children {
  4720. childMap := childrenMap.(map[string]interface{})
  4721. var child models.GroupAdvice
  4722. child.Remark = Remark
  4723. child.AdviceType = adviceType
  4724. child.StartTime = StartTime
  4725. child.AdviceDate = AdviceDate
  4726. child.RecordDate = RecordDate
  4727. child.Status = 1
  4728. child.CreatedTime = time.Now().Unix()
  4729. child.UpdatedTime = time.Now().Unix()
  4730. child.StopState = 2
  4731. child.ExecutionState = 2
  4732. child.UserOrgId = adminUserInfo.Org.Id
  4733. child.PatientId = patient
  4734. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4735. child.IsSettle = 1
  4736. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4737. utils.ErrorLog("child advice_name")
  4738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4739. return
  4740. }
  4741. childAdviceName, _ := childMap["advice_name"].(string)
  4742. if len(childAdviceName) == 0 {
  4743. utils.ErrorLog("len(child advice_name) == 0")
  4744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4745. return
  4746. }
  4747. child.AdviceName = childAdviceName
  4748. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4749. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4750. child.AdviceDesc = childAdviceDesc
  4751. }
  4752. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4753. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4754. child.DrugSpec = childDrugSpec
  4755. }
  4756. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4757. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4758. child.DrugSpecUnit = childDrugSpecUnit
  4759. }
  4760. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4761. child.SingleDose = childMap["single_dose"].(float64)
  4762. }
  4763. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4764. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4765. child.SingleDoseUnit = childSingleDoseUnit
  4766. }
  4767. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4768. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4769. }
  4770. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4771. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4772. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4773. }
  4774. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4775. groupno := int64(childMap["groupno"].(float64))
  4776. advice.GroupNo = groupno
  4777. }
  4778. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4779. remark, _ := childMap["remark"].(string)
  4780. child.Remark = remark
  4781. }
  4782. child.DeliveryWay = advice.DeliveryWay
  4783. child.ExecutionFrequency = advice.ExecutionFrequency
  4784. advice.Children = append(advice.Children, &child)
  4785. }
  4786. }
  4787. }
  4788. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4789. if temp_advice.ID == 0 {
  4790. advices = append(advices, &advice)
  4791. }
  4792. }
  4793. if len(advices) > 0 {
  4794. finish := models.XtDialysisFinish{
  4795. IsFinish: 1,
  4796. UserOrgId: adminUserInfo.Org.Id,
  4797. Status: 1,
  4798. Ctime: time.Now().Unix(),
  4799. Mtime: 0,
  4800. Module: 4,
  4801. RecordDate: AdviceDate,
  4802. Sourse: 1,
  4803. PatientId: patient,
  4804. }
  4805. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4806. if dialysisFinish.ID == 0 {
  4807. service.CreateDialysisFinish(finish)
  4808. }
  4809. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4810. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4811. for _, item := range advices {
  4812. byterequest, _ := json.Marshal(item)
  4813. adviceLog := models.XtDoctorAdviceLog{
  4814. UserOrgId: adminUserInfo.Org.Id,
  4815. PatientId: patient,
  4816. AdminUserId: adminUserInfo.AdminUser.Id,
  4817. Module: 1,
  4818. ErrLog: string(byterequest),
  4819. Status: 1,
  4820. Ctime: time.Now().Unix(),
  4821. Mtime: 0,
  4822. Source: "手机端医嘱推送",
  4823. RecordDate: item.AdviceDate,
  4824. }
  4825. service.CreateDoctorAdviceLog(adviceLog)
  4826. }
  4827. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4828. redis := service.RedisClient()
  4829. //清空key 值
  4830. redis.Set(key, "", time.Second)
  4831. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4832. redis.Set(keyOne, "", time.Second)
  4833. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4834. defer redis.Close()
  4835. redis.Set(keyThree, "", time.Second)
  4836. if err != nil {
  4837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4838. return
  4839. }
  4840. c.ServeSuccessJSON(map[string]interface{}{
  4841. "msg": "ok",
  4842. "advices": list,
  4843. })
  4844. } else {
  4845. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4846. for _, item := range advices {
  4847. byterequest, _ := json.Marshal(item)
  4848. adviceLog := models.XtDoctorAdviceLog{
  4849. UserOrgId: adminUserInfo.Org.Id,
  4850. PatientId: patient,
  4851. AdminUserId: adminUserInfo.AdminUser.Id,
  4852. Module: 1,
  4853. ErrLog: string(byterequest),
  4854. Status: 1,
  4855. Ctime: time.Now().Unix(),
  4856. Mtime: 0,
  4857. Source: "手机端医嘱推送",
  4858. RecordDate: item.AdviceDate,
  4859. }
  4860. service.CreateDoctorAdviceLog(adviceLog)
  4861. }
  4862. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4863. redis := service.RedisClient()
  4864. //清空key 值
  4865. redis.Set(key, "", time.Second)
  4866. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4867. redis.Set(keyOne, "", time.Second)
  4868. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4869. defer redis.Close()
  4870. redis.Set(keyThree, "", time.Second)
  4871. if err != nil {
  4872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4873. return
  4874. }
  4875. c.ServeSuccessJSON(map[string]interface{}{
  4876. "msg": "ok",
  4877. "advices": list,
  4878. })
  4879. }
  4880. } else {
  4881. c.ServeSuccessJSON(map[string]interface{}{
  4882. "msg": "ok",
  4883. })
  4884. }
  4885. return
  4886. }
  4887. func (c *DialysisAPIController) UploadDryWeight() {
  4888. patient_id, _ := c.GetInt64("id")
  4889. dry_weight, _ := c.GetFloat("dry_weight")
  4890. doctor_id, _ := c.GetInt64("doctor_id")
  4891. remark := c.GetString("remark")
  4892. adminUserInfo := c.GetMobileAdminUserInfo()
  4893. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4894. if err == gorm.ErrRecordNotFound {
  4895. dryWeight := &models.SgjPatientDryweight{
  4896. PatientId: patient_id,
  4897. DryWeight: dry_weight,
  4898. Remakes: remark,
  4899. Ctime: time.Now().Unix(),
  4900. Mtime: time.Now().Unix(),
  4901. Creator: doctor_id,
  4902. Status: 1,
  4903. UserOrgId: adminUserInfo.Org.Id,
  4904. AdjustedValue: "/",
  4905. UserId: adminUserInfo.AdminUser.Id,
  4906. }
  4907. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4908. redis := service.RedisClient()
  4909. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4910. redis.Set(keyOne, "", time.Second)
  4911. loc, _ := time.LoadLocation("Local")
  4912. nowTime := time.Now()
  4913. nowDay := nowTime.Format("2006-01-02")
  4914. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4915. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4916. redis.Set(key, "", time.Second)
  4917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4918. redis.Set(keyTwo, "", time.Second)
  4919. redis.Close()
  4920. if createErr == nil {
  4921. c.ServeSuccessJSON(map[string]interface{}{
  4922. "msg": "提交成功",
  4923. "weight": dryWeight,
  4924. })
  4925. }
  4926. } else {
  4927. dryWeight := &models.SgjPatientDryweight{
  4928. PatientId: patient_id,
  4929. DryWeight: dry_weight,
  4930. Remakes: remark,
  4931. Ctime: time.Now().Unix(),
  4932. Mtime: time.Now().Unix(),
  4933. Creator: doctor_id,
  4934. Status: 1,
  4935. UserOrgId: adminUserInfo.Org.Id,
  4936. AdjustedValue: "/",
  4937. UserId: adminUserInfo.AdminUser.Id,
  4938. }
  4939. var value float64
  4940. value = dry_weight - weightAdjust.DryWeight
  4941. if value < 0 {
  4942. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4943. } else if value == 0 {
  4944. dryWeight.AdjustedValue = "/"
  4945. } else if value > 0 {
  4946. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4947. }
  4948. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4949. redis := service.RedisClient()
  4950. loc, _ := time.LoadLocation("Local")
  4951. nowTime := time.Now()
  4952. nowDay := nowTime.Format("2006-01-02")
  4953. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4954. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4955. redis.Set(keyOne, "", time.Second)
  4956. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4957. redis.Set(key, "", time.Second)
  4958. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4959. redis.Set(keyTwo, "", time.Second)
  4960. redis.Close()
  4961. if createErr == nil {
  4962. c.ServeSuccessJSON(map[string]interface{}{
  4963. "msg": "提交成功",
  4964. "weight": dryWeight,
  4965. })
  4966. }
  4967. }
  4968. }
  4969. func (c *DialysisAPIController) GetSolution() {
  4970. patient_id, _ := c.GetInt64("patient_id")
  4971. mode_id, _ := c.GetInt64("mode_id")
  4972. adminUserInfo := c.GetMobileAdminUserInfo()
  4973. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4974. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4975. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4976. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4977. if err != nil {
  4978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4979. return
  4980. }
  4981. c.ServeSuccessJSON(map[string]interface{}{
  4982. "solution": solution,
  4983. "prescription": prescription,
  4984. "system_prescription": system_prescription,
  4985. "dialysisPrescription": dialysisPrescription,
  4986. })
  4987. }
  4988. func (c *DialysisAPIController) GetSchedule() {
  4989. schedual_type, _ := c.GetInt64("schedual_type")
  4990. adminUserInfo := c.GetMobileAdminUserInfo()
  4991. scheduleTime, _ := c.GetInt64("record_date")
  4992. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4993. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4994. c.ServeSuccessJSON(map[string]interface{}{
  4995. "number": deviceNumber,
  4996. "list": list,
  4997. })
  4998. }
  4999. func (c *DialysisAPIController) GetPatientId() {
  5000. id, _ := c.GetInt64("id")
  5001. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5002. patientId, _ := service.GetPatientId(id)
  5003. //获取该患者的所有传染病
  5004. list, _ := service.GetPatientInfectious(id)
  5005. c.ServeSuccessJSON(map[string]interface{}{
  5006. "patient": patientId,
  5007. "infectioulist": list,
  5008. })
  5009. }
  5010. func (this *DialysisAPIController) GetDialysisSchedule() {
  5011. schedualDate := this.GetString("date")
  5012. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5013. if parseDateErr != nil {
  5014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5015. return
  5016. }
  5017. adminInfo := this.GetMobileAdminUserInfo()
  5018. orgID := adminInfo.Org.Id
  5019. redis := service.RedisClient()
  5020. defer redis.Close()
  5021. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5022. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5023. if len(scheduals) > 0 {
  5024. //缓存数据
  5025. scheduals_json, err := json.Marshal(scheduals)
  5026. if err == nil {
  5027. redis.Set(key, scheduals_json, time.Second*30)
  5028. }
  5029. }
  5030. this.ServeSuccessJSON(map[string]interface{}{
  5031. "scheduals": scheduals,
  5032. })
  5033. }
  5034. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5035. change_type, _ := this.GetInt64("type", 0)
  5036. record_date := this.GetString("record_time")
  5037. patient_id, _ := this.GetInt64("patient_id", 0)
  5038. timeLayout := "2006-01-02"
  5039. loc, _ := time.LoadLocation("Local")
  5040. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5041. record_time := theAdviceRecordTime.Unix()
  5042. adminUserInfo := this.GetMobileAdminUserInfo()
  5043. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5044. if err == nil {
  5045. if len(advices) == 0 {
  5046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5047. return
  5048. } else {
  5049. this.ServeSuccessJSON(map[string]interface{}{
  5050. "advices": advices,
  5051. "schedule": sch,
  5052. })
  5053. return
  5054. }
  5055. } else {
  5056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5057. return
  5058. }
  5059. }
  5060. func (c *DialysisAPIController) CreateConsumables() {
  5061. record_date := c.GetString("record_time")
  5062. patient_id, _ := c.GetInt64("patient_id", 0)
  5063. active, _ := c.GetInt64("active")
  5064. adminUser := c.GetMobileAdminUserInfo()
  5065. timeLayout := "2006-01-02"
  5066. loc, _ := time.LoadLocation("Local")
  5067. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5068. record_time := theRecordTime.Unix()
  5069. // 查询信息规挡的设置天数
  5070. orgid := c.GetMobileAdminUserInfo().Org.Id
  5071. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5072. if infor.ID > 0 {
  5073. var cha_time int64
  5074. timeNowStr := time.Now().Format("2006-01-02")
  5075. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5076. //今日的日期减去设置的日期
  5077. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5078. if cha_time >= record_time {
  5079. //查询审核是否允许
  5080. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5081. //申请状态不允许的情况 拒绝修改
  5082. if infor.ApplicationStatus != 1 {
  5083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5084. return
  5085. }
  5086. }
  5087. }
  5088. dataBody := make(map[string]interface{}, 0)
  5089. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5090. if err != nil {
  5091. utils.ErrorLog(err.Error())
  5092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5093. return
  5094. }
  5095. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5096. var beforePrepares []*models.DialysisBeforePrepareGoods
  5097. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5098. var dialysisBefor []*models.DialysisBeforePrepare
  5099. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5100. goods, _ := dataBody["goods"].([]interface{})
  5101. if len(goods) > 0 {
  5102. for _, item := range goods {
  5103. items := item.(map[string]interface{})
  5104. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5105. utils.ErrorLog("good_id")
  5106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5107. return
  5108. }
  5109. good_id := int64(items["good_id"].(float64))
  5110. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5111. utils.ErrorLog("good_type_id")
  5112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5113. return
  5114. }
  5115. good_type_id := int64(items["good_type_id"].(float64))
  5116. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5117. utils.ErrorLog("count")
  5118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5119. return
  5120. }
  5121. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5122. commdity_code := items["commdity_code"].(string)
  5123. fmt.Println("commdity", commdity_code)
  5124. prepareGoods := &models.DialysisBeforePrepareGoods{
  5125. GoodTypeId: good_type_id,
  5126. GoodId: good_id,
  5127. Count: count,
  5128. StorehouseId: houseConfig.StorehouseOutInfo,
  5129. }
  5130. beforePrepares = append(beforePrepares, prepareGoods)
  5131. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5132. GoodTypeId: good_type_id,
  5133. GoodId: good_id,
  5134. Count: count,
  5135. StorehouseId: houseConfig.StorehouseOutInfo,
  5136. }
  5137. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5138. prepare := &models.DialysisBeforePrepare{
  5139. GoodTypeId: good_type_id,
  5140. GoodId: good_id,
  5141. Count: count,
  5142. PatientId: patient_id,
  5143. RecordDate: record_time,
  5144. UserOrgId: adminUser.Org.Id,
  5145. Status: 1,
  5146. Ctime: time.Now().Unix(),
  5147. Creater: adminUser.AdminUser.Id,
  5148. CommdityCode: commdity_code,
  5149. StorehouseId: houseConfig.StorehouseOutInfo,
  5150. }
  5151. dialysisBefor = append(dialysisBefor, prepare)
  5152. }
  5153. }
  5154. //查询是否有库存
  5155. for _, item := range dialysisBefor {
  5156. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5157. if err == gorm.ErrRecordNotFound {
  5158. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5159. c.ServeSuccessJSON(map[string]interface{}{
  5160. "message": "1",
  5161. "good_name": goodObj.GoodName,
  5162. "specification_name": goodObj.SpecificationName,
  5163. })
  5164. return
  5165. }
  5166. if err != nil {
  5167. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5168. c.ServeSuccessJSON(map[string]interface{}{
  5169. "message": "1",
  5170. "good_name": goodObj.GoodName,
  5171. "specification_name": goodObj.SpecificationName,
  5172. })
  5173. return
  5174. }
  5175. }
  5176. //新增
  5177. if active == 1 && len(goods) > 0 {
  5178. for _, item := range dialysisBefor {
  5179. dialyPrepareOne := models.DialysisBeforePrepare{
  5180. GoodTypeId: item.GoodTypeId,
  5181. GoodId: item.GoodId,
  5182. PatientId: item.PatientId,
  5183. RecordDate: item.RecordDate,
  5184. UserOrgId: item.UserOrgId,
  5185. Count: item.Count,
  5186. Ctime: time.Now().Unix(),
  5187. Creater: item.Creater,
  5188. CommdityCode: item.CommdityCode,
  5189. Status: 1,
  5190. StorehouseId: houseConfig.StorehouseOutInfo,
  5191. }
  5192. //先清除再插入
  5193. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5194. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5195. //查询默认仓库
  5196. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5197. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5198. var total_count int64
  5199. for _, it := range stockList {
  5200. total_count += it.StockCount
  5201. }
  5202. //基础库插入数据
  5203. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5204. //更新库存
  5205. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5206. var flush_count int64
  5207. for _, it := range goodList {
  5208. flush_count += it.StockCount
  5209. }
  5210. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5211. }
  5212. if err == nil {
  5213. c.ServeSuccessJSON(map[string]interface{}{
  5214. "msg": "保存成功",
  5215. "message": "2",
  5216. })
  5217. return
  5218. } else {
  5219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5220. return
  5221. }
  5222. }
  5223. if len(beforePrepares) > 0 && active == 2 {
  5224. for _, item := range beforePrepares {
  5225. //1.查看该患者该耗材型号最后一次出库数量
  5226. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5227. //判断当前出库数量和最后一次出库数量的大小
  5228. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5229. if item.Count <= goodInfo.Count {
  5230. //退库
  5231. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5232. //查询今日出库数据
  5233. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5234. for _, it := range list {
  5235. prepare := models.DialysisBeforePrepare{
  5236. UserOrgId: it.OrgId,
  5237. PatientId: patient_id,
  5238. RecordDate: it.RecordTime,
  5239. GoodId: it.GoodId,
  5240. GoodTypeId: it.GoodTypeId,
  5241. Count: it.Count,
  5242. Ctime: time.Now().Unix(),
  5243. Creater: adminUser.AdminUser.Id,
  5244. Status: 1,
  5245. StorehouseId: houseConfig.StorehouseOutInfo,
  5246. }
  5247. //删除准备表数据
  5248. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5249. service.CreateDialysisBeforePrepareOne(&prepare)
  5250. }
  5251. }
  5252. var last_total int64
  5253. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5254. if item.Count >= goodInfo.Count {
  5255. //查询当前批次当前耗材最后一条出库数据
  5256. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5257. //计算当前出库和最后一次出库数据相差数据
  5258. last_total = item.Count - lastOutInfo.Count
  5259. //查询该批次剩余库存
  5260. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5261. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5262. if lastInfo.StockCount >= last_total {
  5263. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5264. //查询今日出库数据
  5265. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5266. for _, it := range list {
  5267. prepare := models.DialysisBeforePrepare{
  5268. UserOrgId: it.OrgId,
  5269. PatientId: patient_id,
  5270. RecordDate: it.RecordTime,
  5271. GoodId: it.GoodId,
  5272. GoodTypeId: it.GoodTypeId,
  5273. Count: it.Count,
  5274. Ctime: time.Now().Unix(),
  5275. Creater: adminUser.AdminUser.Id,
  5276. Status: 1,
  5277. StorehouseId: houseConfig.StorehouseOutInfo,
  5278. }
  5279. //删除准备表数据
  5280. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5281. service.CreateDialysisBeforePrepareOne(&prepare)
  5282. //查询默认仓库
  5283. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5284. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5285. var total_count int64
  5286. for _, it := range stockList {
  5287. total_count += it.StockCount
  5288. }
  5289. //基础库插入数据
  5290. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5291. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5292. var flush_count int64
  5293. for _, it := range goodList {
  5294. flush_count += it.StockCount
  5295. }
  5296. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5297. }
  5298. }
  5299. //如果库存不够,则出库到下一个批次
  5300. if lastInfo.StockCount < last_total {
  5301. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5302. //查询今日出库数据
  5303. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5304. for _, it := range list {
  5305. prepare := models.DialysisBeforePrepare{
  5306. UserOrgId: it.OrgId,
  5307. PatientId: patient_id,
  5308. RecordDate: it.RecordTime,
  5309. GoodId: it.GoodId,
  5310. GoodTypeId: it.GoodTypeId,
  5311. Count: it.Count,
  5312. Ctime: time.Now().Unix(),
  5313. Creater: adminUser.AdminUser.Id,
  5314. Status: 1,
  5315. StorehouseId: houseConfig.StorehouseOutInfo,
  5316. }
  5317. //删除准备表数据
  5318. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5319. service.CreateDialysisBeforePrepareOne(&prepare)
  5320. //查询默认仓库
  5321. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5322. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5323. var total_count int64
  5324. for _, it := range stockList {
  5325. total_count += it.StockCount
  5326. }
  5327. //基础库插入数据
  5328. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5329. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5330. var flush_count int64
  5331. for _, it := range goodList {
  5332. flush_count += it.StockCount
  5333. }
  5334. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5335. }
  5336. if err != nil {
  5337. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5338. c.ServeSuccessJSON(map[string]interface{}{
  5339. "message": "1",
  5340. "good_name": goodObj.GoodName,
  5341. "specification_name": goodObj.SpecificationName,
  5342. })
  5343. return
  5344. }
  5345. }
  5346. }
  5347. if err != nil {
  5348. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5349. c.ServeSuccessJSON(map[string]interface{}{
  5350. "message": "1",
  5351. "good_name": goodObj.GoodName,
  5352. "specification_name": goodObj.SpecificationName,
  5353. })
  5354. return
  5355. }
  5356. }
  5357. }
  5358. }
  5359. var errs error
  5360. if errs == nil {
  5361. c.ServeSuccessJSON(map[string]interface{}{
  5362. "msg": "提交成功",
  5363. "message": "2",
  5364. "good_name": "",
  5365. "specification_name": "",
  5366. })
  5367. return
  5368. } else {
  5369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5370. return
  5371. }
  5372. }
  5373. func (c *DialysisAPIController) CreateStockOutInfo() {
  5374. patient_id, _ := c.GetInt64("patient_id", 0)
  5375. record_date := c.GetString("record_time")
  5376. if patient_id <= 0 {
  5377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5378. return
  5379. }
  5380. adminInfo := c.GetMobileAdminUserInfo()
  5381. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5382. timeLayout := "2006-01-02"
  5383. loc, _ := time.LoadLocation("Local")
  5384. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5385. record_time := theRecordTime.Unix()
  5386. // 查询信息规挡的设置天数
  5387. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5388. if infor.ID > 0 && infor.WeekDay > 0 {
  5389. var cha_time int64
  5390. timeNowStr := time.Now().Format("2006-01-02")
  5391. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5392. //今日的日期减去设置的日期
  5393. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5394. if cha_time >= record_time {
  5395. //查询审核是否允许
  5396. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5397. //申请状态不允许的情况 拒绝修改
  5398. if infor.ApplicationStatus != 1 {
  5399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5400. return
  5401. }
  5402. }
  5403. }
  5404. //创建步骤表
  5405. finish := models.XtDialysisFinish{
  5406. IsFinish: 1,
  5407. UserOrgId: adminInfo.Org.Id,
  5408. Status: 1,
  5409. Ctime: time.Now().Unix(),
  5410. Mtime: 0,
  5411. Module: 11,
  5412. RecordDate: record_time,
  5413. Sourse: 1,
  5414. PatientId: patient_id,
  5415. }
  5416. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5417. if dialysisFinish.ID == 0 {
  5418. service.CreateDialysisFinish(finish)
  5419. }
  5420. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5421. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5422. //去重
  5423. consumables = RemoveRepeatedGood(consumables)
  5424. if adminInfo.Org.Id == 9919 {
  5425. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5426. //查询是否有库存
  5427. for _, item := range consumables {
  5428. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5429. if item.Count > warehouse.Count {
  5430. goodErrcode := models.XtGoodErrcode{
  5431. UserOrgId: item.UserOrgId,
  5432. Errcode: "自动出库库存不足",
  5433. GoodId: item.GoodId,
  5434. Status: 1,
  5435. Ctime: time.Now().Unix(),
  5436. Mtime: 0,
  5437. Count: 0,
  5438. StockCount: 0,
  5439. Creater: creator,
  5440. BatchNumberId: warehouse.ID,
  5441. WarehouseOutId: 0,
  5442. }
  5443. service.CreateGoodErrcode(goodErrcode)
  5444. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5445. c.ServeSuccessJSON(map[string]interface{}{
  5446. "message": "1",
  5447. "good_name": goodObj.GoodName,
  5448. "specification_name": goodObj.SpecificationName,
  5449. })
  5450. return
  5451. }
  5452. }
  5453. //查询是否有出库单
  5454. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5455. if err == gorm.ErrRecordNotFound {
  5456. //没有记录,则创建出库单
  5457. timeStr := time.Now().Format("2006-01-02")
  5458. timeArr := strings.Split(timeStr, "-")
  5459. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5460. total = total + 1
  5461. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5462. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5463. number = number + total
  5464. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5465. creater := adminInfo.AdminUser.Id
  5466. warehouseOut := models.WarehouseOut{
  5467. WarehouseOutOrderNumber: warehousing_out_order,
  5468. OperationTime: time.Now().Unix(),
  5469. OrgId: adminInfo.Org.Id,
  5470. Creater: creater,
  5471. Ctime: time.Now().Unix(),
  5472. Status: 1,
  5473. WarehouseOutTime: record_time,
  5474. Dealer: 0,
  5475. Manufacturer: 0,
  5476. Type: 1,
  5477. IsSys: 1,
  5478. StorehouseId: houseConfig.StorehouseOutInfo,
  5479. IsCheck: 1,
  5480. }
  5481. err := service.AddSigleWarehouseOut(&warehouseOut)
  5482. if err != nil {
  5483. goodErrcode := models.XtGoodErrcode{
  5484. UserOrgId: adminInfo.Org.Id,
  5485. Errcode: "创建出库单失败",
  5486. GoodId: 0,
  5487. Status: 1,
  5488. Ctime: time.Now().Unix(),
  5489. Mtime: 0,
  5490. Count: 0,
  5491. StockCount: 0,
  5492. Creater: creator,
  5493. BatchNumberId: 0,
  5494. WarehouseOutId: 0,
  5495. }
  5496. service.CreateGoodErrcode(goodErrcode)
  5497. utils.TraceLog("创建出库单失败 err = %v", err)
  5498. } else {
  5499. for _, item := range consumables {
  5500. //出库
  5501. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5502. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5503. if err == nil {
  5504. goodErrcode := models.XtGoodErrcode{
  5505. UserOrgId: adminInfo.Org.Id,
  5506. Errcode: "自动出库接口报错",
  5507. GoodId: 0,
  5508. Status: 1,
  5509. Ctime: time.Now().Unix(),
  5510. Mtime: 0,
  5511. Count: 0,
  5512. StockCount: 0,
  5513. Creater: creator,
  5514. BatchNumberId: 0,
  5515. WarehouseOutId: 0,
  5516. }
  5517. service.CreateGoodErrcode(goodErrcode)
  5518. utils.TraceLog("创建出库单失败 err = %v", err)
  5519. }
  5520. //查询
  5521. //出库数量相加
  5522. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5523. if errs != nil {
  5524. goodErrcode := models.XtGoodErrcode{
  5525. UserOrgId: item.UserOrgId,
  5526. Errcode: "创建剩余库存字段报错",
  5527. GoodId: item.GoodId,
  5528. Status: 1,
  5529. Ctime: time.Now().Unix(),
  5530. Mtime: 0,
  5531. Count: 0,
  5532. StockCount: 0,
  5533. Creater: creater,
  5534. BatchNumberId: 0,
  5535. WarehouseOutId: 0,
  5536. }
  5537. service.CreateGoodErrcode(goodErrcode)
  5538. }
  5539. }
  5540. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5541. if len(list) == 0 {
  5542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5543. return
  5544. }
  5545. for _, item := range list {
  5546. prepare := models.DialysisBeforePrepare{
  5547. UserOrgId: adminInfo.Org.Id,
  5548. PatientId: patient_id,
  5549. RecordDate: record_time,
  5550. GoodId: item.GoodId,
  5551. GoodTypeId: item.GoodTypeId,
  5552. Count: item.Count,
  5553. Creater: adminInfo.AdminUser.Id,
  5554. Status: 1,
  5555. Ctime: time.Now().Unix(),
  5556. StorehouseId: houseConfig.StorehouseOutInfo,
  5557. }
  5558. //清空准备表数据
  5559. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5560. if err != nil {
  5561. goodErrcode := models.XtGoodErrcode{
  5562. UserOrgId: item.OrgId,
  5563. Errcode: "自动出库清空准备表数据报错",
  5564. GoodId: item.GoodId,
  5565. Status: 1,
  5566. Ctime: time.Now().Unix(),
  5567. Mtime: 0,
  5568. Count: 0,
  5569. StockCount: 0,
  5570. Creater: creater,
  5571. BatchNumberId: 0,
  5572. WarehouseOutId: 0,
  5573. }
  5574. service.CreateGoodErrcode(goodErrcode)
  5575. }
  5576. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5577. if errs != nil {
  5578. goodErrcode := models.XtGoodErrcode{
  5579. UserOrgId: item.OrgId,
  5580. Errcode: "自动出库创建准备表数据报错",
  5581. GoodId: item.GoodId,
  5582. Status: 1,
  5583. Ctime: time.Now().Unix(),
  5584. Mtime: 0,
  5585. Count: 0,
  5586. StockCount: 0,
  5587. Creater: creater,
  5588. BatchNumberId: 0,
  5589. WarehouseOutId: 0,
  5590. }
  5591. service.CreateGoodErrcode(goodErrcode)
  5592. }
  5593. //查询默认仓库
  5594. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5595. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5596. var total_count int64
  5597. for _, it := range stockList {
  5598. total_count += it.StockCount
  5599. }
  5600. //基础库插入数据
  5601. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5602. if errcodes != nil {
  5603. goodErrcode := models.XtGoodErrcode{
  5604. UserOrgId: item.OrgId,
  5605. Errcode: "自动出库基础库插入数据",
  5606. GoodId: item.GoodId,
  5607. Status: 1,
  5608. Ctime: time.Now().Unix(),
  5609. Mtime: 0,
  5610. Count: 0,
  5611. StockCount: 0,
  5612. Creater: creater,
  5613. BatchNumberId: 0,
  5614. WarehouseOutId: 0,
  5615. }
  5616. service.CreateGoodErrcode(goodErrcode)
  5617. }
  5618. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5619. var flush_count int64
  5620. for _, it := range goodList {
  5621. flush_count += it.StockCount
  5622. }
  5623. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5624. if errsss != nil {
  5625. goodErrcode := models.XtGoodErrcode{
  5626. UserOrgId: item.OrgId,
  5627. Errcode: "自动出库剩余库存更新数据",
  5628. GoodId: item.GoodId,
  5629. Status: 1,
  5630. Ctime: time.Now().Unix(),
  5631. Mtime: 0,
  5632. Count: 0,
  5633. StockCount: 0,
  5634. Creater: creater,
  5635. BatchNumberId: 0,
  5636. WarehouseOutId: 0,
  5637. }
  5638. service.CreateGoodErrcode(goodErrcode)
  5639. }
  5640. }
  5641. }
  5642. //
  5643. } else if err == nil {
  5644. for _, item := range consumables {
  5645. //出库
  5646. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5647. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5648. if err != nil {
  5649. goodErrcode := models.XtGoodErrcode{
  5650. UserOrgId: adminInfo.Org.Id,
  5651. Errcode: "自动出库接口报错",
  5652. GoodId: 0,
  5653. Status: 1,
  5654. Ctime: time.Now().Unix(),
  5655. Mtime: 0,
  5656. Count: 0,
  5657. StockCount: 0,
  5658. Creater: creator,
  5659. BatchNumberId: 0,
  5660. WarehouseOutId: 0,
  5661. }
  5662. service.CreateGoodErrcode(goodErrcode)
  5663. }
  5664. //出库数量相加
  5665. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5666. if errss != nil {
  5667. goodErrcode := models.XtGoodErrcode{
  5668. UserOrgId: item.UserOrgId,
  5669. Errcode: "创建剩余库存字段报错",
  5670. GoodId: item.GoodId,
  5671. Status: 1,
  5672. Ctime: time.Now().Unix(),
  5673. Mtime: time.Now().Unix(),
  5674. Count: 0,
  5675. StockCount: 0,
  5676. Creater: item.Creater,
  5677. BatchNumberId: 0,
  5678. WarehouseOutId: 0,
  5679. }
  5680. service.CreateGoodErrcode(goodErrcode)
  5681. }
  5682. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5683. if len(list) == 0 {
  5684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5685. return
  5686. }
  5687. for _, item := range list {
  5688. prepare := models.DialysisBeforePrepare{
  5689. UserOrgId: adminInfo.Org.Id,
  5690. PatientId: patient_id,
  5691. RecordDate: record_time,
  5692. GoodId: item.GoodId,
  5693. GoodTypeId: item.GoodTypeId,
  5694. Count: item.Count,
  5695. Creater: adminInfo.AdminUser.Id,
  5696. Status: 1,
  5697. Ctime: time.Now().Unix(),
  5698. StorehouseId: houseConfig.StorehouseOutInfo,
  5699. }
  5700. //清空准备表数据
  5701. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5702. if errs != nil {
  5703. goodErrcode := models.XtGoodErrcode{
  5704. UserOrgId: adminInfo.Org.Id,
  5705. Errcode: "自动出库清空准备表数据报错",
  5706. GoodId: 0,
  5707. Status: 1,
  5708. Ctime: time.Now().Unix(),
  5709. Mtime: 0,
  5710. Count: 0,
  5711. StockCount: 0,
  5712. Creater: creator,
  5713. BatchNumberId: 0,
  5714. WarehouseOutId: 0,
  5715. }
  5716. service.CreateGoodErrcode(goodErrcode)
  5717. }
  5718. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5719. if errcodes != nil {
  5720. goodErrcode := models.XtGoodErrcode{
  5721. UserOrgId: adminInfo.Org.Id,
  5722. Errcode: "自动出库创建准备表数据报错",
  5723. GoodId: 0,
  5724. Status: 1,
  5725. Ctime: time.Now().Unix(),
  5726. Mtime: 0,
  5727. Count: 0,
  5728. StockCount: 0,
  5729. Creater: creator,
  5730. BatchNumberId: 0,
  5731. WarehouseOutId: 0,
  5732. }
  5733. service.CreateGoodErrcode(goodErrcode)
  5734. }
  5735. //查询默认仓库
  5736. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5737. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5738. var total_count int64
  5739. for _, it := range stockList {
  5740. total_count += it.StockCount
  5741. }
  5742. //基础库插入数据
  5743. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5744. if errcodes != nil {
  5745. goodErrcode := models.XtGoodErrcode{
  5746. UserOrgId: adminInfo.Org.Id,
  5747. Errcode: "自动出库基础库插入数据报错",
  5748. GoodId: 0,
  5749. Status: 1,
  5750. Ctime: time.Now().Unix(),
  5751. Mtime: 0,
  5752. Count: 0,
  5753. StockCount: 0,
  5754. Creater: creator,
  5755. BatchNumberId: 0,
  5756. WarehouseOutId: 0,
  5757. }
  5758. service.CreateGoodErrcode(goodErrcode)
  5759. }
  5760. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5761. var flush_count int64
  5762. for _, it := range goodList {
  5763. flush_count += it.StockCount
  5764. }
  5765. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5766. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5767. if errss != nil {
  5768. goodErrcode := models.XtGoodErrcode{
  5769. UserOrgId: item.OrgId,
  5770. Errcode: "自动出库剩余库存更新数据",
  5771. GoodId: item.GoodId,
  5772. Status: 1,
  5773. Ctime: time.Now().Unix(),
  5774. Mtime: 0,
  5775. Count: 0,
  5776. StockCount: 0,
  5777. Creater: creater,
  5778. BatchNumberId: 0,
  5779. WarehouseOutId: 0,
  5780. }
  5781. service.CreateGoodErrcode(goodErrcode)
  5782. }
  5783. }
  5784. }
  5785. }
  5786. c.ServeSuccessJSON(map[string]interface{}{
  5787. "msg": "提交成功",
  5788. "message": "2",
  5789. "good_name": "",
  5790. "specification_name": "",
  5791. })
  5792. return
  5793. }
  5794. if record.IsOpen == 1 {
  5795. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5796. //查询是否有库存
  5797. for _, item := range consumables {
  5798. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5799. if item.Count > warehouse.Count {
  5800. goodErrcode := models.XtGoodErrcode{
  5801. UserOrgId: item.UserOrgId,
  5802. Errcode: "自动出库库存不足",
  5803. GoodId: item.GoodId,
  5804. Status: 1,
  5805. Ctime: time.Now().Unix(),
  5806. Mtime: 0,
  5807. Count: 0,
  5808. StockCount: 0,
  5809. Creater: creator,
  5810. BatchNumberId: warehouse.ID,
  5811. WarehouseOutId: 0,
  5812. }
  5813. service.CreateGoodErrcode(goodErrcode)
  5814. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5815. c.ServeSuccessJSON(map[string]interface{}{
  5816. "message": "1",
  5817. "good_name": goodObj.GoodName,
  5818. "specification_name": goodObj.SpecificationName,
  5819. })
  5820. return
  5821. }
  5822. }
  5823. //查询是否有出库单
  5824. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5825. if err == gorm.ErrRecordNotFound {
  5826. //没有记录,则创建出库单
  5827. timeStr := time.Now().Format("2006-01-02")
  5828. timeArr := strings.Split(timeStr, "-")
  5829. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5830. total = total + 1
  5831. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5832. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5833. number = number + total
  5834. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5835. creater := adminInfo.AdminUser.Id
  5836. warehouseOut := models.WarehouseOut{
  5837. WarehouseOutOrderNumber: warehousing_out_order,
  5838. OperationTime: time.Now().Unix(),
  5839. OrgId: adminInfo.Org.Id,
  5840. Creater: creater,
  5841. Ctime: time.Now().Unix(),
  5842. Status: 1,
  5843. WarehouseOutTime: record_time,
  5844. Dealer: 0,
  5845. Manufacturer: 0,
  5846. Type: 1,
  5847. IsSys: 1,
  5848. StorehouseId: houseConfig.StorehouseOutInfo,
  5849. IsCheck: 1,
  5850. }
  5851. err := service.AddSigleWarehouseOut(&warehouseOut)
  5852. if err != nil {
  5853. goodErrcode := models.XtGoodErrcode{
  5854. UserOrgId: adminInfo.Org.Id,
  5855. Errcode: "创建出库单失败",
  5856. GoodId: 0,
  5857. Status: 1,
  5858. Ctime: time.Now().Unix(),
  5859. Mtime: 0,
  5860. Count: 0,
  5861. StockCount: 0,
  5862. Creater: creator,
  5863. BatchNumberId: 0,
  5864. WarehouseOutId: 0,
  5865. }
  5866. service.CreateGoodErrcode(goodErrcode)
  5867. utils.TraceLog("创建出库单失败 err = %v", err)
  5868. } else {
  5869. for _, item := range consumables {
  5870. //出库
  5871. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5872. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5873. if err == nil {
  5874. goodErrcode := models.XtGoodErrcode{
  5875. UserOrgId: adminInfo.Org.Id,
  5876. Errcode: "自动出库接口报错",
  5877. GoodId: 0,
  5878. Status: 1,
  5879. Ctime: time.Now().Unix(),
  5880. Mtime: 0,
  5881. Count: 0,
  5882. StockCount: 0,
  5883. Creater: creator,
  5884. BatchNumberId: 0,
  5885. WarehouseOutId: 0,
  5886. }
  5887. service.CreateGoodErrcode(goodErrcode)
  5888. utils.TraceLog("创建出库单失败 err = %v", err)
  5889. }
  5890. //查询
  5891. //出库数量相加
  5892. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5893. if errs != nil {
  5894. goodErrcode := models.XtGoodErrcode{
  5895. UserOrgId: item.UserOrgId,
  5896. Errcode: "创建剩余库存字段报错",
  5897. GoodId: item.GoodId,
  5898. Status: 1,
  5899. Ctime: time.Now().Unix(),
  5900. Mtime: 0,
  5901. Count: 0,
  5902. StockCount: 0,
  5903. Creater: creater,
  5904. BatchNumberId: 0,
  5905. WarehouseOutId: 0,
  5906. }
  5907. service.CreateGoodErrcode(goodErrcode)
  5908. }
  5909. }
  5910. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5911. if len(list) == 0 {
  5912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5913. return
  5914. }
  5915. for _, item := range list {
  5916. prepare := models.DialysisBeforePrepare{
  5917. UserOrgId: adminInfo.Org.Id,
  5918. PatientId: patient_id,
  5919. RecordDate: record_time,
  5920. GoodId: item.GoodId,
  5921. GoodTypeId: item.GoodTypeId,
  5922. Count: item.Count,
  5923. Creater: adminInfo.AdminUser.Id,
  5924. Status: 1,
  5925. Ctime: time.Now().Unix(),
  5926. StorehouseId: houseConfig.StorehouseOutInfo,
  5927. }
  5928. //清空准备表数据
  5929. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5930. if err != nil {
  5931. goodErrcode := models.XtGoodErrcode{
  5932. UserOrgId: item.OrgId,
  5933. Errcode: "自动出库清空准备表数据报错",
  5934. GoodId: item.GoodId,
  5935. Status: 1,
  5936. Ctime: time.Now().Unix(),
  5937. Mtime: 0,
  5938. Count: 0,
  5939. StockCount: 0,
  5940. Creater: creater,
  5941. BatchNumberId: 0,
  5942. WarehouseOutId: 0,
  5943. }
  5944. service.CreateGoodErrcode(goodErrcode)
  5945. }
  5946. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5947. if errs != nil {
  5948. goodErrcode := models.XtGoodErrcode{
  5949. UserOrgId: item.OrgId,
  5950. Errcode: "自动出库创建准备表数据报错",
  5951. GoodId: item.GoodId,
  5952. Status: 1,
  5953. Ctime: time.Now().Unix(),
  5954. Mtime: 0,
  5955. Count: 0,
  5956. StockCount: 0,
  5957. Creater: creater,
  5958. BatchNumberId: 0,
  5959. WarehouseOutId: 0,
  5960. }
  5961. service.CreateGoodErrcode(goodErrcode)
  5962. }
  5963. //查询默认仓库
  5964. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5965. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5966. var total_count int64
  5967. for _, it := range stockList {
  5968. total_count += it.StockCount
  5969. }
  5970. //基础库插入数据
  5971. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5972. if errcodes != nil {
  5973. goodErrcode := models.XtGoodErrcode{
  5974. UserOrgId: item.OrgId,
  5975. Errcode: "自动出库基础库插入数据",
  5976. GoodId: item.GoodId,
  5977. Status: 1,
  5978. Ctime: time.Now().Unix(),
  5979. Mtime: 0,
  5980. Count: 0,
  5981. StockCount: 0,
  5982. Creater: creater,
  5983. BatchNumberId: 0,
  5984. WarehouseOutId: 0,
  5985. }
  5986. service.CreateGoodErrcode(goodErrcode)
  5987. }
  5988. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5989. var flush_count int64
  5990. for _, it := range goodList {
  5991. flush_count += it.StockCount
  5992. }
  5993. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5994. if errsss != nil {
  5995. goodErrcode := models.XtGoodErrcode{
  5996. UserOrgId: item.OrgId,
  5997. Errcode: "自动出库剩余库存更新数据",
  5998. GoodId: item.GoodId,
  5999. Status: 1,
  6000. Ctime: time.Now().Unix(),
  6001. Mtime: 0,
  6002. Count: 0,
  6003. StockCount: 0,
  6004. Creater: creater,
  6005. BatchNumberId: 0,
  6006. WarehouseOutId: 0,
  6007. }
  6008. service.CreateGoodErrcode(goodErrcode)
  6009. }
  6010. }
  6011. }
  6012. //
  6013. } else if err == nil {
  6014. for _, item := range consumables {
  6015. //出库
  6016. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6017. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6018. if err != nil {
  6019. goodErrcode := models.XtGoodErrcode{
  6020. UserOrgId: adminInfo.Org.Id,
  6021. Errcode: "自动出库接口报错",
  6022. GoodId: 0,
  6023. Status: 1,
  6024. Ctime: time.Now().Unix(),
  6025. Mtime: 0,
  6026. Count: 0,
  6027. StockCount: 0,
  6028. Creater: creator,
  6029. BatchNumberId: 0,
  6030. WarehouseOutId: 0,
  6031. }
  6032. service.CreateGoodErrcode(goodErrcode)
  6033. }
  6034. //出库数量相加
  6035. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6036. if errss != nil {
  6037. goodErrcode := models.XtGoodErrcode{
  6038. UserOrgId: item.UserOrgId,
  6039. Errcode: "创建剩余库存字段报错",
  6040. GoodId: item.GoodId,
  6041. Status: 1,
  6042. Ctime: time.Now().Unix(),
  6043. Mtime: time.Now().Unix(),
  6044. Count: 0,
  6045. StockCount: 0,
  6046. Creater: item.Creater,
  6047. BatchNumberId: 0,
  6048. WarehouseOutId: 0,
  6049. }
  6050. service.CreateGoodErrcode(goodErrcode)
  6051. }
  6052. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6053. if len(list) == 0 {
  6054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6055. return
  6056. }
  6057. for _, item := range list {
  6058. prepare := models.DialysisBeforePrepare{
  6059. UserOrgId: adminInfo.Org.Id,
  6060. PatientId: patient_id,
  6061. RecordDate: record_time,
  6062. GoodId: item.GoodId,
  6063. GoodTypeId: item.GoodTypeId,
  6064. Count: item.Count,
  6065. Creater: adminInfo.AdminUser.Id,
  6066. Status: 1,
  6067. Ctime: time.Now().Unix(),
  6068. StorehouseId: houseConfig.StorehouseOutInfo,
  6069. }
  6070. //清空准备表数据
  6071. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6072. if errs != nil {
  6073. goodErrcode := models.XtGoodErrcode{
  6074. UserOrgId: adminInfo.Org.Id,
  6075. Errcode: "自动出库清空准备表数据报错",
  6076. GoodId: 0,
  6077. Status: 1,
  6078. Ctime: time.Now().Unix(),
  6079. Mtime: 0,
  6080. Count: 0,
  6081. StockCount: 0,
  6082. Creater: creator,
  6083. BatchNumberId: 0,
  6084. WarehouseOutId: 0,
  6085. }
  6086. service.CreateGoodErrcode(goodErrcode)
  6087. }
  6088. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6089. if errcodes != nil {
  6090. goodErrcode := models.XtGoodErrcode{
  6091. UserOrgId: adminInfo.Org.Id,
  6092. Errcode: "自动出库创建准备表数据报错",
  6093. GoodId: 0,
  6094. Status: 1,
  6095. Ctime: time.Now().Unix(),
  6096. Mtime: 0,
  6097. Count: 0,
  6098. StockCount: 0,
  6099. Creater: creator,
  6100. BatchNumberId: 0,
  6101. WarehouseOutId: 0,
  6102. }
  6103. service.CreateGoodErrcode(goodErrcode)
  6104. }
  6105. //查询默认仓库
  6106. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6107. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6108. var total_count int64
  6109. for _, it := range stockList {
  6110. total_count += it.StockCount
  6111. }
  6112. //基础库插入数据
  6113. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6114. if errcodes != nil {
  6115. goodErrcode := models.XtGoodErrcode{
  6116. UserOrgId: adminInfo.Org.Id,
  6117. Errcode: "自动出库基础库插入数据报错",
  6118. GoodId: 0,
  6119. Status: 1,
  6120. Ctime: time.Now().Unix(),
  6121. Mtime: 0,
  6122. Count: 0,
  6123. StockCount: 0,
  6124. Creater: creator,
  6125. BatchNumberId: 0,
  6126. WarehouseOutId: 0,
  6127. }
  6128. service.CreateGoodErrcode(goodErrcode)
  6129. }
  6130. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6131. var flush_count int64
  6132. for _, it := range goodList {
  6133. flush_count += it.StockCount
  6134. }
  6135. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6136. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6137. if errss != nil {
  6138. goodErrcode := models.XtGoodErrcode{
  6139. UserOrgId: item.OrgId,
  6140. Errcode: "自动出库剩余库存更新数据",
  6141. GoodId: item.GoodId,
  6142. Status: 1,
  6143. Ctime: time.Now().Unix(),
  6144. Mtime: 0,
  6145. Count: 0,
  6146. StockCount: 0,
  6147. Creater: creater,
  6148. BatchNumberId: 0,
  6149. WarehouseOutId: 0,
  6150. }
  6151. service.CreateGoodErrcode(goodErrcode)
  6152. }
  6153. }
  6154. }
  6155. }
  6156. c.ServeSuccessJSON(map[string]interface{}{
  6157. "msg": "提交成功",
  6158. "message": "2",
  6159. "good_name": "",
  6160. "specification_name": "",
  6161. })
  6162. return
  6163. } else {
  6164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6165. return
  6166. }
  6167. }
  6168. func (c *DialysisAPIController) EditConsumables() {
  6169. patient_id, _ := c.GetInt64("patient_id", 0)
  6170. record_date := c.GetString("record_time")
  6171. if patient_id <= 0 {
  6172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6173. return
  6174. }
  6175. adminInfo := c.GetMobileAdminUserInfo()
  6176. timeLayout := "2006-01-02"
  6177. loc, _ := time.LoadLocation("Local")
  6178. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6179. record_time := theRecordTime.Unix()
  6180. // 查询信息规挡的设置天数
  6181. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6182. if infor.ID > 0 && infor.WeekDay > 0 {
  6183. var cha_time int64
  6184. timeNowStr := time.Now().Format("2006-01-02")
  6185. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6186. //今日的日期减去设置的日期
  6187. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6188. if cha_time >= record_time {
  6189. //查询审核是否允许
  6190. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6191. //申请状态不允许的情况 拒绝修改
  6192. if infor.ApplicationStatus != 1 {
  6193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6194. return
  6195. }
  6196. }
  6197. }
  6198. dataBody := make(map[string]interface{}, 0)
  6199. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6200. if err != nil {
  6201. utils.ErrorLog(err.Error())
  6202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6203. return
  6204. }
  6205. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6206. var beforePrepares []*models.DialysisBeforePrepareGoods
  6207. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6208. var cancelbefor []*models.DialysisBeforePrepareGoods
  6209. var outbefor []*models.DialysisBeforePrepareGoods
  6210. //判断是否开启自动出库
  6211. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6212. if record.IsOpen == 1 {
  6213. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6214. goods, _ := dataBody["goods"].([]interface{})
  6215. if len(goods) > 0 {
  6216. for _, item := range goods {
  6217. items := item.(map[string]interface{})
  6218. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6219. utils.ErrorLog("good_id")
  6220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6221. return
  6222. }
  6223. good_id := int64(items["good_id"].(float64))
  6224. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6225. utils.ErrorLog("good_type_id")
  6226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6227. return
  6228. }
  6229. good_type_id := int64(items["good_type_id"].(float64))
  6230. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6231. utils.ErrorLog("count")
  6232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6233. return
  6234. }
  6235. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6236. commdity_code := items["commdity_code"].(string)
  6237. fmt.Println(commdity_code)
  6238. prepareGoods := &models.DialysisBeforePrepareGoods{
  6239. GoodTypeId: good_type_id,
  6240. GoodId: good_id,
  6241. Count: count,
  6242. StorehouseId: houseConfig.StorehouseOutInfo,
  6243. }
  6244. beforePrepares = append(beforePrepares, prepareGoods)
  6245. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6246. GoodTypeId: good_type_id,
  6247. GoodId: good_id,
  6248. Count: count,
  6249. StorehouseId: houseConfig.StorehouseOutInfo,
  6250. }
  6251. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6252. }
  6253. for _, item := range beforePrepares {
  6254. //1.查看该患者该耗材型号最后一次出库数量
  6255. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6256. //判断当前出库数量和最后一次出库数量的大小
  6257. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6258. if item.Count < goodInfo.Count {
  6259. cancelbefor = append(cancelbefor, item)
  6260. }
  6261. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6262. if item.Count > goodInfo.Count {
  6263. outbefor = append(outbefor, item)
  6264. }
  6265. //处理编辑耗材新增不了的问题
  6266. if goodInfo.Count == item.Count {
  6267. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6268. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6269. }
  6270. }
  6271. if len(cancelbefor) > 0 {
  6272. //退库
  6273. for _, item := range cancelbefor {
  6274. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6275. creater := adminInfo.AdminUser.Id
  6276. //查询该患者当天已经出库的耗材信息
  6277. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6278. var delete_count int64 = 0
  6279. delete_count = warehouseOutInfos.Count - item.Count
  6280. //增加库存数量
  6281. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6282. //减少实际出库库存数量
  6283. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6284. // 删除出库完成后,要增加对应批次的库存数量
  6285. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6286. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6287. //更新剩余库存
  6288. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6289. var flush_count int64
  6290. for _, it := range goodListOne {
  6291. flush_count += it.StockCount
  6292. }
  6293. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6294. //查询剩余库存
  6295. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6296. var sum_count int64
  6297. for _, item := range goodList {
  6298. sum_count += item.StockCount
  6299. }
  6300. // 在出库记录表里记录退库详情
  6301. warehouseOutInfo := &models.WarehouseOutInfo{
  6302. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6303. WarehouseOutId: warehouseOut.ID,
  6304. Status: 1,
  6305. Ctime: time.Now().Unix(),
  6306. OrgId: adminInfo.Org.Id,
  6307. Type: 1,
  6308. IsSys: 1,
  6309. SysRecordTime: record_time,
  6310. GoodTypeId: item.GoodTypeId,
  6311. GoodId: item.GoodId,
  6312. PatientId: patient_id,
  6313. ConsumableType: 2,
  6314. StorehouseId: houseConfig.StorehouseOutInfo,
  6315. IsCheck: 1,
  6316. OverCount: sum_count,
  6317. }
  6318. warehouseOutInfo.Count = item.Count
  6319. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6320. warehouseOutInfo.Price = stockInInfo.Price
  6321. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6322. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6323. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6324. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6325. warehouseOutInfo.Number = warehouseOutInfos.Number
  6326. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6327. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6328. //查找当天是否存在出库记录
  6329. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6330. if errcod == gorm.ErrRecordNotFound {
  6331. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6332. //插入详情明细表
  6333. stockFlow := models.VmStockFlow{
  6334. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6335. WarehouseOutId: warehouseOut.ID,
  6336. GoodId: item.GoodId,
  6337. Number: warehouseOutInfos.Number,
  6338. ProductDate: stockInInfo.ProductDate,
  6339. ExpireDate: stockInInfo.ExpiryDate,
  6340. Count: item.Count,
  6341. Price: stockInInfo.Price,
  6342. Status: 1,
  6343. Ctime: time.Now().Unix(),
  6344. UserOrgId: adminInfo.Org.Id,
  6345. Manufacturer: stockInInfo.Manufacturer,
  6346. Dealer: stockInInfo.Dealer,
  6347. LicenseNumber: stockInInfo.LicenseNumber,
  6348. IsEdit: 2,
  6349. Creator: creater,
  6350. SystemTime: record_time,
  6351. ConsumableType: 3,
  6352. WarehousingDetailId: 0,
  6353. IsSys: 1,
  6354. UpdateCreator: creater,
  6355. PatientId: patient_id,
  6356. StorehouseId: houseConfig.StorehouseOutInfo,
  6357. }
  6358. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6359. if errflow == gorm.ErrRecordNotFound {
  6360. //创建流水表
  6361. err := service.CreateStockFlowOne(stockFlow)
  6362. fmt.Println("err", err)
  6363. } else if errflow == nil {
  6364. //插入详情明细表
  6365. stockFlow := models.VmStockFlow{
  6366. ID: exsit.ID,
  6367. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6368. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6369. WarehouseOutId: warehouseOut.ID,
  6370. GoodId: item.GoodId,
  6371. Number: warehouseOutInfos.Number,
  6372. ProductDate: stockInInfo.ProductDate,
  6373. ExpireDate: stockInInfo.ExpiryDate,
  6374. Count: exsit.Count - delete_count,
  6375. Price: stockInInfo.Price,
  6376. Status: 1,
  6377. Ctime: time.Now().Unix(),
  6378. UserOrgId: adminInfo.Org.Id,
  6379. Manufacturer: stockInInfo.Manufacturer,
  6380. Dealer: stockInInfo.Dealer,
  6381. LicenseNumber: stockInInfo.LicenseNumber,
  6382. IsEdit: 2,
  6383. Creator: creater,
  6384. SystemTime: record_time,
  6385. ConsumableType: 3,
  6386. WarehousingDetailId: 0,
  6387. IsSys: 1,
  6388. UpdateCreator: creater,
  6389. PatientId: patient_id,
  6390. StorehouseId: houseConfig.StorehouseOutInfo,
  6391. }
  6392. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6393. }
  6394. } else if errcod == nil {
  6395. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6396. //查询剩余库存
  6397. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6398. var sum_count int64
  6399. for _, item := range goodList {
  6400. sum_count += item.StockCount
  6401. }
  6402. //创建退库单,生成退库数据
  6403. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6404. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6405. operation_time := time.Now().Unix()
  6406. creater := adminInfo.AdminUser.Id
  6407. //创建退库单
  6408. timeStr := time.Now().Format("2006-01-02")
  6409. timeArr := strings.Split(timeStr, "-")
  6410. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6411. total = total + 1
  6412. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6413. cancelStock := models.CancelStock{
  6414. OrderNumber: orderNumber,
  6415. OperaTime: operation_time,
  6416. OrgId: adminInfo.Org.Id,
  6417. Creater: creater,
  6418. Ctime: time.Now().Unix(),
  6419. Status: 1,
  6420. ReturnTime: record_time,
  6421. Type: 1,
  6422. StorehouseId: houseConfig.StorehouseOutInfo,
  6423. IsCheck: 1,
  6424. }
  6425. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6426. if msgerrkonde == gorm.ErrRecordNotFound {
  6427. service.AddSigleCancelStock(&cancelStock)
  6428. }
  6429. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6430. //查询是否有出库
  6431. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6432. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6433. deaerler, _ := service.GetDealerById(info.Dealer)
  6434. if info.ID > 0 {
  6435. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6436. cancelStockInfo := models.CancelStockInfo{
  6437. GoodId: item.GoodId,
  6438. CancelStockId: cancel.ID,
  6439. GoodTypeId: good.GoodTypeId,
  6440. Count: delete_count,
  6441. Price: info.Price,
  6442. Total: 0,
  6443. ProductDate: info.ProductDate,
  6444. ExpiryDate: info.ExpiryDate,
  6445. Ctime: time.Now().Unix(),
  6446. Status: 1,
  6447. OrgId: adminInfo.Org.Id,
  6448. OrderNumber: cancel.OrderNumber,
  6449. Type: 0,
  6450. Dealer: deaerler.DealerName,
  6451. Manufacturer: manufacturer.ManufacturerName,
  6452. Number: info.Number,
  6453. RegisterAccount: "",
  6454. Remark: "",
  6455. WarehouseInfoId: info.WarehouseInfotId,
  6456. PatientId: info.PatientId,
  6457. RecordDate: info.SysRecordTime,
  6458. StorehouseId: houseConfig.StorehouseOutInfo,
  6459. IsCheck: 1,
  6460. }
  6461. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6462. //退库数量增加
  6463. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6464. //查询剩余库存
  6465. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6466. var over_count int64
  6467. for _, it := range goodList {
  6468. over_count += it.StockCount
  6469. }
  6470. flow := models.VmStockFlow{
  6471. WarehousingId: info.WarehouseInfotId,
  6472. GoodId: item.GoodId,
  6473. Number: info.Number,
  6474. LicenseNumber: info.LicenseNumber,
  6475. Count: delete_count,
  6476. UserOrgId: adminInfo.Org.Id,
  6477. PatientId: patient_id,
  6478. SystemTime: info.SysRecordTime,
  6479. ConsumableType: 7,
  6480. IsSys: 0,
  6481. WarehousingOrder: "",
  6482. WarehouseOutId: info.WarehouseOutId,
  6483. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6484. IsEdit: 0,
  6485. CancelStockId: cancel.ID,
  6486. CancelOrderNumber: cancel.OrderNumber,
  6487. Manufacturer: manufacturer.ID,
  6488. Dealer: 0,
  6489. Creator: adminInfo.AdminUser.Id,
  6490. UpdateCreator: 0,
  6491. Status: 1,
  6492. Ctime: time.Now().Unix(),
  6493. Mtime: 0,
  6494. Price: info.Price,
  6495. WarehousingDetailId: info.WarehouseInfotId,
  6496. WarehouseOutDetailId: info.ID,
  6497. CancelOutDetailId: cancelInfo.ID,
  6498. ProductDate: info.ProductDate,
  6499. ExpireDate: info.ExpiryDate,
  6500. StorehouseId: houseConfig.StorehouseOutInfo,
  6501. OverCount: over_count,
  6502. }
  6503. service.CreateStockFlowOne(flow)
  6504. }
  6505. }
  6506. //更改自动出库的表格
  6507. details := models.BloodAutomaticReduceDetail{
  6508. WarehouseOutId: warehouseOutInfo.ID,
  6509. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6510. PatientId: patient_id,
  6511. Ctime: time.Now().Unix(),
  6512. Mtime: time.Now().Unix(),
  6513. Status: 1,
  6514. RecordTime: record_time,
  6515. OrgId: adminInfo.Org.Id,
  6516. GoodId: item.GoodId,
  6517. GoodTypeId: item.GoodTypeId,
  6518. Count: item.Count,
  6519. StorehouseId: houseConfig.StorehouseOutInfo,
  6520. }
  6521. //查询当天耗材是否已经存在数据
  6522. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6523. if errcode == gorm.ErrRecordNotFound {
  6524. service.CreateAutoReduceRecord(&details)
  6525. } else if errcode == nil {
  6526. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6527. service.CreateAutoReduceRecord(&details)
  6528. }
  6529. //查询默认仓库
  6530. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6531. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6532. var total_count int64
  6533. for _, it := range stockList {
  6534. total_count += it.StockCount
  6535. }
  6536. //基础库插入数据
  6537. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6538. }
  6539. }
  6540. if len(outbefor) > 0 {
  6541. //出库
  6542. for _, item := range outbefor {
  6543. var last_total int64
  6544. //1.查看该患者该耗材型号最后一次出库数量
  6545. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6546. //计算当前出库和最后一次出库数据相差数据
  6547. last_total = item.Count - goodInfoOne.Count
  6548. //查询该耗材的总库存
  6549. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6550. // 如果库存差大于剩余库存则提示库存不足
  6551. if last_total > wareinfo.StockCount {
  6552. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6553. c.ServeSuccessJSON(map[string]interface{}{
  6554. "message": "1",
  6555. "good_name": goodObj.GoodName,
  6556. "specification_name": goodObj.SpecificationName,
  6557. })
  6558. return
  6559. } else {
  6560. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6561. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6562. if err == gorm.ErrRecordNotFound {
  6563. //没有记录,则创建出库单
  6564. timeStr := time.Now().Format("2006-01-02")
  6565. timeArr := strings.Split(timeStr, "-")
  6566. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6567. total = total + 1
  6568. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6569. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6570. number = number + total
  6571. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6572. warehouseOut := models.WarehouseOut{
  6573. WarehouseOutOrderNumber: warehousing_out_order,
  6574. OperationTime: time.Now().Unix(),
  6575. OrgId: adminInfo.Org.Id,
  6576. Creater: adminInfo.AdminUser.Id,
  6577. Ctime: time.Now().Unix(),
  6578. Status: 1,
  6579. WarehouseOutTime: record_time,
  6580. Dealer: 0,
  6581. Manufacturer: 0,
  6582. Type: 1,
  6583. IsSys: 1,
  6584. StorehouseId: houseConfig.StorehouseOutInfo,
  6585. IsCheck: 1,
  6586. }
  6587. service.AddSigleWarehouseOut(&warehouseOut)
  6588. }
  6589. //出库
  6590. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6591. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6592. //1.查看该患者该耗材型号最后一次出库数量
  6593. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6594. prepare := models.DialysisBeforePrepare{
  6595. UserOrgId: adminInfo.Org.Id,
  6596. PatientId: patient_id,
  6597. RecordDate: record_time,
  6598. GoodId: item.GoodId,
  6599. GoodTypeId: item.GoodTypeId,
  6600. Count: item.Count - goodInfoTwo.Count,
  6601. Ctime: time.Now().Unix(),
  6602. Mtime: 0,
  6603. Creater: adminInfo.AdminUser.Id,
  6604. Modifier: adminInfo.AdminUser.Id,
  6605. Status: 1,
  6606. CommdityCode: "",
  6607. NewCount: 0,
  6608. ProjectId: 0,
  6609. StorehouseId: houseConfig.StorehouseOutInfo,
  6610. }
  6611. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6612. //增加出库数量
  6613. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6614. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6615. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6616. var total_count int64
  6617. for _, it := range stockList {
  6618. total_count += it.StockCount
  6619. }
  6620. //基础库插入数据
  6621. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6622. //剩余库存
  6623. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6624. var flush_count int64
  6625. for _, it := range goodList {
  6626. flush_count += it.StockCount
  6627. }
  6628. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6629. }
  6630. }
  6631. }
  6632. //查询今日出库数据
  6633. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6634. for _, it := range list {
  6635. prepare := models.DialysisBeforePrepare{
  6636. UserOrgId: it.OrgId,
  6637. PatientId: patient_id,
  6638. RecordDate: it.RecordTime,
  6639. GoodId: it.GoodId,
  6640. GoodTypeId: it.GoodTypeId,
  6641. Count: it.Count,
  6642. Ctime: time.Now().Unix(),
  6643. Creater: adminInfo.AdminUser.Id,
  6644. Status: 1,
  6645. StorehouseId: houseConfig.StorehouseOutInfo,
  6646. ProjectId: it.ProjectId,
  6647. }
  6648. //删除准备表数据
  6649. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6650. service.CreateDialysisBeforePrepareOne(&prepare)
  6651. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6652. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6653. var total_count int64
  6654. for _, it := range stockList {
  6655. total_count += it.StockCount
  6656. }
  6657. //基础库插入数据
  6658. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6659. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6660. var flush_count int64
  6661. for _, it := range goodList {
  6662. flush_count += it.StockCount
  6663. }
  6664. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6665. }
  6666. }
  6667. }
  6668. //更新自动出库的地方
  6669. var errs error
  6670. if errs == nil {
  6671. c.ServeSuccessJSON(map[string]interface{}{
  6672. "msg": "修改成功",
  6673. "message": "2",
  6674. "good_name": "",
  6675. "specification_name": "",
  6676. })
  6677. return
  6678. } else {
  6679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6680. return
  6681. }
  6682. }
  6683. }
  6684. func (c *DialysisAPIController) GetDialysisGoods() {
  6685. schedualDate := c.GetString("schedule_date")
  6686. schedule_type, _ := c.GetInt64("schedule_type")
  6687. partition_id, _ := c.GetInt64("partition_id")
  6688. page, _ := c.GetInt("page")
  6689. patient_id, _ := c.GetInt64("patient_id")
  6690. schedualEndDate := int64(0)
  6691. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6692. if parseDateErr != nil && len(schedualDate) != 0 {
  6693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6694. return
  6695. }
  6696. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6697. if parseDateErr != nil && len(schedualDate) != 0 {
  6698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6699. return
  6700. }
  6701. schedualEndDate = endDate.Unix()
  6702. adminUser := c.GetMobileAdminUserInfo()
  6703. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6704. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6705. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6706. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6707. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6708. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6709. //获取当天该病人的透析处方
  6710. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6711. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6712. if err == gorm.ErrRecordNotFound {
  6713. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6714. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6715. if patient_id != 0 {
  6716. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6717. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6718. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6719. //获取患者总的出库数据
  6720. item.LastAutomaticReduceDetail = goodUser
  6721. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6722. item.Project = project
  6723. }
  6724. }
  6725. c.ServeSuccessJSON(map[string]interface{}{
  6726. "dialysis_goods": dialysisGoods,
  6727. "good_type": goodTypes,
  6728. "total": total,
  6729. "prescribe": prescribe,
  6730. "good_info": good_info,
  6731. "warehouseOutList": warehouseOutList,
  6732. "config": config,
  6733. "outConfig": outConfig,
  6734. "settleConfig": settleConfig,
  6735. })
  6736. return
  6737. } else if err == nil {
  6738. //获取当天排班的每个患者的库存使用情况
  6739. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6740. //获取患者总的出库数据
  6741. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6742. if patient_id != 0 {
  6743. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6744. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6745. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6746. item.Project = project
  6747. item.LastAutomaticReduceDetail = goodUser
  6748. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6749. }
  6750. }
  6751. if err == nil {
  6752. c.ServeSuccessJSON(map[string]interface{}{
  6753. "dialysis_goods": dialysisGoods,
  6754. "good_type": goodTypes,
  6755. "total": total,
  6756. "prescribe": prescribe,
  6757. "good_info": good_info,
  6758. "project": project,
  6759. "warehouseOutList": warehouseOutList,
  6760. "config": config,
  6761. "outConfig": outConfig,
  6762. "settleConfig": settleConfig,
  6763. })
  6764. return
  6765. } else {
  6766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6767. return
  6768. }
  6769. } else if err != nil {
  6770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6771. return
  6772. }
  6773. }
  6774. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6775. start_time := c.GetString("start_time")
  6776. end_time := c.GetString("end_time")
  6777. timeLayout := "2006-01-02"
  6778. loc, _ := time.LoadLocation("Local")
  6779. var theStartTime int64
  6780. if len(start_time) > 0 {
  6781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6782. if err != nil {
  6783. utils.ErrorLog(err.Error())
  6784. }
  6785. theStartTime = theTime.Unix()
  6786. }
  6787. var theEndtTime int64
  6788. if len(end_time) > 0 {
  6789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6790. if err != nil {
  6791. utils.ErrorLog(err.Error())
  6792. }
  6793. theEndtTime = theTime.Unix()
  6794. }
  6795. adminUser := c.GetMobileAdminUserInfo()
  6796. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6797. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6798. if err == nil {
  6799. c.ServeSuccessJSON(map[string]interface{}{
  6800. "stock_out": outInfo,
  6801. "stockCount": stockCount,
  6802. })
  6803. return
  6804. } else {
  6805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6806. return
  6807. }
  6808. }
  6809. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6810. patient_id, _ := c.GetInt64("patient_id", 0)
  6811. record_time := c.GetString("record_time")
  6812. adminUser := c.GetMobileAdminUserInfo()
  6813. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6814. if parseDateErr != nil && len(record_time) != 0 {
  6815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6816. return
  6817. }
  6818. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6819. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6820. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6821. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6822. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6823. //获取今日患者的透析处方参数
  6824. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6825. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6826. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6827. c.ServeSuccessJSON(map[string]interface{}{
  6828. "good_type": goodTypes,
  6829. "good_user": goodUser,
  6830. "good_info": good_info,
  6831. "last_good_user": lastGoodUserDetial,
  6832. "project": project,
  6833. "prescription": prescribe,
  6834. "outInfo": outInfo,
  6835. "configs": configs,
  6836. })
  6837. return
  6838. }
  6839. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6840. patient_id, _ := c.GetInt64("patient_id", 0)
  6841. record_date := c.GetString("record_time")
  6842. timeLayout := "2006-01-02"
  6843. loc, _ := time.LoadLocation("Local")
  6844. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6845. record_time := theRecordTime.Unix()
  6846. adminInfo := c.GetMobileAdminUserInfo()
  6847. dataBody := make(map[string]interface{}, 0)
  6848. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6849. if err != nil {
  6850. utils.ErrorLog(err.Error())
  6851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6852. return
  6853. }
  6854. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6855. var beforePrepares []*models.DialysisBeforePrepareGoods
  6856. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6857. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6858. goods, _ := dataBody["goods"].([]interface{})
  6859. if len(goods) > 0 {
  6860. for _, item := range goods {
  6861. items := item.(map[string]interface{})
  6862. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6863. utils.ErrorLog("good_id")
  6864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6865. return
  6866. }
  6867. good_id := int64(items["good_id"].(float64))
  6868. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6869. utils.ErrorLog("good_type_id")
  6870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6871. return
  6872. }
  6873. good_type_id := int64(items["good_type_id"].(float64))
  6874. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6875. utils.ErrorLog("count")
  6876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6877. return
  6878. }
  6879. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6880. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6881. utils.ErrorLog("project_id")
  6882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6883. return
  6884. }
  6885. project_id := int64(items["project_id"].(float64))
  6886. new_count := int64(items["new_count"].(float64))
  6887. old_count := int64(items["old_count"].(float64))
  6888. prepare := &models.DialysisBeforePrepareGoods{
  6889. GoodId: good_id,
  6890. GoodTypeId: good_type_id,
  6891. Count: count,
  6892. ProjectId: project_id,
  6893. StorehouseId: houseConfig.StorehouseOutInfo,
  6894. NewCount: new_count,
  6895. OldCount: old_count,
  6896. }
  6897. beforePrepares = append(beforePrepares, prepare)
  6898. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6899. GoodId: good_id,
  6900. GoodTypeId: good_type_id,
  6901. Count: count,
  6902. ProjectId: project_id,
  6903. StorehouseId: houseConfig.StorehouseOutInfo,
  6904. NewCount: new_count,
  6905. OldCount: old_count,
  6906. }
  6907. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6908. }
  6909. }
  6910. }
  6911. //查询是否有库存
  6912. for _, item := range beforePrepares {
  6913. if item.NewCount > 0 {
  6914. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6915. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6916. if item.Count > warehouse.Count {
  6917. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6918. c.ServeSuccessJSON(map[string]interface{}{
  6919. "message": "1",
  6920. "good_name": goodObj.GoodName,
  6921. "specification_name": goodObj.SpecificationName,
  6922. })
  6923. return
  6924. }
  6925. }
  6926. }
  6927. // 查询信息规挡的设置天数
  6928. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6929. if infor.ID > 0 && infor.WeekDay > 0 {
  6930. var cha_time int64
  6931. timeNowStr := time.Now().Format("2006-01-02")
  6932. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6933. //今日的日期减去设置的日期
  6934. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6935. if cha_time >= record_time {
  6936. //查询审核是否允许
  6937. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6938. //申请状态不允许的情况 拒绝修改
  6939. if infor.ApplicationStatus != 1 {
  6940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6941. return
  6942. }
  6943. }
  6944. }
  6945. //出库逻辑
  6946. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6947. if err != nil {
  6948. utils.ErrorLog(err.Error())
  6949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6950. return
  6951. }
  6952. finish := models.XtDialysisFinish{
  6953. IsFinish: 1,
  6954. UserOrgId: adminInfo.Org.Id,
  6955. Status: 1,
  6956. Ctime: time.Now().Unix(),
  6957. Mtime: 0,
  6958. Module: 11,
  6959. RecordDate: record_time,
  6960. Sourse: 1,
  6961. PatientId: patient_id,
  6962. }
  6963. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6964. if dialysisFinish.ID == 0 {
  6965. service.CreateDialysisFinish(finish)
  6966. }
  6967. //查询当天出库的数据
  6968. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6969. for _, item := range list {
  6970. prepare := models.DialysisBeforePrepare{
  6971. UserOrgId: item.OrgId,
  6972. PatientId: item.PatientId,
  6973. RecordDate: item.RecordTime,
  6974. GoodId: item.GoodId,
  6975. GoodTypeId: item.GoodTypeId,
  6976. Count: item.Count,
  6977. Creater: adminInfo.AdminUser.Id,
  6978. Status: 1,
  6979. Ctime: time.Now().Unix(),
  6980. ProjectId: item.ProjectId,
  6981. StorehouseId: houseConfig.StorehouseOutInfo,
  6982. }
  6983. //清空准备表的数据
  6984. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6985. //插入准备表数据
  6986. service.CreateDialysisBeforePrepareOne(&prepare)
  6987. //查询默认仓库
  6988. //查询默认仓库
  6989. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6990. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6991. var total_count int64
  6992. for _, it := range stockList {
  6993. total_count += it.StockCount
  6994. }
  6995. //基础库插入数据
  6996. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6997. ////更新剩余库存
  6998. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6999. var flush_count int64
  7000. for _, it := range goodList {
  7001. flush_count += it.StockCount
  7002. }
  7003. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7004. if errs != nil {
  7005. goodErrcode := models.XtGoodErrcode{
  7006. UserOrgId: item.OrgId,
  7007. Errcode: "手动出库更新剩余出库失败",
  7008. GoodId: item.GoodId,
  7009. Status: 1,
  7010. Ctime: time.Now().Unix(),
  7011. Mtime: 0,
  7012. Count: 0,
  7013. StockCount: 0,
  7014. Creater: adminInfo.AdminUser.Id,
  7015. BatchNumberId: 0,
  7016. WarehouseOutId: 0,
  7017. }
  7018. service.CreateGoodErrcode(goodErrcode)
  7019. }
  7020. }
  7021. //更新自动出库的地方
  7022. var errs error
  7023. if errs == nil {
  7024. c.ServeSuccessJSON(map[string]interface{}{
  7025. "msg": "修改成功",
  7026. "message": "2",
  7027. "good_name": "",
  7028. "specification_name": "",
  7029. })
  7030. return
  7031. } else {
  7032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7033. return
  7034. }
  7035. }
  7036. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7037. newArr = make([]*models.DialysisBeforePrepare, 0)
  7038. for i := 0; i < len(arr); i++ {
  7039. repeat := false
  7040. for j := i + 1; j < len(arr); j++ {
  7041. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7042. repeat = true
  7043. break
  7044. }
  7045. }
  7046. if !repeat {
  7047. newArr = append(newArr, arr[i])
  7048. }
  7049. }
  7050. return
  7051. }
  7052. func (c *DialysisAPIController) GetAllDrug() {
  7053. patient_id, _ := c.GetInt64("patient_id", 0)
  7054. adminInfo := c.GetMobileAdminUserInfo()
  7055. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7056. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7057. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7058. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7059. c.ServeSuccessJSON(map[string]interface{}{
  7060. "base_drug_config": drugStockConfig,
  7061. "private_drug_config": privateDrugConfig,
  7062. "base_drug_list": drugList,
  7063. "private_drug_list": privateDrugList,
  7064. })
  7065. }
  7066. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7067. newArr = make([]*models.DialysisBeforePrepare, 0)
  7068. for i := 0; i < len(arr); i++ {
  7069. repeat := false
  7070. for j := i + 1; j < len(arr); j++ {
  7071. if arr[i].GoodId == arr[j].GoodId {
  7072. repeat = true
  7073. break
  7074. }
  7075. }
  7076. if !repeat {
  7077. newArr = append(newArr, arr[i])
  7078. }
  7079. }
  7080. return
  7081. }
  7082. func (c *DialysisAPIController) GetDepartment() {
  7083. adminInfo := c.GetMobileAdminUserInfo()
  7084. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7085. if err == nil {
  7086. c.ServeSuccessJSON(map[string]interface{}{
  7087. "departments": departments,
  7088. })
  7089. } else {
  7090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7091. return
  7092. }
  7093. }
  7094. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7095. types, _ := c.GetInt("type", 0)
  7096. start_time := c.GetString("start_time")
  7097. end_time := c.GetString("end_time")
  7098. orgId := c.GetMobileAdminUserInfo().Org.Id
  7099. timeLayout := "2006-01-02"
  7100. loc, _ := time.LoadLocation("Local")
  7101. var startTime int64
  7102. if len(start_time) > 0 {
  7103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7104. if err != nil {
  7105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7106. return
  7107. }
  7108. startTime = theTime.Unix()
  7109. }
  7110. var endTime int64
  7111. if len(end_time) > 0 {
  7112. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7113. if err != nil {
  7114. utils.ErrorLog(err.Error())
  7115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7116. return
  7117. }
  7118. endTime = theTime.Unix()
  7119. }
  7120. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7121. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7122. if err != nil {
  7123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7124. } else {
  7125. c.ServeSuccessJSON(map[string]interface{}{
  7126. "list": list,
  7127. "type": types,
  7128. "stockTotal": stockTotal,
  7129. })
  7130. }
  7131. }
  7132. func (c *DialysisAPIController) GetPrescriptionList() {
  7133. start_time := c.GetString("start_time")
  7134. end_time := c.GetString("end_time")
  7135. schedule_type, _ := c.GetInt64("schedule_type")
  7136. partion_id, _ := c.GetInt64("partion_id")
  7137. orgId := c.GetMobileAdminUserInfo().Org.Id
  7138. timeLayout := "2006-01-02"
  7139. loc, _ := time.LoadLocation("Local")
  7140. var startTime int64
  7141. if len(start_time) > 0 {
  7142. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7143. if err != nil {
  7144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7145. return
  7146. }
  7147. startTime = theTime.Unix()
  7148. }
  7149. var endTime int64
  7150. if len(end_time) > 0 {
  7151. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7152. if err != nil {
  7153. utils.ErrorLog(err.Error())
  7154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7155. return
  7156. }
  7157. endTime = theTime.Unix()
  7158. }
  7159. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7160. fmt.Println("schedulelist22222222", schedulelist)
  7161. c.ServeSuccessJSON(map[string]interface{}{
  7162. "list": schedulelist,
  7163. })
  7164. return
  7165. }
  7166. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7167. ids := c.GetString("ids")
  7168. //patient_id, _ := c.GetInt64("patient_id")
  7169. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7170. idArray := strings.Split(ids, ",")
  7171. err := service.BatchDeleteMonitor(idArray)
  7172. fmt.Print("err", err)
  7173. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7174. //redis := service.RedisClient()
  7175. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7176. //redis.Set(key, "", time.Second)
  7177. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7178. //redis.Set(keyOne, "", time.Second)
  7179. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7180. //redis.Close()
  7181. c.ServeSuccessJSON(map[string]interface{}{
  7182. "msg": "批量删除成功",
  7183. })
  7184. return
  7185. }
  7186. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7187. id, _ := c.GetInt64("id")
  7188. timeLayout := "2006-01-02"
  7189. loc, _ := time.LoadLocation("Local")
  7190. //start_time := time.Now().Format("2006-01-02")
  7191. start_time := c.GetString("start_time")
  7192. end_time := c.GetString("end_time")
  7193. var startdateunix int64
  7194. if len(start_time) > 0 {
  7195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7196. if err != nil {
  7197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7198. return
  7199. }
  7200. startdateunix = theTime.Unix()
  7201. }
  7202. var enddateunix int64
  7203. if len(end_time) > 0 {
  7204. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7205. if err != nil {
  7206. utils.ErrorLog(err.Error())
  7207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7208. return
  7209. }
  7210. enddateunix = theTime.Unix()
  7211. }
  7212. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7213. //nowTime := time.Now()
  7214. //endTime := nowTime.AddDate(-30, 0, 0)
  7215. //endTimes := endTime.Format("2006-01-02")
  7216. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7217. org_id := c.GetMobileAdminUserInfo().Org.Id
  7218. //if org_id == 10579 {
  7219. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7220. // c.ServeSuccessJSON(map[string]interface{}{
  7221. // "list": list,
  7222. // })
  7223. // return
  7224. //} else {
  7225. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7226. // c.ServeSuccessJSON(map[string]interface{}{
  7227. // "list": list,
  7228. // })
  7229. // return
  7230. //}
  7231. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7232. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7233. c.ServeSuccessJSON(map[string]interface{}{
  7234. "list": list,
  7235. })
  7236. return
  7237. } else {
  7238. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7239. c.ServeSuccessJSON(map[string]interface{}{
  7240. "list": list,
  7241. })
  7242. }
  7243. return
  7244. }
  7245. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7246. dataBody := make(map[string]interface{}, 0)
  7247. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7248. ids := c.GetString("ids")
  7249. idArray := strings.Split(ids, ",")
  7250. origin, _ := c.GetInt64("origin")
  7251. if origin == 1 {
  7252. err = service.BatchDeleteAdvice(idArray)
  7253. fmt.Print("err", err)
  7254. c.ServeSuccessJSON(map[string]interface{}{
  7255. "msg": "批量删除成功",
  7256. })
  7257. return
  7258. }
  7259. if origin == 2 {
  7260. service.BatchDeleteHisAdvice(idArray)
  7261. }
  7262. }
  7263. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7264. good_id, _ := c.GetInt64("good_id")
  7265. count, _ := c.GetInt64("count")
  7266. record_time, _ := c.GetInt64("record_time")
  7267. patient_id, _ := c.GetInt64("patient_id")
  7268. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7269. c.ServeSuccessJSON(map[string]interface{}{
  7270. "detail": detail,
  7271. })
  7272. return
  7273. }
  7274. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7275. good_id, _ := c.GetInt64("good_id")
  7276. record_time, _ := c.GetInt64("record_time")
  7277. patient_id, _ := c.GetInt64("patient_id")
  7278. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7279. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7280. fmt.Print("err", err)
  7281. c.ServeSuccessJSON(map[string]interface{}{
  7282. "msg": "批量删除成功",
  7283. })
  7284. return
  7285. }
  7286. func (c *DialysisAPIController) BatchAdviceCheck() {
  7287. ids := c.GetString("ids")
  7288. idArray := strings.Split(ids, ",")
  7289. creator, _ := c.GetInt64("creator")
  7290. origin, _ := c.GetInt64("origin")
  7291. if origin == 1 {
  7292. err := service.BatchAdviceCheck(idArray, creator)
  7293. fmt.Println(err)
  7294. list, _ := service.GetAdviceExecutionById(idArray)
  7295. c.ServeSuccessJSON(map[string]interface{}{
  7296. "list": list,
  7297. })
  7298. return
  7299. }
  7300. if origin == 2 {
  7301. service.BatchHisAdviceCheck(idArray, creator)
  7302. list, _ := service.GetHisAdviceExecutionById(idArray)
  7303. c.ServeSuccessJSON(map[string]interface{}{
  7304. "list": list,
  7305. })
  7306. return
  7307. }
  7308. }
  7309. func (c *DialysisAPIController) BatchAdviceExecution() {
  7310. ids := c.GetString("ids")
  7311. idArray := strings.Split(ids, ",")
  7312. executionTime := c.GetString("execution_time")
  7313. creator, _ := c.GetInt64("creator")
  7314. timeLayout := "2006-01-02 15:04:05"
  7315. loc, _ := time.LoadLocation("Local")
  7316. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7317. orgin, _ := c.GetInt64("origin")
  7318. if orgin == 1 {
  7319. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7320. list, _ := service.GetAdviceExecutionById(idArray)
  7321. fmt.Println(err)
  7322. c.ServeSuccessJSON(map[string]interface{}{
  7323. "list": list,
  7324. })
  7325. return
  7326. }
  7327. if orgin == 2 {
  7328. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7329. list, _ := service.GetHisAdviceExecutionById(idArray)
  7330. fmt.Println(err)
  7331. c.ServeSuccessJSON(map[string]interface{}{
  7332. "list": list,
  7333. })
  7334. return
  7335. }
  7336. }
  7337. func (c *DialysisAPIController) UpdateStockGoods() {
  7338. good_id, _ := c.GetInt64("good_id")
  7339. record_time, _ := c.GetInt64("record_time")
  7340. patient_id, _ := c.GetInt64("patient_id")
  7341. count, _ := c.GetInt64("count")
  7342. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7343. fmt.Print("err", err)
  7344. c.ServeSuccessJSON(map[string]interface{}{
  7345. "msg": "更新成功",
  7346. })
  7347. return
  7348. }
  7349. // 当前数据比上一次出库数据少
  7350. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7351. //查询该患者当天已经出库的耗材信息
  7352. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7353. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7354. for i := len(goods_yc) - 1; i >= 0; i-- {
  7355. goods_yc_temp := goods_yc[i]
  7356. for j := len(goods) - 1; j >= 0; j-- {
  7357. goods_temp := goods[j]
  7358. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7359. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7360. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7361. if goods_yc_temp.Count == goods_temp.Count {
  7362. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7363. goods = append(goods[:j], goods[j+1:]...)
  7364. break
  7365. }
  7366. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7367. if goods_yc_temp.Count > goods_temp.Count {
  7368. temp_count := goods_yc_temp.Count - goods_temp.Count
  7369. goods_yc[i].Count = temp_count
  7370. goods = append(goods[:j], goods[j+1:]...)
  7371. break
  7372. }
  7373. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7374. if goods_yc_temp.Count < goods_temp.Count {
  7375. temp_count := goods_temp.Count - goods_yc_temp.Count
  7376. goods[j].Count = temp_count
  7377. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7378. break
  7379. }
  7380. }
  7381. }
  7382. }
  7383. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7384. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7385. //退库
  7386. if len(goods_yc) > 0 {
  7387. for _, good_yc := range goods_yc {
  7388. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7389. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7390. }
  7391. }
  7392. return nil
  7393. }
  7394. // 耗材出库删除
  7395. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7396. // 先根据相关信息查询当天该耗材的出库信息
  7397. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7398. if err != nil {
  7399. return err
  7400. }
  7401. var delete_count int64 = 0
  7402. delete_count = warehouseOutInfos.Count - count
  7403. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7404. // 在出库记录表里记录退库详情
  7405. warehouseOutInfo := &models.WarehouseOutInfo{
  7406. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7407. WarehouseOutId: warehouseOut.ID,
  7408. Status: 1,
  7409. Ctime: time.Now().Unix(),
  7410. OrgId: orgID,
  7411. Type: 1,
  7412. IsSys: 1,
  7413. SysRecordTime: record_time,
  7414. GoodTypeId: good_yc.GoodTypeId,
  7415. GoodId: good_yc.GoodId,
  7416. PatientId: good_yc.PatientId,
  7417. ConsumableType: 2,
  7418. StorehouseId: houseConfig.StorehouseOutInfo,
  7419. IsCheck: 1,
  7420. }
  7421. warehouseOutInfo.Count = count
  7422. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7423. warehouseOutInfo.Price = stockInInfo.Price
  7424. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7425. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7426. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7427. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7428. warehouseOutInfo.Number = warehouseOutInfos.Number
  7429. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7430. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7431. //查找当天是否存在出库记录
  7432. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7433. if errcod == gorm.ErrRecordNotFound {
  7434. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7435. //插入详情明细表
  7436. stockFlow := models.VmStockFlow{
  7437. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7438. WarehouseOutId: warehouseOut.ID,
  7439. GoodId: good_yc.GoodId,
  7440. Number: warehouseOutInfos.Number,
  7441. ProductDate: stockInInfo.ProductDate,
  7442. ExpireDate: stockInInfo.ExpiryDate,
  7443. Count: count,
  7444. Price: stockInInfo.Price,
  7445. Status: 1,
  7446. Ctime: time.Now().Unix(),
  7447. UserOrgId: good_yc.OrgId,
  7448. Manufacturer: stockInInfo.Manufacturer,
  7449. Dealer: stockInInfo.Dealer,
  7450. LicenseNumber: stockInInfo.LicenseNumber,
  7451. IsEdit: 2,
  7452. Creator: creater,
  7453. SystemTime: record_time,
  7454. ConsumableType: 3,
  7455. WarehousingDetailId: 0,
  7456. IsSys: 1,
  7457. UpdateCreator: creater,
  7458. PatientId: patient_id,
  7459. StorehouseId: houseConfig.StorehouseOutInfo,
  7460. }
  7461. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7462. if errflow == gorm.ErrRecordNotFound {
  7463. //创建流水表
  7464. err := service.CreateStockFlowOne(stockFlow)
  7465. fmt.Println("err", err)
  7466. } else if errflow == nil {
  7467. //插入详情明细表
  7468. stockFlow := models.VmStockFlow{
  7469. ID: exsit.ID,
  7470. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7471. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7472. WarehouseOutId: warehouseOut.ID,
  7473. GoodId: good_yc.GoodId,
  7474. Number: warehouseOutInfos.Number,
  7475. ProductDate: stockInInfo.ProductDate,
  7476. ExpireDate: stockInInfo.ExpiryDate,
  7477. Count: exsit.Count - delete_count,
  7478. Price: stockInInfo.Price,
  7479. Status: 1,
  7480. Ctime: time.Now().Unix(),
  7481. UserOrgId: good_yc.OrgId,
  7482. Manufacturer: stockInInfo.Manufacturer,
  7483. Dealer: stockInInfo.Dealer,
  7484. LicenseNumber: stockInInfo.LicenseNumber,
  7485. IsEdit: 2,
  7486. Creator: creater,
  7487. SystemTime: record_time,
  7488. ConsumableType: 3,
  7489. WarehousingDetailId: 0,
  7490. IsSys: 1,
  7491. UpdateCreator: creater,
  7492. PatientId: patient_id,
  7493. StorehouseId: houseConfig.StorehouseOutInfo,
  7494. }
  7495. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7496. }
  7497. if errOne != nil {
  7498. return errOne
  7499. }
  7500. } else if errcod == nil {
  7501. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7502. //插入详情明细表
  7503. stockFlow := models.VmStockFlow{
  7504. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7505. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7506. WarehouseOutId: warehouseOut.ID,
  7507. GoodId: good_yc.GoodId,
  7508. Number: warehouseOutInfos.Number,
  7509. ProductDate: stockInInfo.ProductDate,
  7510. ExpireDate: stockInInfo.ExpiryDate,
  7511. Count: count,
  7512. Price: stockInInfo.Price,
  7513. Status: 1,
  7514. Ctime: time.Now().Unix(),
  7515. UserOrgId: good_yc.OrgId,
  7516. Manufacturer: stockInInfo.Manufacturer,
  7517. Dealer: stockInInfo.Dealer,
  7518. LicenseNumber: stockInInfo.LicenseNumber,
  7519. IsEdit: 2,
  7520. Creator: creater,
  7521. SystemTime: record_time,
  7522. ConsumableType: 3,
  7523. WarehousingDetailId: 0,
  7524. IsSys: 1,
  7525. UpdateCreator: creater,
  7526. PatientId: patient_id,
  7527. ReturnCount: delete_count,
  7528. StorehouseId: houseConfig.StorehouseOutInfo,
  7529. }
  7530. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7531. if errflows == gorm.ErrRecordNotFound {
  7532. //创建流水表
  7533. service.CreateStockFlowOne(stockFlow)
  7534. } else if errflows == nil {
  7535. stockFlow := models.VmStockFlow{
  7536. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7537. ID: exsit.ID,
  7538. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7539. WarehouseOutId: warehouseOut.ID,
  7540. GoodId: good_yc.GoodId,
  7541. Number: warehouseOutInfos.Number,
  7542. ProductDate: stockInInfo.ProductDate,
  7543. ExpireDate: stockInInfo.ExpiryDate,
  7544. Count: exsit.Count - delete_count,
  7545. Price: stockInInfo.Price,
  7546. Status: 1,
  7547. Ctime: time.Now().Unix(),
  7548. UserOrgId: good_yc.OrgId,
  7549. Manufacturer: stockInInfo.Manufacturer,
  7550. Dealer: stockInInfo.Dealer,
  7551. LicenseNumber: stockInInfo.LicenseNumber,
  7552. IsEdit: 2,
  7553. Creator: creater,
  7554. SystemTime: record_time,
  7555. ConsumableType: 3,
  7556. WarehousingDetailId: 0,
  7557. IsSys: 1,
  7558. UpdateCreator: creater,
  7559. PatientId: patient_id,
  7560. ReturnCount: delete_count,
  7561. StorehouseId: houseConfig.StorehouseOutInfo,
  7562. }
  7563. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7564. }
  7565. }
  7566. //更改自动出库的表格
  7567. details := models.BloodAutomaticReduceDetail{
  7568. WarehouseOutId: warehouseOutInfo.ID,
  7569. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7570. PatientId: patient_id,
  7571. Ctime: time.Now().Unix(),
  7572. Mtime: time.Now().Unix(),
  7573. Status: 1,
  7574. RecordTime: record_time,
  7575. OrgId: orgID,
  7576. GoodId: good_yc.GoodId,
  7577. GoodTypeId: good_yc.GoodTypeId,
  7578. Count: count,
  7579. StorehouseId: houseConfig.StorehouseOutInfo,
  7580. }
  7581. //查询当天耗材是否已经存在数据
  7582. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7583. if errcode == gorm.ErrRecordNotFound {
  7584. errTwo := service.CreateAutoReduceRecord(&details)
  7585. if errTwo != nil {
  7586. return errTwo
  7587. }
  7588. } else if errcode == nil {
  7589. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7590. service.CreateAutoReduceRecord(&details)
  7591. }
  7592. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7593. //增加出库库存数量
  7594. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7595. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7596. fmt.Println("errOne", errOne)
  7597. // 删除出库完成后,要增加对应批次的库存数量
  7598. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7599. if errThree != nil {
  7600. return errThree
  7601. }
  7602. if good_yc.Count == 0 {
  7603. return nil
  7604. } else {
  7605. return errors.New("退库和出库数据不匹配")
  7606. }
  7607. }
  7608. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7609. //查询该患者当天已经出库的耗材信息
  7610. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7611. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7612. for i := len(goods_yc) - 1; i >= 0; i-- {
  7613. goods_yc_temp := goods_yc[i]
  7614. for j := len(goods) - 1; j >= 0; j-- {
  7615. goods_temp := goods[j]
  7616. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7617. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7618. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7619. if goods_yc_temp.Count == goods_temp.Count {
  7620. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7621. goods = append(goods[:j], goods[j+1:]...)
  7622. break
  7623. }
  7624. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7625. if goods_yc_temp.Count > goods_temp.Count {
  7626. temp_count := goods_yc_temp.Count - goods_temp.Count
  7627. goods_yc[i].Count = temp_count
  7628. goods = append(goods[:j], goods[j+1:]...)
  7629. break
  7630. }
  7631. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7632. if goods_yc_temp.Count < goods_temp.Count {
  7633. temp_count := goods_temp.Count - goods_yc_temp.Count
  7634. goods[j].Count = temp_count
  7635. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7636. break
  7637. }
  7638. }
  7639. }
  7640. }
  7641. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7642. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7643. fmt.Println("剩余需要出库的", len(goods))
  7644. if len(goods) > 0 {
  7645. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7646. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7647. if err == gorm.ErrRecordNotFound {
  7648. //没有记录,则创建出库单
  7649. timeStr := time.Now().Format("2006-01-02")
  7650. timeArr := strings.Split(timeStr, "-")
  7651. total, _ := service.FindAllWarehouseOut(orgID)
  7652. total = total + 1
  7653. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7654. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7655. number = number + total
  7656. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7657. warehouseOut := models.WarehouseOut{
  7658. WarehouseOutOrderNumber: warehousing_out_order,
  7659. OperationTime: time.Now().Unix(),
  7660. OrgId: orgID,
  7661. Creater: creater,
  7662. Ctime: time.Now().Unix(),
  7663. Status: 1,
  7664. WarehouseOutTime: record_time,
  7665. Dealer: 0,
  7666. Manufacturer: 0,
  7667. Type: 1,
  7668. IsSys: 1,
  7669. StorehouseId: houseConfig.StorehouseOutInfo,
  7670. IsCheck: 1,
  7671. }
  7672. err := service.AddSigleWarehouseOut(&warehouseOut)
  7673. if err != nil {
  7674. utils.TraceLog("创建出库单失败 err = %v", err)
  7675. return err
  7676. } else {
  7677. out = warehouseOut
  7678. }
  7679. }
  7680. for _, item := range goods {
  7681. var newCount int64 = 0
  7682. for _, it := range goodOne {
  7683. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7684. newCount = it.Count
  7685. }
  7686. }
  7687. prepare := models.DialysisBeforePrepare{
  7688. GoodTypeId: item.GoodTypeId,
  7689. GoodId: item.GoodId,
  7690. Count: item.Count,
  7691. StorehouseId: houseConfig.StorehouseOutInfo,
  7692. }
  7693. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7694. //增加出库数量
  7695. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7696. }
  7697. }
  7698. if len(goods_yc) > 0 {
  7699. for _, good_yc := range goods_yc {
  7700. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7701. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7702. }
  7703. }
  7704. return nil
  7705. }
  7706. // 耗材出库删除
  7707. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7708. // 先根据相关信息查询当天该耗材的出库信息
  7709. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7710. if err != nil {
  7711. return err
  7712. }
  7713. var delete_count int64 = 0
  7714. for _, ware := range warehouseOutInfos {
  7715. // 判断当前出库的数据和删除出库数量
  7716. if good_yc.Count <= ware.Count {
  7717. delete_count = good_yc.Count
  7718. } else {
  7719. delete_count = ware.Count
  7720. }
  7721. warehouseOutInfo := &models.WarehouseOutInfo{
  7722. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7723. WarehouseOutId: warehouseOut.ID,
  7724. Status: 1,
  7725. Ctime: time.Now().Unix(),
  7726. Remark: "",
  7727. OrgId: orgID,
  7728. Type: 1,
  7729. Manufacturer: 0,
  7730. Dealer: 0,
  7731. IsSys: 0,
  7732. SysRecordTime: record_time,
  7733. GoodTypeId: good_yc.GoodTypeId,
  7734. GoodId: good_yc.GoodId,
  7735. StorehouseId: warehouseOut.StorehouseId,
  7736. IsCheck: 1,
  7737. }
  7738. warehouseOutInfo.Count = delete_count
  7739. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7740. warehouseOutInfo.Price = stockInInfo.Price
  7741. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7742. if errOne != nil {
  7743. return errOne
  7744. }
  7745. // 删除出库完成后,要改变流水库存(有疑问)
  7746. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7747. fmt.Println("errOne", errOne)
  7748. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7749. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7750. //扣减出库数量
  7751. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7752. if errThree != nil {
  7753. return errThree
  7754. }
  7755. }
  7756. if good_yc.Count == 0 {
  7757. return nil
  7758. } else {
  7759. return errors.New("退库和出库数据不匹配")
  7760. }
  7761. }
  7762. func (this *DialysisAPIController) GetMobileScheduleList() {
  7763. limit, _ := this.GetInt64("limit")
  7764. page, _ := this.GetInt64("page")
  7765. type_options_visible, _ := this.GetInt64("type_options_visible")
  7766. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7767. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7768. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7769. }
  7770. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7771. newArr = make([]*models.HisPrescriptionProject, 0)
  7772. for i := 0; i < len(arr); i++ {
  7773. repeat := false
  7774. for j := i + 1; j < len(arr); j++ {
  7775. if arr[i].TeamId == arr[j].TeamId {
  7776. repeat = true
  7777. break
  7778. }
  7779. }
  7780. if !repeat {
  7781. newArr = append(newArr, arr[i])
  7782. }
  7783. }
  7784. return
  7785. }
  7786. func (this *DialysisAPIController) GetRoleList() {
  7787. admin_user_id, _ := this.GetInt64("admin_user_id")
  7788. orgid := this.GetMobileAdminUserInfo().Org.Id
  7789. list, err := service.GetRoleList(orgid, admin_user_id)
  7790. fmt.Println(err)
  7791. this.ServeSuccessJSON(map[string]interface{}{
  7792. "list": list,
  7793. })
  7794. return
  7795. }
  7796. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7797. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7798. // 先根据相关信息查询当天该耗材的出库信息
  7799. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7800. if err != nil {
  7801. return err
  7802. }
  7803. var delete_count int64 = 0
  7804. delete_count = warehouseOutInfos.Count - count
  7805. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7806. // 删除出库完成后,要增加对应批次的库存数量
  7807. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7808. if errThree != nil {
  7809. return errThree
  7810. }
  7811. //增加退库数量
  7812. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7813. //扣减出库数量
  7814. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7815. //查询剩余库存
  7816. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7817. var sum_count int64
  7818. for _, item := range goodList {
  7819. sum_count += item.StockCount
  7820. }
  7821. // 在出库记录表里记录退库详情
  7822. warehouseOutInfo := &models.WarehouseOutInfo{
  7823. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7824. WarehouseOutId: warehouseOut.ID,
  7825. Status: 1,
  7826. Ctime: time.Now().Unix(),
  7827. OrgId: orgID,
  7828. Type: 1,
  7829. IsSys: 1,
  7830. SysRecordTime: record_time,
  7831. GoodTypeId: good_yc.GoodTypeId,
  7832. GoodId: good_yc.GoodId,
  7833. PatientId: good_yc.PatientId,
  7834. ConsumableType: 2,
  7835. StorehouseId: houseConfig.StorehouseOutInfo,
  7836. IsCheck: 1,
  7837. OverCount: sum_count,
  7838. }
  7839. warehouseOutInfo.Count = count
  7840. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7841. warehouseOutInfo.Price = stockInInfo.Price
  7842. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7843. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7844. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7845. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7846. warehouseOutInfo.Number = warehouseOutInfos.Number
  7847. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7848. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7849. //查找当天是否存在出库记录
  7850. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7851. if errcod == gorm.ErrRecordNotFound {
  7852. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7853. //插入详情明细表
  7854. if errOne != nil {
  7855. return errOne
  7856. }
  7857. //插入详情明细表
  7858. stockFlow := models.VmStockFlow{
  7859. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7860. WarehouseOutId: warehouseOut.ID,
  7861. GoodId: good_yc.GoodId,
  7862. Number: warehouseOutInfos.Number,
  7863. ProductDate: stockInInfo.ProductDate,
  7864. ExpireDate: stockInInfo.ExpiryDate,
  7865. Count: count,
  7866. Price: stockInInfo.Price,
  7867. Status: 1,
  7868. Ctime: time.Now().Unix(),
  7869. UserOrgId: good_yc.OrgId,
  7870. Manufacturer: stockInInfo.Manufacturer,
  7871. Dealer: stockInInfo.Dealer,
  7872. LicenseNumber: stockInInfo.LicenseNumber,
  7873. IsEdit: 2,
  7874. Creator: creater,
  7875. SystemTime: record_time,
  7876. ConsumableType: 3,
  7877. WarehousingDetailId: 0,
  7878. IsSys: 1,
  7879. UpdateCreator: creater,
  7880. PatientId: patient_id,
  7881. StorehouseId: houseConfig.StorehouseOutInfo,
  7882. OverCount: sum_count,
  7883. ProjectId: good_yc.ProjectId,
  7884. }
  7885. err := service.CreateStockFlowOne(stockFlow)
  7886. fmt.Println("err", err)
  7887. } else if errcod == nil {
  7888. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7889. }
  7890. //创建退库单
  7891. operation_time := time.Now().Unix()
  7892. //创建退库单
  7893. timeStr := time.Now().Format("2006-01-02")
  7894. timeArr := strings.Split(timeStr, "-")
  7895. total, _ := service.FindAllCancelStockTotal(orgID)
  7896. total = total + 1
  7897. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7898. cancelStock := models.CancelStock{
  7899. OrderNumber: orderNumber,
  7900. OperaTime: operation_time,
  7901. OrgId: orgID,
  7902. Creater: warehouseOut.Creater,
  7903. Ctime: time.Now().Unix(),
  7904. Status: 1,
  7905. ReturnTime: record_time,
  7906. Type: 1,
  7907. StorehouseId: stockInInfo.StorehouseId,
  7908. IsCheck: 1,
  7909. }
  7910. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7911. if msgerrkonde == gorm.ErrRecordNotFound {
  7912. service.AddSigleCancelStock(&cancelStock)
  7913. }
  7914. cancel, _ := service.GetLastCancelStockById(orgID)
  7915. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7916. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7917. cancelStockInfo := models.CancelStockInfo{
  7918. GoodId: stockInInfo.GoodId,
  7919. CancelStockId: cancel.ID,
  7920. GoodTypeId: stockInInfo.GoodTypeId,
  7921. Count: delete_count,
  7922. Price: stockInInfo.PackingPrice,
  7923. Total: 0,
  7924. ProductDate: stockInInfo.ProductDate,
  7925. ExpiryDate: stockInInfo.ExpiryDate,
  7926. Ctime: time.Now().Unix(),
  7927. Status: 1,
  7928. OrgId: orgID,
  7929. OrderNumber: cancel.OrderNumber,
  7930. Type: 0,
  7931. Dealer: deaerler.DealerName,
  7932. Manufacturer: manufacturer.ManufacturerName,
  7933. Number: stockInInfo.Number,
  7934. RegisterAccount: "",
  7935. Remark: "",
  7936. WarehouseInfoId: stockInInfo.ID,
  7937. PatientId: patient_id,
  7938. RecordDate: record_time,
  7939. StorehouseId: stockInInfo.StorehouseId,
  7940. IsCheck: 1,
  7941. }
  7942. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7943. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7944. flow := models.VmStockFlow{
  7945. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7946. GoodId: good_yc.GoodId,
  7947. Number: warehouseOutInfos.Number,
  7948. LicenseNumber: stockInInfo.LicenseNumber,
  7949. Count: delete_count,
  7950. UserOrgId: orgID,
  7951. PatientId: patient_id,
  7952. SystemTime: record_time,
  7953. ConsumableType: 7,
  7954. IsSys: 0,
  7955. WarehousingOrder: "",
  7956. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7957. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7958. IsEdit: 0,
  7959. CancelStockId: cancel.ID,
  7960. CancelOrderNumber: cancel.OrderNumber,
  7961. Manufacturer: manufacturer.ID,
  7962. Dealer: 0,
  7963. Creator: warehouseOut.Creater,
  7964. UpdateCreator: 0,
  7965. Status: 1,
  7966. Ctime: time.Now().Unix(),
  7967. Mtime: 0,
  7968. Price: stockInInfo.Price,
  7969. WarehousingDetailId: stockInInfo.ID,
  7970. WarehouseOutDetailId: warehouseOutInfos.ID,
  7971. CancelOutDetailId: cancelInfo.ID,
  7972. ProductDate: stockInInfo.ProductDate,
  7973. ExpireDate: stockInInfo.ExpiryDate,
  7974. StorehouseId: houseConfig.StorehouseOutInfo,
  7975. OverCount: sum_count,
  7976. }
  7977. service.CreateStockFlowOne(flow)
  7978. //更改自动出库的表格
  7979. details := models.BloodAutomaticReduceDetail{
  7980. WarehouseOutId: warehouseOutInfo.ID,
  7981. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7982. PatientId: patient_id,
  7983. Ctime: time.Now().Unix(),
  7984. Mtime: time.Now().Unix(),
  7985. Status: 1,
  7986. RecordTime: record_time,
  7987. OrgId: orgID,
  7988. GoodId: good_yc.GoodId,
  7989. GoodTypeId: good_yc.GoodTypeId,
  7990. Count: count,
  7991. StorehouseId: houseConfig.StorehouseOutInfo,
  7992. }
  7993. //查询当天耗材是否已经存在数据
  7994. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7995. if errcode == gorm.ErrRecordNotFound {
  7996. errTwo := service.CreateAutoReduceRecord(&details)
  7997. if errTwo != nil {
  7998. return errTwo
  7999. }
  8000. } else if errcode == nil {
  8001. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8002. service.CreateAutoReduceRecord(&details)
  8003. }
  8004. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8005. //增加出库库存数量
  8006. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8007. if good_yc.Count == 0 {
  8008. return nil
  8009. } else {
  8010. return errors.New("退库和出库数据不匹配")
  8011. }
  8012. }
  8013. func (this *DialysisAPIController) SavePatientSign() {
  8014. adminUserInfo := this.GetMobileAdminUserInfo()
  8015. patient_id, _ := this.GetInt64("patient_id")
  8016. dialysis_date, _ := this.GetInt64("dialysis_date")
  8017. orgid := adminUserInfo.Org.Id
  8018. var esdata models.DialysisOrder
  8019. var err error
  8020. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8022. return
  8023. }
  8024. esdata.Hash = esdata.Hash
  8025. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8026. order := models.DialysisOrder{
  8027. Hash: esdata.Hash,
  8028. Url: esdata.Url,
  8029. }
  8030. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8031. redis := service.RedisClient()
  8032. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8033. redis.Set(key, "", time.Second)
  8034. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8035. //清空key 值
  8036. redis.Set(keyOne, "", time.Second)
  8037. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8038. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8039. //redis.Set(keyTwo, "", time.Second)
  8040. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8041. redis.Set(keyThree, "", time.Second)
  8042. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8043. redis.Set(keyFour, "", time.Second)
  8044. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8045. redis.Set(keyFive, "", time.Second)
  8046. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8047. redis.Set(keySix, "", time.Second)
  8048. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8049. redis.Set(keySeven, "", time.Second)
  8050. if err != nil {
  8051. fmt.Println(err)
  8052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8053. return
  8054. }
  8055. this.ServeSuccessJSON(map[string]interface{}{
  8056. "electronic_signature": esdata,
  8057. })
  8058. }
  8059. func (this *DialysisAPIController) GetPatientSign() {
  8060. patient_id, _ := this.GetInt64("patient_id")
  8061. dialysis_date, _ := this.GetInt64("dialysis_date")
  8062. adminUserInfo := this.GetMobileAdminUserInfo()
  8063. orgId := adminUserInfo.Org.Id
  8064. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8065. if err != nil {
  8066. fmt.Println(err)
  8067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8068. return
  8069. }
  8070. this.ServeSuccessJSON(map[string]interface{}{
  8071. "dialysisOrder": dialysisOrder,
  8072. })
  8073. }
  8074. func (this *DialysisAPIController) GetScheduleByPatient() {
  8075. patient_id, _ := this.GetInt64("patient_id")
  8076. schedule_date, _ := this.GetInt64("schedule_date")
  8077. orgid := this.GetMobileAdminUserInfo().Org.Id
  8078. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8079. this.ServeSuccessJSON(map[string]interface{}{
  8080. "schedule": schedule,
  8081. })
  8082. }
  8083. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8084. org_id := this.GetMobileAdminUserInfo().Org.Id
  8085. patient_id, _ := this.GetInt64("patient_id")
  8086. schedule_date, _ := this.GetInt64("schedule_date")
  8087. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8088. this.ServeSuccessJSON(map[string]interface{}{
  8089. "order": order,
  8090. })
  8091. }
  8092. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8093. org_id := this.GetMobileAdminUserInfo().Org.Id
  8094. schedule_date := this.GetString("schedule_date")
  8095. schedule_type, _ := this.GetInt64("schedule_type")
  8096. timeLayout := "2006-01-02"
  8097. loc, _ := time.LoadLocation("Local")
  8098. var startdateunix int64
  8099. if len(schedule_date) > 0 {
  8100. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8101. if err != nil {
  8102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8103. return
  8104. }
  8105. startdateunix = theTime.Unix()
  8106. }
  8107. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8108. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8109. devices, _ := service.GetAllDevicetByListSix(org_id)
  8110. for key, item := range scheduals {
  8111. // 床位信息
  8112. for _, device := range devices {
  8113. if item.BedId == device.ID {
  8114. scheduals[key].DeviceNumber = device
  8115. break
  8116. }
  8117. }
  8118. }
  8119. this.ServeSuccessJSON(map[string]interface{}{
  8120. "list": list,
  8121. "scheduals": scheduals,
  8122. })
  8123. }
  8124. func (this *DialysisAPIController) SavePatientPicture() {
  8125. patient_id, _ := this.GetInt64("patient_id")
  8126. dialysis_date, _ := this.GetInt64("schedule_date")
  8127. avatar := this.GetString("avatar")
  8128. fmt.Println("patient_id", patient_id)
  8129. orgId := this.GetMobileAdminUserInfo().Org.Id
  8130. order := models.DialysisOrder{
  8131. Url: avatar,
  8132. }
  8133. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8134. redis := service.RedisClient()
  8135. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8136. redis.Set(key, "", time.Second)
  8137. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8138. //清空key 值
  8139. redis.Set(keyOne, "", time.Second)
  8140. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8141. redis.Set(keyThree, "", time.Second)
  8142. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8143. redis.Set(keyFour, "", time.Second)
  8144. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8145. redis.Set(keyFive, "", time.Second)
  8146. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8147. redis.Set(keySix, "", time.Second)
  8148. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8149. redis.Set(keySeven, "", time.Second)
  8150. if err != nil {
  8151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8152. return
  8153. }
  8154. this.ServeSuccessJSON(map[string]interface{}{
  8155. "order": order,
  8156. })
  8157. }
  8158. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8159. ids := this.GetString("ids")
  8160. idSplit := strings.Split(ids, ",")
  8161. orgId := this.GetMobileAdminUserInfo().Org.Id
  8162. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8163. execution_time := this.GetString("exce_time")
  8164. timeLayout2 := "2006-01-02 15:04:05"
  8165. loc, _ := time.LoadLocation("Local")
  8166. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8167. if errs != nil {
  8168. utils.ErrorLog(errs.Error())
  8169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8170. return
  8171. }
  8172. //his客户
  8173. if config.IsOpen == 1 {
  8174. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8175. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8176. for _, item := range list {
  8177. for _, it := range adviceList {
  8178. if item.DrugId == it.DrugId {
  8179. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8180. }
  8181. }
  8182. }
  8183. for _, item := range list {
  8184. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8185. var sum_out_count int64
  8186. for _, itemThree := range item.ChildDoctorAdvice {
  8187. var prescribing_number int64
  8188. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8189. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8190. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8191. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8192. }
  8193. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8194. prescribing_number = parseIntPrescribingNumber
  8195. }
  8196. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8197. prescribing_number = parseIntPrescribingNumber
  8198. }
  8199. sum_out_count += prescribing_number
  8200. }
  8201. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8202. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8203. //库存不足
  8204. if sum_out_count > drugStockOut.FlushCount {
  8205. this.ServeSuccessJSON(map[string]interface{}{
  8206. "msg": "2",
  8207. "drug": medical,
  8208. "ids": ids,
  8209. })
  8210. return
  8211. }
  8212. }
  8213. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8214. //执行医嘱
  8215. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8216. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8217. for _, item := range advices {
  8218. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8219. redis := service.RedisClient()
  8220. //清空key 值
  8221. redis.Set(key, "", time.Second)
  8222. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8223. redis.Set(keyTwo, "", time.Second)
  8224. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8225. redis.Set(keyThree, "", time.Second)
  8226. recordDate := theTime.Format("2006-01-02")
  8227. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8228. redis.Set(keyFour, "", time.Second)
  8229. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8230. redis.Set(keyFive, "", time.Second)
  8231. defer redis.Close()
  8232. }
  8233. if errs == nil {
  8234. //药品管理信息
  8235. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8236. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8237. if drugStockConfig.IsOpen == 1 {
  8238. for _, item := range advices {
  8239. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8240. config, _ := service.GetDrugOpenConfigOne(orgId)
  8241. if config.IsOpen != 1 {
  8242. //查询该药品是否有库存
  8243. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8244. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8245. if medical.IsUse == 2 {
  8246. if config.IsOpen != 1 {
  8247. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8248. service.HisDrugsDelivery(orgId, creater, &advice)
  8249. if orgId == 3877 || orgId == 10265 {
  8250. //查询该药品是否有出库记录
  8251. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8252. if len(flowMap) == 0 {
  8253. errs := service.UpdateHisAdviceById(advice.ID)
  8254. if errs != nil {
  8255. drugError := models.XtDrugError{
  8256. UserOrgId: orgId,
  8257. DrugId: item.DrugId,
  8258. RecordDate: item.AdviceDate,
  8259. PatientId: item.PatientId,
  8260. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8261. Status: 1,
  8262. Ctime: time.Now().Unix(),
  8263. Mtime: 0,
  8264. SumCount: 0,
  8265. Prescribingnumber: advice.PrescribingNumber,
  8266. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8267. }
  8268. service.CreateDrugError(drugError)
  8269. }
  8270. this.ServeSuccessJSON(map[string]interface{}{
  8271. "msg": "2",
  8272. "drug": medical,
  8273. "ids": ids,
  8274. })
  8275. return
  8276. }
  8277. }
  8278. }
  8279. if pharmacyConfig.IsOpen != 1 {
  8280. service.HisDrugsDelivery(orgId, creater, &advice)
  8281. if orgId == 3877 || orgId == 10265 {
  8282. //查询该药品是否有出库记录
  8283. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8284. if len(flowMap) == 0 {
  8285. errs := service.UpdateHisAdviceById(advice.ID)
  8286. if errs != nil {
  8287. drugError := models.XtDrugError{
  8288. UserOrgId: orgId,
  8289. DrugId: item.DrugId,
  8290. RecordDate: item.AdviceDate,
  8291. PatientId: item.PatientId,
  8292. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8293. Status: 1,
  8294. Ctime: time.Now().Unix(),
  8295. Mtime: 0,
  8296. SumCount: 0,
  8297. Prescribingnumber: advice.PrescribingNumber,
  8298. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8299. }
  8300. service.CreateDrugError(drugError)
  8301. }
  8302. this.ServeSuccessJSON(map[string]interface{}{
  8303. "msg": "2",
  8304. "drug": medical,
  8305. "ids": ids,
  8306. })
  8307. return
  8308. }
  8309. }
  8310. }
  8311. //更新字典里面的库存
  8312. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8313. var sum_count int64
  8314. for _, its := range stockInfo {
  8315. if its.MaxUnit == medical.MaxUnit {
  8316. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8317. }
  8318. sum_count += its.StockMaxNumber + its.StockMinNumber
  8319. }
  8320. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8321. //剩余库存
  8322. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8323. }
  8324. }
  8325. }
  8326. }
  8327. }
  8328. this.ServeSuccessJSON(map[string]interface{}{
  8329. "msg": "1",
  8330. "ids": ids,
  8331. })
  8332. return
  8333. } else {
  8334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8335. }
  8336. }
  8337. fmt.Println("config233322333223", config.IsOpen)
  8338. //血透客户
  8339. if config.IsOpen == 2 || config.IsOpen == 0 {
  8340. //药品管理信息
  8341. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8342. if drugStockConfig.IsOpen == 1 {
  8343. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8344. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8345. for _, item := range list {
  8346. for _, it := range adviceList {
  8347. if item.DrugId == it.DrugId {
  8348. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8349. }
  8350. }
  8351. }
  8352. for _, item := range list {
  8353. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8354. var sum_out_count int64
  8355. for _, itemThree := range item.ChildDoctorAdvice {
  8356. var prescribing_number int64
  8357. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8358. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8359. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8360. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8361. }
  8362. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8363. prescribing_number = parseIntPrescribingNumber
  8364. }
  8365. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8366. prescribing_number = parseIntPrescribingNumber
  8367. }
  8368. sum_out_count += prescribing_number
  8369. }
  8370. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8371. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8372. //库存不足
  8373. if sum_out_count > drugStockOut.FlushCount {
  8374. this.ServeSuccessJSON(map[string]interface{}{
  8375. "msg": "2",
  8376. "drug": medical,
  8377. "ids": ids,
  8378. })
  8379. return
  8380. }
  8381. }
  8382. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8383. fmt.Println("creater2332243244224242424", creater)
  8384. //执行医嘱
  8385. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8386. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8387. for _, item := range advices {
  8388. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8389. redis := service.RedisClient()
  8390. //清空key 值
  8391. redis.Set(key, "", time.Second)
  8392. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8393. redis.Set(keyTwo, "", time.Second)
  8394. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8395. redis.Set(keyThree, "", time.Second)
  8396. recordDate := theTime.Format("2006-01-02")
  8397. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8398. redis.Set(keyFour, "", time.Second)
  8399. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8400. redis.Set(keyFive, "", time.Second)
  8401. defer redis.Close()
  8402. }
  8403. if errs == nil {
  8404. for _, item := range advices {
  8405. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8406. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8407. //查询是否出库按钮开启
  8408. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8409. if adviceSetting.IsAdviceOpen == 1 {
  8410. //查询是否出库按钮开启
  8411. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8412. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8413. if prescriptionConfig.IsOpen == 1 {
  8414. if medical.IsUse == 2 {
  8415. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8416. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8417. }
  8418. if pharmacyConfig.IsOpen != 1 {
  8419. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8420. }
  8421. //更新字典里面的库存
  8422. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8423. var sum_count int64
  8424. for _, its := range stockInfo {
  8425. if its.MaxUnit == medical.MaxUnit {
  8426. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8427. }
  8428. sum_count += its.StockMaxNumber + its.StockMinNumber
  8429. }
  8430. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8431. //剩余库存
  8432. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8433. }
  8434. }
  8435. } else {
  8436. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8437. if medical.IsUse == 2 {
  8438. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8439. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8440. }
  8441. if pharmacyConfig.IsOpen != 1 {
  8442. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8443. }
  8444. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8445. var sum_count int64
  8446. for _, its := range stockInfo {
  8447. if its.MaxUnit == medical.MaxUnit {
  8448. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8449. }
  8450. sum_count += its.StockMaxNumber + its.StockMinNumber
  8451. }
  8452. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8453. //剩余库存
  8454. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8455. }
  8456. }
  8457. }
  8458. }
  8459. this.ServeSuccessJSON(map[string]interface{}{
  8460. "msg": "1",
  8461. "ids": ids,
  8462. })
  8463. return
  8464. } else {
  8465. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8466. //执行医嘱
  8467. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8468. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8469. for _, item := range advices {
  8470. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8471. redis := service.RedisClient()
  8472. //清空key 值
  8473. redis.Set(key, "", time.Second)
  8474. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8475. redis.Set(keyTwo, "", time.Second)
  8476. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8477. redis.Set(keyThree, "", time.Second)
  8478. recordDate := theTime.Format("2006-01-02")
  8479. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8480. redis.Set(keyFour, "", time.Second)
  8481. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8482. redis.Set(keyFive, "", time.Second)
  8483. defer redis.Close()
  8484. }
  8485. this.ServeSuccessJSON(map[string]interface{}{
  8486. "msg": "1",
  8487. "ids": ids,
  8488. })
  8489. return
  8490. }
  8491. }
  8492. }
  8493. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8494. ids := this.GetString("ids")
  8495. idSplit := strings.Split(ids, ",")
  8496. orgId := this.GetMobileAdminUserInfo().Org.Id
  8497. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8498. if config.IsOpen == 1 {
  8499. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8500. this.ServeSuccessJSON(map[string]interface{}{
  8501. "msg": "1",
  8502. "ids": ids,
  8503. })
  8504. return
  8505. }
  8506. if config.IsOpen == 0 || config.IsOpen == 2 {
  8507. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8508. this.ServeSuccessJSON(map[string]interface{}{
  8509. "msg": "1",
  8510. "ids": ids,
  8511. })
  8512. return
  8513. }
  8514. }
  8515. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8516. ids := this.GetString("ids")
  8517. idSplit := strings.Split(ids, ",")
  8518. orgId := this.GetMobileAdminUserInfo().Org.Id
  8519. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8520. //his
  8521. if config.IsOpen == 1 {
  8522. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8523. theTime := time.Now()
  8524. advices := models.HisDoctorAdviceThirty{
  8525. CheckTime: theTime.Unix(),
  8526. Checker: checker,
  8527. UpdatedTime: time.Now().Unix(),
  8528. }
  8529. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8530. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8531. for _, item := range list {
  8532. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8533. redis := service.RedisClient()
  8534. //清空key 值
  8535. redis.Set(key, "", time.Second)
  8536. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8537. redis.Set(keyTwo, "", time.Second)
  8538. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8539. redis.Set(keyThree, "", time.Second)
  8540. recordDate := theTime.Format("2006-01-02")
  8541. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8542. redis.Set(keyFour, "", time.Second)
  8543. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8544. redis.Set(keyFive, "", time.Second)
  8545. defer redis.Close()
  8546. }
  8547. this.ServeSuccessJSON(map[string]interface{}{
  8548. "msg": "1",
  8549. "ids": ids,
  8550. })
  8551. return
  8552. }
  8553. //血透
  8554. if config.IsOpen == 0 || config.IsOpen == 2 {
  8555. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8556. theTime := time.Now()
  8557. advices := models.DoctorAdvice{
  8558. CheckTime: theTime.Unix(),
  8559. Checker: checker,
  8560. UpdatedTime: time.Now().Unix(),
  8561. }
  8562. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8563. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8564. for _, item := range list {
  8565. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8566. redis := service.RedisClient()
  8567. //清空key 值
  8568. redis.Set(key, "", time.Second)
  8569. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8570. redis.Set(keyTwo, "", time.Second)
  8571. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8572. redis.Set(keyThree, "", time.Second)
  8573. recordDate := theTime.Format("2006-01-02")
  8574. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8575. redis.Set(keyFour, "", time.Second)
  8576. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8577. redis.Set(keyFive, "", time.Second)
  8578. defer redis.Close()
  8579. }
  8580. this.ServeSuccessJSON(map[string]interface{}{
  8581. "msg": "1",
  8582. "ids": ids,
  8583. })
  8584. return
  8585. }
  8586. }
  8587. func (this *DialysisAPIController) CheckSchedule() {
  8588. patientID, _ := this.GetInt64("patient_id")
  8589. recordDateStr := this.GetString("record_date")
  8590. nurseID, _ := this.GetInt64("start_nurse")
  8591. schedual_type, _ := this.GetInt64("schedual_type")
  8592. bedID, _ := this.GetInt64("bed")
  8593. start_time := this.GetString("start_time")
  8594. fmt.Println("patientID", patientID)
  8595. fmt.Println("recordDateStr", recordDateStr)
  8596. fmt.Println("nurseID", nurseID)
  8597. fmt.Println("schedual_type------", schedual_type)
  8598. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8600. return
  8601. }
  8602. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8603. if parseStartDateErr != nil {
  8604. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8606. return
  8607. }
  8608. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8609. if parseErr != nil {
  8610. this.ErrorLog("时间解析失败:%v", parseErr)
  8611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8612. return
  8613. }
  8614. adminUserInfo := this.GetMobileAdminUserInfo()
  8615. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8616. if getPatientErr != nil {
  8617. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8619. return
  8620. } else if patient == nil {
  8621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8622. return
  8623. }
  8624. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8625. if getNurseErr != nil {
  8626. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8627. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8628. return
  8629. } else if nurse == nil {
  8630. this.ErrorLog("护士不存在")
  8631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8632. return
  8633. }
  8634. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8635. if getDeviceNumberErr != nil {
  8636. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8638. return
  8639. } else if deviceNumber == nil {
  8640. this.ErrorLog("床位号不存在")
  8641. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8642. return
  8643. }
  8644. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8645. if getRecordErr != nil {
  8646. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8648. return
  8649. } else if dialysisRecord != nil {
  8650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8651. return
  8652. }
  8653. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8654. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8655. timeLayout := "2006-01-02 15:04:05"
  8656. loc, _ := time.LoadLocation("Local")
  8657. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8658. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8659. schedulestartTime := theStartTime.Unix()
  8660. scheduleendTime := theEndTime.Unix()
  8661. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8662. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8663. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8664. //查询该床位是否有人用了
  8665. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8666. if err == nil {
  8667. if schedule.ID == 0 {
  8668. this.ServeSuccessJSON(map[string]interface{}{
  8669. "status": 0,
  8670. "msg": "请求失败",
  8671. })
  8672. } else {
  8673. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8674. if order.ID > 0 { //该机位被其他人占用了
  8675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8676. return
  8677. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8678. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8679. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8680. this.ServeSuccessJSON(map[string]interface{}{
  8681. "status": 1,
  8682. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8683. })
  8684. return
  8685. } else {
  8686. this.ServeSuccessJSON(map[string]interface{}{
  8687. "status": 0,
  8688. "msg": "",
  8689. })
  8690. }
  8691. }
  8692. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8693. this.ServeSuccessJSON(map[string]interface{}{
  8694. "status": 2,
  8695. "msg": "当前机位已有患者在使用,请重新选择!",
  8696. })
  8697. }
  8698. }
  8699. } else {
  8700. this.ServeSuccessJSON(map[string]interface{}{
  8701. "status": 0,
  8702. "msg": "",
  8703. })
  8704. }
  8705. }
  8706. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8707. orgId := this.GetMobileAdminUserInfo().Org.Id
  8708. schedule_type, _ := this.GetInt64("schedule_type")
  8709. partion_type, _ := this.GetInt64("partion_type")
  8710. start_time := this.GetString("start_time")
  8711. timeLayout := "2006-01-02"
  8712. loc, _ := time.LoadLocation("Local")
  8713. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8714. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8715. _, config := service.FindXTHisRecordByOrgId(orgId)
  8716. appId := this.GetMobileAdminUserInfo().App.Id
  8717. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8718. if err == nil {
  8719. this.ServeSuccessJSON(map[string]interface{}{
  8720. "list": list,
  8721. "config": config,
  8722. "doctorList": doctorList,
  8723. })
  8724. return
  8725. } else {
  8726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8727. return
  8728. }
  8729. }
  8730. func (this *DialysisAPIController) SaveMobileInformation() {
  8731. patient_id, _ := this.GetInt64("patient_id")
  8732. record_date, _ := this.GetInt64("record_date")
  8733. startTime := this.GetString("start_time")
  8734. module, _ := this.GetInt64("module")
  8735. remark := this.GetString("remark")
  8736. timeLayout := "2006-01-02 15:04"
  8737. loc, _ := time.LoadLocation("Local")
  8738. if len(startTime) == 0 {
  8739. utils.ErrorLog("len(start_time) == 0")
  8740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8741. return
  8742. }
  8743. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8744. if err != nil {
  8745. utils.ErrorLog(err.Error())
  8746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8747. return
  8748. }
  8749. StartTime := theTime.Unix()
  8750. fmt.Println("startime-------------", StartTime)
  8751. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8752. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8753. information := models.XtDialysisInformation{
  8754. Module: module,
  8755. PatientId: patient_id,
  8756. RecordDate: record_date,
  8757. ApplicationDate: StartTime,
  8758. Creater: creater,
  8759. ApplicationStatus: 2,
  8760. Checker: 0,
  8761. CheckTime: 0,
  8762. Remark: remark,
  8763. UserOrgId: user_org_id,
  8764. Ctime: time.Now().Unix(),
  8765. Status: 1,
  8766. Mtime: 0,
  8767. }
  8768. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8769. if infor.ID == 0 {
  8770. service.SaveDialysisInformation(information)
  8771. }
  8772. if infor.ID > 0 {
  8773. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8774. }
  8775. this.ServeSuccessJSON(map[string]interface{}{
  8776. "information": information,
  8777. })
  8778. return
  8779. }
  8780. func (this *DialysisAPIController) GetMobileInformation() {
  8781. limit, _ := this.GetInt64("limit")
  8782. page, _ := this.GetInt64("page")
  8783. orgid := this.GetMobileAdminUserInfo().Org.Id
  8784. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8785. appid := this.GetMobileAdminUserInfo().App.Id
  8786. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8787. patients, _ := service.GetAllpatientThirty(orgid)
  8788. this.ServeSuccessJSON(map[string]interface{}{
  8789. "information": information,
  8790. "total": total,
  8791. "doclist": doclist,
  8792. "patients": patients,
  8793. })
  8794. return
  8795. }
  8796. func (this *DialysisAPIController) GetMobileInformationOne() {
  8797. limit, _ := this.GetInt64("limit")
  8798. page, _ := this.GetInt64("page")
  8799. orgid := this.GetMobileAdminUserInfo().Org.Id
  8800. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8801. appid := this.GetMobileAdminUserInfo().App.Id
  8802. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8803. patients, _ := service.GetAllpatientThirty(orgid)
  8804. this.ServeSuccessJSON(map[string]interface{}{
  8805. "information": information,
  8806. "total": total,
  8807. "doclist": doclist,
  8808. "patients": patients,
  8809. })
  8810. return
  8811. }
  8812. func (this *DialysisAPIController) CheckMobileInformation() {
  8813. id, _ := this.GetInt64("id")
  8814. application_status, _ := this.GetInt64("application_status")
  8815. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8816. checktime := time.Now().Unix()
  8817. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8818. if err == nil {
  8819. this.ServeSuccessJSON(map[string]interface{}{
  8820. "msg": "ok",
  8821. })
  8822. return
  8823. }
  8824. }
  8825. func (c *DialysisAPIController) GetControlMonitorList() {
  8826. partition, _ := c.GetInt64("partition")
  8827. monitorDate := c.GetString("date")
  8828. patient_id, _ := c.GetInt64("patient_id")
  8829. pat_type, _ := c.GetInt64("pat_type")
  8830. timeLayout := "2006-01-02"
  8831. loc, _ := time.LoadLocation("Local")
  8832. var theStartTime int64
  8833. if len(monitorDate) > 0 {
  8834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8835. if err != nil {
  8836. theStartTime = 0
  8837. }
  8838. theStartTime = theTime.Unix()
  8839. }
  8840. adminInfo := c.GetMobileAdminUserInfo()
  8841. orgID := adminInfo.Org.Id
  8842. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8843. if err != nil {
  8844. c.ErrorLog("获取排班信息失败:%v", err)
  8845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8846. } else {
  8847. if len(monitor) > 0 {
  8848. //获取所有床位
  8849. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8850. //获取所有分区
  8851. zoneList, _ := service.GetAllZoneByList(orgID)
  8852. //获取透析处方
  8853. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8854. //获取透前评估
  8855. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8856. //获取上机
  8857. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8858. //获取透后
  8859. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8860. //获取透后监测
  8861. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8862. //获取所有的患者
  8863. patients, _ := service.GetAllPatientListByListOne(orgID)
  8864. //获取所有透析模式
  8865. treatments, _ := service.GetAllTreatModeByList(orgID)
  8866. //获取所有医嘱
  8867. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8868. //获取双人核对
  8869. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8870. //治疗小结
  8871. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8872. //待消毒
  8873. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8874. for key, item := range monitor {
  8875. // 获取床位信息
  8876. for _, it := range numberList {
  8877. if item.BedId == it.ID {
  8878. monitor[key].DeviceNumber = it
  8879. break
  8880. }
  8881. }
  8882. //获取分区信息
  8883. for _, it := range zoneList {
  8884. if item.PartitionId == it.ID {
  8885. monitor[key].DeviceZone = it
  8886. }
  8887. }
  8888. for _, prescription := range prescriptions {
  8889. if item.PatientId == prescription.PatientId {
  8890. monitor[key].Prescription = prescription
  8891. break
  8892. }
  8893. }
  8894. for _, it := range checkList {
  8895. if item.PatientId == it.PatientId {
  8896. monitor[key].DoubleCheck = it
  8897. break
  8898. }
  8899. }
  8900. for _, it := range summaryList {
  8901. if item.PatientId == it.PatientId {
  8902. monitor[key].TreatmentSummaryForList = it
  8903. break
  8904. }
  8905. }
  8906. // 透前评估
  8907. for _, assessmentBefore := range assessmentBefores {
  8908. if item.PatientId == assessmentBefore.PatientId {
  8909. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8910. break
  8911. }
  8912. }
  8913. // 透析上下机
  8914. for _, dialysisOrder := range dialysisOrders {
  8915. if item.PatientId == dialysisOrder.PatientId {
  8916. monitor[key].DialysisOrder = dialysisOrder
  8917. break
  8918. }
  8919. }
  8920. // 治疗小节
  8921. for _, afterDislysis := range AssessmentAfterDislysis {
  8922. if item.PatientId == afterDislysis.PatientId {
  8923. monitor[key].AssessmentAfterDislysis = afterDislysis
  8924. break
  8925. }
  8926. }
  8927. for _, it := range monitorlist {
  8928. if item.PatientId == it.PatientId {
  8929. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8930. }
  8931. }
  8932. for _, it := range adviceList {
  8933. if item.PatientId == it.PatientId {
  8934. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8935. }
  8936. }
  8937. for _, patient := range patients {
  8938. if item.PatientId == patient.ID {
  8939. monitor[key].MonitorPatients = patient
  8940. break
  8941. }
  8942. }
  8943. for _, treatment := range treatments {
  8944. if item.ModeId == treatment.ID {
  8945. monitor[key].TreatmentMode = treatment
  8946. break
  8947. }
  8948. }
  8949. for _, infor := range informationList {
  8950. if item.PatientId == infor.PatientId {
  8951. monitor[key].NewDeviceInformation = infor
  8952. break
  8953. }
  8954. }
  8955. }
  8956. }
  8957. }
  8958. patients, err := service.GetAllpatientFourty(orgID)
  8959. var mds []*models.NewMonitorDialysisScheduleList
  8960. if pat_type == 0 {
  8961. for _, item := range monitor {
  8962. mds = append(mds, item)
  8963. }
  8964. }
  8965. //待医嘱核对
  8966. if pat_type == 1 {
  8967. for _, item := range monitor {
  8968. if len(item.AdviceList) > 0 {
  8969. mds = append(mds, item)
  8970. }
  8971. }
  8972. }
  8973. //待开小结
  8974. if pat_type == 2 {
  8975. for _, item := range monitor {
  8976. if item.TreatmentSummaryForList == nil {
  8977. mds = append(mds, item)
  8978. }
  8979. }
  8980. }
  8981. //待下机
  8982. if pat_type == 3 {
  8983. for _, item := range monitor {
  8984. if item.DialysisOrder != nil {
  8985. if item.DialysisOrder.ID > 0 {
  8986. mds = append(mds, item)
  8987. }
  8988. }
  8989. }
  8990. }
  8991. //待消毒
  8992. if pat_type == 4 {
  8993. for _, item := range monitor {
  8994. if item.NewDeviceInformation == nil {
  8995. mds = append(mds, item)
  8996. }
  8997. }
  8998. }
  8999. //待双人核对
  9000. if pat_type == 5 {
  9001. for _, item := range monitor {
  9002. if item.DoubleCheck == nil {
  9003. mds = append(mds, item)
  9004. }
  9005. }
  9006. }
  9007. //医嘱未执行
  9008. if pat_type == 6 {
  9009. for _, item := range monitor {
  9010. if len(item.AdviceList) > 0 {
  9011. mds = append(mds, item)
  9012. }
  9013. }
  9014. }
  9015. //患者未签名
  9016. if pat_type == 7 {
  9017. for _, item := range monitor {
  9018. if item.DialysisOrder != nil {
  9019. if item.DialysisOrder.ID > 0 {
  9020. mds = append(mds, item)
  9021. }
  9022. }
  9023. }
  9024. }
  9025. //目标超滤于实际超滤不同
  9026. if pat_type == 8 {
  9027. for _, item := range monitor {
  9028. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9029. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9030. mds = append(mds, item)
  9031. }
  9032. }
  9033. }
  9034. }
  9035. //血压少于5次
  9036. if pat_type == 9 {
  9037. for _, item := range monitor {
  9038. if len(item.MonitoringRecord) < 5 {
  9039. mds = append(mds, item)
  9040. }
  9041. }
  9042. }
  9043. if pat_type == 10 {
  9044. for _, item := range monitor {
  9045. if len(item.MonitoringRecord) == 0 {
  9046. mds = append(mds, item)
  9047. }
  9048. }
  9049. }
  9050. if pat_type == 11 {
  9051. for _, item := range monitor {
  9052. if len(item.MonitoringRecord) > 0 {
  9053. mds = append(mds, item)
  9054. }
  9055. }
  9056. }
  9057. if pat_type == 12 {
  9058. for _, item := range monitor {
  9059. if len(item.MonitoringRecord) > 0 {
  9060. mds = append(mds, item)
  9061. }
  9062. }
  9063. }
  9064. if err == nil {
  9065. c.ServeSuccessJSON(map[string]interface{}{
  9066. "monitor": mds,
  9067. "patients": patients,
  9068. })
  9069. } else {
  9070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9071. }
  9072. }
  9073. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9074. admin_user_id, _ := c.GetInt64("admin_user_id")
  9075. timeStr := time.Now().Format("2006-01-02")
  9076. timeLayout := "2006-01-02 15:04:05"
  9077. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9078. timenow := timeStringToTime.Unix()
  9079. orgId := c.GetMobileAdminUserInfo().Org.Id
  9080. //查询当前护士的患者
  9081. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9082. var patientIds []int64
  9083. for _, item := range orderList {
  9084. patientIds = append(patientIds, item.PatientId)
  9085. }
  9086. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9087. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9088. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9089. //药品管理信息
  9090. _, drugStockConfig := service.FindHisConfig(orgId)
  9091. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9092. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9093. c.ServeSuccessJSON(map[string]interface{}{
  9094. "adviceList": adviceList,
  9095. "hisAdviceList": hisAdviceList,
  9096. "projectList": projectList,
  9097. "drugStockConfig": drugStockConfig,
  9098. "patientList": patientList,
  9099. "projectConfig": projectConfig,
  9100. })
  9101. }
  9102. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9103. patient_id, _ := c.GetInt64("patient_id")
  9104. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9105. c.ServeSuccessJSON(map[string]interface{}{
  9106. "recrods": recrods,
  9107. })
  9108. }
  9109. func (c *DialysisAPIController) ExMobileChangeSch() {
  9110. id_one, _ := c.GetInt64("id_one")
  9111. id_two, _ := c.GetInt64("id_two")
  9112. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9113. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9114. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9115. //if order2.ID > 0 {
  9116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9117. // return
  9118. //}
  9119. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9120. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9121. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9122. if count > 0 {
  9123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9124. return
  9125. }
  9126. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9127. if count1 > 0 {
  9128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9129. return
  9130. }
  9131. }
  9132. err := service.UpdateScheduleThree(sch, sch_two)
  9133. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9134. if order.ID > 0 {
  9135. //查询该患者的排班机位
  9136. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9137. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9138. redis := service.RedisClient()
  9139. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9140. redis.Set(key, "", time.Second)
  9141. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9142. //清空key 值
  9143. redis.Set(keyOne, "", time.Second)
  9144. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9145. //return
  9146. }
  9147. if err == nil {
  9148. //去除当天患者排班中重复数据,保留最后一条数据
  9149. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9150. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9151. c.ServeSuccessJSON(map[string]interface{}{
  9152. "msg": "交换成功",
  9153. })
  9154. } else {
  9155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9156. return
  9157. }
  9158. }
  9159. func (c *DialysisAPIController) MobileCoverSch() {
  9160. id_one, _ := c.GetInt64("id_one")
  9161. id_two, _ := c.GetInt64("id_two")
  9162. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9163. //针对凤凰医院
  9164. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9165. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9166. if len(advice) > 0 {
  9167. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9168. }
  9169. }
  9170. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9171. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9172. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9173. if len(hisAdvice) > 0 {
  9174. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9175. }
  9176. if len(project) > 0 {
  9177. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9178. }
  9179. }
  9180. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9181. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9182. if order.ID > 0 {
  9183. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9184. redis := service.RedisClient()
  9185. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9186. redis.Set(key, "", time.Second)
  9187. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9188. //清空key 值
  9189. redis.Set(keyOne, "", time.Second)
  9190. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9191. //return
  9192. }
  9193. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9194. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9195. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9196. if count > 0 {
  9197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9198. return
  9199. }
  9200. }
  9201. var new_sch models.Schedule
  9202. new_sch = sch
  9203. new_sch.BedId = sch_two.BedId
  9204. new_sch.ScheduleDate = sch_two.ScheduleDate
  9205. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9206. new_sch.PartitionId = sch_two.PartitionId
  9207. new_sch.ScheduleType = sch_two.ScheduleType
  9208. new_sch.ID = 0
  9209. //删除原来的排班
  9210. err := service.SaveSchTwo(sch, sch_two)
  9211. //生成新的排班
  9212. if err == nil {
  9213. err2 := service.SaveSch(&new_sch)
  9214. if err2 == nil {
  9215. //去除当天患者排班中重复数据,保留最后一条数据
  9216. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9217. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9218. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9219. c.ServeSuccessJSON(map[string]interface{}{
  9220. "msg": "覆盖成功",
  9221. "new_sch": new_sch,
  9222. })
  9223. } else {
  9224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9225. return
  9226. }
  9227. } else {
  9228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9229. return
  9230. }
  9231. }