dialysis_api_controller.go 384KB

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