dialysis_api_controller.go 369KB

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