dialysis_api_controller.go 381KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "math"
  13. "net/http"
  14. "net/url"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. returnData := map[string]interface{}{
  503. "patient": patient,
  504. "schedual": schedual,
  505. "prescription": dialysisPrescribe,
  506. "solution": dialysisSolution,
  507. "last_prescription": lastDialysisPrescribe,
  508. "receiver_treatment_access": receiverTreatmentAccess,
  509. "predialysis_evaluation": predialysisEvaluation,
  510. "doctor_advices": doctorAdvices,
  511. "double_check": doubleCheck,
  512. "assessment_after_dislysis": assessmentAfterDislysis,
  513. "treatment_summary": treatmentSummary,
  514. "monitor_records": monitorRecords,
  515. "dialysis_order": dialysisOrder,
  516. "operators": operators,
  517. "last_predialysis_evaluation": lastPredialysisEvaluation,
  518. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  519. "last_monitor_record": lastMonitorRecord,
  520. "config": gobalConfig,
  521. "dry_weight": lastDryWeightDislysis,
  522. "system_prescription": systemDialysisPrescribe,
  523. "his_advices": his_advices,
  524. "is_open_config": is_open_config,
  525. "stockType": stockType,
  526. "prepare": prepare,
  527. "lastAssessment": lastAssessment,
  528. "prescribeOne": prescribeOne,
  529. "is_project_open_config": is_project_open_config,
  530. "project": projects,
  531. "team_projects": team_projects,
  532. "is_advice_open": is_advice_open,
  533. "prescription_open": prescriptionConfig.IsOpen,
  534. "lastOrder": lastOrder,
  535. "remind_lists": remind_lists,
  536. "lastDialysisPrescription": lastDialysisPrescription,
  537. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  538. "dryWeightList": dryWeightList,
  539. }
  540. this.ServeSuccessJSON(returnData)
  541. }
  542. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  543. adminInfo := c.GetMobileAdminUserInfo()
  544. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  545. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  546. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  547. returnData := map[string]interface{}{
  548. "admin_users": adminUsers,
  549. "devices": devices,
  550. "device_numbers": device_numbers,
  551. }
  552. c.ServeSuccessJSON(returnData)
  553. }
  554. func (c *DialysisAPIController) PostAtreatmentInfo() {
  555. id, _ := c.GetInt64("patient", 0)
  556. recordDateStr := c.GetString("record_date")
  557. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  558. summaryContent := c.GetString("summaryContent")
  559. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  560. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  561. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  562. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  563. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  564. nursingRecord := c.GetString("nursing_record")
  565. fmt.Println("护理记录", nursingRecord)
  566. specialRecord := c.GetString("special_record")
  567. fmt.Println("特殊记录", specialRecord)
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  570. checkStaffId = adminUserInfo.AdminUser.Id
  571. deboardNurseId = adminUserInfo.AdminUser.Id
  572. treatDoctor = adminUserInfo.AdminUser.Id
  573. if id <= 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  578. if patient.ID == 0 {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  580. return
  581. }
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. summary := models.TreatmentSummary{
  592. UserOrgId: adminUserInfo.Org.Id,
  593. PatientId: id,
  594. AssessmentDate: recordDate.Unix(),
  595. Mission: propagandaAndEducationContent,
  596. DialysisSummary: summaryContent,
  597. SjNurse: changeMedicalNurseId,
  598. ZlNurse: treatNurseId,
  599. HdNurse: checkStaffId,
  600. XjNurse: deboardNurseId,
  601. ZlDoctor: treatDoctor,
  602. CreatedTime: time.Now().Unix(),
  603. Status: 1,
  604. NursingRecord: nursingRecord,
  605. SpecialRecord: specialRecord,
  606. }
  607. // 查询信息规挡的设置天数
  608. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  609. if infor.ID > 0 && infor.WeekDay > 0 {
  610. var cha_time int64
  611. timeNowStr := time.Now().Format("2006-01-02")
  612. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  613. //今日的日期减去设置的日期
  614. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  615. if cha_time >= recordDate.Unix() {
  616. //查询审核是否允许
  617. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  618. //申请状态不允许的情况 拒绝修改
  619. if infor.ApplicationStatus != 1 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  621. return
  622. }
  623. }
  624. }
  625. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  626. if treatmentSummary.ID == 0 { //新增
  627. summary.Creater = adminUserInfo.AdminUser.Id
  628. service.AddSigleSummaryRecord(&summary)
  629. finish := models.XtDialysisFinish{
  630. IsFinish: 1,
  631. UserOrgId: adminUserInfo.Org.Id,
  632. Status: 1,
  633. Ctime: time.Now().Unix(),
  634. Mtime: 0,
  635. Module: 10,
  636. RecordDate: recordDate.Unix(),
  637. Sourse: 1,
  638. PatientId: id,
  639. }
  640. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  641. if dialysisFinish.ID == 0 {
  642. service.CreateDialysisFinish(finish)
  643. }
  644. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  645. redis := service.RedisClient()
  646. //清空key 值
  647. redis.Set(key, "", time.Second)
  648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  649. redis.Set(keyOne, "", time.Second)
  650. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  651. redis.Set(keyThree, "", time.Second)
  652. defer redis.Close()
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "summary": summary,
  655. })
  656. } else { //修改
  657. summary.Creater = treatmentSummary.Creater
  658. summary.CreatedTime = treatmentSummary.CreatedTime
  659. summary.Modifier = adminUserInfo.AdminUser.Id
  660. summary.ID = treatmentSummary.ID
  661. service.UpdateSummeRecord(&summary)
  662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  663. redis := service.RedisClient()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  667. redis.Set(keyOne, "", time.Second)
  668. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  669. redis.Set(keyThree, "", time.Second)
  670. defer redis.Close()
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "summary": summary,
  673. })
  674. }
  675. }
  676. func (c *DialysisAPIController) PostDoubleCheck() {
  677. id, _ := c.GetInt64("patient", 0)
  678. recordDateStr := c.GetString("record_date")
  679. checkTimeStr := c.GetString("check_time")
  680. firstCheckTimeStr := c.GetString("first_check_time")
  681. creater, _ := c.GetInt64("creater", 0)
  682. modifier, _ := c.GetInt64("modifier", 0)
  683. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  684. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  685. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  686. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  687. dialysis_item_desc := c.GetString("dialysis_item_desc")
  688. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  689. vascular_access_desc := c.GetString("vascular_access_desc")
  690. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  691. collator, _ := c.GetInt64("collator", 0)
  692. employee_number := c.GetString("employee_number")
  693. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  694. needle_batch_number := c.GetString("needle_batch_number")
  695. if id <= 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetMobileAdminUserInfo()
  700. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  701. if patient.ID == 0 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  703. return
  704. }
  705. if len(recordDateStr) == 0 {
  706. recordDateStr = time.Now().Format("2006-01-02")
  707. }
  708. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  709. if parseDateErr != nil {
  710. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. var checkDate int64
  715. if len(checkTimeStr) == 0 {
  716. checkDate = 0
  717. } else {
  718. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  719. checkDate = checkDateUnix.Unix()
  720. }
  721. var firstCheckDate int64
  722. if len(firstCheckTimeStr) == 0 {
  723. firstCheckDate = 0
  724. } else {
  725. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  726. firstCheckDate = firstCheckDateUnix.Unix()
  727. }
  728. //if adminUserInfo.Org.Id == 10340 {
  729. //
  730. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  731. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  732. // if check.ID == 0 {
  733. // if employee_number != list.JobNumber {
  734. // c.ServeSuccessJSON(map[string]interface{}{
  735. // "doubleCheck": check,
  736. // "msg": "2",
  737. // })
  738. // return
  739. // }
  740. // }
  741. // if check.ID > 0 {
  742. // if employee_number != list.JobNumber {
  743. // c.ServeSuccessJSON(map[string]interface{}{
  744. // "doubleCheck": check,
  745. // "msg": "2",
  746. // })
  747. // return
  748. // }
  749. // }
  750. //
  751. //}
  752. doubleCheck := models.DoubleCheck{
  753. UserOrgId: adminUserInfo.Org.Id,
  754. PatientId: id,
  755. DialysisItemCheck: dialysis_item_check,
  756. DialysisParameterCheck: dialysis_parameter_check,
  757. VascularAccessVerification: vascular_access_verification,
  758. PipelineConnectionCheck: pipeline_connection_check,
  759. DialysisItemDesc: dialysis_item_desc,
  760. DialysisParameterDesc: dialysis_parameter_desc,
  761. VascularAccessDesc: vascular_access_desc,
  762. PipelineConnectionDesc: pipeline_connection_desc,
  763. Collator: collator,
  764. Status: 1,
  765. CreatedTime: time.Now().Unix(),
  766. CheckDate: recordDate.Unix(),
  767. UpdatedTime: time.Now().Unix(),
  768. EmployeeNumber: employee_number,
  769. DialyzerBatchNumber: dialyzer_batch_number,
  770. NeedleBatchNumber: needle_batch_number,
  771. }
  772. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  773. if check.ID == 0 { //新增
  774. doubleCheck.FirstCheckTime = firstCheckDate
  775. doubleCheck.CheckTime = checkDate
  776. doubleCheck.Creater = creater
  777. doubleCheck.Modifier = modifier
  778. if adminUserInfo.Org.Id == 10340 {
  779. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  780. doubleCheck.Creater = order.StartNurse
  781. }
  782. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  783. //查询未核对的医嘱
  784. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  785. for _, advice := range doctorList {
  786. if advice.ExecutionStaff == modifier {
  787. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  789. return
  790. }
  791. }
  792. }
  793. // 查询信息规挡的设置天数
  794. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  795. if infor.ID > 0 && infor.WeekDay > 0 {
  796. var cha_time int64
  797. timeNowStr := time.Now().Format("2006-01-02")
  798. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  799. //今日的日期减去设置的日期
  800. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  801. if cha_time >= recordDate.Unix() {
  802. //查询审核是否允许
  803. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  804. //申请状态不允许的情况 拒绝修改
  805. if infor.ApplicationStatus != 1 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  807. return
  808. }
  809. }
  810. }
  811. err := service.AddSigleDoubleCheck(&doubleCheck)
  812. finish := models.XtDialysisFinish{
  813. IsFinish: 1,
  814. UserOrgId: adminUserInfo.Org.Id,
  815. Status: 1,
  816. Ctime: time.Now().Unix(),
  817. Mtime: 0,
  818. Module: 5,
  819. RecordDate: recordDate.Unix(),
  820. Sourse: 1,
  821. PatientId: id,
  822. }
  823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  824. if dialysisFinish.ID == 0 {
  825. service.CreateDialysisFinish(finish)
  826. }
  827. //针对长沙南雅
  828. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  829. //查询未核对的医嘱
  830. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  831. if len(doctorList) > 0 && modifier > 0 {
  832. for _, advice := range doctorList {
  833. service.UpdateDoctorAdviceList(advice.ID, modifier)
  834. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  835. redis := service.RedisClient()
  836. //清空key 值
  837. redis.Set(key, "", time.Second)
  838. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  839. redis.Set(keyTwo, "", time.Second)
  840. theTime := time.Now()
  841. recordDate := theTime.Format("2006-01-02")
  842. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  843. redis.Set(keyFour, "", time.Second)
  844. defer redis.Close()
  845. }
  846. }
  847. }
  848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  849. redis := service.RedisClient()
  850. //清空key 值
  851. redis.Set(key, "", time.Second)
  852. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  853. redis.Set(keyOne, "", time.Second)
  854. defer redis.Close()
  855. if err == nil {
  856. c.ServeSuccessJSON(map[string]interface{}{
  857. "doubleCheck": &doubleCheck,
  858. })
  859. }
  860. } else { //修改
  861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  862. if infor.ID > 0 {
  863. var cha_time int64
  864. timeNowStr := time.Now().Format("2006-01-02")
  865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  866. //今日的日期减去设置的日期
  867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  868. if cha_time >= recordDate.Unix() {
  869. //查询审核是否允许
  870. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  871. //申请状态不允许的情况 拒绝修改
  872. if infor.ApplicationStatus != 1 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  874. return
  875. }
  876. }
  877. }
  878. doubleCheck.FirstCheckTime = firstCheckDate
  879. doubleCheck.CheckTime = checkDate
  880. doubleCheck.Creater = creater
  881. doubleCheck.Modifier = modifier
  882. doubleCheck.CreatedTime = check.CreatedTime
  883. doubleCheck.ID = check.ID
  884. doubleCheck.EmployeeNumber = employee_number
  885. doubleCheck.NeedleBatchNumber = needle_batch_number
  886. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  887. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  888. //查询未核对的医嘱
  889. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  890. for _, advice := range doctorList {
  891. if advice.ExecutionStaff == modifier {
  892. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  893. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  894. return
  895. }
  896. }
  897. }
  898. err := service.UpdateDoubleCheck(&doubleCheck)
  899. //针对长沙南雅
  900. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  901. //查询未核对的医嘱
  902. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  903. if len(doctorList) > 0 && modifier > 0 {
  904. for _, advice := range doctorList {
  905. service.UpdateDoctorAdviceList(advice.ID, modifier)
  906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  907. redis := service.RedisClient()
  908. //清空key 值
  909. redis.Set(key, "", time.Second)
  910. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  911. redis.Set(keyTwo, "", time.Second)
  912. theTime := time.Now()
  913. recordDate := theTime.Format("2006-01-02")
  914. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  915. redis.Set(keyFour, "", time.Second)
  916. defer redis.Close()
  917. }
  918. }
  919. }
  920. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  925. redis.Set(keyOne, "", time.Second)
  926. defer redis.Close()
  927. if err == nil {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "doubleCheck": &doubleCheck,
  930. "msg": "1",
  931. })
  932. }
  933. }
  934. }
  935. func (c *DialysisAPIController) PostAcceptsAssessment() {
  936. id, _ := c.GetInt64("patient", 0)
  937. recordDateStr := c.GetString("record_date")
  938. way, _ := c.GetInt64("way", 0)
  939. consciousness, _ := c.GetInt64("consciousness", 0)
  940. appetite, _ := c.GetInt64("appetite", 0)
  941. condition, _ := c.GetInt64("condition", 0)
  942. posture, _ := c.GetInt64("posture")
  943. sick_condition, _ := c.GetInt64("sick_condition", 0)
  944. danger_level, _ := c.GetInt64("danger_level", 0)
  945. intake, _ := c.GetInt64("intake", 0)
  946. nutrition, _ := c.GetInt64("nutrition", 0)
  947. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  948. psychological_assessment_other := c.GetString("psychological_assessment_other")
  949. score := c.GetString("score")
  950. sick_condition_other := c.GetString("sick_condition_other")
  951. //precaution, _ := c.GetInt64("precaution", 0)
  952. precaution := c.GetString("precaution")
  953. precaution_other := c.GetString("precaution_other")
  954. psychological_other := c.GetString("psychological_other")
  955. admission_number := c.GetString("admission_number")
  956. tumble, _ := c.GetInt64("tumble")
  957. diacrisis := c.GetString("diacrisis")
  958. his_department := c.GetString("his_department")
  959. his_bed := c.GetString("his_bed")
  960. if id <= 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. adminUserInfo := c.GetMobileAdminUserInfo()
  965. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  966. if patient.ID == 0 {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  968. return
  969. }
  970. //now := time.Now()
  971. //year, month, day := now.Date()
  972. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  973. //todayTimeStamp := today_time.Unix()
  974. if len(recordDateStr) == 0 {
  975. recordDateStr = time.Now().Format("2006-01-02")
  976. }
  977. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  978. if parseDateErr != nil {
  979. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. // 查询信息规挡的设置天数
  984. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  985. if infor.ID > 0 && infor.WeekDay > 0 {
  986. var cha_time int64
  987. timeNowStr := time.Now().Format("2006-01-02")
  988. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  989. //今日的日期减去设置的日期
  990. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  991. if cha_time >= recordDate.Unix() {
  992. //查询审核是否允许
  993. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  994. //申请状态不允许的情况 拒绝修改
  995. if infor.ApplicationStatus != 1 {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  997. return
  998. }
  999. }
  1000. }
  1001. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1002. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1003. UserOrgId: adminUserInfo.Org.Id,
  1004. PatientId: id,
  1005. RecordDate: recordDate.Unix(),
  1006. Way: way,
  1007. Consciousness: consciousness,
  1008. Appetite: appetite,
  1009. Condition: condition,
  1010. SickCondition: sick_condition,
  1011. DangerLevel: danger_level,
  1012. Intake: intake,
  1013. Nutrition: nutrition,
  1014. PsychologicalAssessment: psychological_assessment,
  1015. PsychologicalAssessmentOther: psychological_assessment_other,
  1016. SickConditionOther: sick_condition_other,
  1017. Posture: posture,
  1018. CreatedTime: time.Now().Unix(),
  1019. UpdateTime: time.Now().Unix(),
  1020. Status: 1,
  1021. Score: score,
  1022. Precaution: precaution,
  1023. PrecautionOther: precaution_other,
  1024. PsychologicalOther: psychological_other,
  1025. AdmissionNumber: admission_number,
  1026. Tumble: tumble,
  1027. Diacrisis: diacrisis,
  1028. HisBed: his_bed,
  1029. HisDepartment: his_department,
  1030. }
  1031. if receiveTreatment.ID == 0 { //新增
  1032. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1033. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1034. finish := models.XtDialysisFinish{
  1035. IsFinish: 1,
  1036. UserOrgId: adminUserInfo.Org.Id,
  1037. Status: 1,
  1038. Ctime: time.Now().Unix(),
  1039. Mtime: 0,
  1040. Module: 2,
  1041. RecordDate: recordDate.Unix(),
  1042. Sourse: 1,
  1043. PatientId: id,
  1044. }
  1045. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1046. if dialysisFinish.ID == 0 {
  1047. service.CreateDialysisFinish(finish)
  1048. }
  1049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1050. redis := service.RedisClient()
  1051. defer redis.Close()
  1052. //清空key 值
  1053. redis.Set(key, "", time.Second)
  1054. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1055. redis.Set(keyOne, "", time.Second)
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "receiveTreatmentAsses": receiveTreatmentAsses,
  1059. })
  1060. }
  1061. } else { //修改
  1062. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1063. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1064. // if getPermissionErr != nil {
  1065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. // return
  1067. // } else if headNursePermission == nil {
  1068. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1069. // return
  1070. // }
  1071. //}
  1072. // 查询信息规挡的设置天数
  1073. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1074. if infor.ID > 0 && infor.WeekDay > 0 {
  1075. var cha_time int64
  1076. timeNowStr := time.Now().Format("2006-01-02")
  1077. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1078. //今日的日期减去设置的日期
  1079. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1080. if cha_time >= recordDate.Unix() {
  1081. //查询审核是否允许
  1082. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1083. //申请状态不允许的情况 拒绝修改
  1084. if infor.ApplicationStatus != 1 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1086. return
  1087. }
  1088. }
  1089. }
  1090. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1091. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1092. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1093. receiveTreatmentAsses.ID = receiveTreatment.ID
  1094. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1096. redis := service.RedisClient()
  1097. defer redis.Close()
  1098. //清空key 值
  1099. redis.Set(key, "", time.Second)
  1100. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1101. redis.Set(keyOne, "", time.Second)
  1102. if err == nil {
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "receiveTreatmentAsses": receiveTreatmentAsses,
  1105. })
  1106. }
  1107. }
  1108. }
  1109. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1110. id, _ := c.GetInt64("patient", 0)
  1111. recordDateStr := c.GetString("record_date")
  1112. weightAfter, _ := c.GetFloat("weight_after", 0)
  1113. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1114. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1115. fmt.Println("weight_loss", weightReduce)
  1116. temperature, _ := c.GetFloat("temperature", 0)
  1117. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1118. breathing_rate := c.GetString("breathing_rate")
  1119. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1120. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1121. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1122. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1123. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1124. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1125. cruor := c.GetString("cruor")
  1126. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1127. internalFistula := c.GetString("internal_fistula")
  1128. catheter := c.GetString("catheter")
  1129. complications := c.GetString("complication")
  1130. remark := c.GetString("remark")
  1131. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1132. dialysis_intakes := c.GetString("dialysis_intakes")
  1133. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1134. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1135. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1136. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1137. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1138. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1139. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1140. patientGose, _ := c.GetInt64("patient_gose", 0)
  1141. inpatientDepartment := c.GetString("inpatient_department")
  1142. observationContent := c.GetString("observation_content")
  1143. observationContentOther := c.GetString("observation_content_other")
  1144. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1145. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1146. in_advance_reason := c.GetString("in_advance_reason")
  1147. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1148. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1149. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1150. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1151. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1152. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1153. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1154. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1155. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1156. is_eat, _ := c.GetInt64("is_eat", 0)
  1157. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1158. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1159. channels, _ := c.GetInt64("channel", 0)
  1160. return_blood, _ := c.GetInt64("return_blood", 0)
  1161. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1162. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1163. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1164. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1165. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1166. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1167. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1168. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1169. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1170. setting_pressure := c.GetString("setting_pressure")
  1171. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1172. diastolic_pressure := c.GetString("diastolic_pressure")
  1173. other_complication := c.GetString("other_complication")
  1174. ktv := c.GetString("ktv")
  1175. urr := c.GetString("urr")
  1176. hypertenison, _ := c.GetInt64("hypertenison")
  1177. hypopiesia, _ := c.GetInt64("hypopiesia")
  1178. leave_office_method, _ := c.GetInt64("leave_office_method")
  1179. lapse, _ := c.GetInt64("lapse")
  1180. consciousness, _ := c.GetInt64("consciousness")
  1181. fallrisk, _ := c.GetInt64("fallrisk")
  1182. machine_run := c.GetString("machine_run")
  1183. after_urea := c.GetString("after_urea")
  1184. pip_coagulation := c.GetString("pip_coagulation")
  1185. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1186. transfusion_volume := c.GetString("transfusion_volume")
  1187. last_after_weight := c.GetString("last_after_weight")
  1188. if id <= 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1190. return
  1191. }
  1192. adminUserInfo := c.GetMobileAdminUserInfo()
  1193. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1194. if patient.ID == 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1196. return
  1197. }
  1198. if len(recordDateStr) == 0 {
  1199. recordDateStr = time.Now().Format("2006-01-02")
  1200. }
  1201. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1202. fmt.Println("parseDateErr", parseDateErr)
  1203. if parseDateErr != nil {
  1204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. //now := time.Now()
  1209. //year, month, day := now.Date()
  1210. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1211. //todayTimeStamp := today_time.Unix()
  1212. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1213. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1214. UserOrgId: adminUserInfo.Org.Id,
  1215. PatientId: id,
  1216. AssessmentDate: recordDate.Unix(),
  1217. Temperature: temperature,
  1218. PulseFrequency: pulse_frequency,
  1219. BreathingRate: breathing_rate,
  1220. SystolicBloodPressure: systolic_blood_pressure,
  1221. DiastolicBloodPressure: diastolic_blood_pressure,
  1222. ActualUltrafiltration: actual_ultrafiltration,
  1223. ActualDisplacement: actual_displacement,
  1224. ActualTreatmentHour: actualtreatHour,
  1225. ActualTreatmentMinute: actualtreatmin,
  1226. WeightAfter: weightAfter,
  1227. AdditionalWeight: additionalWeight,
  1228. WeightLoss: weightReduce,
  1229. Cruor: cruor,
  1230. SymptomAfterDialysis: symptomsAfterDialysi,
  1231. InternalFistula: internalFistula,
  1232. Catheter: catheter,
  1233. Complication: complications,
  1234. DialysisIntakes: dialysateVolume,
  1235. CreatedTime: time.Now().Unix(),
  1236. UpdatedTime: time.Now().Unix(),
  1237. Status: 1,
  1238. Remark: remark,
  1239. BloodAccessPartId: blood_access_part_id,
  1240. BloodAccessPartOperaId: blood_access_part_opera_id,
  1241. DialysisIntakesUnit: dialysis_intakes_unit,
  1242. PuncturePointOozingBlood: puncturePointOozingBlood,
  1243. PuncturePointHaematoma: puncturePointHaematoma,
  1244. InternalFistulaTremorAc: internalFistulaTremorAc,
  1245. PatientGose: patientGose,
  1246. InpatientDepartment: inpatientDepartment,
  1247. ObservationContent: observationContent,
  1248. ObservationContentOther: observationContentOther,
  1249. DialysisProcess: dialysis_process,
  1250. InAdvanceMinute: in_advance_minute,
  1251. InAdvanceReason: in_advance_reason,
  1252. HemostasisMinute: hemostasis_minute,
  1253. HemostasisOpera: hemostasis_opera,
  1254. TremorNoise: tremor_noise,
  1255. DisequilibriumSyndrome: disequilibrium_syndrome,
  1256. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1257. ArterialTube: arterial_tube,
  1258. IntravenousTube: intravenous_tube,
  1259. Dialyzer: dialyzer,
  1260. InAdvanceReasonOther: in_advance_reason_other,
  1261. IsEat: is_eat,
  1262. CvcA: cvc_a,
  1263. CvcV: cvc_v,
  1264. Channel: channels,
  1265. ReturnBlood: return_blood,
  1266. RehydrationVolume: rehydration_volume,
  1267. DialysisDuring: dialysis_during,
  1268. StrokeVolume: stroke_volume,
  1269. BloodFlow: blood_flow,
  1270. SealingFluidDispose: sealing_fluid_dispose,
  1271. SealingFluidSpecial: sealing_fluid_special,
  1272. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1273. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1274. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1275. SettingPressure: setting_pressure,
  1276. DiastolicPressure: diastolic_pressure,
  1277. OtherComplication: other_complication,
  1278. Ktv: ktv,
  1279. Urr: urr,
  1280. Hypopiesia: hypopiesia,
  1281. Hypertenison: hypertenison,
  1282. Lapse: lapse,
  1283. LeaveOfficeMethod: leave_office_method,
  1284. Consciousness: consciousness,
  1285. Fallrisk: fallrisk,
  1286. MachineRun: machine_run,
  1287. AfterUrea: after_urea,
  1288. PipCoagulation: pip_coagulation,
  1289. AccumulatedBloodVolume: accumulated_blood_volume,
  1290. TransfusionVolume: transfusion_volume,
  1291. LastAfterWeight: last_after_weight,
  1292. }
  1293. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1294. // 查询信息规挡的设置天数
  1295. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1296. if infor.ID > 0 && infor.WeekDay > 0 {
  1297. var cha_time int64
  1298. timeNowStr := time.Now().Format("2006-01-02")
  1299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1300. //今日的日期减去设置的日期
  1301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1302. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1303. if cha_time >= recordDate.Unix() {
  1304. //查询审核是否允许
  1305. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1306. //申请状态不允许的情况 拒绝修改
  1307. if infor.ApplicationStatus != 1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1309. return
  1310. }
  1311. }
  1312. }
  1313. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1314. if assessmentAfter.ID == 0 { //新增
  1315. if appRole.UserType == 2 || appRole.UserType == 1 {
  1316. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1317. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1318. } else {
  1319. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1320. }
  1321. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1322. //记录日志
  1323. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1324. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1325. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1326. PatientId: assessmentAfterDislysis.PatientId,
  1327. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1328. Status: 1,
  1329. ErrLog: string(byterequest),
  1330. AdminUserId: adminUserInfo.AdminUser.Id,
  1331. Ctime: 0,
  1332. Mtime: 0,
  1333. Source: "手机端保存透后评估",
  1334. }
  1335. service.CreateAfterDialysisLog(afterDialysisLog)
  1336. finish := models.XtDialysisFinish{
  1337. IsFinish: 1,
  1338. UserOrgId: adminUserInfo.Org.Id,
  1339. Status: 1,
  1340. Ctime: time.Now().Unix(),
  1341. Mtime: 0,
  1342. Module: 9,
  1343. RecordDate: recordDate.Unix(),
  1344. Sourse: 1,
  1345. PatientId: id,
  1346. }
  1347. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1348. if dialysisFinish.ID == 0 {
  1349. service.CreateDialysisFinish(finish)
  1350. }
  1351. redis := service.RedisClient()
  1352. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1353. redis.Set(keyTwo, "", time.Second)
  1354. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1355. //清空key 值
  1356. redis.Set(key, "", time.Second)
  1357. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1358. redis.Set(keyOne, "", time.Second)
  1359. defer redis.Close()
  1360. if err == nil {
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "assessmentAfterDislysis": assessmentAfterDislysis,
  1363. })
  1364. }
  1365. return
  1366. } else { //修改
  1367. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1368. if infor.ID > 0 && infor.WeekDay > 0 {
  1369. var cha_time int64
  1370. timeNowStr := time.Now().Format("2006-01-02")
  1371. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1372. //今日的日期减去设置的日期
  1373. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1374. if cha_time >= recordDate.Unix() {
  1375. //查询审核是否允许
  1376. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1377. //申请状态不允许的情况 拒绝修改
  1378. if infor.ApplicationStatus != 1 {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1380. return
  1381. }
  1382. }
  1383. }
  1384. if appRole.UserType == 2 || appRole.UserType == 1 {
  1385. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1386. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1387. } else {
  1388. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1389. if assessmentAfterDislysis.Creater == 0 {
  1390. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1391. }
  1392. }
  1393. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1394. assessmentAfterDislysis.ID = assessmentAfter.ID
  1395. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1396. //记录日志
  1397. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1398. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1399. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1400. PatientId: assessmentAfterDislysis.PatientId,
  1401. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1402. Status: 1,
  1403. ErrLog: string(byterequest),
  1404. AdminUserId: adminUserInfo.AdminUser.Id,
  1405. Ctime: time.Now().Unix(),
  1406. Mtime: 0,
  1407. Source: "手机端修改保存透后评估",
  1408. }
  1409. service.CreateAfterDialysisLog(afterDialysisLog)
  1410. redis := service.RedisClient()
  1411. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1412. redis.Set(keyTwo, "", time.Second)
  1413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1414. //清空key 值
  1415. redis.Set(key, "", time.Second)
  1416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1417. redis.Set(keyOne, "", time.Second)
  1418. if err == nil {
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "assessmentAfterDislysis": assessmentAfterDislysis,
  1421. })
  1422. return
  1423. }
  1424. }
  1425. return
  1426. }
  1427. func (c *DialysisAPIController) PostDialysisPrescription() {
  1428. id, _ := c.GetInt64("patient", 0)
  1429. recordDateStr := c.GetString("record_date")
  1430. if id <= 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adminUserInfo := c.GetMobileAdminUserInfo()
  1435. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1436. if patient.ID == 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1438. return
  1439. }
  1440. if len(recordDateStr) == 0 {
  1441. recordDateStr = time.Now().Format("2006-01-02")
  1442. }
  1443. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1444. if parseDateErr != nil {
  1445. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. mode_id, _ := c.GetInt64("mode_id", 0)
  1450. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1451. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1452. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1453. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1454. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1455. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1456. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1457. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1458. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1459. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1460. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1461. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1462. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1463. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1464. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1465. kalium, _ := c.GetFloat("kalium", 0)
  1466. sodium, _ := c.GetFloat("sodium", 0)
  1467. calcium, _ := c.GetFloat("calcium", 0)
  1468. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1469. glucose, _ := c.GetFloat("glucose", 0)
  1470. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1471. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1472. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1473. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1474. conductivity, _ := c.GetFloat("conductivity", 0)
  1475. remark := c.GetString("remark")
  1476. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1477. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1478. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1479. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1480. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1481. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1482. special_medicine_other := c.GetString("special_medicine_other")
  1483. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1484. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1485. blood_access, _ := c.GetInt64("blood_access", 0)
  1486. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1487. body_fluid_other := c.GetString("body_fluid_other")
  1488. niprocart, _ := c.GetInt64("niprocart", 0)
  1489. jms, _ := c.GetInt64("jms", 0)
  1490. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1491. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1492. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1493. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1494. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1495. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1496. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1497. injector, _ := c.GetInt64("injector", 0)
  1498. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1499. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1500. safe_package, _ := c.GetInt64("package", 0)
  1501. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1502. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1503. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1504. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1505. blood := c.GetString("blood")
  1506. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1507. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1508. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1509. displace_speed := c.GetString("displace_speed")
  1510. illness, _ := c.GetInt64("illness")
  1511. amylaceum := c.GetString("amylaceum")
  1512. single_time := c.GetString("single_time")
  1513. single_water := c.GetString("single_water")
  1514. replacement_flow := c.GetString("replacement_flow")
  1515. plasma_separator := c.GetString("plasma_separator")
  1516. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1517. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1518. oxygen_flow := c.GetString("oxygen_flow")
  1519. oxygen_time := c.GetString("oxygen_time")
  1520. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1521. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1522. puncture_needle := c.GetString("puncture_needle")
  1523. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1524. epo := c.GetString("epo")
  1525. epo_count, _ := c.GetFloat("epo_count", 0)
  1526. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1527. admin_user_id, _ := c.GetInt64("admin_user_id")
  1528. is_water := c.GetString("is_water")
  1529. var is_war int64
  1530. if is_water == "是" {
  1531. is_war = 1
  1532. }
  1533. if is_water == "否" {
  1534. is_war = 2
  1535. }
  1536. if is_water == "请选择" {
  1537. is_war = 0
  1538. }
  1539. drhy_water := c.GetString("drhy_water")
  1540. dry_water_hour := c.GetString("dry_water_hour")
  1541. water_machine := c.GetString("water_machine")
  1542. add_amount, _ := c.GetFloat("add_amount")
  1543. reduce_amount, _ := c.GetFloat("reduce_amount")
  1544. dialysis_remark := c.GetString("dialysis_remark")
  1545. prescribing_number, _ := c.GetFloat("prescribing_number")
  1546. prescription_sodium := c.GetString("prescription_sodium")
  1547. start_sodium := c.GetString("start_sodium")
  1548. sodium_curve := c.GetString("sodium_curve")
  1549. treatment_remark := c.GetString("treatment_remark")
  1550. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1551. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1552. prescription_water, _ := c.GetFloat("prescription_water")
  1553. dialysis_strainer := c.GetString("dialysis_strainer")
  1554. chaptalization := c.GetString("chaptalization")
  1555. washing_time := c.GetString("washing_time")
  1556. warsh_count := c.GetString("warsh_count")
  1557. blood_access_part_id := c.GetString("blood_access_part_id")
  1558. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1559. dialyzate := c.GetString("dialyzate")
  1560. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1561. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1562. //
  1563. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1564. // if appRole.UserType == 3 {
  1565. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1566. // if getPermissionErr != nil {
  1567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1568. // return
  1569. // } else if headNursePermission == nil {
  1570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1571. // return
  1572. // }
  1573. // }
  1574. //}
  1575. // 查询信息规挡的设置天数
  1576. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1577. if infor.ID > 0 && infor.WeekDay > 0 {
  1578. var cha_time int64
  1579. timeNowStr := time.Now().Format("2006-01-02")
  1580. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1581. //今日的日期减去设置的日期
  1582. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1583. if cha_time >= recordDate.Unix() {
  1584. //查询审核是否允许
  1585. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1586. //申请状态不允许的情况 拒绝修改
  1587. if infor.ApplicationStatus != 1 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1589. return
  1590. }
  1591. }
  1592. }
  1593. if mode_id > 0 {
  1594. var str string
  1595. //查找该机构用的是什么透析器
  1596. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1597. if filedConfig.ID > 0 {
  1598. str = dialyzerPerfusionApparatus
  1599. } else {
  1600. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1601. }
  1602. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1603. }
  1604. //TODO 需要根据角色去判断
  1605. prescription := models.DialysisPrescription{
  1606. UserOrgId: adminUserInfo.Org.Id,
  1607. PatientId: id,
  1608. RecordDate: recordDate.Unix(),
  1609. ModeId: mode_id,
  1610. DialysisDuration: dialysis_duration,
  1611. Dialyzer: dialyzer,
  1612. PerfusionApparatus: perfusion_apparatus,
  1613. BloodFlowVolume: blood_flow_volume,
  1614. DewaterAmount: dewater_amount,
  1615. DisplaceLiqui: displace_liqui,
  1616. ReplacementWay: replacement_way,
  1617. Anticoagulant: anticoagulant,
  1618. AnticoagulantShouji: anticoagulant_shouji,
  1619. AnticoagulantWeichi: anticoagulant_weichi,
  1620. AnticoagulantZongliang: anticoagulant_zongliang,
  1621. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1622. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1623. Kalium: kalium,
  1624. Sodium: sodium,
  1625. Calcium: calcium,
  1626. Bicarbonate: bicarbonate,
  1627. Glucose: glucose,
  1628. // DryWeight: dry_weight,
  1629. DialysateFlow: dialysate_flow,
  1630. DialysateTemperature: dialysate_temperature,
  1631. // PrescriptionDoctor: prescription_doctor,
  1632. ReplacementTotal: replacement_total,
  1633. Conductivity: conductivity,
  1634. Remark: remark,
  1635. Status: 1,
  1636. CreatedTime: time.Now().Unix(),
  1637. UpdatedTime: time.Now().Unix(),
  1638. DialysisDurationMinute: dialysisDurationMinute,
  1639. DialysisDurationHour: dialysisDurationHour,
  1640. TargetUltrafiltration: targetUltrafiltration,
  1641. DialysateFormulation: dialysateFormulation,
  1642. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1643. BodyFluid: body_fluid,
  1644. SpecialMedicine: special_medicine,
  1645. SpecialMedicineOther: special_medicine_other,
  1646. DisplaceLiquiPart: displace_liqui_part,
  1647. DisplaceLiquiValue: displace_liqui_value,
  1648. BloodAccess: blood_access,
  1649. Ultrafiltration: ultrafiltration,
  1650. BodyFluidOther: body_fluid_other,
  1651. Niprocart: niprocart,
  1652. Jms: jms,
  1653. FistulaNeedleSet: fistula_needle_set,
  1654. FistulaNeedleSet16: fistula_needle_set_16,
  1655. Hemoperfusion: hemoperfusion,
  1656. DialyserSterilised: dialyser_sterilised,
  1657. Filtryzer: filtryzer,
  1658. Dialyzers: dialyzers,
  1659. Injector: injector,
  1660. Bloodlines: bloodlines,
  1661. TubingHemodialysis: tubing_hemodialysis,
  1662. Package: safe_package,
  1663. ALiquid: a_liquid,
  1664. TargetKtv: target_ktv,
  1665. PreImpulse: pre_impulse,
  1666. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1667. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1668. Blood: blood,
  1669. DialysisDialyszers: dialysis_dialyszers,
  1670. DialysisIrrigation: dialysis_irrigation,
  1671. AntioxidantCommodityName: antioxidant_commodity_name,
  1672. DisplaceSpeed: displace_speed,
  1673. Illness: illness,
  1674. Amylaceum: amylaceum,
  1675. SingleTime: single_time,
  1676. SingleWater: single_water,
  1677. ReplacementFlow: replacement_flow,
  1678. PlasmaSeparator: plasma_separator,
  1679. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1680. OxygenUptake: oxygen_uptake,
  1681. OxygenFlow: oxygen_flow,
  1682. OxygenTime: oxygen_time,
  1683. HemodialysisPipelines: hemodialysis_pipelines,
  1684. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1685. PunctureNeedle: puncture_needle,
  1686. PunctureNeedleCount: puncture_needle_count,
  1687. Epo: epo,
  1688. EpoCount: epo_count,
  1689. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1690. AdminUserId: admin_user_id,
  1691. IsWater: is_war,
  1692. DrhyWater: drhy_water,
  1693. DryWaterHour: dry_water_hour,
  1694. WaterMachine: water_machine,
  1695. AddAmount: add_amount,
  1696. ReduceAmount: reduce_amount,
  1697. DialysisRemark: dialysis_remark,
  1698. PrescribingNumber: prescribing_number,
  1699. StartSodium: start_sodium,
  1700. SodiumCurve: sodium_curve,
  1701. TreatmentRemark: treatment_remark,
  1702. PrescriptionSodium: prescription_sodium,
  1703. DialysisFluidFlow: dialysis_fluid_flow,
  1704. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1705. PrescriptionWater: prescription_water,
  1706. DialysisStrainer: dialysis_strainer,
  1707. Chaptalization: chaptalization,
  1708. WashingTime: washing_time,
  1709. WarshCount: warsh_count,
  1710. BloodAccessPartId: blood_access_part_id,
  1711. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1712. Dialyzate: dialyzate,
  1713. }
  1714. //查询最近透析准备表里是否存在 透析器 灌流器
  1715. //
  1716. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1717. //
  1718. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1719. //
  1720. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1721. //if len(mation)>0{
  1722. // for _, item := range splitStr {
  1723. // for _,it := range mation{
  1724. // if(item == it.SpecificationName){
  1725. //
  1726. // //查询最近一次的透析器
  1727. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1728. //
  1729. // if errcode == gorm.ErrRecordNotFound{
  1730. // //插入数据
  1731. // prepare := models.DialysisBeforePrepare{
  1732. // UserOrgId: adminUserInfo.Org.Id,
  1733. // PatientId: id,
  1734. // RecordDate: recordDate.Unix(),
  1735. // GoodTypeId: it.GoodTypeId,
  1736. // GoodId: it.ID,
  1737. // Count: 1,
  1738. // Ctime: time.Now().Unix(),
  1739. // Creater: adminUserInfo.AdminUser.Id,
  1740. // Status:1,
  1741. //
  1742. // }
  1743. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1744. // fmt.Println("",errcode)
  1745. // }
  1746. // }
  1747. // }
  1748. //
  1749. // }
  1750. //
  1751. // for _, item := range splitIrrigation {
  1752. // for _,it := range mation{
  1753. // if(item == it.SpecificationName){
  1754. // //查询最近一次的透析器
  1755. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1756. // if errcode == gorm.ErrRecordNotFound{
  1757. // //插入数据
  1758. // prepare := models.DialysisBeforePrepare{
  1759. // UserOrgId: adminUserInfo.Org.Id,
  1760. // PatientId: id,
  1761. // RecordDate: recordDate.Unix(),
  1762. // GoodTypeId: it.GoodTypeId,
  1763. // GoodId: it.ID,
  1764. // Count: 1,
  1765. // Ctime: time.Now().Unix(),
  1766. // Creater: adminUserInfo.AdminUser.Id,
  1767. // Status:1,
  1768. //
  1769. // }
  1770. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1771. // fmt.Println(errcode)
  1772. // }
  1773. // }
  1774. // }
  1775. // }
  1776. //}
  1777. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1778. if dialysisPrescription.ID == 0 { //新增
  1779. if appRole.UserType == 2 || appRole.UserType == 1 {
  1780. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1781. }
  1782. prescription.Creater = adminUserInfo.AdminUser.Id
  1783. //针对河间咸得
  1784. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1785. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1786. prescription.DisplaceLiquiPart = 0
  1787. prescription.DisplaceLiquiValue = 0
  1788. }
  1789. }
  1790. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1791. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1792. }
  1793. err := service.AddSigleRecord(&prescription)
  1794. //记录日志
  1795. byterequest, _ := json.Marshal(prescription)
  1796. prescriptionLog := models.XtDialysisPrescriptionLog{
  1797. UserOrgId: prescription.UserOrgId,
  1798. Ctime: time.Now().Unix(),
  1799. Mtime: 0,
  1800. ErrLog: string(byterequest),
  1801. AdminUserId: adminUserInfo.AdminUser.Id,
  1802. RecordDate: prescription.RecordDate,
  1803. PatientId: prescription.PatientId,
  1804. Source: "手机端新增保存处方",
  1805. Status: 1,
  1806. }
  1807. service.CreatePrescriptionLog(prescriptionLog)
  1808. finish := models.XtDialysisFinish{
  1809. IsFinish: 1,
  1810. UserOrgId: adminUserInfo.Org.Id,
  1811. Status: 1,
  1812. Ctime: time.Now().Unix(),
  1813. Mtime: 0,
  1814. Module: 1,
  1815. RecordDate: recordDate.Unix(),
  1816. Sourse: 1,
  1817. PatientId: id,
  1818. }
  1819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1820. if dialysisFinish.ID == 0 {
  1821. service.CreateDialysisFinish(finish)
  1822. }
  1823. //长沙南雅医院,自动生成抗凝剂的临时处方
  1824. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1825. if prescribing_number == 0 {
  1826. prescribing_number = 1
  1827. }
  1828. if prescribing_number == 0 && id == 14682 {
  1829. prescribing_number = 2
  1830. }
  1831. if prescribing_number == 0 && id == 18560 {
  1832. prescribing_number = 2
  1833. }
  1834. advice := models.DoctorAdvice{
  1835. UserOrgId: adminUserInfo.Org.Id,
  1836. PatientId: id,
  1837. GroupNo: 0,
  1838. AdviceType: 2,
  1839. RecordDate: recordDate.Unix(),
  1840. AdviceDate: recordDate.Unix(),
  1841. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1842. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1843. AdviceDesc: "",
  1844. ReminderDate: 0,
  1845. SingleDose: anticoagulant_zongliang,
  1846. SingleDoseUnit: "iu",
  1847. DrugSpec: 0,
  1848. DrugSpecUnit: "",
  1849. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1850. PrescribingNumberUnit: "支",
  1851. DeliveryWay: "静脉注射",
  1852. ExecutionFrequency: "上机前",
  1853. AdviceDoctor: 0,
  1854. Status: 1,
  1855. CreatedTime: time.Now().Unix(),
  1856. UpdatedTime: time.Now().Unix(),
  1857. IsPrescription: 1,
  1858. ExecutionState: 2,
  1859. StopState: 2,
  1860. IsSettle: 2,
  1861. }
  1862. // 查询排班信息
  1863. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1864. if schedulePatient.ID > 0 {
  1865. if schedulePatient.ScheduleType == 1 {
  1866. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1867. }
  1868. if schedulePatient.ScheduleType == 2 {
  1869. advice.StartTime = recordDate.Unix() + 10*60*60
  1870. }
  1871. }
  1872. // 抗凝剂名称
  1873. switch anticoagulant {
  1874. case 1:
  1875. advice.AdviceName = "无肝素"
  1876. break
  1877. case 2:
  1878. advice.AdviceName = "普通肝素"
  1879. break
  1880. case 3:
  1881. advice.AdviceName = "低分子肝素"
  1882. break
  1883. case 4:
  1884. advice.AdviceName = "阿加曲班"
  1885. break
  1886. case 5:
  1887. advice.AdviceName = "枸橼酸钠"
  1888. break
  1889. case 6:
  1890. advice.AdviceName = "低分子肝素钙"
  1891. break
  1892. case 7:
  1893. advice.AdviceName = "低分子肝素钠"
  1894. break
  1895. case 8:
  1896. advice.AdviceName = "依诺肝素"
  1897. break
  1898. case 9:
  1899. advice.AdviceName = "达肝素"
  1900. break
  1901. case 10:
  1902. advice.AdviceName = "体外抗凝"
  1903. break
  1904. case 11:
  1905. advice.AdviceName = "那曲肝素"
  1906. break
  1907. case 12:
  1908. advice.AdviceName = "无抗凝剂"
  1909. break
  1910. }
  1911. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1912. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1913. advice.AdviceDoctor = appRole.AdminUserId
  1914. }
  1915. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1916. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1917. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1918. advice.AdviceName = "低分子肝素钠注射液"
  1919. // 修改患者临时医嘱里的抗凝剂医嘱
  1920. advice.ID = advicePrescription.ID
  1921. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1922. } else {
  1923. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1924. advice.AdviceName = "低分子肝素钠注射液"
  1925. // 新增患者临时医嘱里的抗凝剂医嘱
  1926. service.CreateDoctorAdvice(&advice)
  1927. }
  1928. }
  1929. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1930. redis := service.RedisClient()
  1931. defer redis.Close()
  1932. //清空key 值
  1933. redis.Set(key, "", time.Second)
  1934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1935. redis.Set(keyOne, "", time.Second)
  1936. }
  1937. //获取key,清空redis
  1938. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1939. redis := service.RedisClient()
  1940. //清空key 值
  1941. redis.Set(key, "", time.Second)
  1942. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1943. //清空key 值
  1944. redis.Set(keyOne, "", time.Second)
  1945. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1946. //清空key 值
  1947. redis.Set(keyTwo, "", time.Second)
  1948. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1949. redis.Set(keySix, "", time.Second)
  1950. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1951. redis.Set(keySeven, "", time.Second)
  1952. if err == nil {
  1953. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1954. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1955. //清空key 值
  1956. redis.Set(keyThree, "", time.Second)
  1957. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1958. //清空key 值
  1959. redis.Set(keyFour, "", time.Second)
  1960. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1961. redis.Set(keyFive, "", time.Second)
  1962. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1963. redis.Set(keySix, "", time.Second)
  1964. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1965. redis.Set(keySeven, "", time.Second)
  1966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1967. //清空key 值
  1968. redis.Set(keyOne, "", time.Second)
  1969. if updateErr != nil {
  1970. utils.ErrorLog("%v", updateErr)
  1971. }
  1972. defer redis.Close()
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "prescription": prescription,
  1975. })
  1976. }
  1977. } else { //修改
  1978. //if mode_id > 0 {
  1979. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1980. //}
  1981. //if template.TemplateId == 1 {
  1982. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1983. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1984. // if getPermissionErr != nil {
  1985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1986. // return
  1987. // } else if headNursePermission == nil {
  1988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1989. // return
  1990. // }
  1991. // }
  1992. //}
  1993. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1994. prescription.Modifier = adminUserInfo.AdminUser.Id
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. prescription_doctor := adminUserInfo.AdminUser.Id
  1997. prescription.PrescriptionDoctor = prescription_doctor
  1998. } else {
  1999. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2000. }
  2001. if dialysisPrescription.Creater == 0 { //体重称
  2002. prescription.Creater = adminUserInfo.AdminUser.Id
  2003. } else {
  2004. prescription.Creater = dialysisPrescription.Creater
  2005. if adminUserInfo.Org.Id == 9882 {
  2006. if appRole.UserType == 2 || appRole.UserType == 1 {
  2007. prescription_doctor := adminUserInfo.AdminUser.Id
  2008. prescription.PrescriptionDoctor = prescription_doctor
  2009. prescription.Creater = prescription_doctor
  2010. }
  2011. }
  2012. }
  2013. prescription.ID = dialysisPrescription.ID
  2014. service.UpDateDialysisPrescription(&prescription)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(prescription)
  2017. prescriptionLog := models.XtDialysisPrescriptionLog{
  2018. UserOrgId: prescription.UserOrgId,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. ErrLog: string(byterequest),
  2022. AdminUserId: adminUserInfo.AdminUser.Id,
  2023. RecordDate: prescription.RecordDate,
  2024. PatientId: prescription.PatientId,
  2025. Source: "手机端修改处方",
  2026. Status: 1,
  2027. }
  2028. service.CreatePrescriptionLog(prescriptionLog)
  2029. finish := models.XtDialysisFinish{
  2030. IsFinish: 1,
  2031. UserOrgId: adminUserInfo.Org.Id,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Module: 1,
  2036. RecordDate: recordDate.Unix(),
  2037. Sourse: 1,
  2038. PatientId: id,
  2039. }
  2040. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2041. if dialysisFinish.ID == 0 {
  2042. service.CreateDialysisFinish(finish)
  2043. }
  2044. //修改处方
  2045. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2046. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2047. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2048. if advicePrescription.ID > 0 {
  2049. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2051. redis := service.RedisClient()
  2052. defer redis.Close()
  2053. //清空key 值
  2054. redis.Set(key, "", time.Second)
  2055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2056. redis.Set(keyOne, "", time.Second)
  2057. }
  2058. }
  2059. //获取key,清空redis
  2060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2061. redis := service.RedisClient()
  2062. //清空key 值
  2063. redis.Set(key, "", time.Second)
  2064. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2065. //清空key 值
  2066. redis.Set(keyOne, "", time.Second)
  2067. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2068. redis.Set(keySix, "", time.Second)
  2069. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2070. redis.Set(keySeven, "", time.Second)
  2071. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2072. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2073. //清空key 值
  2074. redis.Set(keyTwoOne, "", time.Second)
  2075. defer redis.Close()
  2076. if updateErr != nil {
  2077. utils.ErrorLog("%v", updateErr)
  2078. }
  2079. c.ServeSuccessJSON(map[string]interface{}{
  2080. "prescription": prescription,
  2081. })
  2082. }
  2083. }
  2084. func (c *DialysisAPIController) Finish() {
  2085. id, _ := c.GetInt64("patient", 0)
  2086. recordDateStr := c.GetString("record_date")
  2087. nurseID, _ := c.GetInt64("nurse")
  2088. end_time := c.GetString("end_time")
  2089. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2090. internal_fistula := c.GetString("blood_access_internal_fistula")
  2091. catheter := c.GetString("catheter")
  2092. cruor := c.GetString("cruor")
  2093. mission := c.GetString("mission")
  2094. condenser := c.GetString("condenser")
  2095. if id <= 0 || nurseID <= 0 {
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2097. return
  2098. }
  2099. adminUserInfo := c.GetMobileAdminUserInfo()
  2100. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2101. if patient.ID == 0 {
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2103. return
  2104. }
  2105. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2106. if getNurseErr != nil {
  2107. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2109. return
  2110. } else if nurse == nil {
  2111. c.ErrorLog("护士不存在")
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. if len(recordDateStr) == 0 {
  2116. recordDateStr = time.Now().Format("2006-01-02")
  2117. }
  2118. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2119. if parseDateErr != nil {
  2120. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2122. return
  2123. }
  2124. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2125. if parseEndDateErr != nil {
  2126. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. // 查询信息规挡的设置天数
  2131. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2132. if infor.ID > 0 && infor.WeekDay > 0 {
  2133. var cha_time int64
  2134. timeNowStr := time.Now().Format("2006-01-02")
  2135. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2136. //今日的日期减去设置的日期
  2137. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2138. if cha_time >= recordDate.Unix() {
  2139. //查询审核是否允许
  2140. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2141. //申请状态不允许的情况 拒绝修改
  2142. if infor.ApplicationStatus != 1 {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2144. return
  2145. }
  2146. }
  2147. }
  2148. //now := time.Now()
  2149. //year, month, day := now.Date()
  2150. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2151. //todayTimeStamp := today_time.Unix()
  2152. // 获取当天的第一条透析纪录
  2153. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2154. if getMonitorRecordsErr != nil {
  2155. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. return
  2158. }
  2159. // 获取当前的最后一条透析纪录
  2160. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2161. if getMonitorRecordsErr != nil {
  2162. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2164. return
  2165. }
  2166. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2167. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2168. if getAADErr != nil {
  2169. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2174. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2175. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2176. if assessmentAfterDislysis != nil {
  2177. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2178. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2179. } else {
  2180. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2181. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2182. tempassessmentAfterDislysis.Status = 1
  2183. tempassessmentAfterDislysis.PatientId = id
  2184. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2185. }
  2186. //长沙南雅
  2187. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2188. //获取最后一条透析处方数据
  2189. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2190. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2191. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2192. }
  2193. if dialysisOrder.Stage == 1 {
  2194. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2195. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2196. fmt.Println(value)
  2197. a, b := math.Modf(value)
  2198. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2199. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2200. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2201. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2202. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2203. }
  2204. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2205. //var num1 int64
  2206. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2207. //fmt.Println(num1)
  2208. //sub := float64(num1 / 3600)
  2209. //fmt.Println(sub)
  2210. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2211. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2212. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2213. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2214. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2215. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2216. if adminUserInfo.Org.Id != 10375 {
  2217. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2218. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2219. }
  2220. if adminUserInfo.Org.Id != 10445 {
  2221. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2222. }
  2223. //北方营口医院
  2224. if adminUserInfo.Org.Id == 10445 {
  2225. //获取最后一条透析处方数据
  2226. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2227. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2228. } else {
  2229. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2230. }
  2231. //新化博翔
  2232. if adminUserInfo.Org.Id == 10447 {
  2233. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2234. }
  2235. //阳春
  2236. if adminUserInfo.Org.Id == 10485 {
  2237. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2238. }
  2239. if adminUserInfo.Org.Id == 10551 {
  2240. //获取最后一条透析处方数据
  2241. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2242. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2243. }
  2244. if adminUserInfo.Org.Id == 10580 {
  2245. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2246. }
  2247. }
  2248. 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 {
  2249. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2250. if evaluation.SystolicBloodPressure == 0 {
  2251. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2252. pre := models.PredialysisEvaluation{
  2253. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2254. }
  2255. fmt.Println("prew", pre)
  2256. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2257. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2258. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2259. redis := service.RedisClient()
  2260. redis.Set(key, "", time.Second)
  2261. redis.Set(keyOne, "", time.Second)
  2262. defer redis.Close()
  2263. fmt.Println(getNurseErr)
  2264. }
  2265. if evaluation.DiastolicBloodPressure == 0 {
  2266. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2267. pres := models.PredialysisEvaluation{
  2268. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2269. }
  2270. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2271. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2272. redis := service.RedisClient()
  2273. redis.Set(key, "", time.Second)
  2274. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2275. redis.Set(keyOne, "", time.Second)
  2276. defer redis.Close()
  2277. fmt.Println(getNurseErr)
  2278. }
  2279. if evaluation.PulseFrequency == 0 {
  2280. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2281. press := models.PredialysisEvaluation{
  2282. PulseFrequency: evaluation.PulseFrequency,
  2283. }
  2284. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2285. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2286. redis := service.RedisClient()
  2287. redis.Set(key, "", time.Second)
  2288. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2289. redis.Set(keyOne, "", time.Second)
  2290. defer redis.Close()
  2291. fmt.Println(getNurseErr)
  2292. }
  2293. if evaluation.Temperature == 0 {
  2294. evaluation.Temperature = fmonitorRecords.Temperature
  2295. press := models.PredialysisEvaluation{
  2296. Temperature: evaluation.Temperature,
  2297. }
  2298. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2299. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2300. redis := service.RedisClient()
  2301. redis.Set(key, "", time.Second)
  2302. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2303. redis.Set(keyOne, "", time.Second)
  2304. defer redis.Close()
  2305. fmt.Println(getNurseErr)
  2306. }
  2307. }
  2308. if adminUserInfo.Org.Id == 9583 {
  2309. //获取透析处方的最后一条数据
  2310. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2311. if diaerr != nil {
  2312. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2314. return
  2315. }
  2316. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2317. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2318. }
  2319. }
  2320. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2321. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2322. }
  2323. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2324. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2325. }
  2326. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2327. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2328. }
  2329. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2330. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2331. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2332. }
  2333. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2334. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2335. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2336. }
  2337. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2338. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2339. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2340. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2341. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2342. }
  2343. if lastAssessmentAfterDislysis != nil {
  2344. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2345. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2346. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2347. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2348. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2349. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2350. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2351. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2352. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2353. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2354. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2355. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2356. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2357. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2358. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2359. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2360. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2361. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2362. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2363. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2364. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2365. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2366. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2367. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2368. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2369. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2370. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2371. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2372. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2373. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2374. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2375. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2376. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2377. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2378. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2379. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2380. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2381. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2382. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2383. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2384. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2385. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2386. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2387. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2388. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2389. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2390. if tempassessmentAfterDislysis.PatientId == 18695 {
  2391. tempassessmentAfterDislysis.ActualDisplacement = 0
  2392. }
  2393. if adminUserInfo.Org.Id != 10375 {
  2394. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2395. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2396. }
  2397. }
  2398. finish := models.XtDialysisFinish{
  2399. IsFinish: 1,
  2400. UserOrgId: adminUserInfo.Org.Id,
  2401. Status: 1,
  2402. Ctime: time.Now().Unix(),
  2403. Mtime: 0,
  2404. Module: 9,
  2405. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2406. Sourse: 1,
  2407. PatientId: tempassessmentAfterDislysis.PatientId,
  2408. }
  2409. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2410. if dialysisFinish.ID == 0 {
  2411. service.CreateDialysisFinish(finish)
  2412. }
  2413. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2415. redis := service.RedisClient()
  2416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2417. redis.Set(keyOne, "", time.Second)
  2418. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2419. redis.Set(keyTwo, "", time.Second)
  2420. defer redis.Close()
  2421. //清空key 值
  2422. redis.Set(key, "", time.Second)
  2423. if err != nil {
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. }
  2427. if dialysisOrder == nil {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2429. return
  2430. }
  2431. if dialysisOrder.Stage == 2 {
  2432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2433. return
  2434. }
  2435. if dialysisOrder.Stage == 1 {
  2436. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2437. finish := models.XtDialysisFinish{
  2438. IsFinish: 1,
  2439. UserOrgId: adminUserInfo.Org.Id,
  2440. Status: 1,
  2441. Ctime: time.Now().Unix(),
  2442. Mtime: 0,
  2443. Module: 8,
  2444. RecordDate: recordDate.Unix(),
  2445. Sourse: 1,
  2446. PatientId: id,
  2447. }
  2448. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2449. if dialysisFinish.ID == 0 {
  2450. service.CreateDialysisFinish(finish)
  2451. }
  2452. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2453. redis := service.RedisClient()
  2454. defer redis.Close()
  2455. //清空key 值
  2456. redis.Set(key, "", time.Second)
  2457. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2458. redis.Set(keyOne, "", time.Second)
  2459. //结束时候透析次数加1
  2460. service.UpdateSolutionByPatientId(id)
  2461. //下机完自动消毒,针对长沙南雅
  2462. if dialysisOrder.Stage == 1 {
  2463. 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 {
  2464. //根据床位号获取设备型号
  2465. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2466. //查询使用消毒最后一条消毒记录
  2467. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2468. fmt.Println("err", err)
  2469. if err == gorm.ErrRecordNotFound {
  2470. //查找排班
  2471. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2472. //查询改设备是否有消毒计划
  2473. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2474. //根据床位号获取设备id
  2475. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2476. //查询病人信息
  2477. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2478. var con = ""
  2479. if patients.IsInfectious == 0 {
  2480. con = ""
  2481. }
  2482. if patients.IsInfectious == 1 {
  2483. con = "无"
  2484. }
  2485. if patients.IsInfectious == 2 {
  2486. con = "有"
  2487. }
  2488. if errcode == nil {
  2489. var end_time int64
  2490. end_time = endDate.Unix() + plan.DisinfecTime*60
  2491. //新增消毒
  2492. information := models.DeviceInformation{
  2493. Date: dialysisOrder.DialysisDate,
  2494. Zone: dialysisOrder.ZoneId,
  2495. Class: dialysisOrder.SchedualType,
  2496. BedNumber: dialysisOrder.BedID,
  2497. PatientId: dialysisOrder.PatientId,
  2498. DialysisMode: scheduleByPatient.ModeId,
  2499. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2500. Disinfection: 1,
  2501. DialysisConcentration: 1,
  2502. DisinfectionStatus: 1,
  2503. Move: 1,
  2504. UserOrgId: dialysisOrder.UserOrgId,
  2505. DisinfectType: plan.Way,
  2506. DisinfectantType: plan.MachineDisinfectant,
  2507. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2508. Disinfectant: plan.Disinfectant,
  2509. Ctime: time.Now().Unix(),
  2510. Status: 1,
  2511. SignName: nurseID,
  2512. EquimentId: addmacher.ID,
  2513. DisinfectionResidue: 2,
  2514. Bed: addmacher.BedNumber,
  2515. StartTime: dialysisOrder.StartTime,
  2516. EndTime: dialysisOrder.EndTime,
  2517. Contagion: con,
  2518. WeightLoss: 0,
  2519. Hyperfiltratio: 0,
  2520. DialysisHour: "",
  2521. MachineRun: 1,
  2522. DisinfecStartime: endDate.Unix(),
  2523. DisinfecEndtime: end_time,
  2524. }
  2525. err := service.CreateInformationTwo(&information)
  2526. fmt.Println("报错", err)
  2527. }
  2528. }
  2529. }
  2530. }
  2531. dialysisOrder.Stage = 2
  2532. dialysisOrder.FinishNurse = nurseID
  2533. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2534. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2535. dialysisOrder.EndTime = endDate.Unix()
  2536. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2537. // 长沙南雅需求
  2538. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2539. //获取最后1条监测的数据
  2540. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2541. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2542. var accumulatedBloodVolume float64
  2543. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2544. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2545. fmt.Println(err)
  2546. // 查询未执行的医嘱
  2547. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2548. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2549. for _, item := range doctorAdvice {
  2550. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2551. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2552. redis := service.RedisClient()
  2553. //清空key 值
  2554. redis.Set(key, "", time.Second)
  2555. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2556. redis.Set(keyTwo, "", time.Second)
  2557. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2558. redis.Set(keyThree, "", time.Second)
  2559. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2560. theTime := toTime.Format("2006-01-02")
  2561. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2562. redis.Set(keyFour, "", time.Second)
  2563. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2564. redis.Set(keyFive, "", time.Second)
  2565. defer redis.Close()
  2566. }
  2567. }
  2568. go func() {
  2569. ssoDomain := beego.AppConfig.String("call_domain")
  2570. api := ssoDomain + "/index/downpatient"
  2571. values := make(url.Values)
  2572. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2573. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2574. values.Set("patient_id", strconv.FormatInt(id, 10))
  2575. http.PostForm(api, values)
  2576. }()
  2577. if err == nil {
  2578. c.ServeSuccessJSON(map[string]interface{}{
  2579. "dialysisOrder": dialysisOrder,
  2580. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2581. })
  2582. } else {
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2584. }
  2585. }
  2586. }
  2587. func (c *DialysisAPIController) GetAllZone() {
  2588. adminUserInfo := c.GetMobileAdminUserInfo()
  2589. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2590. if err == nil {
  2591. c.ServeSuccessJSON(map[string]interface{}{
  2592. "zone": zone,
  2593. })
  2594. }
  2595. }
  2596. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2597. adminUserInfo := c.GetMobileAdminUserInfo()
  2598. page, _ := c.GetInt64("page", 1)
  2599. limit, _ := c.GetInt64("limit", 10)
  2600. schedulType, _ := c.GetInt64("schedul_type", 0)
  2601. startTime, _ := c.GetInt64("schedul_time", 0)
  2602. partitionType, _ := c.GetInt64("partition_type", 0)
  2603. keywords := c.GetString("keywords")
  2604. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2605. if err == nil {
  2606. c.ServeSuccessJSON(map[string]interface{}{
  2607. "schedule": dialysisSchedule,
  2608. })
  2609. }
  2610. return
  2611. }
  2612. // /m/api/dialysis/start [post]
  2613. // @param patient_id:int
  2614. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2615. // @param nurse:int 上机护士
  2616. // @param bed:int 床位号
  2617. func (this *DialysisAPIController) StartDialysis() {
  2618. patientID, _ := this.GetInt64("patient_id")
  2619. recordDateStr := this.GetString("record_date")
  2620. nurseID, _ := this.GetInt64("start_nurse")
  2621. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2622. blood_drawing, _ := this.GetInt64("blood_drawing")
  2623. schedual_type, _ := this.GetInt64("schedual_type")
  2624. bedID, _ := this.GetInt64("bed")
  2625. start_time := this.GetString("start_time")
  2626. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2627. change_nurse, _ := this.GetInt64("change_nurse")
  2628. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2629. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2630. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2631. puncture_needle := this.GetString("puncture_needle")
  2632. puncture_way := this.GetString("puncture_way")
  2633. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2634. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2635. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2636. zone_id, _ := this.GetInt64("zone_id")
  2637. elecsign := this.GetString("url")
  2638. nuclein_date_str := this.GetString("nuclein_date_str")
  2639. schedule_remark := this.GetString("schedule_remark")
  2640. order_remark := this.GetString("order_remark")
  2641. catheter_operation := this.GetString("catheter_operation")
  2642. blood_flow_volume := this.GetString("blood_flow_volume")
  2643. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2644. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2645. return
  2646. }
  2647. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2648. if parseStartDateErr != nil {
  2649. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2651. return
  2652. }
  2653. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2654. if parseErr != nil {
  2655. this.ErrorLog("时间解析失败:%v", parseErr)
  2656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2657. return
  2658. }
  2659. adminUserInfo := this.GetMobileAdminUserInfo()
  2660. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2661. if getPatientErr != nil {
  2662. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2664. return
  2665. } else if patient == nil {
  2666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2667. return
  2668. }
  2669. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2670. if getNurseErr != nil {
  2671. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2673. return
  2674. } else if nurse == nil {
  2675. this.ErrorLog("护士不存在")
  2676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2677. return
  2678. }
  2679. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2680. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2681. if getDeviceNumberErr != nil {
  2682. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2684. return
  2685. } else if deviceNumber == nil {
  2686. this.ErrorLog("床位号不存在")
  2687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2688. return
  2689. }
  2690. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2691. if getRecordErr != nil {
  2692. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2693. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2694. return
  2695. } else if dialysisRecord != nil {
  2696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2697. return
  2698. }
  2699. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2700. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2701. timeLayout := "2006-01-02 15:04:05"
  2702. loc, _ := time.LoadLocation("Local")
  2703. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2704. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2705. schedulestartTime := theStartTime.Unix()
  2706. scheduleendTime := theEndTime.Unix()
  2707. var theNucleinDate int64
  2708. timeLayoutOne := "2006-01-02"
  2709. if len(nuclein_date_str) > 0 {
  2710. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2711. if err != nil {
  2712. utils.ErrorLog(err.Error())
  2713. }
  2714. theNucleinDate = theTime.Unix()
  2715. }
  2716. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2717. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2718. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2719. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2720. //查询该床位是否有人用了
  2721. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2722. if err == gorm.ErrRecordNotFound { //空床位
  2723. // 修改了床位逻辑
  2724. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2725. if daySchedule.ID > 0 {
  2726. daySchedule.PartitionId = deviceNumber.ZoneID
  2727. daySchedule.BedId = bedID
  2728. daySchedule.ScheduleType = schedual_type
  2729. daySchedule.UpdatedTime = time.Now().Unix()
  2730. xtSchedule := models.Schedule{
  2731. PartitionId: deviceNumber.ZoneID,
  2732. BedId: bedID,
  2733. ScheduleType: schedual_type,
  2734. UpdatedTime: time.Now().Unix(),
  2735. }
  2736. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2737. if err != nil {
  2738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2739. return
  2740. }
  2741. }
  2742. } else if err == nil {
  2743. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2744. if order.ID > 0 { //该机位被其他人占用了
  2745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2746. return
  2747. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2748. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2749. if daySchedule.ID > 0 {
  2750. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2751. if err != nil {
  2752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2753. return
  2754. }
  2755. }
  2756. }
  2757. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2759. return
  2760. }
  2761. //else if order.ID == 0 { //该床位没被占用
  2762. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2763. // if daySchedule.ID > 0 {
  2764. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2765. // //daySchedule.BedId = bedID
  2766. // //daySchedule.ScheduleType = schedual_type
  2767. // //daySchedule.UpdatedTime = time.Now().Unix()
  2768. // //err := service.UpdateSchedule(&daySchedule)
  2769. // xtSchedule := models.Schedule{
  2770. // PartitionId: deviceNumber.ZoneID,
  2771. // BedId: bedID,
  2772. // ScheduleType: schedual_type,
  2773. // UpdatedTime: time.Now().Unix(),
  2774. // }
  2775. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2776. // if err != nil {
  2777. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2778. // return
  2779. // }
  2780. // }
  2781. //}
  2782. //}
  2783. } else if err != nil {
  2784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2785. return
  2786. }
  2787. // 查询信息规挡的设置天数
  2788. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2789. if infor.ID > 0 && infor.WeekDay > 0 {
  2790. var cha_time int64
  2791. timeNowStr := time.Now().Format("2006-01-02")
  2792. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2793. //今日的日期减去设置的日期
  2794. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2795. if cha_time >= recordDate.Unix() {
  2796. //查询审核是否允许
  2797. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2798. //申请状态不允许的情况 拒绝修改
  2799. if infor.ApplicationStatus != 1 {
  2800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2801. return
  2802. }
  2803. }
  2804. }
  2805. dialysisRecord = &models.DialysisOrder{
  2806. DialysisDate: recordDate.Unix(),
  2807. UserOrgId: adminUserInfo.Org.Id,
  2808. PatientId: patientID,
  2809. Stage: 1,
  2810. BedID: bedID,
  2811. StartNurse: nurseID,
  2812. Status: 1,
  2813. StartTime: startDate.Unix(),
  2814. CreatedTime: time.Now().Unix(),
  2815. UpdatedTime: time.Now().Unix(),
  2816. PunctureNurse: puncture_nurse,
  2817. Creator: adminUserInfo.AdminUser.Id,
  2818. Modifier: adminUserInfo.AdminUser.Id,
  2819. SchedualType: schedual_type,
  2820. WashpipeNurse: washpipe_nurse,
  2821. ChangeNurse: change_nurse,
  2822. DifficultPunctureNurse: difficult_puncture_nurse,
  2823. NewFistulaNurse: new_fistula_nurse,
  2824. ZoneId: zone_id,
  2825. QualityNurseId: quality_nurse_id,
  2826. PunctureNeedle: puncture_needle,
  2827. PunctureWay: puncture_way,
  2828. DialysisIrrigation: dialysis_irrigation,
  2829. DialysisDialyszers: dialysis_dialyszers,
  2830. BloodAccessId: blood_access_id,
  2831. Url: elecsign,
  2832. NucleinDate: theNucleinDate,
  2833. ScheduleRemark: schedule_remark,
  2834. OrderRemark: order_remark,
  2835. CatheterOperation: catheter_operation,
  2836. BloodFlowVolume: blood_flow_volume,
  2837. }
  2838. //查询该床位是否有人用了
  2839. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2840. if errorscode == gorm.ErrRecordNotFound {
  2841. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2842. finish := models.XtDialysisFinish{
  2843. IsFinish: 1,
  2844. UserOrgId: adminUserInfo.Org.Id,
  2845. Status: 1,
  2846. Ctime: time.Now().Unix(),
  2847. Mtime: 0,
  2848. Module: 6,
  2849. RecordDate: schedulestartTime,
  2850. Sourse: 1,
  2851. PatientId: patientID,
  2852. }
  2853. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2854. if dialysisFinish.ID == 0 {
  2855. service.CreateDialysisFinish(finish)
  2856. }
  2857. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2858. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2859. //统计该患者总次数
  2860. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2861. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2862. }
  2863. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2864. //统计该患者总次数
  2865. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2866. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2867. }
  2868. redis := service.RedisClient()
  2869. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2872. //清空key 值
  2873. redis.Set(keyOne, "", time.Second)
  2874. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2875. //清空key 值
  2876. redis.Set(keyTwo, "", time.Second)
  2877. if createErr != nil {
  2878. this.ErrorLog("上机失败:%v", createErr)
  2879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2880. return
  2881. }
  2882. }
  2883. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2884. var tempdispose string
  2885. // 只针对中能建
  2886. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2887. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2888. }
  2889. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2890. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2891. }
  2892. var ultrafiltration_rate float64
  2893. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2894. //后期预增脱水量
  2895. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2896. if prescription.ID > 0 {
  2897. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2898. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2899. 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
  2900. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2901. }
  2902. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2903. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2904. }
  2905. //针对医师汇
  2906. if adminUserInfo.Org.Id == 10121 {
  2907. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2908. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2909. }
  2910. //针对通道
  2911. if adminUserInfo.Org.Id == 10234 {
  2912. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2913. }
  2914. //针对监利大垸医院
  2915. if template.TemplateId == 41 {
  2916. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2917. }
  2918. //针对肇庆三鹤血液透析中心
  2919. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2920. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2921. }
  2922. if adminUserInfo.Org.Id == 10469 {
  2923. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2924. }
  2925. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2926. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2927. }
  2928. // 只针对方济医院
  2929. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2930. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2931. ultrafiltration_rate = value
  2932. }
  2933. //针对
  2934. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2935. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2936. ultrafiltration_rate = ultrafiltration_rate / 1000
  2937. }
  2938. if adminUserInfo.Org.Id == 10551 {
  2939. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2940. ultrafiltration_rate = ultrafiltration_rate / 1000
  2941. }
  2942. if adminUserInfo.Org.Id == 10612 {
  2943. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2944. ultrafiltration_rate = ultrafiltration_rate / 1000
  2945. }
  2946. }
  2947. }
  2948. record := models.MonitoringRecord{
  2949. UserOrgId: adminUserInfo.Org.Id,
  2950. PatientId: patientID,
  2951. DialysisOrderId: dialysisRecord.ID,
  2952. MonitoringDate: schedulestartTime,
  2953. OperateTime: startDate.Unix(),
  2954. // MonitoringTime: recordTime,
  2955. MonitoringNurse: nurseID,
  2956. Dispose: tempdispose,
  2957. UltrafiltrationRate: ultrafiltration_rate,
  2958. UltrafiltrationVolume: 0,
  2959. Status: 1,
  2960. CreatedTime: time.Now().Unix(),
  2961. UpdatedTime: time.Now().Unix(),
  2962. }
  2963. //只针对广慈医院
  2964. 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 {
  2965. // 查询病人是否有透前评估数据
  2966. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2967. //如果有数据就插入
  2968. if errcode == nil {
  2969. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2970. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2971. record.BreathingRate = befor.BreathingRate
  2972. record.PulseFrequency = befor.PulseFrequency
  2973. record.Temperature = befor.Temperature
  2974. }
  2975. }
  2976. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2977. if newdialysisRecord.ID > 0 {
  2978. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2979. record.Temperature = 36.5
  2980. record.ArterialPressure = -100
  2981. record.DialysateTemperature = 36.5
  2982. record.Conductivity = 14
  2983. record.BreathingRate = "20"
  2984. record.VenousPressure = 80
  2985. record.TransmembranePressure = 60
  2986. record.Dispose = catheter_operation
  2987. }
  2988. //针对新化博翔
  2989. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2990. record.BloodOxygenSaturation = "99"
  2991. record.Conductivity = 14
  2992. record.DialysateTemperature = 36.5
  2993. record.BreathingRate = "20"
  2994. }
  2995. //针对兰溪人民医院的需求
  2996. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2997. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2998. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2999. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3000. record.Temperature = befor.Temperature
  3001. record.PulseFrequency = befor.PulseFrequency
  3002. record.BreathingRate = befor.BreathingRate
  3003. }
  3004. //新化博翔
  3005. if adminUserInfo.Org.Id == 10447 {
  3006. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3007. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3008. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3009. record.BreathingRate = befor.BreathingRate
  3010. }
  3011. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3012. record.PulseFrequency = 80
  3013. record.Temperature = 36.5
  3014. }
  3015. //诊断灵山圣康
  3016. if adminUserInfo.Org.Id == 10375 {
  3017. record.Conductivity = 13.8
  3018. record.DialysateTemperature = 37
  3019. record.DialysateFlow = 500
  3020. record.BloodFlowVolume = 200
  3021. record.BreathingRate = "18"
  3022. record.SodiumConcentration = 140
  3023. }
  3024. //江成肾病医院
  3025. if adminUserInfo.Org.Id == 10517 {
  3026. record.SodiumConcentration = 138
  3027. record.DialysateTemperature = 36.5
  3028. }
  3029. err := service.CreateMonitor(&record)
  3030. //记录日志
  3031. byterequest, _ := json.Marshal(record)
  3032. monitorRecordLog := models.XtMonitorRecordLog{
  3033. RecordDate: record.MonitoringDate,
  3034. PatientId: record.PatientId,
  3035. Module: 1,
  3036. AdminUserId: adminUserInfo.AdminUser.Id,
  3037. Ctime: time.Now().Unix(),
  3038. Mtime: 0,
  3039. Status: 1,
  3040. UserOrgId: record.UserOrgId,
  3041. ErrLog: string(byterequest),
  3042. Source: "执行上机时新增监测",
  3043. }
  3044. service.CreateMonitorRecordLog(monitorRecordLog)
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminUserInfo.Org.Id,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 7,
  3052. RecordDate: schedulestartTime,
  3053. Sourse: 1,
  3054. PatientId: patientID,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3061. redis := service.RedisClient()
  3062. //清空key 值
  3063. redis.Set(key, "", time.Second)
  3064. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3065. redis.Set(keyOne, "", time.Second)
  3066. defer redis.Close()
  3067. if err != nil {
  3068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3069. return
  3070. }
  3071. }
  3072. go func() {
  3073. ssoDomain := beego.AppConfig.String("call_domain")
  3074. api := ssoDomain + "/index/uppatient"
  3075. values := make(url.Values)
  3076. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3077. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3078. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3079. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3080. http.PostForm(api, values)
  3081. }()
  3082. this.ServeSuccessJSON(map[string]interface{}{
  3083. "dialysis_order": newdialysisRecord,
  3084. "monitor": record,
  3085. })
  3086. return
  3087. }
  3088. func (c *DialysisAPIController) PostSolution() {
  3089. id, _ := c.GetInt64("patient", 0)
  3090. recordDateStr := c.GetString("record_date")
  3091. if id <= 0 {
  3092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3093. return
  3094. }
  3095. adminUserInfo := c.GetMobileAdminUserInfo()
  3096. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3097. if patient.ID == 0 {
  3098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3099. return
  3100. }
  3101. if len(recordDateStr) == 0 {
  3102. recordDateStr = time.Now().Format("2006-01-02")
  3103. }
  3104. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3105. if parseDateErr != nil {
  3106. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3108. return
  3109. }
  3110. mode_id, _ := c.GetInt64("mode_id", 0)
  3111. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3112. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3113. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3114. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3115. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3116. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3117. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3118. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3119. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3120. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3121. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3122. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3123. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3124. kalium, _ := c.GetFloat("kalium", 0)
  3125. sodium, _ := c.GetFloat("sodium", 0)
  3126. calcium, _ := c.GetFloat("calcium", 0)
  3127. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3128. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3129. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3130. glucose, _ := c.GetFloat("glucose", 0)
  3131. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3132. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3133. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3134. conductivity, _ := c.GetFloat("conductivity", 0)
  3135. remark := c.GetString("remark")
  3136. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3137. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3138. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3139. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3140. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3141. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3142. special_medicine_other := c.GetString("special_medicine_other")
  3143. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3144. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3145. blood_access, _ := c.GetInt64("blood_access", 0)
  3146. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3147. body_fluid_other := c.GetString("body_fluid_other")
  3148. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3149. niprocart, _ := c.GetInt64("niprocart", 0)
  3150. jms, _ := c.GetInt64("jms", 0)
  3151. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3152. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3153. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3154. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3155. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3156. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3157. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3158. injector, _ := c.GetInt64("injector", 0)
  3159. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3160. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3161. safe_package, _ := c.GetInt64("package", 0)
  3162. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3163. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3164. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3165. blood := c.GetString("blood")
  3166. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3167. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3168. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3169. displace_speed := c.GetString("displace_speed")
  3170. illness, _ := c.GetInt64("illness")
  3171. amylaceum := c.GetString("amylaceum")
  3172. single_time := c.GetString("single_time")
  3173. single_water := c.GetString("single_water")
  3174. replacement_flow := c.GetString("replacement_flow")
  3175. plasma_separator := c.GetString("plasma_separator")
  3176. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3177. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3178. oxygen_flow := c.GetString("oxygen_flow")
  3179. oxygen_time := c.GetString("oxygen_time")
  3180. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3181. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3182. puncture_needle := c.GetString("puncture_needle")
  3183. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3184. epo := c.GetString("epo")
  3185. epo_count, _ := c.GetFloat("epo_count", 0)
  3186. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3187. pre_impulse := c.GetString("pre_impulse")
  3188. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3189. admin_user_id, _ := c.GetInt64("admin_user_id")
  3190. is_water := c.GetString("is_water")
  3191. add_amount, _ := c.GetFloat("add_amount")
  3192. reduce_amount, _ := c.GetFloat("reduce_amount")
  3193. prescribing_number, _ := c.GetFloat("prescribing_number")
  3194. treatment_remark := c.GetString("treatment_remark")
  3195. prescription_sodium := c.GetString("prescription_sodium")
  3196. start_sodium := c.GetString("start_sodium")
  3197. sodium_curve := c.GetString("sodium_curve")
  3198. var is_war int64
  3199. if is_water == "是" {
  3200. is_war = 1
  3201. }
  3202. if is_water == "否" {
  3203. is_war = 2
  3204. }
  3205. if is_water == "请选择" {
  3206. is_war = 0
  3207. }
  3208. drhy_water := c.GetString("drhy_water")
  3209. dry_water_hour := c.GetString("dry_water_hour")
  3210. water_machine := c.GetString("water_machine")
  3211. dialysis_remark := c.GetString("dialysis_remark")
  3212. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3213. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3214. prescription_water, _ := c.GetFloat("prescription_water")
  3215. dialysis_strainer := c.GetString("dialysis_strainer")
  3216. chaptalization := c.GetString("chaptalization")
  3217. washing_time := c.GetString("washing_time")
  3218. warsh_count := c.GetString("warsh_count")
  3219. blood_access_part_id := c.GetString("blood_access_part_id")
  3220. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3221. dialyzate := c.GetString("dialyzate")
  3222. if mode_id > 0 {
  3223. var str string
  3224. //查找该机构用的是什么透析器
  3225. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3226. if filedConfig.ID > 0 {
  3227. str = dialyzerPerfusionApparatus
  3228. } else {
  3229. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3230. }
  3231. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3232. }
  3233. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3234. //
  3235. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3236. // if appRole.UserType == 3 {
  3237. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3238. // if getPermissionErr != nil {
  3239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3240. // return
  3241. // } else if headNursePermission == nil {
  3242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3243. // return
  3244. // }
  3245. // }
  3246. //}
  3247. // 查询信息规挡的设置天数
  3248. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3249. if infor.ID > 0 && infor.WeekDay > 0 {
  3250. var cha_time int64
  3251. timeNowStr := time.Now().Format("2006-01-02")
  3252. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3253. //今日的日期减去设置的日期
  3254. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3255. if cha_time >= recordDate.Unix() {
  3256. //查询审核是否允许
  3257. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3258. //申请状态不允许的情况 拒绝修改
  3259. if infor.ApplicationStatus != 1 {
  3260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3261. return
  3262. }
  3263. }
  3264. }
  3265. prescription := models.DialysisPrescription{
  3266. UserOrgId: adminUserInfo.Org.Id,
  3267. PatientId: id,
  3268. RecordDate: recordDate.Unix(),
  3269. ModeId: mode_id,
  3270. DialysisDuration: dialysis_duration,
  3271. Dialyzer: dialyzer,
  3272. PerfusionApparatus: perfusion_apparatus,
  3273. BloodFlowVolume: blood_flow_volume,
  3274. DewaterAmount: dewater_amount,
  3275. DisplaceLiqui: displace_liqui,
  3276. ReplacementWay: replacement_way,
  3277. Anticoagulant: anticoagulant,
  3278. AnticoagulantShouji: anticoagulant_shouji,
  3279. AnticoagulantWeichi: anticoagulant_weichi,
  3280. AnticoagulantZongliang: anticoagulant_zongliang,
  3281. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3282. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3283. Kalium: kalium,
  3284. Sodium: sodium,
  3285. Calcium: calcium,
  3286. Bicarbonate: bicarbonate,
  3287. Glucose: glucose,
  3288. // DryWeight: dry_weight,
  3289. DialysateFlow: dialysate_flow,
  3290. DialysateTemperature: dialysate_temperature,
  3291. Conductivity: conductivity,
  3292. Remark: remark,
  3293. Status: 1,
  3294. CreatedTime: time.Now().Unix(),
  3295. UpdatedTime: time.Now().Unix(),
  3296. DialysisDurationMinute: dialysisDurationMinute,
  3297. DialysisDurationHour: dialysisDurationHour,
  3298. TargetUltrafiltration: targetUltrafiltration,
  3299. DialysateFormulation: dialysateFormulation,
  3300. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3301. BodyFluid: body_fluid,
  3302. SpecialMedicine: special_medicine,
  3303. SpecialMedicineOther: special_medicine_other,
  3304. DisplaceLiquiPart: displace_liqui_part,
  3305. DisplaceLiquiValue: displace_liqui_value,
  3306. BloodAccess: blood_access,
  3307. Ultrafiltration: ultrafiltration,
  3308. BodyFluidOther: body_fluid_other,
  3309. ReplacementTotal: replacement_total,
  3310. Niprocart: niprocart,
  3311. Jms: jms,
  3312. FistulaNeedleSet: fistula_needle_set,
  3313. FistulaNeedleSet16: fistula_needle_set_16,
  3314. Hemoperfusion: hemoperfusion,
  3315. DialyserSterilised: dialyser_sterilised,
  3316. Filtryzer: filtryzer,
  3317. TargetKtv: target_ktv,
  3318. Dialyzers: dialyzers,
  3319. Injector: injector,
  3320. Bloodlines: bloodlines,
  3321. TubingHemodialysis: tubing_hemodialysis,
  3322. Package: safe_package,
  3323. ALiquid: a_liquid,
  3324. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3325. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3326. Blood: blood,
  3327. DialysisDialyszers: dialysis_dialyszers,
  3328. DialysisIrrigation: dialysis_irrigation,
  3329. AntioxidantCommodityName: antioxidant_commodity_name,
  3330. DisplaceSpeed: displace_speed,
  3331. Illness: illness,
  3332. Amylaceum: amylaceum,
  3333. SingleWater: single_water,
  3334. SingleTime: single_time,
  3335. ReplacementFlow: replacement_flow,
  3336. PlasmaSeparator: plasma_separator,
  3337. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3338. OxygenUptake: oxygen_uptake,
  3339. OxygenTime: oxygen_time,
  3340. OxygenFlow: oxygen_flow,
  3341. HemodialysisPipelines: hemodialysis_pipelines,
  3342. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3343. PunctureNeedle: puncture_needle,
  3344. PunctureNeedleCount: puncture_needle_count,
  3345. Epo: epo,
  3346. EpoCount: epo_count,
  3347. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3348. PreImpulse: impulse,
  3349. AdminUserId: admin_user_id,
  3350. IsWater: is_war,
  3351. DrhyWater: drhy_water,
  3352. DryWaterHour: dry_water_hour,
  3353. WaterMachine: water_machine,
  3354. AddAmount: add_amount,
  3355. ReduceAmount: reduce_amount,
  3356. DialysisRemark: dialysis_remark,
  3357. PrescribingNumber: prescribing_number,
  3358. PrescriptionSodium: prescription_sodium,
  3359. StartSodium: start_sodium,
  3360. SodiumCurve: sodium_curve,
  3361. TreatmentRemark: treatment_remark,
  3362. DialysisFluidFlow: dialysis_fluid_flow,
  3363. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3364. PrescriptionWater: prescription_water,
  3365. DialysisStrainer: dialysis_strainer,
  3366. Chaptalization: chaptalization,
  3367. WashingTime: washing_time,
  3368. WarshCount: warsh_count,
  3369. BloodAccessPartId: blood_access_part_id,
  3370. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3371. Dialyzate: dialyzate,
  3372. }
  3373. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3374. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3375. //
  3376. if appRole.UserType == 2 || appRole.UserType == 1 {
  3377. prescription_doctor = adminUserInfo.AdminUser.Id
  3378. prescription.PrescriptionDoctor = prescription_doctor
  3379. }
  3380. if dialysisPrescription.ID == 0 { //新增
  3381. prescription.Creater = adminUserInfo.AdminUser.Id
  3382. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3383. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3384. }
  3385. } else { //修改
  3386. if dialysisPrescription.Creater == 0 {
  3387. prescription.Creater = adminUserInfo.AdminUser.Id
  3388. } else {
  3389. prescription.Creater = dialysisPrescription.Creater
  3390. if adminUserInfo.Org.Id == 9882 {
  3391. if appRole.UserType == 2 || appRole.UserType == 1 {
  3392. prescription.Creater = adminUserInfo.AdminUser.Id
  3393. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3394. }
  3395. }
  3396. }
  3397. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3398. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3399. }
  3400. //if/**/
  3401. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3402. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3403. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3404. // if getPermissionErr != nil {
  3405. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3406. // return
  3407. // } else if headNursePermission == nil {
  3408. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3409. // return
  3410. // }
  3411. //}
  3412. //prescription.Creater = dialysisPrescription.Creater
  3413. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3414. prescription.Modifier = adminUserInfo.AdminUser.Id
  3415. prescription.ID = dialysisPrescription.ID
  3416. }
  3417. solution := models.DialysisSolution{
  3418. RegistrarsId: adminUserInfo.AdminUser.Id,
  3419. UserOrgId: adminUserInfo.Org.Id,
  3420. Doctor: prescription_doctor,
  3421. PatientId: id,
  3422. ModeId: mode_id,
  3423. DialysisDuration: dialysis_duration,
  3424. PerfusionApparatus: perfusion_apparatus,
  3425. BloodFlowVolume: blood_flow_volume,
  3426. Dewater: dewater_amount,
  3427. DisplaceLiqui: displace_liqui,
  3428. ReplacementWay: replacement_way,
  3429. Anticoagulant: anticoagulant,
  3430. AnticoagulantShouji: anticoagulant_shouji,
  3431. AnticoagulantWeichi: anticoagulant_weichi,
  3432. AnticoagulantZongliang: anticoagulant_zongliang,
  3433. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3434. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3435. Kalium: kalium,
  3436. Sodium: sodium,
  3437. Calcium: calcium,
  3438. Bicarbonate: bicarbonate,
  3439. Glucose: glucose,
  3440. // DryWeight: dry_weight,
  3441. DialysateFlow: dialysate_flow,
  3442. DialysateTemperature: dialysate_temperature,
  3443. Conductivity: conductivity,
  3444. Remark: remark,
  3445. Status: 1,
  3446. CreatedTime: time.Now().Unix(),
  3447. UpdatedTime: time.Now().Unix(),
  3448. DialysisDurationMinute: dialysisDurationMinute,
  3449. DialysisDurationHour: dialysisDurationHour,
  3450. TargetUltrafiltration: targetUltrafiltration,
  3451. DialysateFormulation: dialysateFormulation,
  3452. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3453. BodyFluid: body_fluid,
  3454. SpecialMedicine: special_medicine,
  3455. SpecialMedicineOther: special_medicine_other,
  3456. DisplaceLiquiPart: displace_liqui_part,
  3457. DisplaceLiquiValue: displace_liqui_value,
  3458. BloodAccess: blood_access,
  3459. Ultrafiltration: ultrafiltration,
  3460. BodyFluidOther: body_fluid_other,
  3461. ReplacementTotal: replacement_total,
  3462. TargetKtv: target_ktv,
  3463. DialysisDialyszers: dialysis_dialyszers,
  3464. DialysisIrrigation: dialysis_irrigation,
  3465. HemodialysisPipelines: hemodialysis_pipelines,
  3466. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3467. PunctureNeedle: puncture_needle,
  3468. PunctureNeedleCount: puncture_needle_count,
  3469. Epo: epo,
  3470. EpoCount: epo_count,
  3471. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3472. PreImpulse: impulse,
  3473. SolutionStatus: 1,
  3474. DialysisRemark: dialysis_remark,
  3475. PrescribingNumber: prescribing_number,
  3476. PrescriptionSodium: prescription_sodium,
  3477. StartSodium: start_sodium,
  3478. SodiumCurve: sodium_curve,
  3479. TreatmentRemark: treatment_remark,
  3480. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3481. DialysisFluidFlow: dialysis_fluid_flow,
  3482. PrescriptionWater: prescription_water,
  3483. DialysisStrainer: dialysis_strainer,
  3484. Chaptalization: chaptalization,
  3485. WashingTime: washing_time,
  3486. WarshCount: warsh_count,
  3487. BloodAccessPartId: blood_access_part_id,
  3488. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3489. Dialyzate: dialyzate,
  3490. }
  3491. //针对河间咸的
  3492. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3493. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3494. solution.DisplaceLiquiPart = 0
  3495. solution.DisplaceLiquiValue = 0
  3496. }
  3497. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3498. prescription.DisplaceLiquiPart = 0
  3499. prescription.DisplaceLiquiValue = 0
  3500. }
  3501. }
  3502. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3503. if solution.PrescribingNumber == 0 {
  3504. solution.PrescribingNumber = 1
  3505. }
  3506. if prescription.PrescribingNumber == 0 {
  3507. prescription.PrescribingNumber = 1
  3508. }
  3509. if solution.PrescribingNumber == 0 && id == 14682 {
  3510. solution.PrescribingNumber = 2
  3511. }
  3512. if solution.PrescribingNumber == 0 && id == 18560 {
  3513. solution.PrescribingNumber = 2
  3514. }
  3515. if prescription.PrescribingNumber == 0 && id == 14682 {
  3516. prescription.PrescribingNumber = 2
  3517. }
  3518. if prescription.PrescribingNumber == 0 && id == 18560 {
  3519. prescription.PrescribingNumber = 2
  3520. }
  3521. }
  3522. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3523. //记录日志
  3524. byterequest, _ := json.Marshal(prescription)
  3525. prescriptionLog := models.XtDialysisPrescriptionLog{
  3526. UserOrgId: prescription.UserOrgId,
  3527. Ctime: time.Now().Unix(),
  3528. Mtime: 0,
  3529. ErrLog: string(byterequest),
  3530. AdminUserId: adminUserInfo.AdminUser.Id,
  3531. RecordDate: prescription.RecordDate,
  3532. PatientId: prescription.PatientId,
  3533. Source: "手机端新增长期处方",
  3534. Status: 1,
  3535. }
  3536. service.CreatePrescriptionLog(prescriptionLog)
  3537. finish := models.XtDialysisFinish{
  3538. IsFinish: 1,
  3539. UserOrgId: adminUserInfo.Org.Id,
  3540. Status: 1,
  3541. Ctime: time.Now().Unix(),
  3542. Mtime: 0,
  3543. Module: 1,
  3544. RecordDate: recordDate.Unix(),
  3545. Sourse: 1,
  3546. PatientId: id,
  3547. }
  3548. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3549. if dialysisFinish.ID == 0 {
  3550. service.CreateDialysisFinish(finish)
  3551. }
  3552. //获取最新1条
  3553. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3554. //更新状态
  3555. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3556. //长沙南雅医院,自动生成抗凝剂的临时处方
  3557. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3558. if prescribing_number == 0 {
  3559. prescribing_number = 1
  3560. }
  3561. advice := models.DoctorAdvice{
  3562. UserOrgId: adminUserInfo.Org.Id,
  3563. PatientId: id,
  3564. GroupNo: 0,
  3565. AdviceType: 2,
  3566. RecordDate: recordDate.Unix(),
  3567. AdviceDate: recordDate.Unix(),
  3568. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3569. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3570. AdviceDesc: "",
  3571. ReminderDate: 0,
  3572. SingleDose: prescription.AnticoagulantZongliang,
  3573. SingleDoseUnit: "iu",
  3574. DrugSpec: 0,
  3575. DrugSpecUnit: "",
  3576. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3577. PrescribingNumberUnit: "支",
  3578. DeliveryWay: "静脉注射",
  3579. ExecutionFrequency: "上机前",
  3580. AdviceDoctor: 0,
  3581. Status: 1,
  3582. CreatedTime: time.Now().Unix(),
  3583. UpdatedTime: time.Now().Unix(),
  3584. IsPrescription: 1,
  3585. ExecutionState: 2,
  3586. StopState: 2,
  3587. IsSettle: 2,
  3588. }
  3589. // 查询排班信息
  3590. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3591. if schedulePatient.ID > 0 {
  3592. if schedulePatient.ScheduleType == 1 {
  3593. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3594. }
  3595. if schedulePatient.ScheduleType == 2 {
  3596. advice.StartTime = recordDate.Unix() + 10*60*60
  3597. }
  3598. }
  3599. // 抗凝剂名称
  3600. switch anticoagulant {
  3601. case 1:
  3602. advice.AdviceName = "无肝素"
  3603. break
  3604. case 2:
  3605. advice.AdviceName = "普通肝素"
  3606. break
  3607. case 3:
  3608. advice.AdviceName = "低分子肝素"
  3609. break
  3610. case 4:
  3611. advice.AdviceName = "阿加曲班"
  3612. break
  3613. case 5:
  3614. advice.AdviceName = "枸橼酸钠"
  3615. break
  3616. case 6:
  3617. advice.AdviceName = "低分子肝素钙"
  3618. break
  3619. case 7:
  3620. advice.AdviceName = "低分子肝素钠"
  3621. break
  3622. case 8:
  3623. advice.AdviceName = "依诺肝素"
  3624. break
  3625. case 9:
  3626. advice.AdviceName = "达肝素"
  3627. break
  3628. case 10:
  3629. advice.AdviceName = "体外抗凝"
  3630. break
  3631. case 11:
  3632. advice.AdviceName = "那曲肝素"
  3633. break
  3634. case 12:
  3635. advice.AdviceName = "无抗凝剂"
  3636. break
  3637. }
  3638. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3639. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3640. advice.AdviceDoctor = appRole.AdminUserId
  3641. }
  3642. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3643. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3644. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3645. advice.AdviceName = "低分子肝素钠注射液"
  3646. // 修改患者临时医嘱里的抗凝剂医嘱
  3647. advice.ID = advicePrescription.ID
  3648. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3649. } else {
  3650. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3651. advice.AdviceName = "低分子肝素钠注射液"
  3652. service.CreateDoctorAdvice(&advice)
  3653. }
  3654. }
  3655. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3656. redis := service.RedisClient()
  3657. defer redis.Close()
  3658. //清空key 值
  3659. redis.Set(key, "", time.Second)
  3660. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3661. redis.Set(keyOne, "", time.Second)
  3662. }
  3663. //获取key,清空redis
  3664. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3665. redis := service.RedisClient()
  3666. defer redis.Close()
  3667. //清空key 值
  3668. redis.Set(key, "", time.Second)
  3669. //清空长期医嘱的key
  3670. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3671. redis.Set(soulution_key, "", time.Second)
  3672. //查询最近透析准备表里是否存在 透析器 灌流器
  3673. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3674. redis.Set(keyOne, "", time.Second)
  3675. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3676. redis.Set(keyTwo, "", time.Second)
  3677. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3678. redis.Set(keyThree, "", time.Second)
  3679. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3680. redis.Set(keyFour, "", time.Second)
  3681. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3682. //
  3683. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3684. //
  3685. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3686. //if len(mation)>0{
  3687. // for _, item := range splitStr {
  3688. // for _,it := range mation{
  3689. // if(item == it.SpecificationName){
  3690. //
  3691. // //查询最近一次的透析器
  3692. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3693. //
  3694. // if errcode == gorm.ErrRecordNotFound{
  3695. // //插入数据
  3696. // prepare := models.DialysisBeforePrepare{
  3697. // UserOrgId: adminUserInfo.Org.Id,
  3698. // PatientId: id,
  3699. // RecordDate: recordDate.Unix(),
  3700. // GoodTypeId: it.GoodTypeId,
  3701. // GoodId: it.ID,
  3702. // Count: 1,
  3703. // Ctime: time.Now().Unix(),
  3704. // Creater: adminUserInfo.AdminUser.Id,
  3705. // Status:1,
  3706. //
  3707. // }
  3708. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3709. // fmt.Println("",errcode)
  3710. // }
  3711. // }
  3712. // }
  3713. //
  3714. // }
  3715. //
  3716. // for _, item := range splitIrrigation {
  3717. // for _,it := range mation{
  3718. // if(item == it.SpecificationName){
  3719. // //查询最近一次的透析器
  3720. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3721. // if errcode == gorm.ErrRecordNotFound{
  3722. // //插入数据
  3723. // prepare := models.DialysisBeforePrepare{
  3724. // UserOrgId: adminUserInfo.Org.Id,
  3725. // PatientId: id,
  3726. // RecordDate: recordDate.Unix(),
  3727. // GoodTypeId: it.GoodTypeId,
  3728. // GoodId: it.ID,
  3729. // Count: 1,
  3730. // Ctime: time.Now().Unix(),
  3731. // Creater: adminUserInfo.AdminUser.Id,
  3732. // Status:1,
  3733. //
  3734. // }
  3735. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3736. // fmt.Println(errcode)
  3737. // }
  3738. // }
  3739. // }
  3740. // }
  3741. //}
  3742. c.ServeSuccessJSON(map[string]interface{}{
  3743. "solution": &solution,
  3744. "prescription": &prescription,
  3745. })
  3746. }
  3747. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3748. patient, _ := c.GetInt64("patient", 0)
  3749. adminUserInfo := c.GetMobileAdminUserInfo()
  3750. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3751. c.ServeSuccessJSON(map[string]interface{}{
  3752. "receiveTreatmentAsses": receiveTreatmentAsses,
  3753. })
  3754. }
  3755. func (this *DialysisAPIController) PostSignInfo() {
  3756. patientID, _ := this.GetInt64("patient_id")
  3757. recordDateStr := this.GetString("date")
  3758. if patientID <= 0 {
  3759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3760. return
  3761. }
  3762. if len(recordDateStr) == 0 {
  3763. recordDateStr = time.Now().Format("2006-01-02")
  3764. }
  3765. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3766. if parseDateErr != nil {
  3767. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3769. return
  3770. }
  3771. adminInfo := this.GetMobileAdminUserInfo()
  3772. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3773. if err != nil {
  3774. this.ErrorLog("签名失败:%v", err)
  3775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3776. return
  3777. }
  3778. this.ServeSuccessJSON(map[string]interface{}{
  3779. "doctor_id": adminInfo.AdminUser.Id,
  3780. })
  3781. }
  3782. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3783. patientID, _ := this.GetInt64("patient_id")
  3784. adminInfo := this.GetMobileAdminUserInfo()
  3785. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3786. this.ServeSuccessJSON(map[string]interface{}{
  3787. "monitor": record,
  3788. })
  3789. }
  3790. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3791. thisTime := time.Now()
  3792. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3793. timeLayout := "2006-01-02 15:04:05"
  3794. loc, _ := time.LoadLocation("Local")
  3795. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3796. theAssessmentDateTime := theStartTime.Unix()
  3797. patientID, _ := this.GetInt64("patient_id")
  3798. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3799. adminInfo := this.GetMobileAdminUserInfo()
  3800. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3801. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3802. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3803. var ultrafiltration_rate float64
  3804. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3805. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3806. fmt.Println(evaluation)
  3807. fmt.Println("prescription.ID", prescription.ID)
  3808. if prescription.ID > 0 {
  3809. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3810. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3811. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3812. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3813. record.UltrafiltrationRate = ultrafiltration_rate
  3814. }
  3815. if adminInfo.Org.Id == 10597 {
  3816. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3817. record.UltrafiltrationRate = ultrafiltration_rate
  3818. }
  3819. if adminInfo.Org.Id == 10510 {
  3820. record.UltrafiltrationRate = 0
  3821. }
  3822. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3823. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3824. record.UltrafiltrationRate = ultrafiltration_rate
  3825. }
  3826. if template.TemplateId == 20 || template.TemplateId == 22 {
  3827. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3828. record.UltrafiltrationRate = ultrafiltration_rate
  3829. }
  3830. // 只针对方济医院
  3831. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3832. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3833. ultrafiltration_rate = value
  3834. record.UltrafiltrationRate = ultrafiltration_rate
  3835. }
  3836. if template.TemplateId == 41 || template.TemplateId == 47 {
  3837. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3838. record.UltrafiltrationRate = ultrafiltration_rate
  3839. }
  3840. if template.TemplateId == 43 {
  3841. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3842. record.UltrafiltrationRate = ultrafiltration_rate
  3843. }
  3844. if template.TemplateId == 46 || template.TemplateId == 54 {
  3845. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3846. record.UltrafiltrationRate = ultrafiltration_rate
  3847. }
  3848. 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 {
  3849. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3850. record.UltrafiltrationRate = ultrafiltration_rate
  3851. }
  3852. if adminInfo.Org.Id == 10469 {
  3853. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3854. record.UltrafiltrationRate = ultrafiltration_rate
  3855. }
  3856. if adminInfo.Org.Id == 10471 {
  3857. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3858. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3859. }
  3860. if adminInfo.Org.Id == 10460 {
  3861. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3862. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3863. }
  3864. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3865. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3866. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3867. }
  3868. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3869. record.UltrafiltrationRate = 0
  3870. }
  3871. //if template.TemplateId == 47 {
  3872. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3873. // record.UltrafiltrationRate = ultrafiltration_rate
  3874. //}
  3875. }
  3876. }
  3877. // record.UltrafiltrationRate = ultrafiltration_rate
  3878. record.UltrafiltrationVolume = 0
  3879. 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
  3880. if ultrafiltration_rate > 0 {
  3881. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3882. record.UltrafiltrationVolume = value
  3883. }
  3884. }
  3885. 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
  3886. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3887. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3888. record.UltrafiltrationVolume = ultrafiltration_volume
  3889. }
  3890. }
  3891. if adminInfo.Org.Id == 10597 {
  3892. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3893. record.UltrafiltrationVolume = ultrafiltration_volume
  3894. }
  3895. //长沙南雅
  3896. 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 {
  3897. if ultrafiltration_rate > 0 {
  3898. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3899. record.UltrafiltrationVolume = ultrafiltration_volume
  3900. }
  3901. }
  3902. if adminInfo.Org.Id == 10471 {
  3903. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3904. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3905. }
  3906. if adminInfo.Org.Id == 10460 {
  3907. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3908. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3909. }
  3910. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  3911. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3912. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3913. }
  3914. //长沙南雅累计血容量自动计算
  3915. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3916. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3917. //}
  3918. if template.TemplateId == 47 || template.TemplateId == 54 {
  3919. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3920. }
  3921. if adminInfo.Org.Id == 10510 {
  3922. record.UltrafiltrationVolume = 0
  3923. }
  3924. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3925. this.ServeSuccessJSON(map[string]interface{}{
  3926. "monitor": record,
  3927. "lastMonitorRecordList": lastMonitorRecordList,
  3928. })
  3929. }
  3930. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3931. record_id, _ := this.GetInt64("id")
  3932. nurseID, _ := this.GetInt64("start_nurse")
  3933. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3934. bedID, _ := this.GetInt64("bed")
  3935. start_time := this.GetString("start_time")
  3936. schedual_type, _ := this.GetInt64("schedual_type")
  3937. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3938. change_nurse, _ := this.GetInt64("change_nurse")
  3939. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3940. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3941. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3942. fmt.Println("quality_nurse_id", quality_nurse_id)
  3943. patient_id, _ := this.GetInt64("patient_id")
  3944. record_date, _ := this.GetInt64("record_date")
  3945. puncture_needle := this.GetString("puncture_needle")
  3946. puncture_way := this.GetString("puncture_way")
  3947. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3948. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3949. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3950. nuclein_date_str := this.GetString("nuclein_date_str")
  3951. order_remark := this.GetString("order_remark")
  3952. schedule_remark := this.GetString("schedule_remark")
  3953. catheter_operation := this.GetString("catheter_operation")
  3954. blood_flow_volume := this.GetString("blood_flow_volume")
  3955. if record_id == 0 {
  3956. this.ErrorLog("id:%v", record_id)
  3957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3958. return
  3959. }
  3960. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3961. if parseStartDateErr != nil {
  3962. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3963. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3964. return
  3965. }
  3966. adminUserInfo := this.GetMobileAdminUserInfo()
  3967. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3968. if getNurseErr != nil {
  3969. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3971. return
  3972. } else if nurse == nil {
  3973. this.ErrorLog("护士不存在")
  3974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3975. return
  3976. }
  3977. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3978. //if getNurseErr != nil {
  3979. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3980. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3981. // return
  3982. //} else if nurse == nil {
  3983. // this.ErrorLog("护士不存在")
  3984. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3985. // return
  3986. //}
  3987. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3988. if getDeviceNumberErr != nil {
  3989. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3991. return
  3992. } else if deviceNumber == nil {
  3993. this.ErrorLog("床位号不存在")
  3994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3995. return
  3996. }
  3997. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3998. //
  3999. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4000. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4001. // if getPermissionErr != nil {
  4002. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4003. // return
  4004. // } else if headNursePermission == nil {
  4005. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4006. // return
  4007. // }
  4008. //}
  4009. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4010. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4011. timeLayout := "2006-01-02 15:04:05"
  4012. loc, _ := time.LoadLocation("Local")
  4013. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4014. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4015. schedulestartTime := theStartTime.Unix()
  4016. scheduleendTime := theEndTime.Unix()
  4017. var theNucleinDate int64
  4018. timeLayoutOne := "2006-01-02"
  4019. if len(nuclein_date_str) > 0 {
  4020. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4021. if err != nil {
  4022. utils.ErrorLog(err.Error())
  4023. }
  4024. theNucleinDate = theTime.Unix()
  4025. }
  4026. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4027. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4028. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4029. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4030. if err == gorm.ErrRecordNotFound { //空床位
  4031. // 修改了床位逻辑
  4032. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4033. if daySchedule.ID > 0 {
  4034. //daySchedule.BedId = bedID
  4035. //daySchedule.PartitionId = deviceNumber.ZoneID
  4036. //daySchedule.ScheduleType = schedual_type
  4037. //daySchedule.UpdatedTime = time.Now().Unix()
  4038. //err := service.UpdateSchedule(&daySchedule)
  4039. xtSchedule := models.Schedule{
  4040. PartitionId: deviceNumber.ZoneID,
  4041. BedId: bedID,
  4042. ScheduleType: schedual_type,
  4043. UpdatedTime: time.Now().Unix(),
  4044. }
  4045. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4046. if err != nil {
  4047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4048. return
  4049. }
  4050. }
  4051. } else if err == nil {
  4052. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4053. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4054. if daySchedule.ID > 0 {
  4055. //daySchedule.BedId = bedID
  4056. //daySchedule.PartitionId = deviceNumber.ZoneID
  4057. //
  4058. //daySchedule.ScheduleType = schedual_type
  4059. //daySchedule.UpdatedTime = time.Now().Unix()
  4060. //err := service.UpdateSchedule(&daySchedule)
  4061. xtSchedule := models.Schedule{
  4062. PartitionId: deviceNumber.ZoneID,
  4063. BedId: bedID,
  4064. ScheduleType: schedual_type,
  4065. UpdatedTime: time.Now().Unix(),
  4066. }
  4067. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4068. if err != nil {
  4069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4070. return
  4071. }
  4072. }
  4073. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4075. return
  4076. }
  4077. } else if err != nil {
  4078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4079. return
  4080. }
  4081. }
  4082. dialysisRecord := &models.DialysisOrder{
  4083. ID: record_id,
  4084. UserOrgId: adminUserInfo.Org.Id,
  4085. BedID: bedID,
  4086. StartNurse: nurseID,
  4087. StartTime: startDate.Unix(),
  4088. PunctureNurse: puncture_nurse,
  4089. Creator: adminUserInfo.AdminUser.Id,
  4090. Modifier: adminUserInfo.AdminUser.Id,
  4091. WashpipeNurse: washpipe_nurse,
  4092. SchedualType: schedual_type,
  4093. ChangeNurse: change_nurse,
  4094. DifficultPunctureNurse: difficult_puncture_nurse,
  4095. NewFistulaNurse: new_fistula_nurse,
  4096. QualityNurseId: quality_nurse_id,
  4097. PunctureNeedle: puncture_needle,
  4098. PunctureWay: puncture_way,
  4099. DialysisDialyszers: dialysis_dialyszers,
  4100. DialysisIrrigation: dialysis_irrigation,
  4101. BloodAccessId: blood_access_id,
  4102. NucleinDate: theNucleinDate,
  4103. OrderRemark: order_remark,
  4104. ScheduleRemark: schedule_remark,
  4105. CatheterOperation: catheter_operation,
  4106. BloodFlowVolume: blood_flow_volume,
  4107. }
  4108. //修改床位号需要重新消毒
  4109. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4110. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4111. //查询第一条监测
  4112. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4113. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4114. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4115. redis := service.RedisClient()
  4116. //清空key 值
  4117. redis.Set(key, "", time.Second)
  4118. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4119. redis.Set(keyOne, "", time.Second)
  4120. defer redis.Close()
  4121. }
  4122. // 查询信息规挡的设置天数
  4123. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4124. if infor.ID > 0 && infor.WeekDay > 0 {
  4125. var cha_time int64
  4126. timeNowStr := time.Now().Format("2006-01-02")
  4127. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4128. //今日的日期减去设置的日期
  4129. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4130. if cha_time >= record_date {
  4131. //查询审核是否允许
  4132. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4133. //申请状态不允许的情况 拒绝修改
  4134. if infor.ApplicationStatus != 1 {
  4135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4136. return
  4137. }
  4138. }
  4139. }
  4140. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4141. order, _ := service.GetLastPatientOrder(record_id)
  4142. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4143. redis := service.RedisClient()
  4144. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4145. redis.Set(key, "", time.Second)
  4146. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4147. //清空key 值
  4148. redis.Set(keyOne, "", time.Second)
  4149. scheduleDateStartOne := startDate.Format("2006-01-02")
  4150. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4151. redis.Set(keyTwo, "", time.Second)
  4152. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4153. redis.Set(keyThree, "", time.Second)
  4154. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4155. redis.Set(keyFour, "", time.Second)
  4156. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4157. redis.Set(keyFive, "", time.Second)
  4158. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4159. redis.Set(keySix, "", time.Second)
  4160. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4161. redis.Set(keySeven, "", time.Second)
  4162. if updateErr != nil {
  4163. this.ErrorLog("修改上机失败:%v", updateErr)
  4164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4165. return
  4166. }
  4167. if updateErr == nil {
  4168. if tempDialysisRecord.Stage == 2 {
  4169. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4170. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4171. fmt.Println(value)
  4172. a, b := math.Modf(value)
  4173. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4174. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4175. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4176. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4177. redis := service.RedisClient()
  4178. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4179. redis.Set(key, "", time.Second)
  4180. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4181. redis.Set(keyOne, "", time.Second)
  4182. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4183. //清空key 值
  4184. redis.Set(keySix, "", time.Second)
  4185. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4186. redis.Set(keySeven, "", time.Second)
  4187. redis.Close()
  4188. if updateAssessmentErr != nil {
  4189. utils.ErrorLog("%v", updateAssessmentErr)
  4190. }
  4191. }
  4192. }
  4193. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4194. this.ServeSuccessJSON(map[string]interface{}{
  4195. "dialysis_order": dialysisRecords,
  4196. })
  4197. }
  4198. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4199. record_id, _ := c.GetInt64("id")
  4200. nurseID, _ := c.GetInt64("nurse")
  4201. end_time := c.GetString("end_time")
  4202. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4203. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4204. catheter := c.GetString("catheter")
  4205. cruor := c.GetString("cruor")
  4206. mission := c.GetString("mission")
  4207. condenser := c.GetString("condenser")
  4208. if record_id <= 0 || nurseID <= 0 {
  4209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4210. return
  4211. }
  4212. adminUserInfo := c.GetMobileAdminUserInfo()
  4213. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4214. if getNurseErr != nil {
  4215. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4217. return
  4218. } else if nurse == nil {
  4219. c.ErrorLog("护士不存在")
  4220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4221. return
  4222. }
  4223. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4224. if parseEndDateErr != nil {
  4225. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4227. return
  4228. }
  4229. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4230. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4231. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4232. // if getPermissionErr != nil {
  4233. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4234. // return
  4235. // } else if headNursePermission == nil {
  4236. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4237. // return
  4238. // }
  4239. //}
  4240. // 查询信息规挡的设置天数
  4241. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4242. if infor.ID > 0 {
  4243. var cha_time int64
  4244. timeNowStr := time.Now().Format("2006-01-02")
  4245. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4246. //今日的日期减去设置的日期
  4247. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4248. if cha_time >= tempDialysisRecords.DialysisDate {
  4249. //查询审核是否允许
  4250. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4251. //申请状态不允许的情况 拒绝修改
  4252. if infor.ApplicationStatus != 1 {
  4253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4254. return
  4255. }
  4256. }
  4257. }
  4258. dialysisRecord := &models.DialysisOrder{
  4259. ID: record_id,
  4260. UserOrgId: adminUserInfo.Org.Id,
  4261. EndTime: endDate.Unix(),
  4262. FinishNurse: nurseID,
  4263. FinishModifier: adminUserInfo.AdminUser.Id,
  4264. PuncturePointHaematoma: puncture_point_haematoma,
  4265. BloodAccessInternalFistula: blood_access_internal_fistula,
  4266. Catheter: catheter,
  4267. Cruor: cruor,
  4268. Mission: mission,
  4269. Condenser: condenser,
  4270. }
  4271. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4272. redis := service.RedisClient()
  4273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4274. //清空key 值
  4275. redis.Set(key, "", time.Second)
  4276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4277. //清空key 值
  4278. redis.Set(keyOne, "", time.Second)
  4279. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4280. redis.Set(keySeven, "", time.Second)
  4281. redis.Close()
  4282. if updateErr != nil {
  4283. c.ErrorLog("修改下机失败:%v", updateErr)
  4284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4285. return
  4286. }
  4287. if updateErr == nil {
  4288. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4289. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4290. a, b := math.Modf(value)
  4291. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4292. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4293. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4294. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4295. redis := service.RedisClient()
  4296. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4297. redis.Set(keyTen, "", time.Second)
  4298. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4299. redis.Set(keyTwo, "", time.Second)
  4300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4301. redis.Set(key, "", time.Second)
  4302. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4303. redis.Set(keyThree, "", time.Second)
  4304. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4305. redis.Set(keySeven, "", time.Second)
  4306. defer redis.Close()
  4307. if updateAssessmentErr != nil {
  4308. utils.ErrorLog("%v", updateAssessmentErr)
  4309. }
  4310. }
  4311. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4312. c.ServeSuccessJSON(map[string]interface{}{
  4313. "dialysis_order": dialysisRecords,
  4314. })
  4315. }
  4316. func (c *DialysisAPIController) GetLongAdvice() {
  4317. patient_id, _ := c.GetInt64("id")
  4318. adminUserInfo := c.GetMobileAdminUserInfo()
  4319. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4320. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4321. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4322. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4323. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4324. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4325. c.ServeSuccessJSON(map[string]interface{}{
  4326. "status": "1",
  4327. })
  4328. return
  4329. } else { //开启推送提醒
  4330. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4331. var advice_three []*models.DoctorAdvice
  4332. recordDateStr := time.Now().Format("2006-01-02")
  4333. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4334. nowtime := recordDate.Unix()
  4335. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4336. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4337. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4338. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4339. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4340. for _, advice := range advices {
  4341. if advice.FrequencyType == 3 {
  4342. t := time.Now()
  4343. week := int(t.Weekday())
  4344. fmt.Println(t.Weekday())
  4345. fmt.Println(week)
  4346. switch week {
  4347. case 1:
  4348. if strings.Index(advice.WeekDay, "周一") == -1 {
  4349. advice_three = append(advice_three, advice)
  4350. }
  4351. break
  4352. case 2:
  4353. if strings.Index(advice.WeekDay, "周二") == -1 {
  4354. advice_three = append(advice_three, advice)
  4355. }
  4356. break
  4357. case 3:
  4358. if strings.Index(advice.WeekDay, "周三") == -1 {
  4359. advice_three = append(advice_three, advice)
  4360. }
  4361. break
  4362. case 4:
  4363. if strings.Index(advice.WeekDay, "周四") == -1 {
  4364. advice_three = append(advice_three, advice)
  4365. }
  4366. break
  4367. case 5:
  4368. if strings.Index(advice.WeekDay, "周五") == -1 {
  4369. advice_three = append(advice_three, advice)
  4370. }
  4371. break
  4372. case 6:
  4373. if strings.Index(advice.WeekDay, "周六") == -1 {
  4374. advice_three = append(advice_three, advice)
  4375. }
  4376. break
  4377. case 0:
  4378. if strings.Index(advice.WeekDay, "周日") == -1 {
  4379. advice_three = append(advice_three, advice)
  4380. }
  4381. break
  4382. }
  4383. }
  4384. }
  4385. for _, advice := range advices_two {
  4386. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4387. now := p.Unix()
  4388. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4389. dayStr2 := "-" + dayStr
  4390. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4391. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4392. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4393. for _, ad := range advices {
  4394. advice_three = append(advice_three, ad)
  4395. }
  4396. }
  4397. if err == nil {
  4398. c.ServeSuccessJSON(map[string]interface{}{
  4399. "status": "2",
  4400. "advices": advices,
  4401. "advices_two": RemoveRepeatedElement(advice_three),
  4402. "is_open_remind": config.IsOpenRemind,
  4403. "his_config_open": hisConfig.IsOpen,
  4404. "is_advice_open": is_advice_open.IsAdviceOpen,
  4405. "prescription_open": prescription_open.IsOpen,
  4406. })
  4407. }
  4408. }
  4409. }
  4410. func (c *DialysisAPIController) GetLongAdviceOne() {
  4411. patient_id, _ := c.GetInt64("id")
  4412. startTime := c.GetString("schedule_date")
  4413. timeLayout := "2006-01-02"
  4414. loc, _ := time.LoadLocation("Local")
  4415. var theStartTime int64
  4416. if len(startTime) > 0 {
  4417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4418. if err != nil {
  4419. utils.ErrorLog(err.Error())
  4420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4421. return
  4422. }
  4423. theStartTime = theTime.Unix()
  4424. }
  4425. adminUserInfo := c.GetMobileAdminUserInfo()
  4426. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4427. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4428. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4429. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4430. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4431. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4432. c.ServeSuccessJSON(map[string]interface{}{
  4433. "status": "1",
  4434. })
  4435. return
  4436. } else { //开启推送提醒
  4437. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4438. var advice_three []*models.DoctorAdvice
  4439. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4440. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4441. for _, advice := range advices {
  4442. if advice.FrequencyType == 3 {
  4443. t := time.Now()
  4444. week := int(t.Weekday())
  4445. fmt.Println(t.Weekday())
  4446. fmt.Println(week)
  4447. switch week {
  4448. case 1:
  4449. if strings.Index(advice.WeekDay, "周一") == -1 {
  4450. advice_three = append(advice_three, advice)
  4451. }
  4452. break
  4453. case 2:
  4454. if strings.Index(advice.WeekDay, "周二") == -1 {
  4455. advice_three = append(advice_three, advice)
  4456. }
  4457. break
  4458. case 3:
  4459. if strings.Index(advice.WeekDay, "周三") == -1 {
  4460. advice_three = append(advice_three, advice)
  4461. }
  4462. break
  4463. case 4:
  4464. if strings.Index(advice.WeekDay, "周四") == -1 {
  4465. advice_three = append(advice_three, advice)
  4466. }
  4467. break
  4468. case 5:
  4469. if strings.Index(advice.WeekDay, "周五") == -1 {
  4470. advice_three = append(advice_three, advice)
  4471. }
  4472. break
  4473. case 6:
  4474. if strings.Index(advice.WeekDay, "周六") == -1 {
  4475. advice_three = append(advice_three, advice)
  4476. }
  4477. break
  4478. case 0:
  4479. if strings.Index(advice.WeekDay, "周日") == -1 {
  4480. advice_three = append(advice_three, advice)
  4481. }
  4482. break
  4483. }
  4484. }
  4485. }
  4486. for _, advice := range advices_two {
  4487. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4488. now := p.Unix()
  4489. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4490. dayStr2 := "-" + dayStr
  4491. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4492. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4493. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4494. for _, ad := range advices {
  4495. advice_three = append(advice_three, ad)
  4496. }
  4497. }
  4498. if err == nil {
  4499. c.ServeSuccessJSON(map[string]interface{}{
  4500. "status": "2",
  4501. "advices": advices,
  4502. "advices_two": RemoveRepeatedElement(advice_three),
  4503. "is_open_remind": config.IsOpenRemind,
  4504. "his_config_open": hisConfig.IsOpen,
  4505. "is_advice_open": is_advice_open.IsAdviceOpen,
  4506. "prescription_open": prescription_open.IsOpen,
  4507. })
  4508. }
  4509. }
  4510. }
  4511. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4512. newArr = make([]*models.DoctorAdvice, 0)
  4513. for i := 0; i < len(arr); i++ {
  4514. repeat := false
  4515. for j := i + 1; j < len(arr); j++ {
  4516. if arr[i].ID == arr[j].ID {
  4517. repeat = true
  4518. break
  4519. }
  4520. }
  4521. if !repeat {
  4522. newArr = append(newArr, arr[i])
  4523. }
  4524. }
  4525. return
  4526. }
  4527. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4528. patient, _ := c.GetInt64("id", 0)
  4529. groupNo, _ := c.GetInt64("groupno", 0)
  4530. if patient <= 0 {
  4531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4532. return
  4533. }
  4534. adminUserInfo := c.GetMobileAdminUserInfo()
  4535. dataBody := make(map[string]interface{}, 0)
  4536. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4537. if err != nil {
  4538. utils.ErrorLog(err.Error())
  4539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4540. return
  4541. }
  4542. utils.ErrorLog("%v", dataBody)
  4543. timeLayout := "2006-01-02 15:04"
  4544. loc, _ := time.LoadLocation("Local")
  4545. timeLayout2 := "2006-01-02"
  4546. loc2, _ := time.LoadLocation("Local")
  4547. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4548. utils.ErrorLog("advice_type")
  4549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4550. return
  4551. }
  4552. adviceType := int64(2)
  4553. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4554. utils.ErrorLog("advice_date")
  4555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4556. return
  4557. }
  4558. adviceDate, _ := dataBody["advice_date"].(string)
  4559. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4560. AdviceDate := theTime.Unix()
  4561. RecordDate := theTime.Unix()
  4562. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4563. utils.ErrorLog("start_time")
  4564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4565. return
  4566. }
  4567. startTime, _ := dataBody["start_time"].(string)
  4568. if len(startTime) == 0 {
  4569. utils.ErrorLog("len(start_time) == 0")
  4570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4571. return
  4572. }
  4573. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4574. if err != nil {
  4575. utils.ErrorLog(err.Error())
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4577. return
  4578. }
  4579. StartTime := theTime.Unix()
  4580. Remark := ""
  4581. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4582. remark, _ := dataBody["remark"].(string)
  4583. Remark = remark
  4584. }
  4585. var advices []*models.GroupAdvice
  4586. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4587. utils.ErrorLog("advices")
  4588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4589. return
  4590. }
  4591. adviceNames := dataBody["advices"].([]interface{})
  4592. for _, adviceNameMap := range adviceNames {
  4593. adviceNameM := adviceNameMap.(map[string]interface{})
  4594. var advice models.GroupAdvice
  4595. advice.Remark = Remark
  4596. advice.AdviceType = adviceType
  4597. advice.StartTime = StartTime
  4598. advice.AdviceDate = AdviceDate
  4599. advice.RecordDate = RecordDate
  4600. advice.Status = 1
  4601. advice.CreatedTime = time.Now().Unix()
  4602. advice.UpdatedTime = time.Now().Unix()
  4603. advice.StopState = 2
  4604. advice.ExecutionState = 2
  4605. advice.UserOrgId = adminUserInfo.Org.Id
  4606. advice.PatientId = patient
  4607. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4608. advice.IsSettle = 2
  4609. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4610. utils.ErrorLog("advice_name")
  4611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4612. return
  4613. }
  4614. adviceName, _ := adviceNameM["advice_name"].(string)
  4615. if len(adviceName) == 0 {
  4616. utils.ErrorLog("len(advice_name) == 0")
  4617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4618. return
  4619. }
  4620. advice.AdviceName = adviceName
  4621. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4622. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4623. advice.DrugSpec = drugSpec
  4624. }
  4625. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4626. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4627. advice.AdviceDesc = adviceDesc
  4628. }
  4629. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4630. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4631. advice.DrugSpecUnit = drugSpecUnit
  4632. }
  4633. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4634. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4635. // advice.SingleDose = singleDose
  4636. //}
  4637. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4638. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4639. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4640. }
  4641. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4642. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4643. advice.SingleDoseUnit = singleDoseUnit
  4644. }
  4645. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4646. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4647. // advice.PrescribingNumber = prescribingNumber
  4648. //}
  4649. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4650. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4651. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4652. }
  4653. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4654. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4655. advice.PrescribingNumberUnit = prescribingNumberUnit
  4656. }
  4657. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4658. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4659. advice.DeliveryWay = deliveryWay
  4660. }
  4661. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4662. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4663. advice.ExecutionFrequency = executionFrequency
  4664. }
  4665. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4666. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4667. advice.FrequencyType = frequency_type
  4668. }
  4669. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4670. day_count := int64(adviceNameM["day_count"].(float64))
  4671. advice.DayCount = day_count
  4672. }
  4673. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4674. week_day, _ := adviceNameM["week_day"].(string)
  4675. advice.WeekDay = week_day
  4676. }
  4677. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4678. way := int64(adviceNameM["way"].(float64))
  4679. advice.Way = way
  4680. }
  4681. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4682. drug_id := int64(adviceNameM["drug_id"].(float64))
  4683. advice.DrugId = drug_id
  4684. }
  4685. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4686. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4687. advice.DrugNameId = drug_name_id
  4688. }
  4689. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4690. remark, _ := adviceNameM["remark"].(string)
  4691. advice.Remark = remark
  4692. }
  4693. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4694. groupno := int64(adviceNameM["groupno"].(float64))
  4695. advice.GroupNo = groupno
  4696. }
  4697. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4698. template_id, _ := adviceNameM["template_id"].(string)
  4699. advice.TemplateId = template_id
  4700. }
  4701. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4702. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4703. advice.ExecutionFrequency = executionFrequency
  4704. }
  4705. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4706. children := adviceNameM["child"].([]interface{})
  4707. if len(children) > 0 {
  4708. for _, childrenMap := range children {
  4709. childMap := childrenMap.(map[string]interface{})
  4710. var child models.GroupAdvice
  4711. child.Remark = Remark
  4712. child.AdviceType = adviceType
  4713. child.StartTime = StartTime
  4714. child.AdviceDate = AdviceDate
  4715. child.RecordDate = RecordDate
  4716. child.Status = 1
  4717. child.CreatedTime = time.Now().Unix()
  4718. child.UpdatedTime = time.Now().Unix()
  4719. child.StopState = 2
  4720. child.ExecutionState = 2
  4721. child.UserOrgId = adminUserInfo.Org.Id
  4722. child.PatientId = patient
  4723. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4724. child.IsSettle = 1
  4725. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4726. utils.ErrorLog("child advice_name")
  4727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4728. return
  4729. }
  4730. childAdviceName, _ := childMap["advice_name"].(string)
  4731. if len(childAdviceName) == 0 {
  4732. utils.ErrorLog("len(child advice_name) == 0")
  4733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4734. return
  4735. }
  4736. child.AdviceName = childAdviceName
  4737. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4738. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4739. child.AdviceDesc = childAdviceDesc
  4740. }
  4741. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4742. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4743. child.DrugSpec = childDrugSpec
  4744. }
  4745. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4746. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4747. child.DrugSpecUnit = childDrugSpecUnit
  4748. }
  4749. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4750. child.SingleDose = childMap["single_dose"].(float64)
  4751. }
  4752. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4753. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4754. child.SingleDoseUnit = childSingleDoseUnit
  4755. }
  4756. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4757. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4758. }
  4759. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4760. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4761. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4762. }
  4763. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4764. groupno := int64(childMap["groupno"].(float64))
  4765. advice.GroupNo = groupno
  4766. }
  4767. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4768. remark, _ := childMap["remark"].(string)
  4769. child.Remark = remark
  4770. }
  4771. child.DeliveryWay = advice.DeliveryWay
  4772. child.ExecutionFrequency = advice.ExecutionFrequency
  4773. advice.Children = append(advice.Children, &child)
  4774. }
  4775. }
  4776. }
  4777. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4778. if temp_advice.ID == 0 {
  4779. advices = append(advices, &advice)
  4780. }
  4781. }
  4782. if len(advices) > 0 {
  4783. finish := models.XtDialysisFinish{
  4784. IsFinish: 1,
  4785. UserOrgId: adminUserInfo.Org.Id,
  4786. Status: 1,
  4787. Ctime: time.Now().Unix(),
  4788. Mtime: 0,
  4789. Module: 4,
  4790. RecordDate: AdviceDate,
  4791. Sourse: 1,
  4792. PatientId: patient,
  4793. }
  4794. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4795. if dialysisFinish.ID == 0 {
  4796. service.CreateDialysisFinish(finish)
  4797. }
  4798. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4799. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4800. for _, item := range advices {
  4801. byterequest, _ := json.Marshal(item)
  4802. adviceLog := models.XtDoctorAdviceLog{
  4803. UserOrgId: adminUserInfo.Org.Id,
  4804. PatientId: patient,
  4805. AdminUserId: adminUserInfo.AdminUser.Id,
  4806. Module: 1,
  4807. ErrLog: string(byterequest),
  4808. Status: 1,
  4809. Ctime: time.Now().Unix(),
  4810. Mtime: 0,
  4811. Source: "手机端医嘱推送",
  4812. RecordDate: item.AdviceDate,
  4813. }
  4814. service.CreateDoctorAdviceLog(adviceLog)
  4815. }
  4816. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4817. redis := service.RedisClient()
  4818. //清空key 值
  4819. redis.Set(key, "", time.Second)
  4820. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4821. redis.Set(keyOne, "", time.Second)
  4822. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4823. defer redis.Close()
  4824. redis.Set(keyThree, "", time.Second)
  4825. if err != nil {
  4826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4827. return
  4828. }
  4829. c.ServeSuccessJSON(map[string]interface{}{
  4830. "msg": "ok",
  4831. "advices": list,
  4832. })
  4833. } else {
  4834. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4835. for _, item := range advices {
  4836. byterequest, _ := json.Marshal(item)
  4837. adviceLog := models.XtDoctorAdviceLog{
  4838. UserOrgId: adminUserInfo.Org.Id,
  4839. PatientId: patient,
  4840. AdminUserId: adminUserInfo.AdminUser.Id,
  4841. Module: 1,
  4842. ErrLog: string(byterequest),
  4843. Status: 1,
  4844. Ctime: time.Now().Unix(),
  4845. Mtime: 0,
  4846. Source: "手机端医嘱推送",
  4847. RecordDate: item.AdviceDate,
  4848. }
  4849. service.CreateDoctorAdviceLog(adviceLog)
  4850. }
  4851. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4852. redis := service.RedisClient()
  4853. //清空key 值
  4854. redis.Set(key, "", time.Second)
  4855. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4856. redis.Set(keyOne, "", time.Second)
  4857. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4858. defer redis.Close()
  4859. redis.Set(keyThree, "", time.Second)
  4860. if err != nil {
  4861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4862. return
  4863. }
  4864. c.ServeSuccessJSON(map[string]interface{}{
  4865. "msg": "ok",
  4866. "advices": list,
  4867. })
  4868. }
  4869. } else {
  4870. c.ServeSuccessJSON(map[string]interface{}{
  4871. "msg": "ok",
  4872. })
  4873. }
  4874. return
  4875. }
  4876. func (c *DialysisAPIController) UploadDryWeight() {
  4877. patient_id, _ := c.GetInt64("id")
  4878. dry_weight, _ := c.GetFloat("dry_weight")
  4879. doctor_id, _ := c.GetInt64("doctor_id")
  4880. remark := c.GetString("remark")
  4881. adminUserInfo := c.GetMobileAdminUserInfo()
  4882. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4883. if err == gorm.ErrRecordNotFound {
  4884. dryWeight := &models.SgjPatientDryweight{
  4885. PatientId: patient_id,
  4886. DryWeight: dry_weight,
  4887. Remakes: remark,
  4888. Ctime: time.Now().Unix(),
  4889. Mtime: time.Now().Unix(),
  4890. Creator: doctor_id,
  4891. Status: 1,
  4892. UserOrgId: adminUserInfo.Org.Id,
  4893. AdjustedValue: "/",
  4894. UserId: adminUserInfo.AdminUser.Id,
  4895. }
  4896. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4897. redis := service.RedisClient()
  4898. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4899. redis.Set(keyOne, "", time.Second)
  4900. loc, _ := time.LoadLocation("Local")
  4901. nowTime := time.Now()
  4902. nowDay := nowTime.Format("2006-01-02")
  4903. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4904. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4905. redis.Set(key, "", time.Second)
  4906. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4907. redis.Set(keyTwo, "", time.Second)
  4908. redis.Close()
  4909. if createErr == nil {
  4910. c.ServeSuccessJSON(map[string]interface{}{
  4911. "msg": "提交成功",
  4912. "weight": dryWeight,
  4913. })
  4914. }
  4915. } else {
  4916. dryWeight := &models.SgjPatientDryweight{
  4917. PatientId: patient_id,
  4918. DryWeight: dry_weight,
  4919. Remakes: remark,
  4920. Ctime: time.Now().Unix(),
  4921. Mtime: time.Now().Unix(),
  4922. Creator: doctor_id,
  4923. Status: 1,
  4924. UserOrgId: adminUserInfo.Org.Id,
  4925. AdjustedValue: "/",
  4926. UserId: adminUserInfo.AdminUser.Id,
  4927. }
  4928. var value float64
  4929. value = dry_weight - weightAdjust.DryWeight
  4930. if value < 0 {
  4931. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4932. } else if value == 0 {
  4933. dryWeight.AdjustedValue = "/"
  4934. } else if value > 0 {
  4935. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4936. }
  4937. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4938. redis := service.RedisClient()
  4939. loc, _ := time.LoadLocation("Local")
  4940. nowTime := time.Now()
  4941. nowDay := nowTime.Format("2006-01-02")
  4942. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4943. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4944. redis.Set(keyOne, "", time.Second)
  4945. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4946. redis.Set(key, "", time.Second)
  4947. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4948. redis.Set(keyTwo, "", time.Second)
  4949. redis.Close()
  4950. if createErr == nil {
  4951. c.ServeSuccessJSON(map[string]interface{}{
  4952. "msg": "提交成功",
  4953. "weight": dryWeight,
  4954. })
  4955. }
  4956. }
  4957. }
  4958. func (c *DialysisAPIController) GetSolution() {
  4959. patient_id, _ := c.GetInt64("patient_id")
  4960. mode_id, _ := c.GetInt64("mode_id")
  4961. adminUserInfo := c.GetMobileAdminUserInfo()
  4962. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4963. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4964. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4965. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4966. if err != nil {
  4967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4968. return
  4969. }
  4970. c.ServeSuccessJSON(map[string]interface{}{
  4971. "solution": solution,
  4972. "prescription": prescription,
  4973. "system_prescription": system_prescription,
  4974. "dialysisPrescription": dialysisPrescription,
  4975. })
  4976. }
  4977. func (c *DialysisAPIController) GetSchedule() {
  4978. schedual_type, _ := c.GetInt64("schedual_type")
  4979. adminUserInfo := c.GetMobileAdminUserInfo()
  4980. scheduleTime, _ := c.GetInt64("record_date")
  4981. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4982. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4983. c.ServeSuccessJSON(map[string]interface{}{
  4984. "number": deviceNumber,
  4985. "list": list,
  4986. })
  4987. }
  4988. func (c *DialysisAPIController) GetPatientId() {
  4989. id, _ := c.GetInt64("id")
  4990. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4991. patientId, _ := service.GetPatientId(id)
  4992. //获取该患者的所有传染病
  4993. list, _ := service.GetPatientInfectious(id)
  4994. c.ServeSuccessJSON(map[string]interface{}{
  4995. "patient": patientId,
  4996. "infectioulist": list,
  4997. })
  4998. }
  4999. func (this *DialysisAPIController) GetDialysisSchedule() {
  5000. schedualDate := this.GetString("date")
  5001. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5002. if parseDateErr != nil {
  5003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5004. return
  5005. }
  5006. adminInfo := this.GetMobileAdminUserInfo()
  5007. orgID := adminInfo.Org.Id
  5008. redis := service.RedisClient()
  5009. defer redis.Close()
  5010. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5011. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5012. if len(scheduals) > 0 {
  5013. //缓存数据
  5014. scheduals_json, err := json.Marshal(scheduals)
  5015. if err == nil {
  5016. redis.Set(key, scheduals_json, time.Second*30)
  5017. }
  5018. }
  5019. this.ServeSuccessJSON(map[string]interface{}{
  5020. "scheduals": scheduals,
  5021. })
  5022. }
  5023. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5024. change_type, _ := this.GetInt64("type", 0)
  5025. record_date := this.GetString("record_time")
  5026. patient_id, _ := this.GetInt64("patient_id", 0)
  5027. timeLayout := "2006-01-02"
  5028. loc, _ := time.LoadLocation("Local")
  5029. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5030. record_time := theAdviceRecordTime.Unix()
  5031. adminUserInfo := this.GetMobileAdminUserInfo()
  5032. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5033. if err == nil {
  5034. if len(advices) == 0 {
  5035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5036. return
  5037. } else {
  5038. this.ServeSuccessJSON(map[string]interface{}{
  5039. "advices": advices,
  5040. "schedule": sch,
  5041. })
  5042. return
  5043. }
  5044. } else {
  5045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5046. return
  5047. }
  5048. }
  5049. func (c *DialysisAPIController) CreateConsumables() {
  5050. record_date := c.GetString("record_time")
  5051. patient_id, _ := c.GetInt64("patient_id", 0)
  5052. active, _ := c.GetInt64("active")
  5053. adminUser := c.GetMobileAdminUserInfo()
  5054. timeLayout := "2006-01-02"
  5055. loc, _ := time.LoadLocation("Local")
  5056. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5057. record_time := theRecordTime.Unix()
  5058. // 查询信息规挡的设置天数
  5059. orgid := c.GetMobileAdminUserInfo().Org.Id
  5060. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5061. if infor.ID > 0 {
  5062. var cha_time int64
  5063. timeNowStr := time.Now().Format("2006-01-02")
  5064. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5065. //今日的日期减去设置的日期
  5066. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5067. if cha_time >= record_time {
  5068. //查询审核是否允许
  5069. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5070. //申请状态不允许的情况 拒绝修改
  5071. if infor.ApplicationStatus != 1 {
  5072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5073. return
  5074. }
  5075. }
  5076. }
  5077. dataBody := make(map[string]interface{}, 0)
  5078. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5079. if err != nil {
  5080. utils.ErrorLog(err.Error())
  5081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5082. return
  5083. }
  5084. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5085. var beforePrepares []*models.DialysisBeforePrepareGoods
  5086. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5087. var dialysisBefor []*models.DialysisBeforePrepare
  5088. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5089. goods, _ := dataBody["goods"].([]interface{})
  5090. if len(goods) > 0 {
  5091. for _, item := range goods {
  5092. items := item.(map[string]interface{})
  5093. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5094. utils.ErrorLog("good_id")
  5095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5096. return
  5097. }
  5098. good_id := int64(items["good_id"].(float64))
  5099. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5100. utils.ErrorLog("good_type_id")
  5101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5102. return
  5103. }
  5104. good_type_id := int64(items["good_type_id"].(float64))
  5105. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5106. utils.ErrorLog("count")
  5107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5108. return
  5109. }
  5110. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5111. commdity_code := items["commdity_code"].(string)
  5112. fmt.Println("commdity", commdity_code)
  5113. prepareGoods := &models.DialysisBeforePrepareGoods{
  5114. GoodTypeId: good_type_id,
  5115. GoodId: good_id,
  5116. Count: count,
  5117. StorehouseId: houseConfig.StorehouseOutInfo,
  5118. }
  5119. beforePrepares = append(beforePrepares, prepareGoods)
  5120. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5121. GoodTypeId: good_type_id,
  5122. GoodId: good_id,
  5123. Count: count,
  5124. StorehouseId: houseConfig.StorehouseOutInfo,
  5125. }
  5126. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5127. prepare := &models.DialysisBeforePrepare{
  5128. GoodTypeId: good_type_id,
  5129. GoodId: good_id,
  5130. Count: count,
  5131. PatientId: patient_id,
  5132. RecordDate: record_time,
  5133. UserOrgId: adminUser.Org.Id,
  5134. Status: 1,
  5135. Ctime: time.Now().Unix(),
  5136. Creater: adminUser.AdminUser.Id,
  5137. CommdityCode: commdity_code,
  5138. StorehouseId: houseConfig.StorehouseOutInfo,
  5139. }
  5140. dialysisBefor = append(dialysisBefor, prepare)
  5141. }
  5142. }
  5143. //查询是否有库存
  5144. for _, item := range dialysisBefor {
  5145. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5146. if err == gorm.ErrRecordNotFound {
  5147. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5148. c.ServeSuccessJSON(map[string]interface{}{
  5149. "message": "1",
  5150. "good_name": goodObj.GoodName,
  5151. "specification_name": goodObj.SpecificationName,
  5152. })
  5153. return
  5154. }
  5155. if err != nil {
  5156. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5157. c.ServeSuccessJSON(map[string]interface{}{
  5158. "message": "1",
  5159. "good_name": goodObj.GoodName,
  5160. "specification_name": goodObj.SpecificationName,
  5161. })
  5162. return
  5163. }
  5164. }
  5165. //新增
  5166. if active == 1 && len(goods) > 0 {
  5167. for _, item := range dialysisBefor {
  5168. dialyPrepareOne := models.DialysisBeforePrepare{
  5169. GoodTypeId: item.GoodTypeId,
  5170. GoodId: item.GoodId,
  5171. PatientId: item.PatientId,
  5172. RecordDate: item.RecordDate,
  5173. UserOrgId: item.UserOrgId,
  5174. Count: item.Count,
  5175. Ctime: time.Now().Unix(),
  5176. Creater: item.Creater,
  5177. CommdityCode: item.CommdityCode,
  5178. Status: 1,
  5179. StorehouseId: houseConfig.StorehouseOutInfo,
  5180. }
  5181. //先清除再插入
  5182. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5183. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5184. //查询默认仓库
  5185. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5186. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5187. var total_count int64
  5188. for _, it := range stockList {
  5189. total_count += it.StockCount
  5190. }
  5191. //基础库插入数据
  5192. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5193. //更新库存
  5194. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5195. var flush_count int64
  5196. for _, it := range goodList {
  5197. flush_count += it.StockCount
  5198. }
  5199. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5200. }
  5201. if err == nil {
  5202. c.ServeSuccessJSON(map[string]interface{}{
  5203. "msg": "保存成功",
  5204. "message": "2",
  5205. })
  5206. return
  5207. } else {
  5208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5209. return
  5210. }
  5211. }
  5212. if len(beforePrepares) > 0 && active == 2 {
  5213. for _, item := range beforePrepares {
  5214. //1.查看该患者该耗材型号最后一次出库数量
  5215. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5216. //判断当前出库数量和最后一次出库数量的大小
  5217. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5218. if item.Count <= goodInfo.Count {
  5219. //退库
  5220. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5221. //查询今日出库数据
  5222. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5223. for _, it := range list {
  5224. prepare := models.DialysisBeforePrepare{
  5225. UserOrgId: it.OrgId,
  5226. PatientId: patient_id,
  5227. RecordDate: it.RecordTime,
  5228. GoodId: it.GoodId,
  5229. GoodTypeId: it.GoodTypeId,
  5230. Count: it.Count,
  5231. Ctime: time.Now().Unix(),
  5232. Creater: adminUser.AdminUser.Id,
  5233. Status: 1,
  5234. StorehouseId: houseConfig.StorehouseOutInfo,
  5235. }
  5236. //删除准备表数据
  5237. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5238. service.CreateDialysisBeforePrepareOne(&prepare)
  5239. }
  5240. }
  5241. var last_total int64
  5242. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5243. if item.Count >= goodInfo.Count {
  5244. //查询当前批次当前耗材最后一条出库数据
  5245. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5246. //计算当前出库和最后一次出库数据相差数据
  5247. last_total = item.Count - lastOutInfo.Count
  5248. //查询该批次剩余库存
  5249. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5250. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5251. if lastInfo.StockCount >= last_total {
  5252. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5253. //查询今日出库数据
  5254. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5255. for _, it := range list {
  5256. prepare := models.DialysisBeforePrepare{
  5257. UserOrgId: it.OrgId,
  5258. PatientId: patient_id,
  5259. RecordDate: it.RecordTime,
  5260. GoodId: it.GoodId,
  5261. GoodTypeId: it.GoodTypeId,
  5262. Count: it.Count,
  5263. Ctime: time.Now().Unix(),
  5264. Creater: adminUser.AdminUser.Id,
  5265. Status: 1,
  5266. StorehouseId: houseConfig.StorehouseOutInfo,
  5267. }
  5268. //删除准备表数据
  5269. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5270. service.CreateDialysisBeforePrepareOne(&prepare)
  5271. //查询默认仓库
  5272. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5273. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5274. var total_count int64
  5275. for _, it := range stockList {
  5276. total_count += it.StockCount
  5277. }
  5278. //基础库插入数据
  5279. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5280. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5281. var flush_count int64
  5282. for _, it := range goodList {
  5283. flush_count += it.StockCount
  5284. }
  5285. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5286. }
  5287. }
  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. if err != nil {
  5326. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5327. c.ServeSuccessJSON(map[string]interface{}{
  5328. "message": "1",
  5329. "good_name": goodObj.GoodName,
  5330. "specification_name": goodObj.SpecificationName,
  5331. })
  5332. return
  5333. }
  5334. }
  5335. }
  5336. if err != nil {
  5337. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5338. c.ServeSuccessJSON(map[string]interface{}{
  5339. "message": "1",
  5340. "good_name": goodObj.GoodName,
  5341. "specification_name": goodObj.SpecificationName,
  5342. })
  5343. return
  5344. }
  5345. }
  5346. }
  5347. }
  5348. var errs error
  5349. if errs == nil {
  5350. c.ServeSuccessJSON(map[string]interface{}{
  5351. "msg": "提交成功",
  5352. "message": "2",
  5353. "good_name": "",
  5354. "specification_name": "",
  5355. })
  5356. return
  5357. } else {
  5358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5359. return
  5360. }
  5361. }
  5362. func (c *DialysisAPIController) CreateStockOutInfo() {
  5363. patient_id, _ := c.GetInt64("patient_id", 0)
  5364. record_date := c.GetString("record_time")
  5365. if patient_id <= 0 {
  5366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5367. return
  5368. }
  5369. adminInfo := c.GetMobileAdminUserInfo()
  5370. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5371. timeLayout := "2006-01-02"
  5372. loc, _ := time.LoadLocation("Local")
  5373. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5374. record_time := theRecordTime.Unix()
  5375. // 查询信息规挡的设置天数
  5376. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5377. if infor.ID > 0 && infor.WeekDay > 0 {
  5378. var cha_time int64
  5379. timeNowStr := time.Now().Format("2006-01-02")
  5380. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5381. //今日的日期减去设置的日期
  5382. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5383. if cha_time >= record_time {
  5384. //查询审核是否允许
  5385. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5386. //申请状态不允许的情况 拒绝修改
  5387. if infor.ApplicationStatus != 1 {
  5388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5389. return
  5390. }
  5391. }
  5392. }
  5393. //创建步骤表
  5394. finish := models.XtDialysisFinish{
  5395. IsFinish: 1,
  5396. UserOrgId: adminInfo.Org.Id,
  5397. Status: 1,
  5398. Ctime: time.Now().Unix(),
  5399. Mtime: 0,
  5400. Module: 11,
  5401. RecordDate: record_time,
  5402. Sourse: 1,
  5403. PatientId: patient_id,
  5404. }
  5405. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5406. if dialysisFinish.ID == 0 {
  5407. service.CreateDialysisFinish(finish)
  5408. }
  5409. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5410. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5411. //去重
  5412. consumables = RemoveRepeatedGood(consumables)
  5413. if adminInfo.Org.Id == 9919 {
  5414. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5415. //查询是否有库存
  5416. for _, item := range consumables {
  5417. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5418. if item.Count > warehouse.Count {
  5419. goodErrcode := models.XtGoodErrcode{
  5420. UserOrgId: item.UserOrgId,
  5421. Errcode: "自动出库库存不足",
  5422. GoodId: item.GoodId,
  5423. Status: 1,
  5424. Ctime: time.Now().Unix(),
  5425. Mtime: 0,
  5426. Count: 0,
  5427. StockCount: 0,
  5428. Creater: creator,
  5429. BatchNumberId: warehouse.ID,
  5430. WarehouseOutId: 0,
  5431. }
  5432. service.CreateGoodErrcode(goodErrcode)
  5433. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5434. c.ServeSuccessJSON(map[string]interface{}{
  5435. "message": "1",
  5436. "good_name": goodObj.GoodName,
  5437. "specification_name": goodObj.SpecificationName,
  5438. })
  5439. return
  5440. }
  5441. }
  5442. //查询是否有出库单
  5443. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5444. if err == gorm.ErrRecordNotFound {
  5445. //没有记录,则创建出库单
  5446. timeStr := time.Now().Format("2006-01-02")
  5447. timeArr := strings.Split(timeStr, "-")
  5448. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5449. total = total + 1
  5450. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5451. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5452. number = number + total
  5453. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5454. creater := adminInfo.AdminUser.Id
  5455. warehouseOut := models.WarehouseOut{
  5456. WarehouseOutOrderNumber: warehousing_out_order,
  5457. OperationTime: time.Now().Unix(),
  5458. OrgId: adminInfo.Org.Id,
  5459. Creater: creater,
  5460. Ctime: time.Now().Unix(),
  5461. Status: 1,
  5462. WarehouseOutTime: record_time,
  5463. Dealer: 0,
  5464. Manufacturer: 0,
  5465. Type: 1,
  5466. IsSys: 1,
  5467. StorehouseId: houseConfig.StorehouseOutInfo,
  5468. IsCheck: 1,
  5469. }
  5470. err := service.AddSigleWarehouseOut(&warehouseOut)
  5471. if err != nil {
  5472. goodErrcode := models.XtGoodErrcode{
  5473. UserOrgId: adminInfo.Org.Id,
  5474. Errcode: "创建出库单失败",
  5475. GoodId: 0,
  5476. Status: 1,
  5477. Ctime: time.Now().Unix(),
  5478. Mtime: 0,
  5479. Count: 0,
  5480. StockCount: 0,
  5481. Creater: creator,
  5482. BatchNumberId: 0,
  5483. WarehouseOutId: 0,
  5484. }
  5485. service.CreateGoodErrcode(goodErrcode)
  5486. utils.TraceLog("创建出库单失败 err = %v", err)
  5487. } else {
  5488. for _, item := range consumables {
  5489. //出库
  5490. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5491. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5492. if err == nil {
  5493. goodErrcode := models.XtGoodErrcode{
  5494. UserOrgId: adminInfo.Org.Id,
  5495. Errcode: "自动出库接口报错",
  5496. GoodId: 0,
  5497. Status: 1,
  5498. Ctime: time.Now().Unix(),
  5499. Mtime: 0,
  5500. Count: 0,
  5501. StockCount: 0,
  5502. Creater: creator,
  5503. BatchNumberId: 0,
  5504. WarehouseOutId: 0,
  5505. }
  5506. service.CreateGoodErrcode(goodErrcode)
  5507. utils.TraceLog("创建出库单失败 err = %v", err)
  5508. }
  5509. //查询
  5510. //出库数量相加
  5511. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5512. if errs != nil {
  5513. goodErrcode := models.XtGoodErrcode{
  5514. UserOrgId: item.UserOrgId,
  5515. Errcode: "创建剩余库存字段报错",
  5516. GoodId: item.GoodId,
  5517. Status: 1,
  5518. Ctime: time.Now().Unix(),
  5519. Mtime: 0,
  5520. Count: 0,
  5521. StockCount: 0,
  5522. Creater: creater,
  5523. BatchNumberId: 0,
  5524. WarehouseOutId: 0,
  5525. }
  5526. service.CreateGoodErrcode(goodErrcode)
  5527. }
  5528. }
  5529. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5530. if len(list) == 0 {
  5531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5532. return
  5533. }
  5534. for _, item := range list {
  5535. prepare := models.DialysisBeforePrepare{
  5536. UserOrgId: adminInfo.Org.Id,
  5537. PatientId: patient_id,
  5538. RecordDate: record_time,
  5539. GoodId: item.GoodId,
  5540. GoodTypeId: item.GoodTypeId,
  5541. Count: item.Count,
  5542. Creater: adminInfo.AdminUser.Id,
  5543. Status: 1,
  5544. Ctime: time.Now().Unix(),
  5545. StorehouseId: houseConfig.StorehouseOutInfo,
  5546. }
  5547. //清空准备表数据
  5548. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5549. if err != nil {
  5550. goodErrcode := models.XtGoodErrcode{
  5551. UserOrgId: item.OrgId,
  5552. Errcode: "自动出库清空准备表数据报错",
  5553. GoodId: item.GoodId,
  5554. Status: 1,
  5555. Ctime: time.Now().Unix(),
  5556. Mtime: 0,
  5557. Count: 0,
  5558. StockCount: 0,
  5559. Creater: creater,
  5560. BatchNumberId: 0,
  5561. WarehouseOutId: 0,
  5562. }
  5563. service.CreateGoodErrcode(goodErrcode)
  5564. }
  5565. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5566. if errs != nil {
  5567. goodErrcode := models.XtGoodErrcode{
  5568. UserOrgId: item.OrgId,
  5569. Errcode: "自动出库创建准备表数据报错",
  5570. GoodId: item.GoodId,
  5571. Status: 1,
  5572. Ctime: time.Now().Unix(),
  5573. Mtime: 0,
  5574. Count: 0,
  5575. StockCount: 0,
  5576. Creater: creater,
  5577. BatchNumberId: 0,
  5578. WarehouseOutId: 0,
  5579. }
  5580. service.CreateGoodErrcode(goodErrcode)
  5581. }
  5582. //查询默认仓库
  5583. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5584. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5585. var total_count int64
  5586. for _, it := range stockList {
  5587. total_count += it.StockCount
  5588. }
  5589. //基础库插入数据
  5590. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5591. if errcodes != nil {
  5592. goodErrcode := models.XtGoodErrcode{
  5593. UserOrgId: item.OrgId,
  5594. Errcode: "自动出库基础库插入数据",
  5595. GoodId: item.GoodId,
  5596. Status: 1,
  5597. Ctime: time.Now().Unix(),
  5598. Mtime: 0,
  5599. Count: 0,
  5600. StockCount: 0,
  5601. Creater: creater,
  5602. BatchNumberId: 0,
  5603. WarehouseOutId: 0,
  5604. }
  5605. service.CreateGoodErrcode(goodErrcode)
  5606. }
  5607. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5608. var flush_count int64
  5609. for _, it := range goodList {
  5610. flush_count += it.StockCount
  5611. }
  5612. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5613. if errsss != nil {
  5614. goodErrcode := models.XtGoodErrcode{
  5615. UserOrgId: item.OrgId,
  5616. Errcode: "自动出库剩余库存更新数据",
  5617. GoodId: item.GoodId,
  5618. Status: 1,
  5619. Ctime: time.Now().Unix(),
  5620. Mtime: 0,
  5621. Count: 0,
  5622. StockCount: 0,
  5623. Creater: creater,
  5624. BatchNumberId: 0,
  5625. WarehouseOutId: 0,
  5626. }
  5627. service.CreateGoodErrcode(goodErrcode)
  5628. }
  5629. }
  5630. }
  5631. //
  5632. } else if err == nil {
  5633. for _, item := range consumables {
  5634. //出库
  5635. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5636. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5637. if err != nil {
  5638. goodErrcode := models.XtGoodErrcode{
  5639. UserOrgId: adminInfo.Org.Id,
  5640. Errcode: "自动出库接口报错",
  5641. GoodId: 0,
  5642. Status: 1,
  5643. Ctime: time.Now().Unix(),
  5644. Mtime: 0,
  5645. Count: 0,
  5646. StockCount: 0,
  5647. Creater: creator,
  5648. BatchNumberId: 0,
  5649. WarehouseOutId: 0,
  5650. }
  5651. service.CreateGoodErrcode(goodErrcode)
  5652. }
  5653. //出库数量相加
  5654. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5655. if errss != nil {
  5656. goodErrcode := models.XtGoodErrcode{
  5657. UserOrgId: item.UserOrgId,
  5658. Errcode: "创建剩余库存字段报错",
  5659. GoodId: item.GoodId,
  5660. Status: 1,
  5661. Ctime: time.Now().Unix(),
  5662. Mtime: time.Now().Unix(),
  5663. Count: 0,
  5664. StockCount: 0,
  5665. Creater: item.Creater,
  5666. BatchNumberId: 0,
  5667. WarehouseOutId: 0,
  5668. }
  5669. service.CreateGoodErrcode(goodErrcode)
  5670. }
  5671. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5672. if len(list) == 0 {
  5673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5674. return
  5675. }
  5676. for _, item := range list {
  5677. prepare := models.DialysisBeforePrepare{
  5678. UserOrgId: adminInfo.Org.Id,
  5679. PatientId: patient_id,
  5680. RecordDate: record_time,
  5681. GoodId: item.GoodId,
  5682. GoodTypeId: item.GoodTypeId,
  5683. Count: item.Count,
  5684. Creater: adminInfo.AdminUser.Id,
  5685. Status: 1,
  5686. Ctime: time.Now().Unix(),
  5687. StorehouseId: houseConfig.StorehouseOutInfo,
  5688. }
  5689. //清空准备表数据
  5690. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5691. if errs != nil {
  5692. goodErrcode := models.XtGoodErrcode{
  5693. UserOrgId: adminInfo.Org.Id,
  5694. Errcode: "自动出库清空准备表数据报错",
  5695. GoodId: 0,
  5696. Status: 1,
  5697. Ctime: time.Now().Unix(),
  5698. Mtime: 0,
  5699. Count: 0,
  5700. StockCount: 0,
  5701. Creater: creator,
  5702. BatchNumberId: 0,
  5703. WarehouseOutId: 0,
  5704. }
  5705. service.CreateGoodErrcode(goodErrcode)
  5706. }
  5707. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5708. if errcodes != nil {
  5709. goodErrcode := models.XtGoodErrcode{
  5710. UserOrgId: adminInfo.Org.Id,
  5711. Errcode: "自动出库创建准备表数据报错",
  5712. GoodId: 0,
  5713. Status: 1,
  5714. Ctime: time.Now().Unix(),
  5715. Mtime: 0,
  5716. Count: 0,
  5717. StockCount: 0,
  5718. Creater: creator,
  5719. BatchNumberId: 0,
  5720. WarehouseOutId: 0,
  5721. }
  5722. service.CreateGoodErrcode(goodErrcode)
  5723. }
  5724. //查询默认仓库
  5725. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5726. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5727. var total_count int64
  5728. for _, it := range stockList {
  5729. total_count += it.StockCount
  5730. }
  5731. //基础库插入数据
  5732. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5733. if errcodes != nil {
  5734. goodErrcode := models.XtGoodErrcode{
  5735. UserOrgId: adminInfo.Org.Id,
  5736. Errcode: "自动出库基础库插入数据报错",
  5737. GoodId: 0,
  5738. Status: 1,
  5739. Ctime: time.Now().Unix(),
  5740. Mtime: 0,
  5741. Count: 0,
  5742. StockCount: 0,
  5743. Creater: creator,
  5744. BatchNumberId: 0,
  5745. WarehouseOutId: 0,
  5746. }
  5747. service.CreateGoodErrcode(goodErrcode)
  5748. }
  5749. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5750. var flush_count int64
  5751. for _, it := range goodList {
  5752. flush_count += it.StockCount
  5753. }
  5754. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5755. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5756. if errss != nil {
  5757. goodErrcode := models.XtGoodErrcode{
  5758. UserOrgId: item.OrgId,
  5759. Errcode: "自动出库剩余库存更新数据",
  5760. GoodId: item.GoodId,
  5761. Status: 1,
  5762. Ctime: time.Now().Unix(),
  5763. Mtime: 0,
  5764. Count: 0,
  5765. StockCount: 0,
  5766. Creater: creater,
  5767. BatchNumberId: 0,
  5768. WarehouseOutId: 0,
  5769. }
  5770. service.CreateGoodErrcode(goodErrcode)
  5771. }
  5772. }
  5773. }
  5774. }
  5775. c.ServeSuccessJSON(map[string]interface{}{
  5776. "msg": "提交成功",
  5777. "message": "2",
  5778. "good_name": "",
  5779. "specification_name": "",
  5780. })
  5781. return
  5782. }
  5783. if record.IsOpen == 1 {
  5784. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5785. //查询是否有库存
  5786. for _, item := range consumables {
  5787. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5788. if item.Count > warehouse.Count {
  5789. goodErrcode := models.XtGoodErrcode{
  5790. UserOrgId: item.UserOrgId,
  5791. Errcode: "自动出库库存不足",
  5792. GoodId: item.GoodId,
  5793. Status: 1,
  5794. Ctime: time.Now().Unix(),
  5795. Mtime: 0,
  5796. Count: 0,
  5797. StockCount: 0,
  5798. Creater: creator,
  5799. BatchNumberId: warehouse.ID,
  5800. WarehouseOutId: 0,
  5801. }
  5802. service.CreateGoodErrcode(goodErrcode)
  5803. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5804. c.ServeSuccessJSON(map[string]interface{}{
  5805. "message": "1",
  5806. "good_name": goodObj.GoodName,
  5807. "specification_name": goodObj.SpecificationName,
  5808. })
  5809. return
  5810. }
  5811. }
  5812. //查询是否有出库单
  5813. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5814. if err == gorm.ErrRecordNotFound {
  5815. //没有记录,则创建出库单
  5816. timeStr := time.Now().Format("2006-01-02")
  5817. timeArr := strings.Split(timeStr, "-")
  5818. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5819. total = total + 1
  5820. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5821. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5822. number = number + total
  5823. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5824. creater := adminInfo.AdminUser.Id
  5825. warehouseOut := models.WarehouseOut{
  5826. WarehouseOutOrderNumber: warehousing_out_order,
  5827. OperationTime: time.Now().Unix(),
  5828. OrgId: adminInfo.Org.Id,
  5829. Creater: creater,
  5830. Ctime: time.Now().Unix(),
  5831. Status: 1,
  5832. WarehouseOutTime: record_time,
  5833. Dealer: 0,
  5834. Manufacturer: 0,
  5835. Type: 1,
  5836. IsSys: 1,
  5837. StorehouseId: houseConfig.StorehouseOutInfo,
  5838. IsCheck: 1,
  5839. }
  5840. err := service.AddSigleWarehouseOut(&warehouseOut)
  5841. if err != nil {
  5842. goodErrcode := models.XtGoodErrcode{
  5843. UserOrgId: adminInfo.Org.Id,
  5844. Errcode: "创建出库单失败",
  5845. GoodId: 0,
  5846. Status: 1,
  5847. Ctime: time.Now().Unix(),
  5848. Mtime: 0,
  5849. Count: 0,
  5850. StockCount: 0,
  5851. Creater: creator,
  5852. BatchNumberId: 0,
  5853. WarehouseOutId: 0,
  5854. }
  5855. service.CreateGoodErrcode(goodErrcode)
  5856. utils.TraceLog("创建出库单失败 err = %v", err)
  5857. } else {
  5858. for _, item := range consumables {
  5859. //出库
  5860. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5861. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5862. if err == nil {
  5863. goodErrcode := models.XtGoodErrcode{
  5864. UserOrgId: adminInfo.Org.Id,
  5865. Errcode: "自动出库接口报错",
  5866. GoodId: 0,
  5867. Status: 1,
  5868. Ctime: time.Now().Unix(),
  5869. Mtime: 0,
  5870. Count: 0,
  5871. StockCount: 0,
  5872. Creater: creator,
  5873. BatchNumberId: 0,
  5874. WarehouseOutId: 0,
  5875. }
  5876. service.CreateGoodErrcode(goodErrcode)
  5877. utils.TraceLog("创建出库单失败 err = %v", err)
  5878. }
  5879. //查询
  5880. //出库数量相加
  5881. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5882. if errs != nil {
  5883. goodErrcode := models.XtGoodErrcode{
  5884. UserOrgId: item.UserOrgId,
  5885. Errcode: "创建剩余库存字段报错",
  5886. GoodId: item.GoodId,
  5887. Status: 1,
  5888. Ctime: time.Now().Unix(),
  5889. Mtime: 0,
  5890. Count: 0,
  5891. StockCount: 0,
  5892. Creater: creater,
  5893. BatchNumberId: 0,
  5894. WarehouseOutId: 0,
  5895. }
  5896. service.CreateGoodErrcode(goodErrcode)
  5897. }
  5898. }
  5899. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5900. if len(list) == 0 {
  5901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5902. return
  5903. }
  5904. for _, item := range list {
  5905. prepare := models.DialysisBeforePrepare{
  5906. UserOrgId: adminInfo.Org.Id,
  5907. PatientId: patient_id,
  5908. RecordDate: record_time,
  5909. GoodId: item.GoodId,
  5910. GoodTypeId: item.GoodTypeId,
  5911. Count: item.Count,
  5912. Creater: adminInfo.AdminUser.Id,
  5913. Status: 1,
  5914. Ctime: time.Now().Unix(),
  5915. StorehouseId: houseConfig.StorehouseOutInfo,
  5916. }
  5917. //清空准备表数据
  5918. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5919. if err != nil {
  5920. goodErrcode := models.XtGoodErrcode{
  5921. UserOrgId: item.OrgId,
  5922. Errcode: "自动出库清空准备表数据报错",
  5923. GoodId: item.GoodId,
  5924. Status: 1,
  5925. Ctime: time.Now().Unix(),
  5926. Mtime: 0,
  5927. Count: 0,
  5928. StockCount: 0,
  5929. Creater: creater,
  5930. BatchNumberId: 0,
  5931. WarehouseOutId: 0,
  5932. }
  5933. service.CreateGoodErrcode(goodErrcode)
  5934. }
  5935. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5936. if errs != nil {
  5937. goodErrcode := models.XtGoodErrcode{
  5938. UserOrgId: item.OrgId,
  5939. Errcode: "自动出库创建准备表数据报错",
  5940. GoodId: item.GoodId,
  5941. Status: 1,
  5942. Ctime: time.Now().Unix(),
  5943. Mtime: 0,
  5944. Count: 0,
  5945. StockCount: 0,
  5946. Creater: creater,
  5947. BatchNumberId: 0,
  5948. WarehouseOutId: 0,
  5949. }
  5950. service.CreateGoodErrcode(goodErrcode)
  5951. }
  5952. //查询默认仓库
  5953. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5954. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5955. var total_count int64
  5956. for _, it := range stockList {
  5957. total_count += it.StockCount
  5958. }
  5959. //基础库插入数据
  5960. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5961. if errcodes != nil {
  5962. goodErrcode := models.XtGoodErrcode{
  5963. UserOrgId: item.OrgId,
  5964. Errcode: "自动出库基础库插入数据",
  5965. GoodId: item.GoodId,
  5966. Status: 1,
  5967. Ctime: time.Now().Unix(),
  5968. Mtime: 0,
  5969. Count: 0,
  5970. StockCount: 0,
  5971. Creater: creater,
  5972. BatchNumberId: 0,
  5973. WarehouseOutId: 0,
  5974. }
  5975. service.CreateGoodErrcode(goodErrcode)
  5976. }
  5977. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5978. var flush_count int64
  5979. for _, it := range goodList {
  5980. flush_count += it.StockCount
  5981. }
  5982. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5983. if errsss != nil {
  5984. goodErrcode := models.XtGoodErrcode{
  5985. UserOrgId: item.OrgId,
  5986. Errcode: "自动出库剩余库存更新数据",
  5987. GoodId: item.GoodId,
  5988. Status: 1,
  5989. Ctime: time.Now().Unix(),
  5990. Mtime: 0,
  5991. Count: 0,
  5992. StockCount: 0,
  5993. Creater: creater,
  5994. BatchNumberId: 0,
  5995. WarehouseOutId: 0,
  5996. }
  5997. service.CreateGoodErrcode(goodErrcode)
  5998. }
  5999. }
  6000. }
  6001. //
  6002. } else if err == nil {
  6003. for _, item := range consumables {
  6004. //出库
  6005. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6006. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6007. if err != nil {
  6008. goodErrcode := models.XtGoodErrcode{
  6009. UserOrgId: adminInfo.Org.Id,
  6010. Errcode: "自动出库接口报错",
  6011. GoodId: 0,
  6012. Status: 1,
  6013. Ctime: time.Now().Unix(),
  6014. Mtime: 0,
  6015. Count: 0,
  6016. StockCount: 0,
  6017. Creater: creator,
  6018. BatchNumberId: 0,
  6019. WarehouseOutId: 0,
  6020. }
  6021. service.CreateGoodErrcode(goodErrcode)
  6022. }
  6023. //出库数量相加
  6024. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6025. if errss != nil {
  6026. goodErrcode := models.XtGoodErrcode{
  6027. UserOrgId: item.UserOrgId,
  6028. Errcode: "创建剩余库存字段报错",
  6029. GoodId: item.GoodId,
  6030. Status: 1,
  6031. Ctime: time.Now().Unix(),
  6032. Mtime: time.Now().Unix(),
  6033. Count: 0,
  6034. StockCount: 0,
  6035. Creater: item.Creater,
  6036. BatchNumberId: 0,
  6037. WarehouseOutId: 0,
  6038. }
  6039. service.CreateGoodErrcode(goodErrcode)
  6040. }
  6041. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6042. if len(list) == 0 {
  6043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6044. return
  6045. }
  6046. for _, item := range list {
  6047. prepare := models.DialysisBeforePrepare{
  6048. UserOrgId: adminInfo.Org.Id,
  6049. PatientId: patient_id,
  6050. RecordDate: record_time,
  6051. GoodId: item.GoodId,
  6052. GoodTypeId: item.GoodTypeId,
  6053. Count: item.Count,
  6054. Creater: adminInfo.AdminUser.Id,
  6055. Status: 1,
  6056. Ctime: time.Now().Unix(),
  6057. StorehouseId: houseConfig.StorehouseOutInfo,
  6058. }
  6059. //清空准备表数据
  6060. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6061. if errs != nil {
  6062. goodErrcode := models.XtGoodErrcode{
  6063. UserOrgId: adminInfo.Org.Id,
  6064. Errcode: "自动出库清空准备表数据报错",
  6065. GoodId: 0,
  6066. Status: 1,
  6067. Ctime: time.Now().Unix(),
  6068. Mtime: 0,
  6069. Count: 0,
  6070. StockCount: 0,
  6071. Creater: creator,
  6072. BatchNumberId: 0,
  6073. WarehouseOutId: 0,
  6074. }
  6075. service.CreateGoodErrcode(goodErrcode)
  6076. }
  6077. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6078. if errcodes != nil {
  6079. goodErrcode := models.XtGoodErrcode{
  6080. UserOrgId: adminInfo.Org.Id,
  6081. Errcode: "自动出库创建准备表数据报错",
  6082. GoodId: 0,
  6083. Status: 1,
  6084. Ctime: time.Now().Unix(),
  6085. Mtime: 0,
  6086. Count: 0,
  6087. StockCount: 0,
  6088. Creater: creator,
  6089. BatchNumberId: 0,
  6090. WarehouseOutId: 0,
  6091. }
  6092. service.CreateGoodErrcode(goodErrcode)
  6093. }
  6094. //查询默认仓库
  6095. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6096. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6097. var total_count int64
  6098. for _, it := range stockList {
  6099. total_count += it.StockCount
  6100. }
  6101. //基础库插入数据
  6102. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6103. if errcodes != nil {
  6104. goodErrcode := models.XtGoodErrcode{
  6105. UserOrgId: adminInfo.Org.Id,
  6106. Errcode: "自动出库基础库插入数据报错",
  6107. GoodId: 0,
  6108. Status: 1,
  6109. Ctime: time.Now().Unix(),
  6110. Mtime: 0,
  6111. Count: 0,
  6112. StockCount: 0,
  6113. Creater: creator,
  6114. BatchNumberId: 0,
  6115. WarehouseOutId: 0,
  6116. }
  6117. service.CreateGoodErrcode(goodErrcode)
  6118. }
  6119. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6120. var flush_count int64
  6121. for _, it := range goodList {
  6122. flush_count += it.StockCount
  6123. }
  6124. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6125. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6126. if errss != nil {
  6127. goodErrcode := models.XtGoodErrcode{
  6128. UserOrgId: item.OrgId,
  6129. Errcode: "自动出库剩余库存更新数据",
  6130. GoodId: item.GoodId,
  6131. Status: 1,
  6132. Ctime: time.Now().Unix(),
  6133. Mtime: 0,
  6134. Count: 0,
  6135. StockCount: 0,
  6136. Creater: creater,
  6137. BatchNumberId: 0,
  6138. WarehouseOutId: 0,
  6139. }
  6140. service.CreateGoodErrcode(goodErrcode)
  6141. }
  6142. }
  6143. }
  6144. }
  6145. c.ServeSuccessJSON(map[string]interface{}{
  6146. "msg": "提交成功",
  6147. "message": "2",
  6148. "good_name": "",
  6149. "specification_name": "",
  6150. })
  6151. return
  6152. } else {
  6153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6154. return
  6155. }
  6156. }
  6157. func (c *DialysisAPIController) EditConsumables() {
  6158. patient_id, _ := c.GetInt64("patient_id", 0)
  6159. record_date := c.GetString("record_time")
  6160. if patient_id <= 0 {
  6161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6162. return
  6163. }
  6164. adminInfo := c.GetMobileAdminUserInfo()
  6165. timeLayout := "2006-01-02"
  6166. loc, _ := time.LoadLocation("Local")
  6167. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6168. record_time := theRecordTime.Unix()
  6169. // 查询信息规挡的设置天数
  6170. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6171. if infor.ID > 0 && infor.WeekDay > 0 {
  6172. var cha_time int64
  6173. timeNowStr := time.Now().Format("2006-01-02")
  6174. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6175. //今日的日期减去设置的日期
  6176. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6177. if cha_time >= record_time {
  6178. //查询审核是否允许
  6179. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6180. //申请状态不允许的情况 拒绝修改
  6181. if infor.ApplicationStatus != 1 {
  6182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6183. return
  6184. }
  6185. }
  6186. }
  6187. dataBody := make(map[string]interface{}, 0)
  6188. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6189. if err != nil {
  6190. utils.ErrorLog(err.Error())
  6191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6192. return
  6193. }
  6194. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6195. var beforePrepares []*models.DialysisBeforePrepareGoods
  6196. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6197. var cancelbefor []*models.DialysisBeforePrepareGoods
  6198. var outbefor []*models.DialysisBeforePrepareGoods
  6199. //判断是否开启自动出库
  6200. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6201. if record.IsOpen == 1 {
  6202. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6203. goods, _ := dataBody["goods"].([]interface{})
  6204. if len(goods) > 0 {
  6205. for _, item := range goods {
  6206. items := item.(map[string]interface{})
  6207. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6208. utils.ErrorLog("good_id")
  6209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6210. return
  6211. }
  6212. good_id := int64(items["good_id"].(float64))
  6213. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6214. utils.ErrorLog("good_type_id")
  6215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6216. return
  6217. }
  6218. good_type_id := int64(items["good_type_id"].(float64))
  6219. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6220. utils.ErrorLog("count")
  6221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6222. return
  6223. }
  6224. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6225. commdity_code := items["commdity_code"].(string)
  6226. fmt.Println(commdity_code)
  6227. prepareGoods := &models.DialysisBeforePrepareGoods{
  6228. GoodTypeId: good_type_id,
  6229. GoodId: good_id,
  6230. Count: count,
  6231. StorehouseId: houseConfig.StorehouseOutInfo,
  6232. }
  6233. beforePrepares = append(beforePrepares, prepareGoods)
  6234. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6235. GoodTypeId: good_type_id,
  6236. GoodId: good_id,
  6237. Count: count,
  6238. StorehouseId: houseConfig.StorehouseOutInfo,
  6239. }
  6240. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6241. }
  6242. for _, item := range beforePrepares {
  6243. //1.查看该患者该耗材型号最后一次出库数量
  6244. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6245. //判断当前出库数量和最后一次出库数量的大小
  6246. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6247. if item.Count < goodInfo.Count {
  6248. cancelbefor = append(cancelbefor, item)
  6249. }
  6250. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6251. if item.Count > goodInfo.Count {
  6252. outbefor = append(outbefor, item)
  6253. }
  6254. //处理编辑耗材新增不了的问题
  6255. if goodInfo.Count == item.Count {
  6256. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6257. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6258. }
  6259. }
  6260. if len(cancelbefor) > 0 {
  6261. //退库
  6262. for _, item := range cancelbefor {
  6263. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6264. creater := adminInfo.AdminUser.Id
  6265. //查询该患者当天已经出库的耗材信息
  6266. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6267. var delete_count int64 = 0
  6268. delete_count = warehouseOutInfos.Count - item.Count
  6269. //增加库存数量
  6270. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6271. //减少实际出库库存数量
  6272. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6273. // 删除出库完成后,要增加对应批次的库存数量
  6274. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6275. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6276. //更新剩余库存
  6277. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6278. var flush_count int64
  6279. for _, it := range goodListOne {
  6280. flush_count += it.StockCount
  6281. }
  6282. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6283. //查询剩余库存
  6284. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6285. var sum_count int64
  6286. for _, item := range goodList {
  6287. sum_count += item.StockCount
  6288. }
  6289. // 在出库记录表里记录退库详情
  6290. warehouseOutInfo := &models.WarehouseOutInfo{
  6291. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6292. WarehouseOutId: warehouseOut.ID,
  6293. Status: 1,
  6294. Ctime: time.Now().Unix(),
  6295. OrgId: adminInfo.Org.Id,
  6296. Type: 1,
  6297. IsSys: 1,
  6298. SysRecordTime: record_time,
  6299. GoodTypeId: item.GoodTypeId,
  6300. GoodId: item.GoodId,
  6301. PatientId: patient_id,
  6302. ConsumableType: 2,
  6303. StorehouseId: houseConfig.StorehouseOutInfo,
  6304. IsCheck: 1,
  6305. OverCount: sum_count,
  6306. }
  6307. warehouseOutInfo.Count = item.Count
  6308. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6309. warehouseOutInfo.Price = stockInInfo.Price
  6310. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6311. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6312. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6313. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6314. warehouseOutInfo.Number = warehouseOutInfos.Number
  6315. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6316. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6317. //查找当天是否存在出库记录
  6318. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6319. if errcod == gorm.ErrRecordNotFound {
  6320. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6321. //插入详情明细表
  6322. stockFlow := models.VmStockFlow{
  6323. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6324. WarehouseOutId: warehouseOut.ID,
  6325. GoodId: item.GoodId,
  6326. Number: warehouseOutInfos.Number,
  6327. ProductDate: stockInInfo.ProductDate,
  6328. ExpireDate: stockInInfo.ExpiryDate,
  6329. Count: item.Count,
  6330. Price: stockInInfo.Price,
  6331. Status: 1,
  6332. Ctime: time.Now().Unix(),
  6333. UserOrgId: adminInfo.Org.Id,
  6334. Manufacturer: stockInInfo.Manufacturer,
  6335. Dealer: stockInInfo.Dealer,
  6336. LicenseNumber: stockInInfo.LicenseNumber,
  6337. IsEdit: 2,
  6338. Creator: creater,
  6339. SystemTime: record_time,
  6340. ConsumableType: 3,
  6341. WarehousingDetailId: 0,
  6342. IsSys: 1,
  6343. UpdateCreator: creater,
  6344. PatientId: patient_id,
  6345. StorehouseId: houseConfig.StorehouseOutInfo,
  6346. }
  6347. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6348. if errflow == gorm.ErrRecordNotFound {
  6349. //创建流水表
  6350. err := service.CreateStockFlowOne(stockFlow)
  6351. fmt.Println("err", err)
  6352. } else if errflow == nil {
  6353. //插入详情明细表
  6354. stockFlow := models.VmStockFlow{
  6355. ID: exsit.ID,
  6356. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6357. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6358. WarehouseOutId: warehouseOut.ID,
  6359. GoodId: item.GoodId,
  6360. Number: warehouseOutInfos.Number,
  6361. ProductDate: stockInInfo.ProductDate,
  6362. ExpireDate: stockInInfo.ExpiryDate,
  6363. Count: exsit.Count - delete_count,
  6364. Price: stockInInfo.Price,
  6365. Status: 1,
  6366. Ctime: time.Now().Unix(),
  6367. UserOrgId: adminInfo.Org.Id,
  6368. Manufacturer: stockInInfo.Manufacturer,
  6369. Dealer: stockInInfo.Dealer,
  6370. LicenseNumber: stockInInfo.LicenseNumber,
  6371. IsEdit: 2,
  6372. Creator: creater,
  6373. SystemTime: record_time,
  6374. ConsumableType: 3,
  6375. WarehousingDetailId: 0,
  6376. IsSys: 1,
  6377. UpdateCreator: creater,
  6378. PatientId: patient_id,
  6379. StorehouseId: houseConfig.StorehouseOutInfo,
  6380. }
  6381. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6382. }
  6383. } else if errcod == nil {
  6384. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6385. //查询剩余库存
  6386. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6387. var sum_count int64
  6388. for _, item := range goodList {
  6389. sum_count += item.StockCount
  6390. }
  6391. //创建退库单,生成退库数据
  6392. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6393. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6394. operation_time := time.Now().Unix()
  6395. creater := adminInfo.AdminUser.Id
  6396. //创建退库单
  6397. timeStr := time.Now().Format("2006-01-02")
  6398. timeArr := strings.Split(timeStr, "-")
  6399. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6400. total = total + 1
  6401. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6402. cancelStock := models.CancelStock{
  6403. OrderNumber: orderNumber,
  6404. OperaTime: operation_time,
  6405. OrgId: adminInfo.Org.Id,
  6406. Creater: creater,
  6407. Ctime: time.Now().Unix(),
  6408. Status: 1,
  6409. ReturnTime: record_time,
  6410. Type: 1,
  6411. StorehouseId: houseConfig.StorehouseOutInfo,
  6412. IsCheck: 1,
  6413. }
  6414. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6415. if msgerrkonde == gorm.ErrRecordNotFound {
  6416. service.AddSigleCancelStock(&cancelStock)
  6417. }
  6418. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6419. //查询是否有出库
  6420. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6421. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6422. deaerler, _ := service.GetDealerById(info.Dealer)
  6423. if info.ID > 0 {
  6424. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6425. cancelStockInfo := models.CancelStockInfo{
  6426. GoodId: item.GoodId,
  6427. CancelStockId: cancel.ID,
  6428. GoodTypeId: good.GoodTypeId,
  6429. Count: delete_count,
  6430. Price: info.Price,
  6431. Total: 0,
  6432. ProductDate: info.ProductDate,
  6433. ExpiryDate: info.ExpiryDate,
  6434. Ctime: time.Now().Unix(),
  6435. Status: 1,
  6436. OrgId: adminInfo.Org.Id,
  6437. OrderNumber: cancel.OrderNumber,
  6438. Type: 0,
  6439. Dealer: deaerler.DealerName,
  6440. Manufacturer: manufacturer.ManufacturerName,
  6441. Number: info.Number,
  6442. RegisterAccount: "",
  6443. Remark: "",
  6444. WarehouseInfoId: info.WarehouseInfotId,
  6445. PatientId: info.PatientId,
  6446. RecordDate: info.SysRecordTime,
  6447. StorehouseId: houseConfig.StorehouseOutInfo,
  6448. IsCheck: 1,
  6449. }
  6450. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6451. //退库数量增加
  6452. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6453. //查询剩余库存
  6454. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6455. var over_count int64
  6456. for _, it := range goodList {
  6457. over_count += it.StockCount
  6458. }
  6459. flow := models.VmStockFlow{
  6460. WarehousingId: info.WarehouseInfotId,
  6461. GoodId: item.GoodId,
  6462. Number: info.Number,
  6463. LicenseNumber: info.LicenseNumber,
  6464. Count: delete_count,
  6465. UserOrgId: adminInfo.Org.Id,
  6466. PatientId: patient_id,
  6467. SystemTime: info.SysRecordTime,
  6468. ConsumableType: 7,
  6469. IsSys: 0,
  6470. WarehousingOrder: "",
  6471. WarehouseOutId: info.WarehouseOutId,
  6472. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6473. IsEdit: 0,
  6474. CancelStockId: cancel.ID,
  6475. CancelOrderNumber: cancel.OrderNumber,
  6476. Manufacturer: manufacturer.ID,
  6477. Dealer: 0,
  6478. Creator: adminInfo.AdminUser.Id,
  6479. UpdateCreator: 0,
  6480. Status: 1,
  6481. Ctime: time.Now().Unix(),
  6482. Mtime: 0,
  6483. Price: info.Price,
  6484. WarehousingDetailId: info.WarehouseInfotId,
  6485. WarehouseOutDetailId: info.ID,
  6486. CancelOutDetailId: cancelInfo.ID,
  6487. ProductDate: info.ProductDate,
  6488. ExpireDate: info.ExpiryDate,
  6489. StorehouseId: houseConfig.StorehouseOutInfo,
  6490. OverCount: over_count,
  6491. }
  6492. service.CreateStockFlowOne(flow)
  6493. }
  6494. }
  6495. //更改自动出库的表格
  6496. details := models.BloodAutomaticReduceDetail{
  6497. WarehouseOutId: warehouseOutInfo.ID,
  6498. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6499. PatientId: patient_id,
  6500. Ctime: time.Now().Unix(),
  6501. Mtime: time.Now().Unix(),
  6502. Status: 1,
  6503. RecordTime: record_time,
  6504. OrgId: adminInfo.Org.Id,
  6505. GoodId: item.GoodId,
  6506. GoodTypeId: item.GoodTypeId,
  6507. Count: item.Count,
  6508. StorehouseId: houseConfig.StorehouseOutInfo,
  6509. }
  6510. //查询当天耗材是否已经存在数据
  6511. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6512. if errcode == gorm.ErrRecordNotFound {
  6513. service.CreateAutoReduceRecord(&details)
  6514. } else if errcode == nil {
  6515. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6516. service.CreateAutoReduceRecord(&details)
  6517. }
  6518. //查询默认仓库
  6519. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6520. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6521. var total_count int64
  6522. for _, it := range stockList {
  6523. total_count += it.StockCount
  6524. }
  6525. //基础库插入数据
  6526. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6527. }
  6528. }
  6529. if len(outbefor) > 0 {
  6530. //出库
  6531. for _, item := range outbefor {
  6532. var last_total int64
  6533. //1.查看该患者该耗材型号最后一次出库数量
  6534. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6535. //计算当前出库和最后一次出库数据相差数据
  6536. last_total = item.Count - goodInfoOne.Count
  6537. //查询该耗材的总库存
  6538. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6539. // 如果库存差大于剩余库存则提示库存不足
  6540. if last_total > wareinfo.StockCount {
  6541. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6542. c.ServeSuccessJSON(map[string]interface{}{
  6543. "message": "1",
  6544. "good_name": goodObj.GoodName,
  6545. "specification_name": goodObj.SpecificationName,
  6546. })
  6547. return
  6548. } else {
  6549. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6550. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6551. if err == gorm.ErrRecordNotFound {
  6552. //没有记录,则创建出库单
  6553. timeStr := time.Now().Format("2006-01-02")
  6554. timeArr := strings.Split(timeStr, "-")
  6555. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6556. total = total + 1
  6557. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6558. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6559. number = number + total
  6560. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6561. warehouseOut := models.WarehouseOut{
  6562. WarehouseOutOrderNumber: warehousing_out_order,
  6563. OperationTime: time.Now().Unix(),
  6564. OrgId: adminInfo.Org.Id,
  6565. Creater: adminInfo.AdminUser.Id,
  6566. Ctime: time.Now().Unix(),
  6567. Status: 1,
  6568. WarehouseOutTime: record_time,
  6569. Dealer: 0,
  6570. Manufacturer: 0,
  6571. Type: 1,
  6572. IsSys: 1,
  6573. StorehouseId: houseConfig.StorehouseOutInfo,
  6574. IsCheck: 1,
  6575. }
  6576. service.AddSigleWarehouseOut(&warehouseOut)
  6577. }
  6578. //出库
  6579. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6580. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6581. //1.查看该患者该耗材型号最后一次出库数量
  6582. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6583. prepare := models.DialysisBeforePrepare{
  6584. UserOrgId: adminInfo.Org.Id,
  6585. PatientId: patient_id,
  6586. RecordDate: record_time,
  6587. GoodId: item.GoodId,
  6588. GoodTypeId: item.GoodTypeId,
  6589. Count: item.Count - goodInfoTwo.Count,
  6590. Ctime: time.Now().Unix(),
  6591. Mtime: 0,
  6592. Creater: adminInfo.AdminUser.Id,
  6593. Modifier: adminInfo.AdminUser.Id,
  6594. Status: 1,
  6595. CommdityCode: "",
  6596. NewCount: 0,
  6597. ProjectId: 0,
  6598. StorehouseId: houseConfig.StorehouseOutInfo,
  6599. }
  6600. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6601. //增加出库数量
  6602. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6603. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6604. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6605. var total_count int64
  6606. for _, it := range stockList {
  6607. total_count += it.StockCount
  6608. }
  6609. //基础库插入数据
  6610. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6611. //剩余库存
  6612. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6613. var flush_count int64
  6614. for _, it := range goodList {
  6615. flush_count += it.StockCount
  6616. }
  6617. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6618. }
  6619. }
  6620. }
  6621. //查询今日出库数据
  6622. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6623. for _, it := range list {
  6624. prepare := models.DialysisBeforePrepare{
  6625. UserOrgId: it.OrgId,
  6626. PatientId: patient_id,
  6627. RecordDate: it.RecordTime,
  6628. GoodId: it.GoodId,
  6629. GoodTypeId: it.GoodTypeId,
  6630. Count: it.Count,
  6631. Ctime: time.Now().Unix(),
  6632. Creater: adminInfo.AdminUser.Id,
  6633. Status: 1,
  6634. StorehouseId: houseConfig.StorehouseOutInfo,
  6635. ProjectId: it.ProjectId,
  6636. }
  6637. //删除准备表数据
  6638. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6639. service.CreateDialysisBeforePrepareOne(&prepare)
  6640. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6641. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6642. var total_count int64
  6643. for _, it := range stockList {
  6644. total_count += it.StockCount
  6645. }
  6646. //基础库插入数据
  6647. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6648. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6649. var flush_count int64
  6650. for _, it := range goodList {
  6651. flush_count += it.StockCount
  6652. }
  6653. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6654. }
  6655. }
  6656. }
  6657. //更新自动出库的地方
  6658. var errs error
  6659. if errs == nil {
  6660. c.ServeSuccessJSON(map[string]interface{}{
  6661. "msg": "修改成功",
  6662. "message": "2",
  6663. "good_name": "",
  6664. "specification_name": "",
  6665. })
  6666. return
  6667. } else {
  6668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6669. return
  6670. }
  6671. }
  6672. }
  6673. func (c *DialysisAPIController) GetDialysisGoods() {
  6674. schedualDate := c.GetString("schedule_date")
  6675. schedule_type, _ := c.GetInt64("schedule_type")
  6676. partition_id, _ := c.GetInt64("partition_id")
  6677. page, _ := c.GetInt("page")
  6678. patient_id, _ := c.GetInt64("patient_id")
  6679. schedualEndDate := int64(0)
  6680. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6681. if parseDateErr != nil && len(schedualDate) != 0 {
  6682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6683. return
  6684. }
  6685. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6686. if parseDateErr != nil && len(schedualDate) != 0 {
  6687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6688. return
  6689. }
  6690. schedualEndDate = endDate.Unix()
  6691. adminUser := c.GetMobileAdminUserInfo()
  6692. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6693. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6694. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6695. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6696. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6697. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6698. //获取当天该病人的透析处方
  6699. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6700. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6701. if err == gorm.ErrRecordNotFound {
  6702. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6703. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6704. if patient_id != 0 {
  6705. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6706. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6707. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6708. //获取患者总的出库数据
  6709. item.LastAutomaticReduceDetail = goodUser
  6710. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6711. item.Project = project
  6712. }
  6713. }
  6714. c.ServeSuccessJSON(map[string]interface{}{
  6715. "dialysis_goods": dialysisGoods,
  6716. "good_type": goodTypes,
  6717. "total": total,
  6718. "prescribe": prescribe,
  6719. "good_info": good_info,
  6720. "warehouseOutList": warehouseOutList,
  6721. "config": config,
  6722. "outConfig": outConfig,
  6723. "settleConfig": settleConfig,
  6724. })
  6725. return
  6726. } else if err == nil {
  6727. //获取当天排班的每个患者的库存使用情况
  6728. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6729. //获取患者总的出库数据
  6730. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6731. if patient_id != 0 {
  6732. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6733. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6734. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6735. item.Project = project
  6736. item.LastAutomaticReduceDetail = goodUser
  6737. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6738. }
  6739. }
  6740. if err == nil {
  6741. c.ServeSuccessJSON(map[string]interface{}{
  6742. "dialysis_goods": dialysisGoods,
  6743. "good_type": goodTypes,
  6744. "total": total,
  6745. "prescribe": prescribe,
  6746. "good_info": good_info,
  6747. "project": project,
  6748. "warehouseOutList": warehouseOutList,
  6749. "config": config,
  6750. "outConfig": outConfig,
  6751. "settleConfig": settleConfig,
  6752. })
  6753. return
  6754. } else {
  6755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6756. return
  6757. }
  6758. } else if err != nil {
  6759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6760. return
  6761. }
  6762. }
  6763. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6764. start_time := c.GetString("start_time")
  6765. end_time := c.GetString("end_time")
  6766. timeLayout := "2006-01-02"
  6767. loc, _ := time.LoadLocation("Local")
  6768. var theStartTime int64
  6769. if len(start_time) > 0 {
  6770. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6771. if err != nil {
  6772. utils.ErrorLog(err.Error())
  6773. }
  6774. theStartTime = theTime.Unix()
  6775. }
  6776. var theEndtTime int64
  6777. if len(end_time) > 0 {
  6778. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6779. if err != nil {
  6780. utils.ErrorLog(err.Error())
  6781. }
  6782. theEndtTime = theTime.Unix()
  6783. }
  6784. adminUser := c.GetMobileAdminUserInfo()
  6785. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6786. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6787. if err == nil {
  6788. c.ServeSuccessJSON(map[string]interface{}{
  6789. "stock_out": outInfo,
  6790. "stockCount": stockCount,
  6791. })
  6792. return
  6793. } else {
  6794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6795. return
  6796. }
  6797. }
  6798. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6799. patient_id, _ := c.GetInt64("patient_id", 0)
  6800. record_time := c.GetString("record_time")
  6801. adminUser := c.GetMobileAdminUserInfo()
  6802. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6803. if parseDateErr != nil && len(record_time) != 0 {
  6804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6805. return
  6806. }
  6807. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6808. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6809. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6810. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6811. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6812. //获取今日患者的透析处方参数
  6813. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6814. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6815. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6816. c.ServeSuccessJSON(map[string]interface{}{
  6817. "good_type": goodTypes,
  6818. "good_user": goodUser,
  6819. "good_info": good_info,
  6820. "last_good_user": lastGoodUserDetial,
  6821. "project": project,
  6822. "prescription": prescribe,
  6823. "outInfo": outInfo,
  6824. "configs": configs,
  6825. })
  6826. return
  6827. }
  6828. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6829. patient_id, _ := c.GetInt64("patient_id", 0)
  6830. record_date := c.GetString("record_time")
  6831. timeLayout := "2006-01-02"
  6832. loc, _ := time.LoadLocation("Local")
  6833. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6834. record_time := theRecordTime.Unix()
  6835. adminInfo := c.GetMobileAdminUserInfo()
  6836. dataBody := make(map[string]interface{}, 0)
  6837. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6838. if err != nil {
  6839. utils.ErrorLog(err.Error())
  6840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6841. return
  6842. }
  6843. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6844. var beforePrepares []*models.DialysisBeforePrepareGoods
  6845. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6846. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6847. goods, _ := dataBody["goods"].([]interface{})
  6848. if len(goods) > 0 {
  6849. for _, item := range goods {
  6850. items := item.(map[string]interface{})
  6851. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6852. utils.ErrorLog("good_id")
  6853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6854. return
  6855. }
  6856. good_id := int64(items["good_id"].(float64))
  6857. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6858. utils.ErrorLog("good_type_id")
  6859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6860. return
  6861. }
  6862. good_type_id := int64(items["good_type_id"].(float64))
  6863. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6864. utils.ErrorLog("count")
  6865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6866. return
  6867. }
  6868. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6869. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6870. utils.ErrorLog("project_id")
  6871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6872. return
  6873. }
  6874. project_id := int64(items["project_id"].(float64))
  6875. new_count := int64(items["new_count"].(float64))
  6876. old_count := int64(items["old_count"].(float64))
  6877. prepare := &models.DialysisBeforePrepareGoods{
  6878. GoodId: good_id,
  6879. GoodTypeId: good_type_id,
  6880. Count: count,
  6881. ProjectId: project_id,
  6882. StorehouseId: houseConfig.StorehouseOutInfo,
  6883. NewCount: new_count,
  6884. OldCount: old_count,
  6885. }
  6886. beforePrepares = append(beforePrepares, prepare)
  6887. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6888. GoodId: good_id,
  6889. GoodTypeId: good_type_id,
  6890. Count: count,
  6891. ProjectId: project_id,
  6892. StorehouseId: houseConfig.StorehouseOutInfo,
  6893. NewCount: new_count,
  6894. OldCount: old_count,
  6895. }
  6896. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6897. }
  6898. }
  6899. }
  6900. //查询是否有库存
  6901. for _, item := range beforePrepares {
  6902. if item.NewCount > 0 {
  6903. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6904. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6905. if item.Count > warehouse.Count {
  6906. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6907. c.ServeSuccessJSON(map[string]interface{}{
  6908. "message": "1",
  6909. "good_name": goodObj.GoodName,
  6910. "specification_name": goodObj.SpecificationName,
  6911. })
  6912. return
  6913. }
  6914. }
  6915. }
  6916. // 查询信息规挡的设置天数
  6917. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6918. if infor.ID > 0 && infor.WeekDay > 0 {
  6919. var cha_time int64
  6920. timeNowStr := time.Now().Format("2006-01-02")
  6921. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6922. //今日的日期减去设置的日期
  6923. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6924. if cha_time >= record_time {
  6925. //查询审核是否允许
  6926. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6927. //申请状态不允许的情况 拒绝修改
  6928. if infor.ApplicationStatus != 1 {
  6929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6930. return
  6931. }
  6932. }
  6933. }
  6934. //出库逻辑
  6935. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6936. if err != nil {
  6937. utils.ErrorLog(err.Error())
  6938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6939. return
  6940. }
  6941. finish := models.XtDialysisFinish{
  6942. IsFinish: 1,
  6943. UserOrgId: adminInfo.Org.Id,
  6944. Status: 1,
  6945. Ctime: time.Now().Unix(),
  6946. Mtime: 0,
  6947. Module: 11,
  6948. RecordDate: record_time,
  6949. Sourse: 1,
  6950. PatientId: patient_id,
  6951. }
  6952. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6953. if dialysisFinish.ID == 0 {
  6954. service.CreateDialysisFinish(finish)
  6955. }
  6956. //查询当天出库的数据
  6957. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6958. for _, item := range list {
  6959. prepare := models.DialysisBeforePrepare{
  6960. UserOrgId: item.OrgId,
  6961. PatientId: item.PatientId,
  6962. RecordDate: item.RecordTime,
  6963. GoodId: item.GoodId,
  6964. GoodTypeId: item.GoodTypeId,
  6965. Count: item.Count,
  6966. Creater: adminInfo.AdminUser.Id,
  6967. Status: 1,
  6968. Ctime: time.Now().Unix(),
  6969. ProjectId: item.ProjectId,
  6970. StorehouseId: houseConfig.StorehouseOutInfo,
  6971. }
  6972. //清空准备表的数据
  6973. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6974. //插入准备表数据
  6975. service.CreateDialysisBeforePrepareOne(&prepare)
  6976. //查询默认仓库
  6977. //查询默认仓库
  6978. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6979. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6980. var total_count int64
  6981. for _, it := range stockList {
  6982. total_count += it.StockCount
  6983. }
  6984. //基础库插入数据
  6985. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6986. ////更新剩余库存
  6987. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6988. var flush_count int64
  6989. for _, it := range goodList {
  6990. flush_count += it.StockCount
  6991. }
  6992. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6993. if errs != nil {
  6994. goodErrcode := models.XtGoodErrcode{
  6995. UserOrgId: item.OrgId,
  6996. Errcode: "手动出库更新剩余出库失败",
  6997. GoodId: item.GoodId,
  6998. Status: 1,
  6999. Ctime: time.Now().Unix(),
  7000. Mtime: 0,
  7001. Count: 0,
  7002. StockCount: 0,
  7003. Creater: adminInfo.AdminUser.Id,
  7004. BatchNumberId: 0,
  7005. WarehouseOutId: 0,
  7006. }
  7007. service.CreateGoodErrcode(goodErrcode)
  7008. }
  7009. }
  7010. //更新自动出库的地方
  7011. var errs error
  7012. if errs == nil {
  7013. c.ServeSuccessJSON(map[string]interface{}{
  7014. "msg": "修改成功",
  7015. "message": "2",
  7016. "good_name": "",
  7017. "specification_name": "",
  7018. })
  7019. return
  7020. } else {
  7021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7022. return
  7023. }
  7024. }
  7025. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7026. newArr = make([]*models.DialysisBeforePrepare, 0)
  7027. for i := 0; i < len(arr); i++ {
  7028. repeat := false
  7029. for j := i + 1; j < len(arr); j++ {
  7030. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7031. repeat = true
  7032. break
  7033. }
  7034. }
  7035. if !repeat {
  7036. newArr = append(newArr, arr[i])
  7037. }
  7038. }
  7039. return
  7040. }
  7041. func (c *DialysisAPIController) GetAllDrug() {
  7042. patient_id, _ := c.GetInt64("patient_id", 0)
  7043. adminInfo := c.GetMobileAdminUserInfo()
  7044. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7045. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7046. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7047. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7048. c.ServeSuccessJSON(map[string]interface{}{
  7049. "base_drug_config": drugStockConfig,
  7050. "private_drug_config": privateDrugConfig,
  7051. "base_drug_list": drugList,
  7052. "private_drug_list": privateDrugList,
  7053. })
  7054. }
  7055. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7056. newArr = make([]*models.DialysisBeforePrepare, 0)
  7057. for i := 0; i < len(arr); i++ {
  7058. repeat := false
  7059. for j := i + 1; j < len(arr); j++ {
  7060. if arr[i].GoodId == arr[j].GoodId {
  7061. repeat = true
  7062. break
  7063. }
  7064. }
  7065. if !repeat {
  7066. newArr = append(newArr, arr[i])
  7067. }
  7068. }
  7069. return
  7070. }
  7071. func (c *DialysisAPIController) GetDepartment() {
  7072. adminInfo := c.GetMobileAdminUserInfo()
  7073. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7074. if err == nil {
  7075. c.ServeSuccessJSON(map[string]interface{}{
  7076. "departments": departments,
  7077. })
  7078. } else {
  7079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7080. return
  7081. }
  7082. }
  7083. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7084. types, _ := c.GetInt("type", 0)
  7085. start_time := c.GetString("start_time")
  7086. end_time := c.GetString("end_time")
  7087. orgId := c.GetMobileAdminUserInfo().Org.Id
  7088. timeLayout := "2006-01-02"
  7089. loc, _ := time.LoadLocation("Local")
  7090. var startTime int64
  7091. if len(start_time) > 0 {
  7092. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7093. if err != nil {
  7094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7095. return
  7096. }
  7097. startTime = theTime.Unix()
  7098. }
  7099. var endTime int64
  7100. if len(end_time) > 0 {
  7101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7102. if err != nil {
  7103. utils.ErrorLog(err.Error())
  7104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7105. return
  7106. }
  7107. endTime = theTime.Unix()
  7108. }
  7109. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7110. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7111. if err != nil {
  7112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7113. } else {
  7114. c.ServeSuccessJSON(map[string]interface{}{
  7115. "list": list,
  7116. "type": types,
  7117. "stockTotal": stockTotal,
  7118. })
  7119. }
  7120. }
  7121. func (c *DialysisAPIController) GetPrescriptionList() {
  7122. start_time := c.GetString("start_time")
  7123. end_time := c.GetString("end_time")
  7124. schedule_type, _ := c.GetInt64("schedule_type")
  7125. partion_id, _ := c.GetInt64("partion_id")
  7126. orgId := c.GetMobileAdminUserInfo().Org.Id
  7127. timeLayout := "2006-01-02"
  7128. loc, _ := time.LoadLocation("Local")
  7129. var startTime int64
  7130. if len(start_time) > 0 {
  7131. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7132. if err != nil {
  7133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7134. return
  7135. }
  7136. startTime = theTime.Unix()
  7137. }
  7138. var endTime int64
  7139. if len(end_time) > 0 {
  7140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7141. if err != nil {
  7142. utils.ErrorLog(err.Error())
  7143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7144. return
  7145. }
  7146. endTime = theTime.Unix()
  7147. }
  7148. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7149. fmt.Println("schedulelist22222222", schedulelist)
  7150. c.ServeSuccessJSON(map[string]interface{}{
  7151. "list": schedulelist,
  7152. })
  7153. return
  7154. }
  7155. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7156. ids := c.GetString("ids")
  7157. //patient_id, _ := c.GetInt64("patient_id")
  7158. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7159. idArray := strings.Split(ids, ",")
  7160. err := service.BatchDeleteMonitor(idArray)
  7161. fmt.Print("err", err)
  7162. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7163. //redis := service.RedisClient()
  7164. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7165. //redis.Set(key, "", time.Second)
  7166. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7167. //redis.Set(keyOne, "", time.Second)
  7168. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7169. //redis.Close()
  7170. c.ServeSuccessJSON(map[string]interface{}{
  7171. "msg": "批量删除成功",
  7172. })
  7173. return
  7174. }
  7175. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7176. id, _ := c.GetInt64("id")
  7177. timeLayout := "2006-01-02"
  7178. loc, _ := time.LoadLocation("Local")
  7179. //start_time := time.Now().Format("2006-01-02")
  7180. start_time := c.GetString("start_time")
  7181. end_time := c.GetString("end_time")
  7182. var startdateunix int64
  7183. if len(start_time) > 0 {
  7184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7185. if err != nil {
  7186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7187. return
  7188. }
  7189. startdateunix = theTime.Unix()
  7190. }
  7191. var enddateunix int64
  7192. if len(end_time) > 0 {
  7193. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7194. if err != nil {
  7195. utils.ErrorLog(err.Error())
  7196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7197. return
  7198. }
  7199. enddateunix = theTime.Unix()
  7200. }
  7201. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7202. //nowTime := time.Now()
  7203. //endTime := nowTime.AddDate(-30, 0, 0)
  7204. //endTimes := endTime.Format("2006-01-02")
  7205. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7206. org_id := c.GetMobileAdminUserInfo().Org.Id
  7207. //if org_id == 10579 {
  7208. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7209. // c.ServeSuccessJSON(map[string]interface{}{
  7210. // "list": list,
  7211. // })
  7212. // return
  7213. //} else {
  7214. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7215. // c.ServeSuccessJSON(map[string]interface{}{
  7216. // "list": list,
  7217. // })
  7218. // return
  7219. //}
  7220. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7221. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7222. c.ServeSuccessJSON(map[string]interface{}{
  7223. "list": list,
  7224. })
  7225. return
  7226. } else {
  7227. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7228. c.ServeSuccessJSON(map[string]interface{}{
  7229. "list": list,
  7230. })
  7231. }
  7232. return
  7233. }
  7234. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7235. dataBody := make(map[string]interface{}, 0)
  7236. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7237. ids := c.GetString("ids")
  7238. idArray := strings.Split(ids, ",")
  7239. origin, _ := c.GetInt64("origin")
  7240. if origin == 1 {
  7241. err = service.BatchDeleteAdvice(idArray)
  7242. fmt.Print("err", err)
  7243. c.ServeSuccessJSON(map[string]interface{}{
  7244. "msg": "批量删除成功",
  7245. })
  7246. return
  7247. }
  7248. if origin == 2 {
  7249. service.BatchDeleteHisAdvice(idArray)
  7250. }
  7251. }
  7252. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7253. good_id, _ := c.GetInt64("good_id")
  7254. count, _ := c.GetInt64("count")
  7255. record_time, _ := c.GetInt64("record_time")
  7256. patient_id, _ := c.GetInt64("patient_id")
  7257. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7258. c.ServeSuccessJSON(map[string]interface{}{
  7259. "detail": detail,
  7260. })
  7261. return
  7262. }
  7263. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7264. good_id, _ := c.GetInt64("good_id")
  7265. record_time, _ := c.GetInt64("record_time")
  7266. patient_id, _ := c.GetInt64("patient_id")
  7267. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7268. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7269. fmt.Print("err", err)
  7270. c.ServeSuccessJSON(map[string]interface{}{
  7271. "msg": "批量删除成功",
  7272. })
  7273. return
  7274. }
  7275. func (c *DialysisAPIController) BatchAdviceCheck() {
  7276. ids := c.GetString("ids")
  7277. idArray := strings.Split(ids, ",")
  7278. creator, _ := c.GetInt64("creator")
  7279. origin, _ := c.GetInt64("origin")
  7280. if origin == 1 {
  7281. err := service.BatchAdviceCheck(idArray, creator)
  7282. fmt.Println(err)
  7283. list, _ := service.GetAdviceExecutionById(idArray)
  7284. c.ServeSuccessJSON(map[string]interface{}{
  7285. "list": list,
  7286. })
  7287. return
  7288. }
  7289. if origin == 2 {
  7290. service.BatchHisAdviceCheck(idArray, creator)
  7291. list, _ := service.GetHisAdviceExecutionById(idArray)
  7292. c.ServeSuccessJSON(map[string]interface{}{
  7293. "list": list,
  7294. })
  7295. return
  7296. }
  7297. }
  7298. func (c *DialysisAPIController) BatchAdviceExecution() {
  7299. ids := c.GetString("ids")
  7300. idArray := strings.Split(ids, ",")
  7301. executionTime := c.GetString("execution_time")
  7302. creator, _ := c.GetInt64("creator")
  7303. timeLayout := "2006-01-02 15:04:05"
  7304. loc, _ := time.LoadLocation("Local")
  7305. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7306. orgin, _ := c.GetInt64("origin")
  7307. if orgin == 1 {
  7308. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7309. list, _ := service.GetAdviceExecutionById(idArray)
  7310. fmt.Println(err)
  7311. c.ServeSuccessJSON(map[string]interface{}{
  7312. "list": list,
  7313. })
  7314. return
  7315. }
  7316. if orgin == 2 {
  7317. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7318. list, _ := service.GetHisAdviceExecutionById(idArray)
  7319. fmt.Println(err)
  7320. c.ServeSuccessJSON(map[string]interface{}{
  7321. "list": list,
  7322. })
  7323. return
  7324. }
  7325. }
  7326. func (c *DialysisAPIController) UpdateStockGoods() {
  7327. good_id, _ := c.GetInt64("good_id")
  7328. record_time, _ := c.GetInt64("record_time")
  7329. patient_id, _ := c.GetInt64("patient_id")
  7330. count, _ := c.GetInt64("count")
  7331. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7332. fmt.Print("err", err)
  7333. c.ServeSuccessJSON(map[string]interface{}{
  7334. "msg": "更新成功",
  7335. })
  7336. return
  7337. }
  7338. // 当前数据比上一次出库数据少
  7339. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7340. //查询该患者当天已经出库的耗材信息
  7341. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7342. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7343. for i := len(goods_yc) - 1; i >= 0; i-- {
  7344. goods_yc_temp := goods_yc[i]
  7345. for j := len(goods) - 1; j >= 0; j-- {
  7346. goods_temp := goods[j]
  7347. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7348. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7349. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7350. if goods_yc_temp.Count == goods_temp.Count {
  7351. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7352. goods = append(goods[:j], goods[j+1:]...)
  7353. break
  7354. }
  7355. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7356. if goods_yc_temp.Count > goods_temp.Count {
  7357. temp_count := goods_yc_temp.Count - goods_temp.Count
  7358. goods_yc[i].Count = temp_count
  7359. goods = append(goods[:j], goods[j+1:]...)
  7360. break
  7361. }
  7362. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7363. if goods_yc_temp.Count < goods_temp.Count {
  7364. temp_count := goods_temp.Count - goods_yc_temp.Count
  7365. goods[j].Count = temp_count
  7366. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7367. break
  7368. }
  7369. }
  7370. }
  7371. }
  7372. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7373. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7374. //退库
  7375. if len(goods_yc) > 0 {
  7376. for _, good_yc := range goods_yc {
  7377. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7378. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7379. }
  7380. }
  7381. return nil
  7382. }
  7383. // 耗材出库删除
  7384. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7385. // 先根据相关信息查询当天该耗材的出库信息
  7386. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7387. if err != nil {
  7388. return err
  7389. }
  7390. var delete_count int64 = 0
  7391. delete_count = warehouseOutInfos.Count - count
  7392. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7393. // 在出库记录表里记录退库详情
  7394. warehouseOutInfo := &models.WarehouseOutInfo{
  7395. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7396. WarehouseOutId: warehouseOut.ID,
  7397. Status: 1,
  7398. Ctime: time.Now().Unix(),
  7399. OrgId: orgID,
  7400. Type: 1,
  7401. IsSys: 1,
  7402. SysRecordTime: record_time,
  7403. GoodTypeId: good_yc.GoodTypeId,
  7404. GoodId: good_yc.GoodId,
  7405. PatientId: good_yc.PatientId,
  7406. ConsumableType: 2,
  7407. StorehouseId: houseConfig.StorehouseOutInfo,
  7408. IsCheck: 1,
  7409. }
  7410. warehouseOutInfo.Count = count
  7411. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7412. warehouseOutInfo.Price = stockInInfo.Price
  7413. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7414. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7415. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7416. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7417. warehouseOutInfo.Number = warehouseOutInfos.Number
  7418. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7419. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7420. //查找当天是否存在出库记录
  7421. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7422. if errcod == gorm.ErrRecordNotFound {
  7423. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7424. //插入详情明细表
  7425. stockFlow := models.VmStockFlow{
  7426. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7427. WarehouseOutId: warehouseOut.ID,
  7428. GoodId: good_yc.GoodId,
  7429. Number: warehouseOutInfos.Number,
  7430. ProductDate: stockInInfo.ProductDate,
  7431. ExpireDate: stockInInfo.ExpiryDate,
  7432. Count: count,
  7433. Price: stockInInfo.Price,
  7434. Status: 1,
  7435. Ctime: time.Now().Unix(),
  7436. UserOrgId: good_yc.OrgId,
  7437. Manufacturer: stockInInfo.Manufacturer,
  7438. Dealer: stockInInfo.Dealer,
  7439. LicenseNumber: stockInInfo.LicenseNumber,
  7440. IsEdit: 2,
  7441. Creator: creater,
  7442. SystemTime: record_time,
  7443. ConsumableType: 3,
  7444. WarehousingDetailId: 0,
  7445. IsSys: 1,
  7446. UpdateCreator: creater,
  7447. PatientId: patient_id,
  7448. StorehouseId: houseConfig.StorehouseOutInfo,
  7449. }
  7450. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7451. if errflow == gorm.ErrRecordNotFound {
  7452. //创建流水表
  7453. err := service.CreateStockFlowOne(stockFlow)
  7454. fmt.Println("err", err)
  7455. } else if errflow == nil {
  7456. //插入详情明细表
  7457. stockFlow := models.VmStockFlow{
  7458. ID: exsit.ID,
  7459. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7460. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7461. WarehouseOutId: warehouseOut.ID,
  7462. GoodId: good_yc.GoodId,
  7463. Number: warehouseOutInfos.Number,
  7464. ProductDate: stockInInfo.ProductDate,
  7465. ExpireDate: stockInInfo.ExpiryDate,
  7466. Count: exsit.Count - delete_count,
  7467. Price: stockInInfo.Price,
  7468. Status: 1,
  7469. Ctime: time.Now().Unix(),
  7470. UserOrgId: good_yc.OrgId,
  7471. Manufacturer: stockInInfo.Manufacturer,
  7472. Dealer: stockInInfo.Dealer,
  7473. LicenseNumber: stockInInfo.LicenseNumber,
  7474. IsEdit: 2,
  7475. Creator: creater,
  7476. SystemTime: record_time,
  7477. ConsumableType: 3,
  7478. WarehousingDetailId: 0,
  7479. IsSys: 1,
  7480. UpdateCreator: creater,
  7481. PatientId: patient_id,
  7482. StorehouseId: houseConfig.StorehouseOutInfo,
  7483. }
  7484. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7485. }
  7486. if errOne != nil {
  7487. return errOne
  7488. }
  7489. } else if errcod == nil {
  7490. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7491. //插入详情明细表
  7492. stockFlow := models.VmStockFlow{
  7493. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7494. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7495. WarehouseOutId: warehouseOut.ID,
  7496. GoodId: good_yc.GoodId,
  7497. Number: warehouseOutInfos.Number,
  7498. ProductDate: stockInInfo.ProductDate,
  7499. ExpireDate: stockInInfo.ExpiryDate,
  7500. Count: count,
  7501. Price: stockInInfo.Price,
  7502. Status: 1,
  7503. Ctime: time.Now().Unix(),
  7504. UserOrgId: good_yc.OrgId,
  7505. Manufacturer: stockInInfo.Manufacturer,
  7506. Dealer: stockInInfo.Dealer,
  7507. LicenseNumber: stockInInfo.LicenseNumber,
  7508. IsEdit: 2,
  7509. Creator: creater,
  7510. SystemTime: record_time,
  7511. ConsumableType: 3,
  7512. WarehousingDetailId: 0,
  7513. IsSys: 1,
  7514. UpdateCreator: creater,
  7515. PatientId: patient_id,
  7516. ReturnCount: delete_count,
  7517. StorehouseId: houseConfig.StorehouseOutInfo,
  7518. }
  7519. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7520. if errflows == gorm.ErrRecordNotFound {
  7521. //创建流水表
  7522. service.CreateStockFlowOne(stockFlow)
  7523. } else if errflows == nil {
  7524. stockFlow := models.VmStockFlow{
  7525. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7526. ID: exsit.ID,
  7527. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7528. WarehouseOutId: warehouseOut.ID,
  7529. GoodId: good_yc.GoodId,
  7530. Number: warehouseOutInfos.Number,
  7531. ProductDate: stockInInfo.ProductDate,
  7532. ExpireDate: stockInInfo.ExpiryDate,
  7533. Count: exsit.Count - delete_count,
  7534. Price: stockInInfo.Price,
  7535. Status: 1,
  7536. Ctime: time.Now().Unix(),
  7537. UserOrgId: good_yc.OrgId,
  7538. Manufacturer: stockInInfo.Manufacturer,
  7539. Dealer: stockInInfo.Dealer,
  7540. LicenseNumber: stockInInfo.LicenseNumber,
  7541. IsEdit: 2,
  7542. Creator: creater,
  7543. SystemTime: record_time,
  7544. ConsumableType: 3,
  7545. WarehousingDetailId: 0,
  7546. IsSys: 1,
  7547. UpdateCreator: creater,
  7548. PatientId: patient_id,
  7549. ReturnCount: delete_count,
  7550. StorehouseId: houseConfig.StorehouseOutInfo,
  7551. }
  7552. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7553. }
  7554. }
  7555. //更改自动出库的表格
  7556. details := models.BloodAutomaticReduceDetail{
  7557. WarehouseOutId: warehouseOutInfo.ID,
  7558. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7559. PatientId: patient_id,
  7560. Ctime: time.Now().Unix(),
  7561. Mtime: time.Now().Unix(),
  7562. Status: 1,
  7563. RecordTime: record_time,
  7564. OrgId: orgID,
  7565. GoodId: good_yc.GoodId,
  7566. GoodTypeId: good_yc.GoodTypeId,
  7567. Count: count,
  7568. StorehouseId: houseConfig.StorehouseOutInfo,
  7569. }
  7570. //查询当天耗材是否已经存在数据
  7571. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7572. if errcode == gorm.ErrRecordNotFound {
  7573. errTwo := service.CreateAutoReduceRecord(&details)
  7574. if errTwo != nil {
  7575. return errTwo
  7576. }
  7577. } else if errcode == nil {
  7578. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7579. service.CreateAutoReduceRecord(&details)
  7580. }
  7581. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7582. //增加出库库存数量
  7583. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7584. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7585. fmt.Println("errOne", errOne)
  7586. // 删除出库完成后,要增加对应批次的库存数量
  7587. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7588. if errThree != nil {
  7589. return errThree
  7590. }
  7591. if good_yc.Count == 0 {
  7592. return nil
  7593. } else {
  7594. return errors.New("退库和出库数据不匹配")
  7595. }
  7596. }
  7597. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7598. //查询该患者当天已经出库的耗材信息
  7599. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7600. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7601. for i := len(goods_yc) - 1; i >= 0; i-- {
  7602. goods_yc_temp := goods_yc[i]
  7603. for j := len(goods) - 1; j >= 0; j-- {
  7604. goods_temp := goods[j]
  7605. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7606. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7607. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7608. if goods_yc_temp.Count == goods_temp.Count {
  7609. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7610. goods = append(goods[:j], goods[j+1:]...)
  7611. break
  7612. }
  7613. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7614. if goods_yc_temp.Count > goods_temp.Count {
  7615. temp_count := goods_yc_temp.Count - goods_temp.Count
  7616. goods_yc[i].Count = temp_count
  7617. goods = append(goods[:j], goods[j+1:]...)
  7618. break
  7619. }
  7620. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7621. if goods_yc_temp.Count < goods_temp.Count {
  7622. temp_count := goods_temp.Count - goods_yc_temp.Count
  7623. goods[j].Count = temp_count
  7624. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7625. break
  7626. }
  7627. }
  7628. }
  7629. }
  7630. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7631. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7632. fmt.Println("剩余需要出库的", len(goods))
  7633. if len(goods) > 0 {
  7634. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7635. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7636. if err == gorm.ErrRecordNotFound {
  7637. //没有记录,则创建出库单
  7638. timeStr := time.Now().Format("2006-01-02")
  7639. timeArr := strings.Split(timeStr, "-")
  7640. total, _ := service.FindAllWarehouseOut(orgID)
  7641. total = total + 1
  7642. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7643. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7644. number = number + total
  7645. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7646. warehouseOut := models.WarehouseOut{
  7647. WarehouseOutOrderNumber: warehousing_out_order,
  7648. OperationTime: time.Now().Unix(),
  7649. OrgId: orgID,
  7650. Creater: creater,
  7651. Ctime: time.Now().Unix(),
  7652. Status: 1,
  7653. WarehouseOutTime: record_time,
  7654. Dealer: 0,
  7655. Manufacturer: 0,
  7656. Type: 1,
  7657. IsSys: 1,
  7658. StorehouseId: houseConfig.StorehouseOutInfo,
  7659. IsCheck: 1,
  7660. }
  7661. err := service.AddSigleWarehouseOut(&warehouseOut)
  7662. if err != nil {
  7663. utils.TraceLog("创建出库单失败 err = %v", err)
  7664. return err
  7665. } else {
  7666. out = warehouseOut
  7667. }
  7668. }
  7669. for _, item := range goods {
  7670. var newCount int64 = 0
  7671. for _, it := range goodOne {
  7672. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7673. newCount = it.Count
  7674. }
  7675. }
  7676. prepare := models.DialysisBeforePrepare{
  7677. GoodTypeId: item.GoodTypeId,
  7678. GoodId: item.GoodId,
  7679. Count: item.Count,
  7680. StorehouseId: houseConfig.StorehouseOutInfo,
  7681. }
  7682. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7683. //增加出库数量
  7684. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7685. }
  7686. }
  7687. if len(goods_yc) > 0 {
  7688. for _, good_yc := range goods_yc {
  7689. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7690. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7691. }
  7692. }
  7693. return nil
  7694. }
  7695. // 耗材出库删除
  7696. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7697. // 先根据相关信息查询当天该耗材的出库信息
  7698. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7699. if err != nil {
  7700. return err
  7701. }
  7702. var delete_count int64 = 0
  7703. for _, ware := range warehouseOutInfos {
  7704. // 判断当前出库的数据和删除出库数量
  7705. if good_yc.Count <= ware.Count {
  7706. delete_count = good_yc.Count
  7707. } else {
  7708. delete_count = ware.Count
  7709. }
  7710. warehouseOutInfo := &models.WarehouseOutInfo{
  7711. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7712. WarehouseOutId: warehouseOut.ID,
  7713. Status: 1,
  7714. Ctime: time.Now().Unix(),
  7715. Remark: "",
  7716. OrgId: orgID,
  7717. Type: 1,
  7718. Manufacturer: 0,
  7719. Dealer: 0,
  7720. IsSys: 0,
  7721. SysRecordTime: record_time,
  7722. GoodTypeId: good_yc.GoodTypeId,
  7723. GoodId: good_yc.GoodId,
  7724. StorehouseId: warehouseOut.StorehouseId,
  7725. IsCheck: 1,
  7726. }
  7727. warehouseOutInfo.Count = delete_count
  7728. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7729. warehouseOutInfo.Price = stockInInfo.Price
  7730. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7731. if errOne != nil {
  7732. return errOne
  7733. }
  7734. // 删除出库完成后,要改变流水库存(有疑问)
  7735. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7736. fmt.Println("errOne", errOne)
  7737. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7738. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7739. //扣减出库数量
  7740. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7741. if errThree != nil {
  7742. return errThree
  7743. }
  7744. }
  7745. if good_yc.Count == 0 {
  7746. return nil
  7747. } else {
  7748. return errors.New("退库和出库数据不匹配")
  7749. }
  7750. }
  7751. func (this *DialysisAPIController) GetMobileScheduleList() {
  7752. limit, _ := this.GetInt64("limit")
  7753. page, _ := this.GetInt64("page")
  7754. type_options_visible, _ := this.GetInt64("type_options_visible")
  7755. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7756. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7757. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7758. }
  7759. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7760. newArr = make([]*models.HisPrescriptionProject, 0)
  7761. for i := 0; i < len(arr); i++ {
  7762. repeat := false
  7763. for j := i + 1; j < len(arr); j++ {
  7764. if arr[i].TeamId == arr[j].TeamId {
  7765. repeat = true
  7766. break
  7767. }
  7768. }
  7769. if !repeat {
  7770. newArr = append(newArr, arr[i])
  7771. }
  7772. }
  7773. return
  7774. }
  7775. func (this *DialysisAPIController) GetRoleList() {
  7776. admin_user_id, _ := this.GetInt64("admin_user_id")
  7777. orgid := this.GetMobileAdminUserInfo().Org.Id
  7778. list, err := service.GetRoleList(orgid, admin_user_id)
  7779. fmt.Println(err)
  7780. this.ServeSuccessJSON(map[string]interface{}{
  7781. "list": list,
  7782. })
  7783. return
  7784. }
  7785. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7786. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7787. // 先根据相关信息查询当天该耗材的出库信息
  7788. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7789. if err != nil {
  7790. return err
  7791. }
  7792. var delete_count int64 = 0
  7793. delete_count = warehouseOutInfos.Count - count
  7794. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7795. // 删除出库完成后,要增加对应批次的库存数量
  7796. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7797. if errThree != nil {
  7798. return errThree
  7799. }
  7800. //增加退库数量
  7801. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7802. //扣减出库数量
  7803. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7804. //查询剩余库存
  7805. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7806. var sum_count int64
  7807. for _, item := range goodList {
  7808. sum_count += item.StockCount
  7809. }
  7810. // 在出库记录表里记录退库详情
  7811. warehouseOutInfo := &models.WarehouseOutInfo{
  7812. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7813. WarehouseOutId: warehouseOut.ID,
  7814. Status: 1,
  7815. Ctime: time.Now().Unix(),
  7816. OrgId: orgID,
  7817. Type: 1,
  7818. IsSys: 1,
  7819. SysRecordTime: record_time,
  7820. GoodTypeId: good_yc.GoodTypeId,
  7821. GoodId: good_yc.GoodId,
  7822. PatientId: good_yc.PatientId,
  7823. ConsumableType: 2,
  7824. StorehouseId: houseConfig.StorehouseOutInfo,
  7825. IsCheck: 1,
  7826. OverCount: sum_count,
  7827. }
  7828. warehouseOutInfo.Count = count
  7829. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7830. warehouseOutInfo.Price = stockInInfo.Price
  7831. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7832. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7833. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7834. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7835. warehouseOutInfo.Number = warehouseOutInfos.Number
  7836. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7837. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7838. //查找当天是否存在出库记录
  7839. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7840. if errcod == gorm.ErrRecordNotFound {
  7841. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7842. //插入详情明细表
  7843. if errOne != nil {
  7844. return errOne
  7845. }
  7846. //插入详情明细表
  7847. stockFlow := models.VmStockFlow{
  7848. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7849. WarehouseOutId: warehouseOut.ID,
  7850. GoodId: good_yc.GoodId,
  7851. Number: warehouseOutInfos.Number,
  7852. ProductDate: stockInInfo.ProductDate,
  7853. ExpireDate: stockInInfo.ExpiryDate,
  7854. Count: count,
  7855. Price: stockInInfo.Price,
  7856. Status: 1,
  7857. Ctime: time.Now().Unix(),
  7858. UserOrgId: good_yc.OrgId,
  7859. Manufacturer: stockInInfo.Manufacturer,
  7860. Dealer: stockInInfo.Dealer,
  7861. LicenseNumber: stockInInfo.LicenseNumber,
  7862. IsEdit: 2,
  7863. Creator: creater,
  7864. SystemTime: record_time,
  7865. ConsumableType: 3,
  7866. WarehousingDetailId: 0,
  7867. IsSys: 1,
  7868. UpdateCreator: creater,
  7869. PatientId: patient_id,
  7870. StorehouseId: houseConfig.StorehouseOutInfo,
  7871. OverCount: sum_count,
  7872. ProjectId: good_yc.ProjectId,
  7873. }
  7874. err := service.CreateStockFlowOne(stockFlow)
  7875. fmt.Println("err", err)
  7876. } else if errcod == nil {
  7877. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7878. }
  7879. //创建退库单
  7880. operation_time := time.Now().Unix()
  7881. //创建退库单
  7882. timeStr := time.Now().Format("2006-01-02")
  7883. timeArr := strings.Split(timeStr, "-")
  7884. total, _ := service.FindAllCancelStockTotal(orgID)
  7885. total = total + 1
  7886. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7887. cancelStock := models.CancelStock{
  7888. OrderNumber: orderNumber,
  7889. OperaTime: operation_time,
  7890. OrgId: orgID,
  7891. Creater: warehouseOut.Creater,
  7892. Ctime: time.Now().Unix(),
  7893. Status: 1,
  7894. ReturnTime: record_time,
  7895. Type: 1,
  7896. StorehouseId: stockInInfo.StorehouseId,
  7897. IsCheck: 1,
  7898. }
  7899. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7900. if msgerrkonde == gorm.ErrRecordNotFound {
  7901. service.AddSigleCancelStock(&cancelStock)
  7902. }
  7903. cancel, _ := service.GetLastCancelStockById(orgID)
  7904. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7905. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7906. cancelStockInfo := models.CancelStockInfo{
  7907. GoodId: stockInInfo.GoodId,
  7908. CancelStockId: cancel.ID,
  7909. GoodTypeId: stockInInfo.GoodTypeId,
  7910. Count: delete_count,
  7911. Price: stockInInfo.PackingPrice,
  7912. Total: 0,
  7913. ProductDate: stockInInfo.ProductDate,
  7914. ExpiryDate: stockInInfo.ExpiryDate,
  7915. Ctime: time.Now().Unix(),
  7916. Status: 1,
  7917. OrgId: orgID,
  7918. OrderNumber: cancel.OrderNumber,
  7919. Type: 0,
  7920. Dealer: deaerler.DealerName,
  7921. Manufacturer: manufacturer.ManufacturerName,
  7922. Number: stockInInfo.Number,
  7923. RegisterAccount: "",
  7924. Remark: "",
  7925. WarehouseInfoId: stockInInfo.ID,
  7926. PatientId: patient_id,
  7927. RecordDate: record_time,
  7928. StorehouseId: stockInInfo.StorehouseId,
  7929. IsCheck: 1,
  7930. }
  7931. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7932. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7933. flow := models.VmStockFlow{
  7934. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7935. GoodId: good_yc.GoodId,
  7936. Number: warehouseOutInfos.Number,
  7937. LicenseNumber: stockInInfo.LicenseNumber,
  7938. Count: delete_count,
  7939. UserOrgId: orgID,
  7940. PatientId: patient_id,
  7941. SystemTime: record_time,
  7942. ConsumableType: 7,
  7943. IsSys: 0,
  7944. WarehousingOrder: "",
  7945. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7946. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7947. IsEdit: 0,
  7948. CancelStockId: cancel.ID,
  7949. CancelOrderNumber: cancel.OrderNumber,
  7950. Manufacturer: manufacturer.ID,
  7951. Dealer: 0,
  7952. Creator: warehouseOut.Creater,
  7953. UpdateCreator: 0,
  7954. Status: 1,
  7955. Ctime: time.Now().Unix(),
  7956. Mtime: 0,
  7957. Price: stockInInfo.Price,
  7958. WarehousingDetailId: stockInInfo.ID,
  7959. WarehouseOutDetailId: warehouseOutInfos.ID,
  7960. CancelOutDetailId: cancelInfo.ID,
  7961. ProductDate: stockInInfo.ProductDate,
  7962. ExpireDate: stockInInfo.ExpiryDate,
  7963. StorehouseId: houseConfig.StorehouseOutInfo,
  7964. OverCount: sum_count,
  7965. }
  7966. service.CreateStockFlowOne(flow)
  7967. //更改自动出库的表格
  7968. details := models.BloodAutomaticReduceDetail{
  7969. WarehouseOutId: warehouseOutInfo.ID,
  7970. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7971. PatientId: patient_id,
  7972. Ctime: time.Now().Unix(),
  7973. Mtime: time.Now().Unix(),
  7974. Status: 1,
  7975. RecordTime: record_time,
  7976. OrgId: orgID,
  7977. GoodId: good_yc.GoodId,
  7978. GoodTypeId: good_yc.GoodTypeId,
  7979. Count: count,
  7980. StorehouseId: houseConfig.StorehouseOutInfo,
  7981. }
  7982. //查询当天耗材是否已经存在数据
  7983. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7984. if errcode == gorm.ErrRecordNotFound {
  7985. errTwo := service.CreateAutoReduceRecord(&details)
  7986. if errTwo != nil {
  7987. return errTwo
  7988. }
  7989. } else if errcode == nil {
  7990. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7991. service.CreateAutoReduceRecord(&details)
  7992. }
  7993. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7994. //增加出库库存数量
  7995. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7996. if good_yc.Count == 0 {
  7997. return nil
  7998. } else {
  7999. return errors.New("退库和出库数据不匹配")
  8000. }
  8001. }
  8002. func (this *DialysisAPIController) SavePatientSign() {
  8003. adminUserInfo := this.GetMobileAdminUserInfo()
  8004. patient_id, _ := this.GetInt64("patient_id")
  8005. dialysis_date, _ := this.GetInt64("dialysis_date")
  8006. orgid := adminUserInfo.Org.Id
  8007. var esdata models.DialysisOrder
  8008. var err error
  8009. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8011. return
  8012. }
  8013. esdata.Hash = esdata.Hash
  8014. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8015. order := models.DialysisOrder{
  8016. Hash: esdata.Hash,
  8017. Url: esdata.Url,
  8018. }
  8019. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8020. redis := service.RedisClient()
  8021. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8022. redis.Set(key, "", time.Second)
  8023. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8024. //清空key 值
  8025. redis.Set(keyOne, "", time.Second)
  8026. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8027. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8028. //redis.Set(keyTwo, "", time.Second)
  8029. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8030. redis.Set(keyThree, "", time.Second)
  8031. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8032. redis.Set(keyFour, "", time.Second)
  8033. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8034. redis.Set(keyFive, "", time.Second)
  8035. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8036. redis.Set(keySix, "", time.Second)
  8037. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8038. redis.Set(keySeven, "", time.Second)
  8039. if err != nil {
  8040. fmt.Println(err)
  8041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8042. return
  8043. }
  8044. this.ServeSuccessJSON(map[string]interface{}{
  8045. "electronic_signature": esdata,
  8046. })
  8047. }
  8048. func (this *DialysisAPIController) GetPatientSign() {
  8049. patient_id, _ := this.GetInt64("patient_id")
  8050. dialysis_date, _ := this.GetInt64("dialysis_date")
  8051. adminUserInfo := this.GetMobileAdminUserInfo()
  8052. orgId := adminUserInfo.Org.Id
  8053. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8054. if err != nil {
  8055. fmt.Println(err)
  8056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8057. return
  8058. }
  8059. this.ServeSuccessJSON(map[string]interface{}{
  8060. "dialysisOrder": dialysisOrder,
  8061. })
  8062. }
  8063. func (this *DialysisAPIController) GetScheduleByPatient() {
  8064. patient_id, _ := this.GetInt64("patient_id")
  8065. schedule_date, _ := this.GetInt64("schedule_date")
  8066. orgid := this.GetMobileAdminUserInfo().Org.Id
  8067. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8068. this.ServeSuccessJSON(map[string]interface{}{
  8069. "schedule": schedule,
  8070. })
  8071. }
  8072. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8073. org_id := this.GetMobileAdminUserInfo().Org.Id
  8074. patient_id, _ := this.GetInt64("patient_id")
  8075. schedule_date, _ := this.GetInt64("schedule_date")
  8076. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8077. this.ServeSuccessJSON(map[string]interface{}{
  8078. "order": order,
  8079. })
  8080. }
  8081. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8082. org_id := this.GetMobileAdminUserInfo().Org.Id
  8083. schedule_date := this.GetString("schedule_date")
  8084. schedule_type, _ := this.GetInt64("schedule_type")
  8085. timeLayout := "2006-01-02"
  8086. loc, _ := time.LoadLocation("Local")
  8087. var startdateunix int64
  8088. if len(schedule_date) > 0 {
  8089. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8090. if err != nil {
  8091. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8092. return
  8093. }
  8094. startdateunix = theTime.Unix()
  8095. }
  8096. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8097. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8098. devices, _ := service.GetAllDevicetByListSix(org_id)
  8099. for key, item := range scheduals {
  8100. // 床位信息
  8101. for _, device := range devices {
  8102. if item.BedId == device.ID {
  8103. scheduals[key].DeviceNumber = device
  8104. break
  8105. }
  8106. }
  8107. }
  8108. this.ServeSuccessJSON(map[string]interface{}{
  8109. "list": list,
  8110. "scheduals": scheduals,
  8111. })
  8112. }
  8113. func (this *DialysisAPIController) SavePatientPicture() {
  8114. patient_id, _ := this.GetInt64("patient_id")
  8115. dialysis_date, _ := this.GetInt64("schedule_date")
  8116. avatar := this.GetString("avatar")
  8117. fmt.Println("patient_id", patient_id)
  8118. orgId := this.GetMobileAdminUserInfo().Org.Id
  8119. order := models.DialysisOrder{
  8120. Url: avatar,
  8121. }
  8122. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8123. redis := service.RedisClient()
  8124. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8125. redis.Set(key, "", time.Second)
  8126. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8127. //清空key 值
  8128. redis.Set(keyOne, "", time.Second)
  8129. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8130. redis.Set(keyThree, "", time.Second)
  8131. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8132. redis.Set(keyFour, "", time.Second)
  8133. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8134. redis.Set(keyFive, "", time.Second)
  8135. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8136. redis.Set(keySix, "", time.Second)
  8137. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8138. redis.Set(keySeven, "", time.Second)
  8139. if err != nil {
  8140. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8141. return
  8142. }
  8143. this.ServeSuccessJSON(map[string]interface{}{
  8144. "order": order,
  8145. })
  8146. }
  8147. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8148. ids := this.GetString("ids")
  8149. idSplit := strings.Split(ids, ",")
  8150. orgId := this.GetMobileAdminUserInfo().Org.Id
  8151. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8152. execution_time := this.GetString("exce_time")
  8153. timeLayout2 := "2006-01-02 15:04:05"
  8154. loc, _ := time.LoadLocation("Local")
  8155. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8156. if errs != nil {
  8157. utils.ErrorLog(errs.Error())
  8158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8159. return
  8160. }
  8161. //his客户
  8162. if config.IsOpen == 1 {
  8163. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8164. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8165. for _, item := range list {
  8166. for _, it := range adviceList {
  8167. if item.DrugId == it.DrugId {
  8168. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8169. }
  8170. }
  8171. }
  8172. for _, item := range list {
  8173. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8174. var sum_out_count int64
  8175. for _, itemThree := range item.ChildDoctorAdvice {
  8176. var prescribing_number int64
  8177. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8178. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8179. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8180. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8181. }
  8182. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8183. prescribing_number = parseIntPrescribingNumber
  8184. }
  8185. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8186. prescribing_number = parseIntPrescribingNumber
  8187. }
  8188. sum_out_count += prescribing_number
  8189. }
  8190. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8191. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8192. //库存不足
  8193. if sum_out_count > drugStockOut.FlushCount {
  8194. this.ServeSuccessJSON(map[string]interface{}{
  8195. "msg": "2",
  8196. "drug": medical,
  8197. "ids": ids,
  8198. })
  8199. return
  8200. }
  8201. }
  8202. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8203. //执行医嘱
  8204. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8205. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8206. for _, item := range advices {
  8207. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8208. redis := service.RedisClient()
  8209. //清空key 值
  8210. redis.Set(key, "", time.Second)
  8211. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8212. redis.Set(keyTwo, "", time.Second)
  8213. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8214. redis.Set(keyThree, "", time.Second)
  8215. recordDate := theTime.Format("2006-01-02")
  8216. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8217. redis.Set(keyFour, "", time.Second)
  8218. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8219. redis.Set(keyFive, "", time.Second)
  8220. defer redis.Close()
  8221. }
  8222. if errs == nil {
  8223. //药品管理信息
  8224. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8225. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8226. if drugStockConfig.IsOpen == 1 {
  8227. for _, item := range advices {
  8228. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8229. config, _ := service.GetDrugOpenConfigOne(orgId)
  8230. if config.IsOpen != 1 {
  8231. //查询该药品是否有库存
  8232. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8233. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8234. if medical.IsUse == 2 {
  8235. if config.IsOpen != 1 {
  8236. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8237. service.HisDrugsDelivery(orgId, creater, &advice)
  8238. if orgId == 3877 || orgId == 10265 {
  8239. //查询该药品是否有出库记录
  8240. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8241. if len(flowMap) == 0 {
  8242. errs := service.UpdateHisAdviceById(advice.ID)
  8243. if errs != nil {
  8244. drugError := models.XtDrugError{
  8245. UserOrgId: orgId,
  8246. DrugId: item.DrugId,
  8247. RecordDate: item.AdviceDate,
  8248. PatientId: item.PatientId,
  8249. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8250. Status: 1,
  8251. Ctime: time.Now().Unix(),
  8252. Mtime: 0,
  8253. SumCount: 0,
  8254. Prescribingnumber: advice.PrescribingNumber,
  8255. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8256. }
  8257. service.CreateDrugError(drugError)
  8258. }
  8259. this.ServeSuccessJSON(map[string]interface{}{
  8260. "msg": "2",
  8261. "drug": medical,
  8262. "ids": ids,
  8263. })
  8264. return
  8265. }
  8266. }
  8267. }
  8268. if pharmacyConfig.IsOpen != 1 {
  8269. service.HisDrugsDelivery(orgId, creater, &advice)
  8270. if orgId == 3877 || orgId == 10265 {
  8271. //查询该药品是否有出库记录
  8272. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8273. if len(flowMap) == 0 {
  8274. errs := service.UpdateHisAdviceById(advice.ID)
  8275. if errs != nil {
  8276. drugError := models.XtDrugError{
  8277. UserOrgId: orgId,
  8278. DrugId: item.DrugId,
  8279. RecordDate: item.AdviceDate,
  8280. PatientId: item.PatientId,
  8281. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8282. Status: 1,
  8283. Ctime: time.Now().Unix(),
  8284. Mtime: 0,
  8285. SumCount: 0,
  8286. Prescribingnumber: advice.PrescribingNumber,
  8287. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8288. }
  8289. service.CreateDrugError(drugError)
  8290. }
  8291. this.ServeSuccessJSON(map[string]interface{}{
  8292. "msg": "2",
  8293. "drug": medical,
  8294. "ids": ids,
  8295. })
  8296. return
  8297. }
  8298. }
  8299. }
  8300. //更新字典里面的库存
  8301. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8302. var sum_count int64
  8303. for _, its := range stockInfo {
  8304. if its.MaxUnit == medical.MaxUnit {
  8305. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8306. }
  8307. sum_count += its.StockMaxNumber + its.StockMinNumber
  8308. }
  8309. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8310. //剩余库存
  8311. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8312. }
  8313. }
  8314. }
  8315. }
  8316. }
  8317. this.ServeSuccessJSON(map[string]interface{}{
  8318. "msg": "1",
  8319. "ids": ids,
  8320. })
  8321. return
  8322. } else {
  8323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8324. }
  8325. }
  8326. fmt.Println("config233322333223", config.IsOpen)
  8327. //血透客户
  8328. if config.IsOpen == 2 || config.IsOpen == 0 {
  8329. //药品管理信息
  8330. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8331. if drugStockConfig.IsOpen == 1 {
  8332. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8333. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8334. for _, item := range list {
  8335. for _, it := range adviceList {
  8336. if item.DrugId == it.DrugId {
  8337. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8338. }
  8339. }
  8340. }
  8341. for _, item := range list {
  8342. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8343. var sum_out_count int64
  8344. for _, itemThree := range item.ChildDoctorAdvice {
  8345. var prescribing_number int64
  8346. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8347. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8348. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8349. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8350. }
  8351. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8352. prescribing_number = parseIntPrescribingNumber
  8353. }
  8354. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8355. prescribing_number = parseIntPrescribingNumber
  8356. }
  8357. sum_out_count += prescribing_number
  8358. }
  8359. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8360. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8361. //库存不足
  8362. if sum_out_count > drugStockOut.FlushCount {
  8363. this.ServeSuccessJSON(map[string]interface{}{
  8364. "msg": "2",
  8365. "drug": medical,
  8366. "ids": ids,
  8367. })
  8368. return
  8369. }
  8370. }
  8371. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8372. fmt.Println("creater2332243244224242424", creater)
  8373. //执行医嘱
  8374. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8375. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8376. for _, item := range advices {
  8377. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8378. redis := service.RedisClient()
  8379. //清空key 值
  8380. redis.Set(key, "", time.Second)
  8381. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8382. redis.Set(keyTwo, "", time.Second)
  8383. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8384. redis.Set(keyThree, "", time.Second)
  8385. recordDate := theTime.Format("2006-01-02")
  8386. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8387. redis.Set(keyFour, "", time.Second)
  8388. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8389. redis.Set(keyFive, "", time.Second)
  8390. defer redis.Close()
  8391. }
  8392. if errs == nil {
  8393. for _, item := range advices {
  8394. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8395. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8396. //查询是否出库按钮开启
  8397. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8398. if adviceSetting.IsAdviceOpen == 1 {
  8399. //查询是否出库按钮开启
  8400. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8401. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8402. if prescriptionConfig.IsOpen == 1 {
  8403. if medical.IsUse == 2 {
  8404. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8405. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8406. }
  8407. if pharmacyConfig.IsOpen != 1 {
  8408. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8409. }
  8410. //更新字典里面的库存
  8411. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8412. var sum_count int64
  8413. for _, its := range stockInfo {
  8414. if its.MaxUnit == medical.MaxUnit {
  8415. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8416. }
  8417. sum_count += its.StockMaxNumber + its.StockMinNumber
  8418. }
  8419. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8420. //剩余库存
  8421. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8422. }
  8423. }
  8424. } else {
  8425. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8426. if medical.IsUse == 2 {
  8427. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8428. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8429. }
  8430. if pharmacyConfig.IsOpen != 1 {
  8431. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8432. }
  8433. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8434. var sum_count int64
  8435. for _, its := range stockInfo {
  8436. if its.MaxUnit == medical.MaxUnit {
  8437. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8438. }
  8439. sum_count += its.StockMaxNumber + its.StockMinNumber
  8440. }
  8441. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8442. //剩余库存
  8443. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8444. }
  8445. }
  8446. }
  8447. }
  8448. this.ServeSuccessJSON(map[string]interface{}{
  8449. "msg": "1",
  8450. "ids": ids,
  8451. })
  8452. return
  8453. } else {
  8454. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8455. //执行医嘱
  8456. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8457. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8458. for _, item := range advices {
  8459. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8460. redis := service.RedisClient()
  8461. //清空key 值
  8462. redis.Set(key, "", time.Second)
  8463. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8464. redis.Set(keyTwo, "", time.Second)
  8465. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8466. redis.Set(keyThree, "", time.Second)
  8467. recordDate := theTime.Format("2006-01-02")
  8468. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8469. redis.Set(keyFour, "", time.Second)
  8470. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8471. redis.Set(keyFive, "", time.Second)
  8472. defer redis.Close()
  8473. }
  8474. this.ServeSuccessJSON(map[string]interface{}{
  8475. "msg": "1",
  8476. "ids": ids,
  8477. })
  8478. return
  8479. }
  8480. }
  8481. }
  8482. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8483. ids := this.GetString("ids")
  8484. idSplit := strings.Split(ids, ",")
  8485. orgId := this.GetMobileAdminUserInfo().Org.Id
  8486. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8487. if config.IsOpen == 1 {
  8488. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8489. this.ServeSuccessJSON(map[string]interface{}{
  8490. "msg": "1",
  8491. "ids": ids,
  8492. })
  8493. return
  8494. }
  8495. if config.IsOpen == 0 || config.IsOpen == 2 {
  8496. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8497. this.ServeSuccessJSON(map[string]interface{}{
  8498. "msg": "1",
  8499. "ids": ids,
  8500. })
  8501. return
  8502. }
  8503. }
  8504. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8505. ids := this.GetString("ids")
  8506. idSplit := strings.Split(ids, ",")
  8507. orgId := this.GetMobileAdminUserInfo().Org.Id
  8508. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8509. //his
  8510. if config.IsOpen == 1 {
  8511. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8512. theTime := time.Now()
  8513. advices := models.HisDoctorAdviceThirty{
  8514. CheckTime: theTime.Unix(),
  8515. Checker: checker,
  8516. UpdatedTime: time.Now().Unix(),
  8517. }
  8518. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8519. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8520. for _, item := range list {
  8521. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8522. redis := service.RedisClient()
  8523. //清空key 值
  8524. redis.Set(key, "", time.Second)
  8525. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8526. redis.Set(keyTwo, "", time.Second)
  8527. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8528. redis.Set(keyThree, "", time.Second)
  8529. recordDate := theTime.Format("2006-01-02")
  8530. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8531. redis.Set(keyFour, "", time.Second)
  8532. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8533. redis.Set(keyFive, "", time.Second)
  8534. defer redis.Close()
  8535. }
  8536. this.ServeSuccessJSON(map[string]interface{}{
  8537. "msg": "1",
  8538. "ids": ids,
  8539. })
  8540. return
  8541. }
  8542. //血透
  8543. if config.IsOpen == 0 || config.IsOpen == 2 {
  8544. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8545. theTime := time.Now()
  8546. advices := models.DoctorAdvice{
  8547. CheckTime: theTime.Unix(),
  8548. Checker: checker,
  8549. UpdatedTime: time.Now().Unix(),
  8550. }
  8551. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8552. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8553. for _, item := range list {
  8554. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8555. redis := service.RedisClient()
  8556. //清空key 值
  8557. redis.Set(key, "", time.Second)
  8558. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8559. redis.Set(keyTwo, "", time.Second)
  8560. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8561. redis.Set(keyThree, "", time.Second)
  8562. recordDate := theTime.Format("2006-01-02")
  8563. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8564. redis.Set(keyFour, "", time.Second)
  8565. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8566. redis.Set(keyFive, "", time.Second)
  8567. defer redis.Close()
  8568. }
  8569. this.ServeSuccessJSON(map[string]interface{}{
  8570. "msg": "1",
  8571. "ids": ids,
  8572. })
  8573. return
  8574. }
  8575. }
  8576. func (this *DialysisAPIController) CheckSchedule() {
  8577. patientID, _ := this.GetInt64("patient_id")
  8578. recordDateStr := this.GetString("record_date")
  8579. nurseID, _ := this.GetInt64("start_nurse")
  8580. schedual_type, _ := this.GetInt64("schedual_type")
  8581. bedID, _ := this.GetInt64("bed")
  8582. start_time := this.GetString("start_time")
  8583. fmt.Println("patientID", patientID)
  8584. fmt.Println("recordDateStr", recordDateStr)
  8585. fmt.Println("nurseID", nurseID)
  8586. fmt.Println("schedual_type------", schedual_type)
  8587. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8589. return
  8590. }
  8591. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8592. if parseStartDateErr != nil {
  8593. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8595. return
  8596. }
  8597. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8598. if parseErr != nil {
  8599. this.ErrorLog("时间解析失败:%v", parseErr)
  8600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8601. return
  8602. }
  8603. adminUserInfo := this.GetMobileAdminUserInfo()
  8604. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8605. if getPatientErr != nil {
  8606. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8608. return
  8609. } else if patient == nil {
  8610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8611. return
  8612. }
  8613. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8614. if getNurseErr != nil {
  8615. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8617. return
  8618. } else if nurse == nil {
  8619. this.ErrorLog("护士不存在")
  8620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8621. return
  8622. }
  8623. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8624. if getDeviceNumberErr != nil {
  8625. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8627. return
  8628. } else if deviceNumber == nil {
  8629. this.ErrorLog("床位号不存在")
  8630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8631. return
  8632. }
  8633. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8634. if getRecordErr != nil {
  8635. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8637. return
  8638. } else if dialysisRecord != nil {
  8639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8640. return
  8641. }
  8642. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8643. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8644. timeLayout := "2006-01-02 15:04:05"
  8645. loc, _ := time.LoadLocation("Local")
  8646. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8647. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8648. schedulestartTime := theStartTime.Unix()
  8649. scheduleendTime := theEndTime.Unix()
  8650. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8651. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8652. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8653. //查询该床位是否有人用了
  8654. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8655. if err == nil {
  8656. if schedule.ID == 0 {
  8657. this.ServeSuccessJSON(map[string]interface{}{
  8658. "status": 0,
  8659. "msg": "请求失败",
  8660. })
  8661. } else {
  8662. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8663. if order.ID > 0 { //该机位被其他人占用了
  8664. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8665. return
  8666. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8667. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8668. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8669. this.ServeSuccessJSON(map[string]interface{}{
  8670. "status": 1,
  8671. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8672. })
  8673. return
  8674. } else {
  8675. this.ServeSuccessJSON(map[string]interface{}{
  8676. "status": 0,
  8677. "msg": "",
  8678. })
  8679. }
  8680. }
  8681. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8682. this.ServeSuccessJSON(map[string]interface{}{
  8683. "status": 2,
  8684. "msg": "当前机位已有患者在使用,请重新选择!",
  8685. })
  8686. }
  8687. }
  8688. } else {
  8689. this.ServeSuccessJSON(map[string]interface{}{
  8690. "status": 0,
  8691. "msg": "",
  8692. })
  8693. }
  8694. }
  8695. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8696. orgId := this.GetMobileAdminUserInfo().Org.Id
  8697. schedule_type, _ := this.GetInt64("schedule_type")
  8698. partion_type, _ := this.GetInt64("partion_type")
  8699. start_time := this.GetString("start_time")
  8700. timeLayout := "2006-01-02"
  8701. loc, _ := time.LoadLocation("Local")
  8702. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8703. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8704. _, config := service.FindXTHisRecordByOrgId(orgId)
  8705. appId := this.GetMobileAdminUserInfo().App.Id
  8706. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8707. if err == nil {
  8708. this.ServeSuccessJSON(map[string]interface{}{
  8709. "list": list,
  8710. "config": config,
  8711. "doctorList": doctorList,
  8712. })
  8713. return
  8714. } else {
  8715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8716. return
  8717. }
  8718. }
  8719. func (this *DialysisAPIController) SaveMobileInformation() {
  8720. patient_id, _ := this.GetInt64("patient_id")
  8721. record_date, _ := this.GetInt64("record_date")
  8722. startTime := this.GetString("start_time")
  8723. module, _ := this.GetInt64("module")
  8724. remark := this.GetString("remark")
  8725. timeLayout := "2006-01-02 15:04"
  8726. loc, _ := time.LoadLocation("Local")
  8727. if len(startTime) == 0 {
  8728. utils.ErrorLog("len(start_time) == 0")
  8729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8730. return
  8731. }
  8732. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8733. if err != nil {
  8734. utils.ErrorLog(err.Error())
  8735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8736. return
  8737. }
  8738. StartTime := theTime.Unix()
  8739. fmt.Println("startime-------------", StartTime)
  8740. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8741. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8742. information := models.XtDialysisInformation{
  8743. Module: module,
  8744. PatientId: patient_id,
  8745. RecordDate: record_date,
  8746. ApplicationDate: StartTime,
  8747. Creater: creater,
  8748. ApplicationStatus: 2,
  8749. Checker: 0,
  8750. CheckTime: 0,
  8751. Remark: remark,
  8752. UserOrgId: user_org_id,
  8753. Ctime: time.Now().Unix(),
  8754. Status: 1,
  8755. Mtime: 0,
  8756. }
  8757. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8758. if infor.ID == 0 {
  8759. service.SaveDialysisInformation(information)
  8760. }
  8761. if infor.ID > 0 {
  8762. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8763. }
  8764. this.ServeSuccessJSON(map[string]interface{}{
  8765. "information": information,
  8766. })
  8767. return
  8768. }
  8769. func (this *DialysisAPIController) GetMobileInformation() {
  8770. limit, _ := this.GetInt64("limit")
  8771. page, _ := this.GetInt64("page")
  8772. orgid := this.GetMobileAdminUserInfo().Org.Id
  8773. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8774. appid := this.GetMobileAdminUserInfo().App.Id
  8775. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8776. patients, _ := service.GetAllpatientThirty(orgid)
  8777. this.ServeSuccessJSON(map[string]interface{}{
  8778. "information": information,
  8779. "total": total,
  8780. "doclist": doclist,
  8781. "patients": patients,
  8782. })
  8783. return
  8784. }
  8785. func (this *DialysisAPIController) GetMobileInformationOne() {
  8786. limit, _ := this.GetInt64("limit")
  8787. page, _ := this.GetInt64("page")
  8788. orgid := this.GetMobileAdminUserInfo().Org.Id
  8789. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8790. appid := this.GetMobileAdminUserInfo().App.Id
  8791. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8792. patients, _ := service.GetAllpatientThirty(orgid)
  8793. this.ServeSuccessJSON(map[string]interface{}{
  8794. "information": information,
  8795. "total": total,
  8796. "doclist": doclist,
  8797. "patients": patients,
  8798. })
  8799. return
  8800. }
  8801. func (this *DialysisAPIController) CheckMobileInformation() {
  8802. id, _ := this.GetInt64("id")
  8803. application_status, _ := this.GetInt64("application_status")
  8804. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8805. checktime := time.Now().Unix()
  8806. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8807. if err == nil {
  8808. this.ServeSuccessJSON(map[string]interface{}{
  8809. "msg": "ok",
  8810. })
  8811. return
  8812. }
  8813. }
  8814. func (c *DialysisAPIController) GetControlMonitorList() {
  8815. partition, _ := c.GetInt64("partition")
  8816. monitorDate := c.GetString("date")
  8817. patient_id, _ := c.GetInt64("patient_id")
  8818. pat_type, _ := c.GetInt64("pat_type")
  8819. timeLayout := "2006-01-02"
  8820. loc, _ := time.LoadLocation("Local")
  8821. var theStartTime int64
  8822. if len(monitorDate) > 0 {
  8823. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8824. if err != nil {
  8825. theStartTime = 0
  8826. }
  8827. theStartTime = theTime.Unix()
  8828. }
  8829. adminInfo := c.GetMobileAdminUserInfo()
  8830. orgID := adminInfo.Org.Id
  8831. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8832. if err != nil {
  8833. c.ErrorLog("获取排班信息失败:%v", err)
  8834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8835. } else {
  8836. if len(monitor) > 0 {
  8837. //获取所有床位
  8838. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8839. //获取所有分区
  8840. zoneList, _ := service.GetAllZoneByList(orgID)
  8841. //获取透析处方
  8842. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8843. //获取透前评估
  8844. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8845. //获取上机
  8846. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8847. //获取透后
  8848. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8849. //获取透后监测
  8850. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8851. //获取所有的患者
  8852. patients, _ := service.GetAllPatientListByListOne(orgID)
  8853. //获取所有透析模式
  8854. treatments, _ := service.GetAllTreatModeByList(orgID)
  8855. //获取所有医嘱
  8856. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8857. //获取双人核对
  8858. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8859. //治疗小结
  8860. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8861. //待消毒
  8862. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8863. for key, item := range monitor {
  8864. // 获取床位信息
  8865. for _, it := range numberList {
  8866. if item.BedId == it.ID {
  8867. monitor[key].DeviceNumber = it
  8868. break
  8869. }
  8870. }
  8871. //获取分区信息
  8872. for _, it := range zoneList {
  8873. if item.PartitionId == it.ID {
  8874. monitor[key].DeviceZone = it
  8875. }
  8876. }
  8877. for _, prescription := range prescriptions {
  8878. if item.PatientId == prescription.PatientId {
  8879. monitor[key].Prescription = prescription
  8880. break
  8881. }
  8882. }
  8883. for _, it := range checkList {
  8884. if item.PatientId == it.PatientId {
  8885. monitor[key].DoubleCheck = it
  8886. break
  8887. }
  8888. }
  8889. for _, it := range summaryList {
  8890. if item.PatientId == it.PatientId {
  8891. monitor[key].TreatmentSummaryForList = it
  8892. break
  8893. }
  8894. }
  8895. // 透前评估
  8896. for _, assessmentBefore := range assessmentBefores {
  8897. if item.PatientId == assessmentBefore.PatientId {
  8898. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8899. break
  8900. }
  8901. }
  8902. // 透析上下机
  8903. for _, dialysisOrder := range dialysisOrders {
  8904. if item.PatientId == dialysisOrder.PatientId {
  8905. monitor[key].DialysisOrder = dialysisOrder
  8906. break
  8907. }
  8908. }
  8909. // 治疗小节
  8910. for _, afterDislysis := range AssessmentAfterDislysis {
  8911. if item.PatientId == afterDislysis.PatientId {
  8912. monitor[key].AssessmentAfterDislysis = afterDislysis
  8913. break
  8914. }
  8915. }
  8916. for _, it := range monitorlist {
  8917. if item.PatientId == it.PatientId {
  8918. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8919. }
  8920. }
  8921. for _, it := range adviceList {
  8922. if item.PatientId == it.PatientId {
  8923. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8924. }
  8925. }
  8926. for _, patient := range patients {
  8927. if item.PatientId == patient.ID {
  8928. monitor[key].MonitorPatients = patient
  8929. break
  8930. }
  8931. }
  8932. for _, treatment := range treatments {
  8933. if item.ModeId == treatment.ID {
  8934. monitor[key].TreatmentMode = treatment
  8935. break
  8936. }
  8937. }
  8938. for _, infor := range informationList {
  8939. if item.PatientId == infor.PatientId {
  8940. monitor[key].NewDeviceInformation = infor
  8941. break
  8942. }
  8943. }
  8944. }
  8945. }
  8946. }
  8947. patients, err := service.GetAllpatientFourty(orgID)
  8948. var mds []*models.NewMonitorDialysisScheduleList
  8949. if pat_type == 0 {
  8950. for _, item := range monitor {
  8951. mds = append(mds, item)
  8952. }
  8953. }
  8954. //待医嘱核对
  8955. if pat_type == 1 {
  8956. for _, item := range monitor {
  8957. if len(item.AdviceList) > 0 {
  8958. mds = append(mds, item)
  8959. }
  8960. }
  8961. }
  8962. //待开小结
  8963. if pat_type == 2 {
  8964. for _, item := range monitor {
  8965. if item.TreatmentSummaryForList == nil {
  8966. mds = append(mds, item)
  8967. }
  8968. }
  8969. }
  8970. //待下机
  8971. if pat_type == 3 {
  8972. for _, item := range monitor {
  8973. if item.DialysisOrder != nil {
  8974. if item.DialysisOrder.ID > 0 {
  8975. mds = append(mds, item)
  8976. }
  8977. }
  8978. }
  8979. }
  8980. //待消毒
  8981. if pat_type == 4 {
  8982. for _, item := range monitor {
  8983. if item.NewDeviceInformation == nil {
  8984. mds = append(mds, item)
  8985. }
  8986. }
  8987. }
  8988. //待双人核对
  8989. if pat_type == 5 {
  8990. for _, item := range monitor {
  8991. if item.DoubleCheck == nil {
  8992. mds = append(mds, item)
  8993. }
  8994. }
  8995. }
  8996. //医嘱未执行
  8997. if pat_type == 6 {
  8998. for _, item := range monitor {
  8999. if len(item.AdviceList) > 0 {
  9000. mds = append(mds, item)
  9001. }
  9002. }
  9003. }
  9004. //患者未签名
  9005. if pat_type == 7 {
  9006. for _, item := range monitor {
  9007. if item.DialysisOrder != nil {
  9008. if item.DialysisOrder.ID > 0 {
  9009. mds = append(mds, item)
  9010. }
  9011. }
  9012. }
  9013. }
  9014. //目标超滤于实际超滤不同
  9015. if pat_type == 8 {
  9016. for _, item := range monitor {
  9017. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9018. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9019. mds = append(mds, item)
  9020. }
  9021. }
  9022. }
  9023. }
  9024. //血压少于5次
  9025. if pat_type == 9 {
  9026. for _, item := range monitor {
  9027. if len(item.MonitoringRecord) < 5 {
  9028. mds = append(mds, item)
  9029. }
  9030. }
  9031. }
  9032. if pat_type == 10 {
  9033. for _, item := range monitor {
  9034. if len(item.MonitoringRecord) == 0 {
  9035. mds = append(mds, item)
  9036. }
  9037. }
  9038. }
  9039. if pat_type == 11 {
  9040. for _, item := range monitor {
  9041. if len(item.MonitoringRecord) > 0 {
  9042. mds = append(mds, item)
  9043. }
  9044. }
  9045. }
  9046. if pat_type == 12 {
  9047. for _, item := range monitor {
  9048. if len(item.MonitoringRecord) > 0 {
  9049. mds = append(mds, item)
  9050. }
  9051. }
  9052. }
  9053. if err == nil {
  9054. c.ServeSuccessJSON(map[string]interface{}{
  9055. "monitor": mds,
  9056. "patients": patients,
  9057. })
  9058. } else {
  9059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9060. }
  9061. }
  9062. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9063. admin_user_id, _ := c.GetInt64("admin_user_id")
  9064. timeStr := time.Now().Format("2006-01-02")
  9065. timeLayout := "2006-01-02 15:04:05"
  9066. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9067. timenow := timeStringToTime.Unix()
  9068. orgId := c.GetMobileAdminUserInfo().Org.Id
  9069. //查询当前护士的患者
  9070. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9071. var patientIds []int64
  9072. for _, item := range orderList {
  9073. patientIds = append(patientIds, item.PatientId)
  9074. }
  9075. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9076. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9077. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9078. //药品管理信息
  9079. _, drugStockConfig := service.FindHisConfig(orgId)
  9080. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9081. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9082. c.ServeSuccessJSON(map[string]interface{}{
  9083. "adviceList": adviceList,
  9084. "hisAdviceList": hisAdviceList,
  9085. "projectList": projectList,
  9086. "drugStockConfig": drugStockConfig,
  9087. "patientList": patientList,
  9088. "projectConfig": projectConfig,
  9089. })
  9090. }
  9091. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9092. patient_id, _ := c.GetInt64("patient_id")
  9093. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9094. c.ServeSuccessJSON(map[string]interface{}{
  9095. "recrods": recrods,
  9096. })
  9097. }
  9098. func (c *DialysisAPIController) ExMobileChangeSch() {
  9099. id_one, _ := c.GetInt64("id_one")
  9100. id_two, _ := c.GetInt64("id_two")
  9101. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9102. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9103. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9104. //if order2.ID > 0 {
  9105. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9106. // return
  9107. //}
  9108. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9109. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9110. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9111. if count > 0 {
  9112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9113. return
  9114. }
  9115. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9116. if count1 > 0 {
  9117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9118. return
  9119. }
  9120. }
  9121. err := service.UpdateScheduleThree(sch, sch_two)
  9122. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9123. if order.ID > 0 {
  9124. //查询该患者的排班机位
  9125. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9126. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9127. redis := service.RedisClient()
  9128. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9129. redis.Set(key, "", time.Second)
  9130. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9131. //清空key 值
  9132. redis.Set(keyOne, "", time.Second)
  9133. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9134. //return
  9135. }
  9136. if err == nil {
  9137. //去除当天患者排班中重复数据,保留最后一条数据
  9138. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9139. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9140. c.ServeSuccessJSON(map[string]interface{}{
  9141. "msg": "交换成功",
  9142. })
  9143. } else {
  9144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9145. return
  9146. }
  9147. }
  9148. func (c *DialysisAPIController) MobileCoverSch() {
  9149. id_one, _ := c.GetInt64("id_one")
  9150. id_two, _ := c.GetInt64("id_two")
  9151. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9152. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9153. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9154. if order.ID > 0 {
  9155. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9156. redis := service.RedisClient()
  9157. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9158. redis.Set(key, "", time.Second)
  9159. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9160. //清空key 值
  9161. redis.Set(keyOne, "", time.Second)
  9162. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9163. //return
  9164. }
  9165. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9166. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9167. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9168. if count > 0 {
  9169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9170. return
  9171. }
  9172. }
  9173. var new_sch models.Schedule
  9174. new_sch = sch
  9175. new_sch.BedId = sch_two.BedId
  9176. new_sch.ScheduleDate = sch_two.ScheduleDate
  9177. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9178. new_sch.PartitionId = sch_two.PartitionId
  9179. new_sch.ScheduleType = sch_two.ScheduleType
  9180. new_sch.ID = 0
  9181. //删除原来的排班
  9182. err := service.SaveSchTwo(sch, sch_two)
  9183. //生成新的排班
  9184. if err == nil {
  9185. err2 := service.SaveSch(&new_sch)
  9186. if err2 == nil {
  9187. //去除当天患者排班中重复数据,保留最后一条数据
  9188. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9189. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9190. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9191. c.ServeSuccessJSON(map[string]interface{}{
  9192. "msg": "覆盖成功",
  9193. "new_sch": new_sch,
  9194. })
  9195. } else {
  9196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9197. return
  9198. }
  9199. } else {
  9200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9201. return
  9202. }
  9203. }