dialysis_api_controller.go 371KB

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