dialysis_api_controller.go 286KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "github.com/astaxie/beego"
  16. "math"
  17. "net/http"
  18. "net/url"
  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. scheduals_json_str, _ := redis.Get(key).Result()
  77. redis.Set(key, "", time.Second)
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. if err != nil {
  82. this.ErrorLog("获取排班信息失败:%v", err)
  83. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  84. } else {
  85. if len(scheduals) > 0 {
  86. devices, _ := service.GetAllDevicetByListSix(orgID)
  87. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  88. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  89. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  90. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  91. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  92. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  93. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  94. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  95. for key, item := range scheduals {
  96. // 获取患者信息
  97. for _, patient := range patients {
  98. if item.PatientId == patient.ID {
  99. scheduals[key].SchedualPatient = patient
  100. break
  101. }
  102. }
  103. // 床位信息
  104. for _, device := range devices {
  105. if item.BedId == device.ID {
  106. scheduals[key].DeviceNumber = device
  107. break
  108. }
  109. }
  110. // 医嘱信息
  111. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  112. for _, advice := range advices {
  113. if item.PatientId == advice.PatientId {
  114. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  115. }
  116. }
  117. // 医嘱信息
  118. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  119. for _, hisAdvice := range hisAdvices {
  120. if item.PatientId == hisAdvice.PatientId {
  121. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  122. }
  123. }
  124. // 医嘱信息
  125. for _, prescription := range prescriptions {
  126. if item.PatientId == prescription.PatientId {
  127. scheduals[key].Prescription = prescription
  128. break
  129. }
  130. }
  131. // 透前评估
  132. for _, assessmentBefore := range assessmentBefores {
  133. if item.PatientId == assessmentBefore.PatientId {
  134. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  135. break
  136. }
  137. }
  138. // 透析上下机
  139. for _, dialysisOrder := range dialysisOrders {
  140. if item.PatientId == dialysisOrder.PatientId {
  141. scheduals[key].DialysisOrder = dialysisOrder
  142. break
  143. }
  144. }
  145. // 治疗小节
  146. for _, afterDislysis := range AssessmentAfterDislysis {
  147. if item.PatientId == afterDislysis.PatientId {
  148. scheduals[key].AssessmentAfterDislysis = afterDislysis
  149. break
  150. }
  151. }
  152. // 透后评估
  153. for _, treatmentSummary := range treatmentSummarys {
  154. if item.PatientId == treatmentSummary.PatientId {
  155. scheduals[key].TreatmentSummary = treatmentSummary
  156. break
  157. }
  158. }
  159. for _, check := range dobulecheck {
  160. if item.PatientId == check.PatientId {
  161. scheduals[key].DoubleCheck = check
  162. break
  163. }
  164. }
  165. }
  166. //缓存数据
  167. scheduals_json, err := json.Marshal(&scheduals)
  168. if err == nil {
  169. redis.Set(key, scheduals_json, time.Second*60)
  170. }
  171. }
  172. //获取今日所有的处方开的耗材
  173. _, configs := service.FindXTHisProjectByOrgId(orgID)
  174. project := make([]*models.HisPrescriptionProjectTwo, 0)
  175. if configs.ID > 0 && configs.IsOpen == 1 {
  176. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  177. }
  178. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  179. this.ServeSuccessJSON(map[string]interface{}{
  180. "scheduals": scheduals,
  181. "project": project,
  182. })
  183. }
  184. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  185. var dat []map[string]interface{}
  186. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  187. } else {
  188. }
  189. //获取今日所有的处方开的耗材
  190. _, configs := service.FindXTHisProjectByOrgId(orgID)
  191. project := make([]*models.HisPrescriptionProjectTwo, 0)
  192. if configs.ID > 0 && configs.IsOpen == 1 {
  193. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  194. }
  195. this.ServeSuccessJSON(map[string]interface{}{
  196. "scheduals": dat,
  197. "redis": "true",
  198. "date": schedualDate,
  199. "project": project,
  200. })
  201. }
  202. }
  203. // /m/api/waiting_scheduals [get]
  204. // @param date:string
  205. func (this *DialysisAPIController) WaitingScheduals() {
  206. schedualDate := this.GetString("date")
  207. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  208. if parseDateErr != nil && len(schedualDate) != 0 {
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. adminInfo := this.GetMobileAdminUserInfo()
  213. orgID := adminInfo.Org.Id
  214. redis := service.RedisClient()
  215. defer redis.Close()
  216. // cur_date := time.Now().Format("2006-01-02")
  217. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  218. wait_scheduals, _ := redis.Get(key).Result()
  219. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  220. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  221. if err != nil {
  222. this.ErrorLog("获取排班信息失败:%v", err)
  223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  224. } else {
  225. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  226. for _, s := range scheduals {
  227. returnScheduals = append(returnScheduals, s)
  228. }
  229. if len(returnScheduals) > 0 {
  230. //缓存数据
  231. wait_scheduals_json, err := json.Marshal(scheduals)
  232. if err == nil {
  233. redis.Set(key, wait_scheduals_json, time.Second*30)
  234. }
  235. }
  236. this.ServeSuccessJSON(map[string]interface{}{
  237. "scheduals": scheduals,
  238. })
  239. }
  240. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  241. var dat []map[string]interface{}
  242. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  243. } else {
  244. }
  245. this.ServeSuccessJSON(map[string]interface{}{
  246. "scheduals": dat,
  247. "redis": "true",
  248. "date": schedualDate,
  249. })
  250. }
  251. }
  252. //else{
  253. // fmt.Println("33333333")
  254. //
  255. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  256. // if err != nil {
  257. // this.ErrorLog("获取排班信息失败:%v", err)
  258. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  259. // } else {
  260. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  261. // for _, s := range scheduals {
  262. //
  263. // returnScheduals = append(returnScheduals, s)
  264. // }
  265. //
  266. // this.ServeSuccessJSON(map[string]interface{}{
  267. // "scheduals": returnScheduals,
  268. // })
  269. // }
  270. //
  271. // }
  272. //if err == nil{
  273. //
  274. //
  275. //
  276. //
  277. //
  278. //}else{
  279. //}
  280. // /m/api/dialysis/record [get]
  281. // @param patient_id:int
  282. // @param date:string (yyyy-MM-dd)
  283. func (this *DialysisAPIController) DialysisRecord() {
  284. patientID, _ := this.GetInt64("patient_id")
  285. recordDateStr := this.GetString("date")
  286. if patientID <= 0 {
  287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  288. return
  289. }
  290. if len(recordDateStr) == 0 {
  291. recordDateStr = time.Now().Format("2006-01-02")
  292. }
  293. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  294. if parseDateErr != nil {
  295. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. adminInfo := this.GetMobileAdminUserInfo()
  300. ch := make(chan struct{})
  301. count := 24 // count 表示活动的协程个数
  302. var patient models.Patients
  303. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  304. var predialysisEvaluation *models.PredialysisEvaluation
  305. var lastPredialysisEvaluation *models.PredialysisEvaluation
  306. var doctorAdvices []*models.DoctorAdvice
  307. var dialysisOrder *models.DialysisOrder
  308. var doubleCheck *models.DoubleCheck
  309. var monitorRecords []*models.MonitoringRecord
  310. var lastMonitorRecord *models.MonitoringRecord
  311. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  312. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  313. var treatmentSummary *models.TreatmentSummary
  314. var dialysisPrescribe *models.DialysisPrescription
  315. var dialysisSolution *models.DialysisSolution
  316. var lastDialysisPrescribe *models.DialysisPrescription
  317. var systemDialysisPrescribe *models.SystemPrescription
  318. var is_project_open_config models.XtHisProjectConfig
  319. var projects []*models.HisPrescriptionProject
  320. var stockType []*models.GoodsTypeOne
  321. var prepare []*models.XtDialysisBeforePrepare
  322. var lastAssessment models.XtPatientVascularAccess
  323. var lastDryWeightDislysis *models.SgjPatientDryweight
  324. var gobalConfig models.GobalConfig
  325. var operators []*models.SgjUserAdminRoles
  326. // 先走redis,没有走数据库
  327. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  328. go func() {
  329. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  330. ch <- struct{}{}
  331. }()
  332. go func() {
  333. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  334. ch <- struct{}{}
  335. }()
  336. go func() {
  337. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  338. ch <- struct{}{}
  339. }()
  340. go func() {
  341. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  342. ch <- struct{}{}
  343. }()
  344. go func() {
  345. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  346. ch <- struct{}{}
  347. }()
  348. go func() {
  349. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  350. ch <- struct{}{}
  351. }()
  352. go func() {
  353. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  354. ch <- struct{}{}
  355. }()
  356. go func() {
  357. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  358. ch <- struct{}{}
  359. }()
  360. go func() {
  361. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  362. ch <- struct{}{}
  363. }()
  364. go func() {
  365. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  366. ch <- struct{}{}
  367. }()
  368. go func() {
  369. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  370. ch <- struct{}{}
  371. }()
  372. go func() {
  373. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  374. ch <- struct{}{}
  375. }()
  376. go func() {
  377. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  378. ch <- struct{}{}
  379. }()
  380. go func() {
  381. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  382. ch <- struct{}{}
  383. }()
  384. go func() {
  385. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  386. ch <- struct{}{}
  387. }()
  388. go func() {
  389. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  390. ch <- struct{}{}
  391. }()
  392. go func() {
  393. // 先走redis,没有走数据库
  394. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. // 先走redis,没有走数据库
  399. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. // // 先走redis,没有走数据库
  404. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  405. ch <- struct{}{}
  406. }()
  407. go func() {
  408. // 先走redis,没有走数据库
  409. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  410. ch <- struct{}{}
  411. }()
  412. go func() {
  413. // //获取最后一次血管通路
  414. // 先走redis,没有走数据库
  415. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // 先走redis,没有走数据库
  425. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  431. ch <- struct{}{}
  432. }()
  433. for range ch {
  434. // 每次从ch中接收数据,表明一个活动的协程结束
  435. count--
  436. // 当所有活动的协程都结束时,关闭管道
  437. if count == 0 {
  438. close(ch)
  439. }
  440. }
  441. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  442. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  443. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  444. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  445. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  446. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  447. var team_projects []*models.HisPrescriptionProject
  448. //var index int64 = 0
  449. for _, item := range temp_team_projects {
  450. //组套里面非检验项目的
  451. if item.HisProject.CostClassify != 3 {
  452. projects = append(projects, item)
  453. }
  454. //组套里面检验项目的
  455. if item.HisProject.CostClassify == 3 {
  456. team_projects = append(team_projects, item)
  457. }
  458. }
  459. team_projects = RemoveRepeatedCheckRecod(team_projects)
  460. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  461. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  462. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. var his_advices []*models.HisDoctorAdviceInfo
  464. if is_open_config.IsOpen == 1 {
  465. // 先走redis,没有走数据库
  466. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  467. }
  468. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  469. if is_advice_open.IsAdviceOpen == 1 {
  470. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  471. }
  472. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  473. returnData := map[string]interface{}{
  474. "patient": patient,
  475. "schedual": schedual,
  476. "prescription": dialysisPrescribe,
  477. "solution": dialysisSolution,
  478. "last_prescription": lastDialysisPrescribe,
  479. "receiver_treatment_access": receiverTreatmentAccess,
  480. "predialysis_evaluation": predialysisEvaluation,
  481. "doctor_advices": doctorAdvices,
  482. "double_check": doubleCheck,
  483. "assessment_after_dislysis": assessmentAfterDislysis,
  484. "treatment_summary": treatmentSummary,
  485. "monitor_records": monitorRecords,
  486. "dialysis_order": dialysisOrder,
  487. "operators": operators,
  488. "last_predialysis_evaluation": lastPredialysisEvaluation,
  489. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  490. "last_monitor_record": lastMonitorRecord,
  491. "config": gobalConfig,
  492. "dry_weight": lastDryWeightDislysis,
  493. "system_prescription": systemDialysisPrescribe,
  494. "his_advices": his_advices,
  495. "is_open_config": is_open_config,
  496. "stockType": stockType,
  497. "prepare": prepare,
  498. "lastAssessment": lastAssessment,
  499. "prescribeOne": prescribeOne,
  500. "is_project_open_config": is_project_open_config,
  501. "project": projects,
  502. "team_projects": team_projects,
  503. "is_advice_open": is_advice_open,
  504. "prescription_open": prescriptionConfig.IsOpen,
  505. "lastOrder": lastOrder,
  506. }
  507. this.ServeSuccessJSON(returnData)
  508. }
  509. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  510. adminInfo := c.GetMobileAdminUserInfo()
  511. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  512. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  513. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  514. returnData := map[string]interface{}{
  515. "admin_users": adminUsers,
  516. "devices": devices,
  517. "device_numbers": device_numbers,
  518. }
  519. c.ServeSuccessJSON(returnData)
  520. }
  521. func (c *DialysisAPIController) PostAtreatmentInfo() {
  522. id, _ := c.GetInt64("patient", 0)
  523. recordDateStr := c.GetString("record_date")
  524. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  525. summaryContent := c.GetString("summaryContent")
  526. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  527. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  528. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  529. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  530. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  531. nursingRecord := c.GetString("nursing_record")
  532. fmt.Println("护理记录", nursingRecord)
  533. specialRecord := c.GetString("special_record")
  534. fmt.Println("特殊记录", specialRecord)
  535. adminUserInfo := c.GetMobileAdminUserInfo()
  536. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  537. checkStaffId = adminUserInfo.AdminUser.Id
  538. deboardNurseId = adminUserInfo.AdminUser.Id
  539. treatDoctor = adminUserInfo.AdminUser.Id
  540. if id <= 0 {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  542. return
  543. }
  544. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  545. if patient.ID == 0 {
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  547. return
  548. }
  549. if len(recordDateStr) == 0 {
  550. recordDateStr = time.Now().Format("2006-01-02")
  551. }
  552. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  553. if parseDateErr != nil {
  554. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  556. return
  557. }
  558. summary := models.TreatmentSummary{
  559. UserOrgId: adminUserInfo.Org.Id,
  560. PatientId: id,
  561. AssessmentDate: recordDate.Unix(),
  562. Mission: propagandaAndEducationContent,
  563. DialysisSummary: summaryContent,
  564. SjNurse: changeMedicalNurseId,
  565. ZlNurse: treatNurseId,
  566. HdNurse: checkStaffId,
  567. XjNurse: deboardNurseId,
  568. ZlDoctor: treatDoctor,
  569. CreatedTime: time.Now().Unix(),
  570. Status: 1,
  571. NursingRecord: nursingRecord,
  572. SpecialRecord: specialRecord,
  573. }
  574. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  575. if treatmentSummary.ID == 0 { //新增
  576. summary.Creater = adminUserInfo.AdminUser.Id
  577. service.AddSigleSummaryRecord(&summary)
  578. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  579. redis := service.RedisClient()
  580. //清空key 值
  581. redis.Set(key, "", time.Second)
  582. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  583. redis.Set(keyOne, "", time.Second)
  584. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  585. redis.Set(keyThree, "", time.Second)
  586. defer redis.Close()
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "summary": summary,
  589. })
  590. } else { //修改
  591. summary.Creater = treatmentSummary.Creater
  592. summary.CreatedTime = treatmentSummary.CreatedTime
  593. summary.Modifier = adminUserInfo.AdminUser.Id
  594. summary.ID = treatmentSummary.ID
  595. service.UpdateSummeRecord(&summary)
  596. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  597. redis := service.RedisClient()
  598. //清空key 值
  599. redis.Set(key, "", time.Second)
  600. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  601. redis.Set(keyOne, "", time.Second)
  602. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  603. redis.Set(keyThree, "", time.Second)
  604. defer redis.Close()
  605. c.ServeSuccessJSON(map[string]interface{}{
  606. "summary": summary,
  607. })
  608. }
  609. }
  610. func (c *DialysisAPIController) PostDoubleCheck() {
  611. id, _ := c.GetInt64("patient", 0)
  612. recordDateStr := c.GetString("record_date")
  613. checkTimeStr := c.GetString("check_time")
  614. firstCheckTimeStr := c.GetString("first_check_time")
  615. creater, _ := c.GetInt64("creater", 0)
  616. modifier, _ := c.GetInt64("modifier", 0)
  617. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  618. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  619. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  620. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  621. dialysis_item_desc := c.GetString("dialysis_item_desc")
  622. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  623. vascular_access_desc := c.GetString("vascular_access_desc")
  624. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  625. collator, _ := c.GetInt64("collator", 0)
  626. employee_number := c.GetString("employee_number")
  627. if id <= 0 {
  628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  629. return
  630. }
  631. adminUserInfo := c.GetMobileAdminUserInfo()
  632. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  633. if patient.ID == 0 {
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  635. return
  636. }
  637. if len(recordDateStr) == 0 {
  638. recordDateStr = time.Now().Format("2006-01-02")
  639. }
  640. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  641. if parseDateErr != nil {
  642. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  644. return
  645. }
  646. var checkDate int64
  647. if len(checkTimeStr) == 0 {
  648. checkDate = 0
  649. } else {
  650. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  651. checkDate = checkDateUnix.Unix()
  652. }
  653. var firstCheckDate int64
  654. if len(firstCheckTimeStr) == 0 {
  655. firstCheckDate = 0
  656. } else {
  657. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  658. firstCheckDate = firstCheckDateUnix.Unix()
  659. }
  660. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  661. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  662. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  663. if check.ID == 0 {
  664. if employee_number != list.JobNumber {
  665. c.ServeSuccessJSON(map[string]interface{}{
  666. "doubleCheck": check,
  667. "msg": "2",
  668. })
  669. return
  670. }
  671. }
  672. if check.ID > 0 {
  673. if employee_number != list.JobNumber {
  674. c.ServeSuccessJSON(map[string]interface{}{
  675. "doubleCheck": check,
  676. "msg": "2",
  677. })
  678. return
  679. }
  680. }
  681. }
  682. doubleCheck := models.DoubleCheck{
  683. UserOrgId: adminUserInfo.Org.Id,
  684. PatientId: id,
  685. DialysisItemCheck: dialysis_item_check,
  686. DialysisParameterCheck: dialysis_parameter_check,
  687. VascularAccessVerification: vascular_access_verification,
  688. PipelineConnectionCheck: pipeline_connection_check,
  689. DialysisItemDesc: dialysis_item_desc,
  690. DialysisParameterDesc: dialysis_parameter_desc,
  691. VascularAccessDesc: vascular_access_desc,
  692. PipelineConnectionDesc: pipeline_connection_desc,
  693. Collator: collator,
  694. Status: 1,
  695. CreatedTime: time.Now().Unix(),
  696. CheckDate: recordDate.Unix(),
  697. UpdatedTime: time.Now().Unix(),
  698. EmployeeNumber: employee_number,
  699. }
  700. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  701. if check.ID == 0 { //新增
  702. doubleCheck.FirstCheckTime = firstCheckDate
  703. doubleCheck.CheckTime = checkDate
  704. doubleCheck.Creater = creater
  705. doubleCheck.Modifier = modifier
  706. err := service.AddSigleDoubleCheck(&doubleCheck)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  708. redis := service.RedisClient()
  709. defer redis.Close()
  710. //清空key 值
  711. redis.Set(key, "", time.Second)
  712. if err == nil {
  713. c.ServeSuccessJSON(map[string]interface{}{
  714. "doubleCheck": &doubleCheck,
  715. })
  716. }
  717. } else { //修改
  718. doubleCheck.FirstCheckTime = firstCheckDate
  719. doubleCheck.CheckTime = checkDate
  720. doubleCheck.Creater = creater
  721. doubleCheck.Modifier = modifier
  722. doubleCheck.CreatedTime = check.CreatedTime
  723. doubleCheck.ID = check.ID
  724. doubleCheck.EmployeeNumber = employee_number
  725. err := service.UpdateDoubleCheck(&doubleCheck)
  726. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  727. redis := service.RedisClient()
  728. defer redis.Close()
  729. //清空key 值
  730. redis.Set(key, "", time.Second)
  731. if err == nil {
  732. c.ServeSuccessJSON(map[string]interface{}{
  733. "doubleCheck": &doubleCheck,
  734. "msg": "1",
  735. })
  736. }
  737. }
  738. }
  739. func (c *DialysisAPIController) PostAcceptsAssessment() {
  740. id, _ := c.GetInt64("patient", 0)
  741. recordDateStr := c.GetString("record_date")
  742. way, _ := c.GetInt64("way", 0)
  743. consciousness, _ := c.GetInt64("consciousness", 0)
  744. appetite, _ := c.GetInt64("appetite", 0)
  745. condition, _ := c.GetInt64("condition", 0)
  746. posture, _ := c.GetInt64("posture")
  747. sick_condition, _ := c.GetInt64("sick_condition", 0)
  748. danger_level, _ := c.GetInt64("danger_level", 0)
  749. intake, _ := c.GetInt64("intake", 0)
  750. nutrition, _ := c.GetInt64("nutrition", 0)
  751. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  752. psychological_assessment_other := c.GetString("psychological_assessment_other")
  753. score := c.GetString("score")
  754. sick_condition_other := c.GetString("sick_condition_other")
  755. //precaution, _ := c.GetInt64("precaution", 0)
  756. precaution := c.GetString("precaution")
  757. precaution_other := c.GetString("precaution_other")
  758. psychological_other := c.GetString("psychological_other")
  759. admission_number := c.GetString("admission_number")
  760. tumble, _ := c.GetInt64("tumble")
  761. diacrisis := c.GetString("diacrisis")
  762. his_department := c.GetString("his_department")
  763. his_bed := c.GetString("his_bed")
  764. if id <= 0 {
  765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  766. return
  767. }
  768. adminUserInfo := c.GetMobileAdminUserInfo()
  769. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  770. if patient.ID == 0 {
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  772. return
  773. }
  774. //now := time.Now()
  775. //year, month, day := now.Date()
  776. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  777. //todayTimeStamp := today_time.Unix()
  778. if len(recordDateStr) == 0 {
  779. recordDateStr = time.Now().Format("2006-01-02")
  780. }
  781. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  782. if parseDateErr != nil {
  783. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  785. return
  786. }
  787. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  788. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  789. UserOrgId: adminUserInfo.Org.Id,
  790. PatientId: id,
  791. RecordDate: recordDate.Unix(),
  792. Way: way,
  793. Consciousness: consciousness,
  794. Appetite: appetite,
  795. Condition: condition,
  796. SickCondition: sick_condition,
  797. DangerLevel: danger_level,
  798. Intake: intake,
  799. Nutrition: nutrition,
  800. PsychologicalAssessment: psychological_assessment,
  801. PsychologicalAssessmentOther: psychological_assessment_other,
  802. SickConditionOther: sick_condition_other,
  803. Posture: posture,
  804. CreatedTime: time.Now().Unix(),
  805. UpdateTime: time.Now().Unix(),
  806. Status: 1,
  807. Score: score,
  808. Precaution: precaution,
  809. PrecautionOther: precaution_other,
  810. PsychologicalOther: psychological_other,
  811. AdmissionNumber: admission_number,
  812. Tumble: tumble,
  813. Diacrisis: diacrisis,
  814. HisBed: his_bed,
  815. HisDepartment: his_department,
  816. }
  817. if receiveTreatment.ID == 0 { //新增
  818. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  819. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  820. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  821. redis := service.RedisClient()
  822. defer redis.Close()
  823. //清空key 值
  824. redis.Set(key, "", time.Second)
  825. if err == nil {
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "receiveTreatmentAsses": receiveTreatmentAsses,
  828. })
  829. }
  830. } else { //修改
  831. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  832. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  833. // if getPermissionErr != nil {
  834. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  835. // return
  836. // } else if headNursePermission == nil {
  837. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  838. // return
  839. // }
  840. //}
  841. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  842. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  843. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  844. receiveTreatmentAsses.ID = receiveTreatment.ID
  845. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  846. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  847. redis := service.RedisClient()
  848. defer redis.Close()
  849. //清空key 值
  850. redis.Set(key, "", time.Second)
  851. if err == nil {
  852. c.ServeSuccessJSON(map[string]interface{}{
  853. "receiveTreatmentAsses": receiveTreatmentAsses,
  854. })
  855. }
  856. }
  857. }
  858. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  859. id, _ := c.GetInt64("patient", 0)
  860. recordDateStr := c.GetString("record_date")
  861. weightAfter, _ := c.GetFloat("weight_after", 0)
  862. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  863. weightReduce, _ := c.GetFloat("weight_loss", 0)
  864. temperature, _ := c.GetFloat("temperature", 0)
  865. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  866. breathing_rate := c.GetString("breathing_rate")
  867. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  868. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  869. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  870. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  871. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  872. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  873. cruor := c.GetString("cruor")
  874. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  875. internalFistula := c.GetString("internal_fistula")
  876. catheter := c.GetString("catheter")
  877. complications := c.GetString("complication")
  878. remark := c.GetString("remark")
  879. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  880. dialysis_intakes := c.GetString("dialysis_intakes")
  881. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  882. fmt.Println("dialysateVolumewode 23323233223232wode", dialysateVolume)
  883. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  884. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  885. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  886. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  887. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  888. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  889. patientGose, _ := c.GetInt64("patient_gose", 0)
  890. inpatientDepartment := c.GetString("inpatient_department")
  891. observationContent := c.GetString("observation_content")
  892. observationContentOther := c.GetString("observation_content_other")
  893. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  894. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  895. in_advance_reason := c.GetString("in_advance_reason")
  896. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  897. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  898. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  899. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  900. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  901. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  902. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  903. dialyzer, _ := c.GetInt64("dialyzer", 0)
  904. in_advance_reason_other := c.GetString("in_advance_reason_other")
  905. is_eat, _ := c.GetInt64("is_eat", 0)
  906. cvc_a, _ := c.GetFloat("cvc_a", 0)
  907. cvc_v, _ := c.GetFloat("cvc_v", 0)
  908. channels, _ := c.GetInt64("channel", 0)
  909. return_blood, _ := c.GetInt64("return_blood", 0)
  910. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  911. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  912. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  913. blood_flow, _ := c.GetInt64("blood_flow", 0)
  914. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  915. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  916. sealing_fluid_special := c.GetString("sealing_fluid_special")
  917. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  918. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  919. setting_pressure := c.GetString("setting_pressure")
  920. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  921. diastolic_pressure := c.GetString("diastolic_pressure")
  922. other_complication := c.GetString("other_complication")
  923. ktv := c.GetString("ktv")
  924. urr := c.GetString("urr")
  925. hypertenison, _ := c.GetInt64("hypertenison")
  926. hypopiesia, _ := c.GetInt64("hypopiesia")
  927. leave_office_method, _ := c.GetInt64("leave_office_method")
  928. lapse, _ := c.GetInt64("lapse")
  929. consciousness, _ := c.GetInt64("consciousness")
  930. fallrisk, _ := c.GetInt64("fallrisk")
  931. machine_run := c.GetString("machine_run")
  932. after_urea := c.GetString("after_urea")
  933. pip_coagulation := c.GetString("pip_coagulation")
  934. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  935. if id <= 0 {
  936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  937. return
  938. }
  939. adminUserInfo := c.GetMobileAdminUserInfo()
  940. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  941. if patient.ID == 0 {
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  943. return
  944. }
  945. if len(recordDateStr) == 0 {
  946. recordDateStr = time.Now().Format("2006-01-02")
  947. }
  948. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  949. if parseDateErr != nil {
  950. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  952. return
  953. }
  954. //now := time.Now()
  955. //year, month, day := now.Date()
  956. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  957. //todayTimeStamp := today_time.Unix()
  958. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  959. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  960. UserOrgId: adminUserInfo.Org.Id,
  961. PatientId: id,
  962. AssessmentDate: recordDate.Unix(),
  963. Temperature: temperature,
  964. PulseFrequency: pulse_frequency,
  965. BreathingRate: breathing_rate,
  966. SystolicBloodPressure: systolic_blood_pressure,
  967. DiastolicBloodPressure: diastolic_blood_pressure,
  968. ActualUltrafiltration: actual_ultrafiltration,
  969. ActualDisplacement: actual_displacement,
  970. ActualTreatmentHour: actualtreatHour,
  971. ActualTreatmentMinute: actualtreatmin,
  972. WeightAfter: weightAfter,
  973. AdditionalWeight: additionalWeight,
  974. WeightLoss: weightReduce,
  975. Cruor: cruor,
  976. SymptomAfterDialysis: symptomsAfterDialysi,
  977. InternalFistula: internalFistula,
  978. Catheter: catheter,
  979. Complication: complications,
  980. DialysisIntakes: dialysateVolume,
  981. CreatedTime: time.Now().Unix(),
  982. UpdatedTime: time.Now().Unix(),
  983. Status: 1,
  984. Remark: remark,
  985. BloodAccessPartId: blood_access_part_id,
  986. BloodAccessPartOperaId: blood_access_part_opera_id,
  987. DialysisIntakesUnit: dialysis_intakes_unit,
  988. PuncturePointOozingBlood: puncturePointOozingBlood,
  989. PuncturePointHaematoma: puncturePointHaematoma,
  990. InternalFistulaTremorAc: internalFistulaTremorAc,
  991. PatientGose: patientGose,
  992. InpatientDepartment: inpatientDepartment,
  993. ObservationContent: observationContent,
  994. ObservationContentOther: observationContentOther,
  995. DialysisProcess: dialysis_process,
  996. InAdvanceMinute: in_advance_minute,
  997. InAdvanceReason: in_advance_reason,
  998. HemostasisMinute: hemostasis_minute,
  999. HemostasisOpera: hemostasis_opera,
  1000. TremorNoise: tremor_noise,
  1001. DisequilibriumSyndrome: disequilibrium_syndrome,
  1002. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1003. ArterialTube: arterial_tube,
  1004. IntravenousTube: intravenous_tube,
  1005. Dialyzer: dialyzer,
  1006. InAdvanceReasonOther: in_advance_reason_other,
  1007. IsEat: is_eat,
  1008. CvcA: cvc_a,
  1009. CvcV: cvc_v,
  1010. Channel: channels,
  1011. ReturnBlood: return_blood,
  1012. RehydrationVolume: rehydration_volume,
  1013. DialysisDuring: dialysis_during,
  1014. StrokeVolume: stroke_volume,
  1015. BloodFlow: blood_flow,
  1016. SealingFluidDispose: sealing_fluid_dispose,
  1017. SealingFluidSpecial: sealing_fluid_special,
  1018. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1019. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1020. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1021. SettingPressure: setting_pressure,
  1022. DiastolicPressure: diastolic_pressure,
  1023. OtherComplication: other_complication,
  1024. Ktv: ktv,
  1025. Urr: urr,
  1026. Hypopiesia: hypopiesia,
  1027. Hypertenison: hypertenison,
  1028. Lapse: lapse,
  1029. LeaveOfficeMethod: leave_office_method,
  1030. Consciousness: consciousness,
  1031. Fallrisk: fallrisk,
  1032. MachineRun: machine_run,
  1033. AfterUrea: after_urea,
  1034. PipCoagulation: pip_coagulation,
  1035. AccumulatedBloodVolume: accumulated_blood_volume,
  1036. }
  1037. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1038. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1039. if assessmentAfter.ID == 0 { //新增
  1040. if appRole.UserType == 2 || appRole.UserType == 1 {
  1041. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1042. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1043. } else {
  1044. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1045. }
  1046. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1047. redis := service.RedisClient()
  1048. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1049. redis.Set(keyTwo, "", time.Second)
  1050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1051. //清空key 值
  1052. redis.Set(key, "", time.Second)
  1053. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1054. redis.Set(keyOne, "", time.Second)
  1055. defer redis.Close()
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "assessmentAfterDislysis": assessmentAfterDislysis,
  1059. })
  1060. }
  1061. } else { //修改
  1062. if appRole.UserType == 2 || appRole.UserType == 1 {
  1063. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1064. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1065. } else {
  1066. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1067. if assessmentAfterDislysis.Creater == 0 {
  1068. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1069. }
  1070. }
  1071. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1072. assessmentAfterDislysis.ID = assessmentAfter.ID
  1073. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1074. redis := service.RedisClient()
  1075. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1076. redis.Set(keyTwo, "", time.Second)
  1077. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1078. //清空key 值
  1079. redis.Set(key, "", time.Second)
  1080. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1081. redis.Set(keyOne, "", time.Second)
  1082. fmt.Println("err233332323232232323", err)
  1083. if err == nil {
  1084. c.ServeSuccessJSON(map[string]interface{}{
  1085. "assessmentAfterDislysis": assessmentAfterDislysis,
  1086. })
  1087. }
  1088. }
  1089. }
  1090. func (c *DialysisAPIController) PostDialysisPrescription() {
  1091. id, _ := c.GetInt64("patient", 0)
  1092. recordDateStr := c.GetString("record_date")
  1093. if id <= 0 {
  1094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1095. return
  1096. }
  1097. adminUserInfo := c.GetMobileAdminUserInfo()
  1098. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1099. if patient.ID == 0 {
  1100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1101. return
  1102. }
  1103. if len(recordDateStr) == 0 {
  1104. recordDateStr = time.Now().Format("2006-01-02")
  1105. }
  1106. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1107. if parseDateErr != nil {
  1108. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. mode_id, _ := c.GetInt64("mode_id", 0)
  1113. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1114. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1115. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1116. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1117. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1118. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1119. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1120. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1121. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1122. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1123. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1124. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1125. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1126. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1127. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1128. kalium, _ := c.GetFloat("kalium", 0)
  1129. sodium, _ := c.GetFloat("sodium", 0)
  1130. calcium, _ := c.GetFloat("calcium", 0)
  1131. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1132. glucose, _ := c.GetFloat("glucose", 0)
  1133. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1134. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1135. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1136. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1137. conductivity, _ := c.GetFloat("conductivity", 0)
  1138. remark := c.GetString("remark")
  1139. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1140. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1141. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1142. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1143. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1144. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1145. special_medicine_other := c.GetString("special_medicine_other")
  1146. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1147. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1148. blood_access, _ := c.GetInt64("blood_access", 0)
  1149. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1150. body_fluid_other := c.GetString("body_fluid_other")
  1151. niprocart, _ := c.GetInt64("niprocart", 0)
  1152. jms, _ := c.GetInt64("jms", 0)
  1153. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1154. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1155. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1156. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1157. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1158. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1159. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1160. injector, _ := c.GetInt64("injector", 0)
  1161. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1162. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1163. safe_package, _ := c.GetInt64("package", 0)
  1164. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1165. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1166. fmt.Println("预冲量", pre_impulse)
  1167. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1168. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1169. blood := c.GetString("blood")
  1170. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1171. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1172. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1173. displace_speed := c.GetString("displace_speed")
  1174. illness, _ := c.GetInt64("illness")
  1175. amylaceum := c.GetString("amylaceum")
  1176. single_time := c.GetString("single_time")
  1177. single_water := c.GetString("single_water")
  1178. replacement_flow := c.GetString("replacement_flow")
  1179. plasma_separator := c.GetString("plasma_separator")
  1180. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1181. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1182. oxygen_flow := c.GetString("oxygen_flow")
  1183. oxygen_time := c.GetString("oxygen_time")
  1184. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1185. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1186. puncture_needle := c.GetString("puncture_needle")
  1187. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1188. epo := c.GetString("epo")
  1189. epo_count, _ := c.GetFloat("epo_count", 0)
  1190. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1191. admin_user_id, _ := c.GetInt64("admin_user_id")
  1192. is_water := c.GetString("is_water")
  1193. var is_war int64
  1194. if is_water == "是" {
  1195. is_war = 1
  1196. }
  1197. if is_water == "否" {
  1198. is_war = 2
  1199. }
  1200. if is_water == "请选择" {
  1201. is_war = 0
  1202. }
  1203. drhy_water := c.GetString("drhy_water")
  1204. dry_water_hour := c.GetString("dry_water_hour")
  1205. water_machine := c.GetString("water_machine")
  1206. add_amount, _ := c.GetFloat("add_amount")
  1207. reduce_amount, _ := c.GetFloat("reduce_amount")
  1208. dialysis_remark := c.GetString("dialysis_remark")
  1209. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1210. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1211. //
  1212. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1213. // if appRole.UserType == 3 {
  1214. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1215. // if getPermissionErr != nil {
  1216. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1217. // return
  1218. // } else if headNursePermission == nil {
  1219. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1220. // return
  1221. // }
  1222. // }
  1223. //}
  1224. //TODO 需要根据角色去判断
  1225. prescription := models.DialysisPrescription{
  1226. UserOrgId: adminUserInfo.Org.Id,
  1227. PatientId: id,
  1228. RecordDate: recordDate.Unix(),
  1229. ModeId: mode_id,
  1230. DialysisDuration: dialysis_duration,
  1231. Dialyzer: dialyzer,
  1232. PerfusionApparatus: perfusion_apparatus,
  1233. BloodFlowVolume: blood_flow_volume,
  1234. DewaterAmount: dewater_amount,
  1235. DisplaceLiqui: displace_liqui,
  1236. ReplacementWay: replacement_way,
  1237. Anticoagulant: anticoagulant,
  1238. AnticoagulantShouji: anticoagulant_shouji,
  1239. AnticoagulantWeichi: anticoagulant_weichi,
  1240. AnticoagulantZongliang: anticoagulant_zongliang,
  1241. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1242. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1243. Kalium: kalium,
  1244. Sodium: sodium,
  1245. Calcium: calcium,
  1246. Bicarbonate: bicarbonate,
  1247. Glucose: glucose,
  1248. // DryWeight: dry_weight,
  1249. DialysateFlow: dialysate_flow,
  1250. DialysateTemperature: dialysate_temperature,
  1251. // PrescriptionDoctor: prescription_doctor,
  1252. ReplacementTotal: replacement_total,
  1253. Conductivity: conductivity,
  1254. Remark: remark,
  1255. Status: 1,
  1256. CreatedTime: time.Now().Unix(),
  1257. UpdatedTime: time.Now().Unix(),
  1258. DialysisDurationMinute: dialysisDurationMinute,
  1259. DialysisDurationHour: dialysisDurationHour,
  1260. TargetUltrafiltration: targetUltrafiltration,
  1261. DialysateFormulation: dialysateFormulation,
  1262. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1263. BodyFluid: body_fluid,
  1264. SpecialMedicine: special_medicine,
  1265. SpecialMedicineOther: special_medicine_other,
  1266. DisplaceLiquiPart: displace_liqui_part,
  1267. DisplaceLiquiValue: displace_liqui_value,
  1268. BloodAccess: blood_access,
  1269. Ultrafiltration: ultrafiltration,
  1270. BodyFluidOther: body_fluid_other,
  1271. Niprocart: niprocart,
  1272. Jms: jms,
  1273. FistulaNeedleSet: fistula_needle_set,
  1274. FistulaNeedleSet16: fistula_needle_set_16,
  1275. Hemoperfusion: hemoperfusion,
  1276. DialyserSterilised: dialyser_sterilised,
  1277. Filtryzer: filtryzer,
  1278. Dialyzers: dialyzers,
  1279. Injector: injector,
  1280. Bloodlines: bloodlines,
  1281. TubingHemodialysis: tubing_hemodialysis,
  1282. Package: safe_package,
  1283. ALiquid: a_liquid,
  1284. TargetKtv: target_ktv,
  1285. PreImpulse: pre_impulse,
  1286. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1287. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1288. Blood: blood,
  1289. DialysisDialyszers: dialysis_dialyszers,
  1290. DialysisIrrigation: dialysis_irrigation,
  1291. AntioxidantCommodityName: antioxidant_commodity_name,
  1292. DisplaceSpeed: displace_speed,
  1293. Illness: illness,
  1294. Amylaceum: amylaceum,
  1295. SingleTime: single_time,
  1296. SingleWater: single_water,
  1297. ReplacementFlow: replacement_flow,
  1298. PlasmaSeparator: plasma_separator,
  1299. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1300. OxygenUptake: oxygen_uptake,
  1301. OxygenFlow: oxygen_flow,
  1302. OxygenTime: oxygen_time,
  1303. HemodialysisPipelines: hemodialysis_pipelines,
  1304. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1305. PunctureNeedle: puncture_needle,
  1306. PunctureNeedleCount: puncture_needle_count,
  1307. Epo: epo,
  1308. EpoCount: epo_count,
  1309. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1310. AdminUserId: admin_user_id,
  1311. IsWater: is_war,
  1312. DrhyWater: drhy_water,
  1313. DryWaterHour: dry_water_hour,
  1314. WaterMachine: water_machine,
  1315. AddAmount: add_amount,
  1316. ReduceAmount: reduce_amount,
  1317. DialysisRemark: dialysis_remark,
  1318. }
  1319. //查询最近透析准备表里是否存在 透析器 灌流器
  1320. //
  1321. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1322. //
  1323. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1324. //
  1325. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1326. //if len(mation)>0{
  1327. // for _, item := range splitStr {
  1328. // for _,it := range mation{
  1329. // if(item == it.SpecificationName){
  1330. //
  1331. // //查询最近一次的透析器
  1332. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1333. //
  1334. // if errcode == gorm.ErrRecordNotFound{
  1335. // //插入数据
  1336. // prepare := models.DialysisBeforePrepare{
  1337. // UserOrgId: adminUserInfo.Org.Id,
  1338. // PatientId: id,
  1339. // RecordDate: recordDate.Unix(),
  1340. // GoodTypeId: it.GoodTypeId,
  1341. // GoodId: it.ID,
  1342. // Count: 1,
  1343. // Ctime: time.Now().Unix(),
  1344. // Creater: adminUserInfo.AdminUser.Id,
  1345. // Status:1,
  1346. //
  1347. // }
  1348. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1349. // fmt.Println("",errcode)
  1350. // }
  1351. // }
  1352. // }
  1353. //
  1354. // }
  1355. //
  1356. // for _, item := range splitIrrigation {
  1357. // for _,it := range mation{
  1358. // if(item == it.SpecificationName){
  1359. // //查询最近一次的透析器
  1360. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1361. // if errcode == gorm.ErrRecordNotFound{
  1362. // //插入数据
  1363. // prepare := models.DialysisBeforePrepare{
  1364. // UserOrgId: adminUserInfo.Org.Id,
  1365. // PatientId: id,
  1366. // RecordDate: recordDate.Unix(),
  1367. // GoodTypeId: it.GoodTypeId,
  1368. // GoodId: it.ID,
  1369. // Count: 1,
  1370. // Ctime: time.Now().Unix(),
  1371. // Creater: adminUserInfo.AdminUser.Id,
  1372. // Status:1,
  1373. //
  1374. // }
  1375. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1376. // fmt.Println(errcode)
  1377. // }
  1378. // }
  1379. // }
  1380. // }
  1381. //}
  1382. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1383. if dialysisPrescription.ID == 0 { //新增
  1384. if appRole.UserType == 2 || appRole.UserType == 1 {
  1385. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1386. }
  1387. prescription.Creater = adminUserInfo.AdminUser.Id
  1388. //针对河间咸得
  1389. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1390. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1391. prescription.DisplaceLiquiPart = 0
  1392. prescription.DisplaceLiquiValue = 0
  1393. }
  1394. }
  1395. err := service.AddSigleRecord(&prescription)
  1396. //获取key,清空redis
  1397. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1398. redis := service.RedisClient()
  1399. //清空key 值
  1400. redis.Set(key, "", time.Second)
  1401. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1402. //清空key 值
  1403. redis.Set(keyOne, "", time.Second)
  1404. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1405. //清空key 值
  1406. redis.Set(keyTwo, "", time.Second)
  1407. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1408. redis.Set(keySix, "", time.Second)
  1409. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1410. redis.Set(keySeven, "", time.Second)
  1411. if err == nil {
  1412. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1413. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1414. //清空key 值
  1415. redis.Set(keyThree, "", time.Second)
  1416. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1417. //清空key 值
  1418. redis.Set(keyFour, "", time.Second)
  1419. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1420. redis.Set(keyFive, "", time.Second)
  1421. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1422. redis.Set(keySix, "", time.Second)
  1423. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1424. redis.Set(keySeven, "", time.Second)
  1425. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1426. //清空key 值
  1427. redis.Set(keyOne, "", time.Second)
  1428. if updateErr != nil {
  1429. utils.ErrorLog("%v", updateErr)
  1430. }
  1431. defer redis.Close()
  1432. c.ServeSuccessJSON(map[string]interface{}{
  1433. "prescription": prescription,
  1434. })
  1435. }
  1436. } else { //修改
  1437. //if mode_id > 0 {
  1438. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1439. //}
  1440. //if template.TemplateId == 1 {
  1441. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1442. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1443. // if getPermissionErr != nil {
  1444. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1445. // return
  1446. // } else if headNursePermission == nil {
  1447. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1448. // return
  1449. // }
  1450. // }
  1451. //}
  1452. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1453. prescription.Modifier = adminUserInfo.AdminUser.Id
  1454. if appRole.UserType == 2 || appRole.UserType == 1 {
  1455. prescription_doctor := adminUserInfo.AdminUser.Id
  1456. prescription.PrescriptionDoctor = prescription_doctor
  1457. } else {
  1458. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1459. }
  1460. if dialysisPrescription.Creater == 0 { //体重称
  1461. prescription.Creater = adminUserInfo.AdminUser.Id
  1462. } else {
  1463. prescription.Creater = dialysisPrescription.Creater
  1464. }
  1465. prescription.ID = dialysisPrescription.ID
  1466. err := service.UpDateDialysisPrescription(&prescription)
  1467. //获取key,清空redis
  1468. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1469. redis := service.RedisClient()
  1470. //清空key 值
  1471. redis.Set(key, "", time.Second)
  1472. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1473. //清空key 值
  1474. redis.Set(keyOne, "", time.Second)
  1475. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1476. redis.Set(keySix, "", time.Second)
  1477. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1478. redis.Set(keySeven, "", time.Second)
  1479. if err == nil {
  1480. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1481. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1482. //清空key 值
  1483. redis.Set(keyOne, "", time.Second)
  1484. defer redis.Close()
  1485. if updateErr != nil {
  1486. utils.ErrorLog("%v", updateErr)
  1487. }
  1488. c.ServeSuccessJSON(map[string]interface{}{
  1489. "prescription": prescription,
  1490. })
  1491. }
  1492. }
  1493. }
  1494. func (c *DialysisAPIController) Finish() {
  1495. id, _ := c.GetInt64("patient", 0)
  1496. recordDateStr := c.GetString("record_date")
  1497. nurseID, _ := c.GetInt64("nurse")
  1498. end_time := c.GetString("end_time")
  1499. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  1500. internal_fistula := c.GetString("blood_access_internal_fistula")
  1501. catheter := c.GetString("catheter")
  1502. cruor := c.GetString("cruor")
  1503. mission := c.GetString("mission")
  1504. if id <= 0 || nurseID <= 0 {
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1506. return
  1507. }
  1508. adminUserInfo := c.GetMobileAdminUserInfo()
  1509. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1510. if patient.ID == 0 {
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1512. return
  1513. }
  1514. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1515. if getNurseErr != nil {
  1516. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1518. return
  1519. } else if nurse == nil {
  1520. c.ErrorLog("护士不存在")
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1522. return
  1523. }
  1524. if len(recordDateStr) == 0 {
  1525. recordDateStr = time.Now().Format("2006-01-02")
  1526. }
  1527. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1528. if parseDateErr != nil {
  1529. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1531. return
  1532. }
  1533. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1534. if parseEndDateErr != nil {
  1535. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1537. return
  1538. }
  1539. //now := time.Now()
  1540. //year, month, day := now.Date()
  1541. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1542. //todayTimeStamp := today_time.Unix()
  1543. // 获取当天的第一条透析纪录
  1544. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1545. if getMonitorRecordsErr != nil {
  1546. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1548. return
  1549. }
  1550. // 获取当前的最后一条透析纪录
  1551. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1552. if getMonitorRecordsErr != nil {
  1553. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1555. return
  1556. }
  1557. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1558. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1559. if getAADErr != nil {
  1560. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1562. return
  1563. }
  1564. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1565. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1566. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1567. if assessmentAfterDislysis != nil {
  1568. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1569. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1570. } else {
  1571. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1572. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1573. tempassessmentAfterDislysis.Status = 1
  1574. tempassessmentAfterDislysis.PatientId = id
  1575. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1576. }
  1577. //长沙南雅
  1578. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  1579. //获取最后一条透析处方数据
  1580. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1581. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  1582. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  1583. }
  1584. if dialysisOrder.Stage == 1 {
  1585. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1586. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1587. fmt.Println(value)
  1588. a, b := math.Modf(value)
  1589. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1590. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1591. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1592. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1593. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1594. }
  1595. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1596. //var num1 int64
  1597. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1598. //fmt.Println(num1)
  1599. //sub := float64(num1 / 3600)
  1600. //fmt.Println(sub)
  1601. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1602. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1603. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1604. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1605. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1606. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1607. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1608. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1609. if adminUserInfo.Org.Id != 10445 {
  1610. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1611. }
  1612. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1613. }
  1614. 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 {
  1615. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  1616. if evaluation.SystolicBloodPressure == 0 {
  1617. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  1618. pre := models.PredialysisEvaluation{
  1619. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  1620. }
  1621. fmt.Println("prew", pre)
  1622. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  1623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1624. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1625. redis := service.RedisClient()
  1626. redis.Set(key, "", time.Second)
  1627. redis.Set(keyOne, "", time.Second)
  1628. defer redis.Close()
  1629. fmt.Println(getNurseErr)
  1630. }
  1631. if evaluation.DiastolicBloodPressure == 0 {
  1632. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  1633. pres := models.PredialysisEvaluation{
  1634. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  1635. }
  1636. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  1637. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1638. redis := service.RedisClient()
  1639. redis.Set(key, "", time.Second)
  1640. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1641. redis.Set(keyOne, "", time.Second)
  1642. defer redis.Close()
  1643. fmt.Println(getNurseErr)
  1644. }
  1645. if evaluation.PulseFrequency == 0 {
  1646. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  1647. press := models.PredialysisEvaluation{
  1648. PulseFrequency: evaluation.PulseFrequency,
  1649. }
  1650. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  1651. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1652. redis := service.RedisClient()
  1653. redis.Set(key, "", time.Second)
  1654. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1655. redis.Set(keyOne, "", time.Second)
  1656. defer redis.Close()
  1657. fmt.Println(getNurseErr)
  1658. }
  1659. if evaluation.Temperature == 0 {
  1660. evaluation.Temperature = fmonitorRecords.Temperature
  1661. press := models.PredialysisEvaluation{
  1662. Temperature: evaluation.Temperature,
  1663. }
  1664. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  1665. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1666. redis := service.RedisClient()
  1667. redis.Set(key, "", time.Second)
  1668. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1669. redis.Set(keyOne, "", time.Second)
  1670. defer redis.Close()
  1671. fmt.Println(getNurseErr)
  1672. }
  1673. }
  1674. if adminUserInfo.Org.Id == 9583 {
  1675. //获取透析处方的最后一条数据
  1676. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1677. if diaerr != nil {
  1678. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1680. return
  1681. }
  1682. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1683. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1684. }
  1685. }
  1686. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  1687. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1688. }
  1689. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  1690. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  1691. }
  1692. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  1693. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1694. }
  1695. if lastAssessmentAfterDislysis != nil {
  1696. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1697. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1698. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1699. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1700. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1701. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1702. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1703. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1704. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1705. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1706. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1707. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1708. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1709. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1710. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1711. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1712. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1713. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1714. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1715. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1716. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1717. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1718. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1719. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1720. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1721. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1722. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1723. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1724. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1725. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1726. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1727. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1728. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1729. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1730. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1731. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1732. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1733. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1734. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1735. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1736. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1737. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1738. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1739. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1740. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1741. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1742. }
  1743. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1744. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1745. redis := service.RedisClient()
  1746. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1747. redis.Set(keyOne, "", time.Second)
  1748. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  1749. redis.Set(keyTwo, "", time.Second)
  1750. defer redis.Close()
  1751. //清空key 值
  1752. redis.Set(key, "", time.Second)
  1753. if err != nil {
  1754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1755. return
  1756. }
  1757. if dialysisOrder == nil {
  1758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1759. return
  1760. }
  1761. if dialysisOrder.Stage == 2 {
  1762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1763. return
  1764. }
  1765. if dialysisOrder.Stage == 1 {
  1766. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  1767. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  1768. redis := service.RedisClient()
  1769. defer redis.Close()
  1770. //清空key 值
  1771. redis.Set(key, "", time.Second)
  1772. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  1773. redis.Set(keyOne, "", time.Second)
  1774. //结束时候透析次数加1
  1775. service.UpdateSolutionByPatientId(id)
  1776. dialysisOrder.Stage = 2
  1777. dialysisOrder.FinishNurse = nurseID
  1778. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1779. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1780. dialysisOrder.EndTime = endDate.Unix()
  1781. go func() {
  1782. ssoDomain := beego.AppConfig.String("call_domain")
  1783. api := ssoDomain + "/index/downpatient"
  1784. values := make(url.Values)
  1785. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  1786. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1787. values.Set("patient_id", strconv.FormatInt(id, 10))
  1788. http.PostForm(api, values)
  1789. }()
  1790. if err == nil {
  1791. c.ServeSuccessJSON(map[string]interface{}{
  1792. "dialysisOrder": dialysisOrder,
  1793. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1794. })
  1795. } else {
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1797. }
  1798. }
  1799. }
  1800. func (c *DialysisAPIController) GetAllZone() {
  1801. adminUserInfo := c.GetMobileAdminUserInfo()
  1802. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1803. if err == nil {
  1804. c.ServeSuccessJSON(map[string]interface{}{
  1805. "zone": zone,
  1806. })
  1807. }
  1808. }
  1809. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1810. adminUserInfo := c.GetMobileAdminUserInfo()
  1811. page, _ := c.GetInt64("page", 1)
  1812. limit, _ := c.GetInt64("limit", 10)
  1813. schedulType, _ := c.GetInt64("schedul_type", 0)
  1814. startTime, _ := c.GetInt64("schedul_time", 0)
  1815. partitionType, _ := c.GetInt64("partition_type", 0)
  1816. keywords := c.GetString("keywords")
  1817. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1818. if err == nil {
  1819. c.ServeSuccessJSON(map[string]interface{}{
  1820. "schedule": dialysisSchedule,
  1821. })
  1822. }
  1823. return
  1824. }
  1825. // /m/api/dialysis/start [post]
  1826. // @param patient_id:int
  1827. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1828. // @param nurse:int 上机护士
  1829. // @param bed:int 床位号
  1830. func (this *DialysisAPIController) StartDialysis() {
  1831. patientID, _ := this.GetInt64("patient_id")
  1832. recordDateStr := this.GetString("record_date")
  1833. nurseID, _ := this.GetInt64("nurse")
  1834. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1835. blood_drawing, _ := this.GetInt64("blood_drawing")
  1836. schedual_type, _ := this.GetInt64("schedual_type")
  1837. bedID, _ := this.GetInt64("bed")
  1838. start_time := this.GetString("start_time")
  1839. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1840. change_nurse, _ := this.GetInt64("change_nurse")
  1841. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1842. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1843. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  1844. puncture_needle := this.GetString("puncture_needle")
  1845. puncture_way := this.GetString("puncture_way")
  1846. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  1847. dialysis_irrigation := this.GetString("dialysis_irrigation")
  1848. blood_access_id, _ := this.GetInt64("blood_access_id")
  1849. zone_id, _ := this.GetInt64("zone_id")
  1850. elecsign := this.GetString("url")
  1851. nuclein_date_str := this.GetString("nuclein_date_str")
  1852. schedule_remark := this.GetString("schedule_remark")
  1853. order_remark := this.GetString("order_remark")
  1854. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1856. return
  1857. }
  1858. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1859. if parseStartDateErr != nil {
  1860. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1865. if parseErr != nil {
  1866. this.ErrorLog("时间解析失败:%v", parseErr)
  1867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1868. return
  1869. }
  1870. adminUserInfo := this.GetMobileAdminUserInfo()
  1871. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1872. if getPatientErr != nil {
  1873. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1875. return
  1876. } else if patient == nil {
  1877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1878. return
  1879. }
  1880. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1881. if getNurseErr != nil {
  1882. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1884. return
  1885. } else if nurse == nil {
  1886. this.ErrorLog("护士不存在")
  1887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1888. return
  1889. }
  1890. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1891. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1892. if getDeviceNumberErr != nil {
  1893. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1895. return
  1896. } else if deviceNumber == nil {
  1897. this.ErrorLog("床位号不存在")
  1898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1899. return
  1900. }
  1901. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1902. if getRecordErr != nil {
  1903. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1905. return
  1906. } else if dialysisRecord != nil {
  1907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1908. return
  1909. }
  1910. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1911. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1912. timeLayout := "2006-01-02 15:04:05"
  1913. loc, _ := time.LoadLocation("Local")
  1914. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1915. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1916. schedulestartTime := theStartTime.Unix()
  1917. scheduleendTime := theEndTime.Unix()
  1918. var theNucleinDate int64
  1919. timeLayoutOne := "2006-01-02"
  1920. if len(nuclein_date_str) > 0 {
  1921. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  1922. if err != nil {
  1923. utils.ErrorLog(err.Error())
  1924. }
  1925. theNucleinDate = theTime.Unix()
  1926. }
  1927. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1928. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1929. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  1930. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1931. //查询该床位是否有人用了
  1932. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1933. if err == gorm.ErrRecordNotFound { //空床位
  1934. // 修改了床位逻辑
  1935. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1936. if daySchedule.ID > 0 {
  1937. daySchedule.PartitionId = deviceNumber.ZoneID
  1938. daySchedule.BedId = bedID
  1939. daySchedule.ScheduleType = schedual_type
  1940. daySchedule.UpdatedTime = time.Now().Unix()
  1941. xtSchedule := models.Schedule{
  1942. PartitionId: deviceNumber.ZoneID,
  1943. BedId: bedID,
  1944. ScheduleType: schedual_type,
  1945. UpdatedTime: time.Now().Unix(),
  1946. }
  1947. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1948. if err != nil {
  1949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1950. return
  1951. }
  1952. }
  1953. } else if err == nil {
  1954. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1955. if order.ID > 0 { //该机位被其他人占用了
  1956. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1957. return
  1958. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  1959. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1960. if daySchedule.ID > 0 {
  1961. //daySchedule.PartitionId = deviceNumber.ZoneID
  1962. //daySchedule.BedId = bedID
  1963. //daySchedule.ScheduleType = schedual_type
  1964. //daySchedule.UpdatedTime = time.Now().Unix()
  1965. //err := service.UpdateSchedule(&daySchedule)
  1966. //xtSchedule := models.Schedule{
  1967. // PartitionId: deviceNumber.ZoneID,
  1968. // BedId: bedID,
  1969. // ScheduleType: schedual_type,
  1970. // UpdatedTime: time.Now().Unix(),
  1971. //}
  1972. //err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1973. service.UpdateScheduleTwo(daySchedule, schedule)
  1974. }
  1975. }
  1976. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1978. return
  1979. }
  1980. //else if order.ID == 0 { //该床位没被占用
  1981. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1982. // if daySchedule.ID > 0 {
  1983. // //daySchedule.PartitionId = deviceNumber.ZoneID
  1984. // //daySchedule.BedId = bedID
  1985. // //daySchedule.ScheduleType = schedual_type
  1986. // //daySchedule.UpdatedTime = time.Now().Unix()
  1987. // //err := service.UpdateSchedule(&daySchedule)
  1988. // xtSchedule := models.Schedule{
  1989. // PartitionId: deviceNumber.ZoneID,
  1990. // BedId: bedID,
  1991. // ScheduleType: schedual_type,
  1992. // UpdatedTime: time.Now().Unix(),
  1993. // }
  1994. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  1995. // if err != nil {
  1996. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1997. // return
  1998. // }
  1999. // }
  2000. //}
  2001. //}
  2002. } else if err != nil {
  2003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2004. return
  2005. }
  2006. dialysisRecord = &models.DialysisOrder{
  2007. DialysisDate: recordDate.Unix(),
  2008. UserOrgId: adminUserInfo.Org.Id,
  2009. PatientId: patientID,
  2010. Stage: 1,
  2011. BedID: bedID,
  2012. StartNurse: nurseID,
  2013. Status: 1,
  2014. StartTime: startDate.Unix(),
  2015. CreatedTime: time.Now().Unix(),
  2016. UpdatedTime: time.Now().Unix(),
  2017. PunctureNurse: puncture_nurse,
  2018. Creator: adminUserInfo.AdminUser.Id,
  2019. Modifier: adminUserInfo.AdminUser.Id,
  2020. SchedualType: schedual_type,
  2021. WashpipeNurse: washpipe_nurse,
  2022. ChangeNurse: change_nurse,
  2023. DifficultPunctureNurse: difficult_puncture_nurse,
  2024. NewFistulaNurse: new_fistula_nurse,
  2025. ZoneId: zone_id,
  2026. QualityNurseId: quality_nurse_id,
  2027. PunctureNeedle: puncture_needle,
  2028. PunctureWay: puncture_way,
  2029. DialysisIrrigation: dialysis_irrigation,
  2030. DialysisDialyszers: dialysis_dialyszers,
  2031. BloodAccessId: blood_access_id,
  2032. Url: elecsign,
  2033. NucleinDate: theNucleinDate,
  2034. ScheduleRemark: schedule_remark,
  2035. OrderRemark: order_remark,
  2036. }
  2037. //查询该床位是否有人用了
  2038. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2039. if errorscode == gorm.ErrRecordNotFound {
  2040. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2041. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2042. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2043. //统计该患者总次数
  2044. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2045. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2046. }
  2047. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2048. //统计该患者总次数
  2049. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2050. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2051. }
  2052. redis := service.RedisClient()
  2053. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2054. redis.Set(key, "", time.Second)
  2055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2056. //清空key 值
  2057. redis.Set(keyOne, "", time.Second)
  2058. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2059. //清空key 值
  2060. redis.Set(keyTwo, "", time.Second)
  2061. if createErr != nil {
  2062. this.ErrorLog("上机失败:%v", createErr)
  2063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2064. return
  2065. }
  2066. }
  2067. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2068. var tempdispose string
  2069. // 只针对中能建
  2070. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2071. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2072. }
  2073. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2074. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2075. }
  2076. var ultrafiltration_rate float64
  2077. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2078. //后期预增脱水量
  2079. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2080. if prescription.ID > 0 {
  2081. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2082. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2083. if (template.TemplateId == 6 || template.TemplateId == 32) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2084. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2085. }
  2086. //针对医师汇
  2087. if adminUserInfo.Org.Id == 10121 {
  2088. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2089. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2090. }
  2091. //针对通道
  2092. if adminUserInfo.Org.Id == 10234 {
  2093. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2094. }
  2095. //针对监利大垸医院
  2096. if template.TemplateId == 41 {
  2097. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2098. }
  2099. //针对肇庆三鹤血液透析中心
  2100. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 {
  2101. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2102. }
  2103. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2104. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2105. }
  2106. // 只针对方济医院
  2107. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2108. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2109. ultrafiltration_rate = value
  2110. }
  2111. }
  2112. }
  2113. record := models.MonitoringRecord{
  2114. UserOrgId: adminUserInfo.Org.Id,
  2115. PatientId: patientID,
  2116. DialysisOrderId: dialysisRecord.ID,
  2117. MonitoringDate: schedulestartTime,
  2118. OperateTime: startDate.Unix(),
  2119. // MonitoringTime: recordTime,
  2120. MonitoringNurse: nurseID,
  2121. Dispose: tempdispose,
  2122. UltrafiltrationRate: ultrafiltration_rate,
  2123. UltrafiltrationVolume: 0,
  2124. Status: 1,
  2125. CreatedTime: time.Now().Unix(),
  2126. UpdatedTime: time.Now().Unix(),
  2127. }
  2128. //只针对广慈医院
  2129. 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 {
  2130. // 查询病人是否有透前评估数据
  2131. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2132. //如果有数据就插入
  2133. if errcode == nil {
  2134. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2135. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2136. record.BreathingRate = befor.BreathingRate
  2137. record.PulseFrequency = befor.PulseFrequency
  2138. record.Temperature = befor.Temperature
  2139. }
  2140. }
  2141. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2142. if newdialysisRecord.ID > 0 {
  2143. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 {
  2144. record.Temperature = 36.5
  2145. record.ArterialPressure = -100
  2146. record.DialysateTemperature = 36.5
  2147. record.Conductivity = 14
  2148. record.BreathingRate = "20"
  2149. record.VenousPressure = 80
  2150. record.TransmembranePressure = 60
  2151. }
  2152. //针对兰溪人民医院的需求
  2153. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2154. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2155. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2156. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2157. record.Temperature = befor.Temperature
  2158. record.PulseFrequency = befor.PulseFrequency
  2159. record.BreathingRate = befor.BreathingRate
  2160. }
  2161. err := service.CreateMonitor(&record)
  2162. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2163. redis := service.RedisClient()
  2164. //清空key 值
  2165. redis.Set(key, "", time.Second)
  2166. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2167. redis.Set(keyOne, "", time.Second)
  2168. defer redis.Close()
  2169. if err != nil {
  2170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2171. return
  2172. }
  2173. }
  2174. go func() {
  2175. ssoDomain := beego.AppConfig.String("call_domain")
  2176. api := ssoDomain + "/index/uppatient"
  2177. values := make(url.Values)
  2178. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2179. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2180. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2181. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2182. http.PostForm(api, values)
  2183. }()
  2184. this.ServeSuccessJSON(map[string]interface{}{
  2185. "dialysis_order": newdialysisRecord,
  2186. "monitor": record,
  2187. })
  2188. return
  2189. }
  2190. func (c *DialysisAPIController) PostSolution() {
  2191. id, _ := c.GetInt64("patient", 0)
  2192. recordDateStr := c.GetString("record_date")
  2193. if id <= 0 {
  2194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2195. return
  2196. }
  2197. adminUserInfo := c.GetMobileAdminUserInfo()
  2198. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2199. if patient.ID == 0 {
  2200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2201. return
  2202. }
  2203. if len(recordDateStr) == 0 {
  2204. recordDateStr = time.Now().Format("2006-01-02")
  2205. }
  2206. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2207. if parseDateErr != nil {
  2208. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2210. return
  2211. }
  2212. mode_id, _ := c.GetInt64("mode_id", 0)
  2213. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  2214. dialyzer, _ := c.GetInt64("dialyzer", 0)
  2215. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  2216. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2217. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  2218. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  2219. replacement_way, _ := c.GetInt64("replacement_way", 0)
  2220. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  2221. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  2222. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  2223. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  2224. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  2225. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  2226. kalium, _ := c.GetFloat("kalium", 0)
  2227. sodium, _ := c.GetFloat("sodium", 0)
  2228. calcium, _ := c.GetFloat("calcium", 0)
  2229. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  2230. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  2231. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  2232. glucose, _ := c.GetFloat("glucose", 0)
  2233. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  2234. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2235. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2236. conductivity, _ := c.GetFloat("conductivity", 0)
  2237. remark := c.GetString("remark")
  2238. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  2239. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  2240. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  2241. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  2242. body_fluid, _ := c.GetInt64("body_fluid", 0)
  2243. special_medicine, _ := c.GetInt64("special_medicine", 0)
  2244. special_medicine_other := c.GetString("special_medicine_other")
  2245. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  2246. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  2247. blood_access, _ := c.GetInt64("blood_access", 0)
  2248. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  2249. body_fluid_other := c.GetString("body_fluid_other")
  2250. replacement_total, _ := c.GetFloat("replacement_total", 0)
  2251. niprocart, _ := c.GetInt64("niprocart", 0)
  2252. jms, _ := c.GetInt64("jms", 0)
  2253. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  2254. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  2255. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  2256. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  2257. filtryzer, _ := c.GetInt64("filtryzer", 0)
  2258. target_ktv, _ := c.GetFloat("target_ktv", 0)
  2259. dialyzers, _ := c.GetInt64("dialyzers", 0)
  2260. injector, _ := c.GetInt64("injector", 0)
  2261. bloodlines, _ := c.GetInt64("bloodlines", 0)
  2262. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  2263. safe_package, _ := c.GetInt64("package", 0)
  2264. a_liquid, _ := c.GetInt64("a_liquid", 0)
  2265. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  2266. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  2267. blood := c.GetString("blood")
  2268. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  2269. dialysis_irrigation := c.GetString("dialysis_irrigation")
  2270. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  2271. displace_speed := c.GetString("displace_speed")
  2272. illness, _ := c.GetInt64("illness")
  2273. amylaceum := c.GetString("amylaceum")
  2274. single_time := c.GetString("single_time")
  2275. single_water := c.GetString("single_water")
  2276. replacement_flow := c.GetString("replacement_flow")
  2277. plasma_separator := c.GetString("plasma_separator")
  2278. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  2279. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  2280. oxygen_flow := c.GetString("oxygen_flow")
  2281. oxygen_time := c.GetString("oxygen_time")
  2282. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  2283. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  2284. puncture_needle := c.GetString("puncture_needle")
  2285. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  2286. epo := c.GetString("epo")
  2287. epo_count, _ := c.GetFloat("epo_count", 0)
  2288. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  2289. pre_impulse := c.GetString("pre_impulse")
  2290. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  2291. admin_user_id, _ := c.GetInt64("admin_user_id")
  2292. is_water := c.GetString("is_water")
  2293. add_amount, _ := c.GetFloat("add_amount")
  2294. reduce_amount, _ := c.GetFloat("reduce_amount")
  2295. var is_war int64
  2296. if is_water == "是" {
  2297. is_war = 1
  2298. }
  2299. if is_water == "否" {
  2300. is_war = 2
  2301. }
  2302. if is_water == "请选择" {
  2303. is_war = 0
  2304. }
  2305. drhy_water := c.GetString("drhy_water")
  2306. dry_water_hour := c.GetString("dry_water_hour")
  2307. water_machine := c.GetString("water_machine")
  2308. dialysis_remark := c.GetString("dialysis_remark")
  2309. if mode_id > 0 {
  2310. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2311. }
  2312. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2313. //
  2314. //if template.TemplateId == 2 || template.TemplateId == 6 {
  2315. // if appRole.UserType == 3 {
  2316. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2317. // if getPermissionErr != nil {
  2318. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2319. // return
  2320. // } else if headNursePermission == nil {
  2321. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2322. // return
  2323. // }
  2324. // }
  2325. //}
  2326. prescription := models.DialysisPrescription{
  2327. UserOrgId: adminUserInfo.Org.Id,
  2328. PatientId: id,
  2329. RecordDate: recordDate.Unix(),
  2330. ModeId: mode_id,
  2331. DialysisDuration: dialysis_duration,
  2332. Dialyzer: dialyzer,
  2333. PerfusionApparatus: perfusion_apparatus,
  2334. BloodFlowVolume: blood_flow_volume,
  2335. DewaterAmount: dewater_amount,
  2336. DisplaceLiqui: displace_liqui,
  2337. ReplacementWay: replacement_way,
  2338. Anticoagulant: anticoagulant,
  2339. AnticoagulantShouji: anticoagulant_shouji,
  2340. AnticoagulantWeichi: anticoagulant_weichi,
  2341. AnticoagulantZongliang: anticoagulant_zongliang,
  2342. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2343. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2344. Kalium: kalium,
  2345. Sodium: sodium,
  2346. Calcium: calcium,
  2347. Bicarbonate: bicarbonate,
  2348. Glucose: glucose,
  2349. // DryWeight: dry_weight,
  2350. DialysateFlow: dialysate_flow,
  2351. DialysateTemperature: dialysate_temperature,
  2352. Conductivity: conductivity,
  2353. Remark: remark,
  2354. Status: 1,
  2355. CreatedTime: time.Now().Unix(),
  2356. UpdatedTime: time.Now().Unix(),
  2357. DialysisDurationMinute: dialysisDurationMinute,
  2358. DialysisDurationHour: dialysisDurationHour,
  2359. TargetUltrafiltration: targetUltrafiltration,
  2360. DialysateFormulation: dialysateFormulation,
  2361. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2362. BodyFluid: body_fluid,
  2363. SpecialMedicine: special_medicine,
  2364. SpecialMedicineOther: special_medicine_other,
  2365. DisplaceLiquiPart: displace_liqui_part,
  2366. DisplaceLiquiValue: displace_liqui_value,
  2367. BloodAccess: blood_access,
  2368. Ultrafiltration: ultrafiltration,
  2369. BodyFluidOther: body_fluid_other,
  2370. ReplacementTotal: replacement_total,
  2371. Niprocart: niprocart,
  2372. Jms: jms,
  2373. FistulaNeedleSet: fistula_needle_set,
  2374. FistulaNeedleSet16: fistula_needle_set_16,
  2375. Hemoperfusion: hemoperfusion,
  2376. DialyserSterilised: dialyser_sterilised,
  2377. Filtryzer: filtryzer,
  2378. TargetKtv: target_ktv,
  2379. Dialyzers: dialyzers,
  2380. Injector: injector,
  2381. Bloodlines: bloodlines,
  2382. TubingHemodialysis: tubing_hemodialysis,
  2383. Package: safe_package,
  2384. ALiquid: a_liquid,
  2385. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  2386. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  2387. Blood: blood,
  2388. DialysisDialyszers: dialysis_dialyszers,
  2389. DialysisIrrigation: dialysis_irrigation,
  2390. AntioxidantCommodityName: antioxidant_commodity_name,
  2391. DisplaceSpeed: displace_speed,
  2392. Illness: illness,
  2393. Amylaceum: amylaceum,
  2394. SingleWater: single_water,
  2395. SingleTime: single_time,
  2396. ReplacementFlow: replacement_flow,
  2397. PlasmaSeparator: plasma_separator,
  2398. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  2399. OxygenUptake: oxygen_uptake,
  2400. OxygenTime: oxygen_time,
  2401. OxygenFlow: oxygen_flow,
  2402. HemodialysisPipelines: hemodialysis_pipelines,
  2403. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2404. PunctureNeedle: puncture_needle,
  2405. PunctureNeedleCount: puncture_needle_count,
  2406. Epo: epo,
  2407. EpoCount: epo_count,
  2408. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2409. PreImpulse: impulse,
  2410. AdminUserId: admin_user_id,
  2411. IsWater: is_war,
  2412. DrhyWater: drhy_water,
  2413. DryWaterHour: dry_water_hour,
  2414. WaterMachine: water_machine,
  2415. AddAmount: add_amount,
  2416. ReduceAmount: reduce_amount,
  2417. DialysisRemark: dialysis_remark,
  2418. }
  2419. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2420. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2421. //
  2422. if appRole.UserType == 2 || appRole.UserType == 1 {
  2423. prescription_doctor = adminUserInfo.AdminUser.Id
  2424. prescription.PrescriptionDoctor = prescription_doctor
  2425. }
  2426. if dialysisPrescription.ID == 0 { //新增
  2427. prescription.Creater = adminUserInfo.AdminUser.Id
  2428. } else { //修改
  2429. if dialysisPrescription.Creater == 0 {
  2430. prescription.Creater = adminUserInfo.AdminUser.Id
  2431. } else {
  2432. prescription.Creater = dialysisPrescription.Creater
  2433. }
  2434. //if/**/
  2435. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2436. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  2437. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2438. // if getPermissionErr != nil {
  2439. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2440. // return
  2441. // } else if headNursePermission == nil {
  2442. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2443. // return
  2444. // }
  2445. //}
  2446. //prescription.Creater = dialysisPrescription.Creater
  2447. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2448. prescription.Modifier = adminUserInfo.AdminUser.Id
  2449. prescription.ID = dialysisPrescription.ID
  2450. }
  2451. solution := models.DialysisSolution{
  2452. RegistrarsId: adminUserInfo.AdminUser.Id,
  2453. UserOrgId: adminUserInfo.Org.Id,
  2454. Doctor: prescription_doctor,
  2455. PatientId: id,
  2456. ModeId: mode_id,
  2457. DialysisDuration: dialysis_duration,
  2458. PerfusionApparatus: perfusion_apparatus,
  2459. BloodFlowVolume: blood_flow_volume,
  2460. Dewater: dewater_amount,
  2461. DisplaceLiqui: displace_liqui,
  2462. ReplacementWay: replacement_way,
  2463. Anticoagulant: anticoagulant,
  2464. AnticoagulantShouji: anticoagulant_shouji,
  2465. AnticoagulantWeichi: anticoagulant_weichi,
  2466. AnticoagulantZongliang: anticoagulant_zongliang,
  2467. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2468. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2469. Kalium: kalium,
  2470. Sodium: sodium,
  2471. Calcium: calcium,
  2472. Bicarbonate: bicarbonate,
  2473. Glucose: glucose,
  2474. // DryWeight: dry_weight,
  2475. DialysateFlow: dialysate_flow,
  2476. DialysateTemperature: dialysate_temperature,
  2477. Conductivity: conductivity,
  2478. Remark: remark,
  2479. Status: 1,
  2480. CreatedTime: time.Now().Unix(),
  2481. UpdatedTime: time.Now().Unix(),
  2482. DialysisDurationMinute: dialysisDurationMinute,
  2483. DialysisDurationHour: dialysisDurationHour,
  2484. TargetUltrafiltration: targetUltrafiltration,
  2485. DialysateFormulation: dialysateFormulation,
  2486. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2487. BodyFluid: body_fluid,
  2488. SpecialMedicine: special_medicine,
  2489. SpecialMedicineOther: special_medicine_other,
  2490. DisplaceLiquiPart: displace_liqui_part,
  2491. DisplaceLiquiValue: displace_liqui_value,
  2492. BloodAccess: blood_access,
  2493. Ultrafiltration: ultrafiltration,
  2494. BodyFluidOther: body_fluid_other,
  2495. ReplacementTotal: replacement_total,
  2496. TargetKtv: target_ktv,
  2497. DialysisDialyszers: dialysis_dialyszers,
  2498. DialysisIrrigation: dialysis_irrigation,
  2499. HemodialysisPipelines: hemodialysis_pipelines,
  2500. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  2501. PunctureNeedle: puncture_needle,
  2502. PunctureNeedleCount: puncture_needle_count,
  2503. Epo: epo,
  2504. EpoCount: epo_count,
  2505. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  2506. PreImpulse: impulse,
  2507. SolutionStatus: 1,
  2508. DialysisRemark: dialysis_remark,
  2509. }
  2510. //针对河间咸的
  2511. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  2512. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  2513. solution.DisplaceLiquiPart = 0
  2514. solution.DisplaceLiquiValue = 0
  2515. }
  2516. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2517. prescription.DisplaceLiquiPart = 0
  2518. prescription.DisplaceLiquiValue = 0
  2519. }
  2520. }
  2521. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2522. //获取最新1条
  2523. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  2524. //更新状态
  2525. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  2526. //获取key,清空redis
  2527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2528. redis := service.RedisClient()
  2529. defer redis.Close()
  2530. //清空key 值
  2531. redis.Set(key, "", time.Second)
  2532. //清空长期医嘱的key
  2533. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2534. redis.Set(soulution_key, "", time.Second)
  2535. //查询最近透析准备表里是否存在 透析器 灌流器
  2536. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2537. redis.Set(keyOne, "", time.Second)
  2538. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2539. redis.Set(keyTwo, "", time.Second)
  2540. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2541. redis.Set(keyThree, "", time.Second)
  2542. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2543. redis.Set(keyFour, "", time.Second)
  2544. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2545. //
  2546. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2547. //
  2548. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2549. //if len(mation)>0{
  2550. // for _, item := range splitStr {
  2551. // for _,it := range mation{
  2552. // if(item == it.SpecificationName){
  2553. //
  2554. // //查询最近一次的透析器
  2555. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2556. //
  2557. // if errcode == gorm.ErrRecordNotFound{
  2558. // //插入数据
  2559. // prepare := models.DialysisBeforePrepare{
  2560. // UserOrgId: adminUserInfo.Org.Id,
  2561. // PatientId: id,
  2562. // RecordDate: recordDate.Unix(),
  2563. // GoodTypeId: it.GoodTypeId,
  2564. // GoodId: it.ID,
  2565. // Count: 1,
  2566. // Ctime: time.Now().Unix(),
  2567. // Creater: adminUserInfo.AdminUser.Id,
  2568. // Status:1,
  2569. //
  2570. // }
  2571. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2572. // fmt.Println("",errcode)
  2573. // }
  2574. // }
  2575. // }
  2576. //
  2577. // }
  2578. //
  2579. // for _, item := range splitIrrigation {
  2580. // for _,it := range mation{
  2581. // if(item == it.SpecificationName){
  2582. // //查询最近一次的透析器
  2583. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2584. // if errcode == gorm.ErrRecordNotFound{
  2585. // //插入数据
  2586. // prepare := models.DialysisBeforePrepare{
  2587. // UserOrgId: adminUserInfo.Org.Id,
  2588. // PatientId: id,
  2589. // RecordDate: recordDate.Unix(),
  2590. // GoodTypeId: it.GoodTypeId,
  2591. // GoodId: it.ID,
  2592. // Count: 1,
  2593. // Ctime: time.Now().Unix(),
  2594. // Creater: adminUserInfo.AdminUser.Id,
  2595. // Status:1,
  2596. //
  2597. // }
  2598. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2599. // fmt.Println(errcode)
  2600. // }
  2601. // }
  2602. // }
  2603. // }
  2604. //}
  2605. c.ServeSuccessJSON(map[string]interface{}{
  2606. "solution": &solution,
  2607. "prescription": &prescription,
  2608. })
  2609. }
  2610. func (c *DialysisAPIController) GetAcceptsAssessment() {
  2611. patient, _ := c.GetInt64("patient", 0)
  2612. adminUserInfo := c.GetMobileAdminUserInfo()
  2613. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  2614. c.ServeSuccessJSON(map[string]interface{}{
  2615. "receiveTreatmentAsses": receiveTreatmentAsses,
  2616. })
  2617. }
  2618. func (this *DialysisAPIController) PostSignInfo() {
  2619. patientID, _ := this.GetInt64("patient_id")
  2620. recordDateStr := this.GetString("date")
  2621. if patientID <= 0 {
  2622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2623. return
  2624. }
  2625. if len(recordDateStr) == 0 {
  2626. recordDateStr = time.Now().Format("2006-01-02")
  2627. }
  2628. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2629. if parseDateErr != nil {
  2630. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2632. return
  2633. }
  2634. adminInfo := this.GetMobileAdminUserInfo()
  2635. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  2636. if err != nil {
  2637. this.ErrorLog("签名失败:%v", err)
  2638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2639. return
  2640. }
  2641. this.ServeSuccessJSON(map[string]interface{}{
  2642. "doctor_id": adminInfo.AdminUser.Id,
  2643. })
  2644. }
  2645. func (this *DialysisAPIController) GetLastMonitorRecord() {
  2646. patientID, _ := this.GetInt64("patient_id")
  2647. adminInfo := this.GetMobileAdminUserInfo()
  2648. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  2649. this.ServeSuccessJSON(map[string]interface{}{
  2650. "monitor": record,
  2651. })
  2652. }
  2653. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  2654. thisTime := time.Now()
  2655. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2656. timeLayout := "2006-01-02 15:04:05"
  2657. loc, _ := time.LoadLocation("Local")
  2658. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2659. theAssessmentDateTime := theStartTime.Unix()
  2660. patientID, _ := this.GetInt64("patient_id")
  2661. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2662. adminInfo := this.GetMobileAdminUserInfo()
  2663. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2664. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2665. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  2666. var ultrafiltration_rate float64
  2667. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2668. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2669. fmt.Println(evaluation)
  2670. if prescription.ID > 0 {
  2671. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2672. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2673. if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
  2674. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2675. record.UltrafiltrationRate = ultrafiltration_rate
  2676. }
  2677. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  2678. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  2679. record.UltrafiltrationRate = ultrafiltration_rate
  2680. }
  2681. if template.TemplateId == 20 || template.TemplateId == 22 {
  2682. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2683. record.UltrafiltrationRate = ultrafiltration_rate
  2684. }
  2685. // 只针对方济医院
  2686. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  2687. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2688. ultrafiltration_rate = value
  2689. record.UltrafiltrationRate = ultrafiltration_rate
  2690. }
  2691. if template.TemplateId == 41 || template.TemplateId == 47 {
  2692. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2693. record.UltrafiltrationRate = ultrafiltration_rate
  2694. }
  2695. if template.TemplateId == 43 {
  2696. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2697. record.UltrafiltrationRate = ultrafiltration_rate
  2698. }
  2699. if template.TemplateId == 46 || template.TemplateId == 54 {
  2700. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2701. record.UltrafiltrationRate = ultrafiltration_rate
  2702. }
  2703. 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 {
  2704. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  2705. record.UltrafiltrationRate = ultrafiltration_rate
  2706. }
  2707. //if template.TemplateId == 47 {
  2708. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2709. // record.UltrafiltrationRate = ultrafiltration_rate
  2710. //}
  2711. }
  2712. }
  2713. // record.UltrafiltrationRate = ultrafiltration_rate
  2714. record.UltrafiltrationVolume = 0
  2715. 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
  2716. if ultrafiltration_rate > 0 {
  2717. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2718. record.UltrafiltrationVolume = value
  2719. }
  2720. }
  2721. if template.TemplateId == 6 || 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
  2722. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  2723. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2724. record.UltrafiltrationVolume = ultrafiltration_volume
  2725. }
  2726. }
  2727. 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 {
  2728. if ultrafiltration_rate > 0 {
  2729. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2730. record.UltrafiltrationVolume = ultrafiltration_volume
  2731. }
  2732. }
  2733. if template.TemplateId == 47 || template.TemplateId == 54 {
  2734. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  2735. }
  2736. this.ServeSuccessJSON(map[string]interface{}{
  2737. "monitor": record,
  2738. })
  2739. }
  2740. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  2741. record_id, _ := this.GetInt64("id")
  2742. nurseID, _ := this.GetInt64("nurse")
  2743. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2744. bedID, _ := this.GetInt64("bed")
  2745. start_time := this.GetString("start_time")
  2746. schedual_type, _ := this.GetInt64("schedual_type")
  2747. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2748. change_nurse, _ := this.GetInt64("change_nurse")
  2749. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2750. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2751. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2752. patient_id, _ := this.GetInt64("patient_id")
  2753. record_date, _ := this.GetInt64("record_date")
  2754. puncture_needle := this.GetString("puncture_needle")
  2755. puncture_way := this.GetString("puncture_way")
  2756. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2757. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2758. blood_access_id, _ := this.GetInt64("blood_access_id")
  2759. nuclein_date_str := this.GetString("nuclein_date_str")
  2760. order_remark := this.GetString("order_remark")
  2761. schedule_remark := this.GetString("schedule_remark")
  2762. if record_id == 0 {
  2763. this.ErrorLog("id:%v", record_id)
  2764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2765. return
  2766. }
  2767. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2768. if parseStartDateErr != nil {
  2769. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2771. return
  2772. }
  2773. adminUserInfo := this.GetMobileAdminUserInfo()
  2774. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2775. if getNurseErr != nil {
  2776. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2778. return
  2779. } else if nurse == nil {
  2780. this.ErrorLog("护士不存在")
  2781. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2782. return
  2783. }
  2784. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2785. //if getNurseErr != nil {
  2786. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  2787. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2788. // return
  2789. //} else if nurse == nil {
  2790. // this.ErrorLog("护士不存在")
  2791. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2792. // return
  2793. //}
  2794. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2795. if getDeviceNumberErr != nil {
  2796. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2798. return
  2799. } else if deviceNumber == nil {
  2800. this.ErrorLog("床位号不存在")
  2801. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2802. return
  2803. }
  2804. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2805. //
  2806. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2807. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2808. // if getPermissionErr != nil {
  2809. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2810. // return
  2811. // } else if headNursePermission == nil {
  2812. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2813. // return
  2814. // }
  2815. //}
  2816. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2817. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2818. timeLayout := "2006-01-02 15:04:05"
  2819. loc, _ := time.LoadLocation("Local")
  2820. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2821. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2822. schedulestartTime := theStartTime.Unix()
  2823. scheduleendTime := theEndTime.Unix()
  2824. var theNucleinDate int64
  2825. timeLayoutOne := "2006-01-02"
  2826. if len(nuclein_date_str) > 0 {
  2827. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2828. if err != nil {
  2829. utils.ErrorLog(err.Error())
  2830. }
  2831. theNucleinDate = theTime.Unix()
  2832. }
  2833. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2834. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2835. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2836. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2837. if err == gorm.ErrRecordNotFound { //空床位
  2838. // 修改了床位逻辑
  2839. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2840. if daySchedule.ID > 0 {
  2841. //daySchedule.BedId = bedID
  2842. //daySchedule.PartitionId = deviceNumber.ZoneID
  2843. //daySchedule.ScheduleType = schedual_type
  2844. //daySchedule.UpdatedTime = time.Now().Unix()
  2845. //err := service.UpdateSchedule(&daySchedule)
  2846. xtSchedule := models.Schedule{
  2847. PartitionId: deviceNumber.ZoneID,
  2848. BedId: bedID,
  2849. ScheduleType: schedual_type,
  2850. UpdatedTime: time.Now().Unix(),
  2851. }
  2852. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2853. if err != nil {
  2854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2855. return
  2856. }
  2857. }
  2858. } else if err == nil {
  2859. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2860. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2861. if daySchedule.ID > 0 {
  2862. //daySchedule.BedId = bedID
  2863. //daySchedule.PartitionId = deviceNumber.ZoneID
  2864. //
  2865. //daySchedule.ScheduleType = schedual_type
  2866. //daySchedule.UpdatedTime = time.Now().Unix()
  2867. //err := service.UpdateSchedule(&daySchedule)
  2868. xtSchedule := models.Schedule{
  2869. PartitionId: deviceNumber.ZoneID,
  2870. BedId: bedID,
  2871. ScheduleType: schedual_type,
  2872. UpdatedTime: time.Now().Unix(),
  2873. }
  2874. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2875. if err != nil {
  2876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2877. return
  2878. }
  2879. }
  2880. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2882. return
  2883. }
  2884. } else if err != nil {
  2885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2886. return
  2887. }
  2888. }
  2889. dialysisRecord := &models.DialysisOrder{
  2890. ID: record_id,
  2891. UserOrgId: adminUserInfo.Org.Id,
  2892. BedID: bedID,
  2893. StartNurse: nurseID,
  2894. StartTime: startDate.Unix(),
  2895. PunctureNurse: puncture_nurse,
  2896. Creator: adminUserInfo.AdminUser.Id,
  2897. Modifier: adminUserInfo.AdminUser.Id,
  2898. WashpipeNurse: washpipe_nurse,
  2899. SchedualType: schedual_type,
  2900. ChangeNurse: change_nurse,
  2901. DifficultPunctureNurse: difficult_puncture_nurse,
  2902. NewFistulaNurse: new_fistula_nurse,
  2903. QualityNurseId: quality_nurse_id,
  2904. PunctureNeedle: puncture_needle,
  2905. PunctureWay: puncture_way,
  2906. DialysisDialyszers: dialysis_dialyszers,
  2907. DialysisIrrigation: dialysis_irrigation,
  2908. BloodAccessId: blood_access_id,
  2909. NucleinDate: theNucleinDate,
  2910. OrderRemark: order_remark,
  2911. ScheduleRemark: schedule_remark,
  2912. }
  2913. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2914. order, _ := service.GetLastPatientOrder(record_id)
  2915. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  2916. redis := service.RedisClient()
  2917. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  2918. redis.Set(key, "", time.Second)
  2919. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  2920. //清空key 值
  2921. redis.Set(keyOne, "", time.Second)
  2922. scheduleDateStartOne := startDate.Format("2006-01-02")
  2923. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2924. redis.Set(keyTwo, "", time.Second)
  2925. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  2926. redis.Set(keyThree, "", time.Second)
  2927. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  2928. redis.Set(keyFour, "", time.Second)
  2929. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  2930. redis.Set(keyFive, "", time.Second)
  2931. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  2932. redis.Set(keySix, "", time.Second)
  2933. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  2934. redis.Set(keySeven, "", time.Second)
  2935. if updateErr != nil {
  2936. this.ErrorLog("修改上机失败:%v", updateErr)
  2937. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2938. return
  2939. }
  2940. if updateErr == nil {
  2941. if tempDialysisRecord.Stage == 2 {
  2942. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2943. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2944. fmt.Println(value)
  2945. a, b := math.Modf(value)
  2946. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2947. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2948. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2949. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2950. redis := service.RedisClient()
  2951. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  2952. redis.Set(key, "", time.Second)
  2953. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  2954. redis.Set(keyOne, "", time.Second)
  2955. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  2956. //清空key 值
  2957. redis.Set(keySix, "", time.Second)
  2958. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  2959. redis.Set(keySeven, "", time.Second)
  2960. redis.Close()
  2961. if updateAssessmentErr != nil {
  2962. utils.ErrorLog("%v", updateAssessmentErr)
  2963. }
  2964. }
  2965. }
  2966. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2967. this.ServeSuccessJSON(map[string]interface{}{
  2968. "dialysis_order": dialysisRecords,
  2969. })
  2970. }
  2971. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  2972. record_id, _ := c.GetInt64("id")
  2973. nurseID, _ := c.GetInt64("nurse")
  2974. end_time := c.GetString("end_time")
  2975. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2976. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2977. catheter := c.GetString("catheter")
  2978. cruor := c.GetString("cruor")
  2979. mission := c.GetString("mission")
  2980. if record_id <= 0 || nurseID <= 0 {
  2981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2982. return
  2983. }
  2984. adminUserInfo := c.GetMobileAdminUserInfo()
  2985. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2986. if getNurseErr != nil {
  2987. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2989. return
  2990. } else if nurse == nil {
  2991. c.ErrorLog("护士不存在")
  2992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2993. return
  2994. }
  2995. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2996. if parseEndDateErr != nil {
  2997. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2999. return
  3000. }
  3001. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  3002. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  3003. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3004. // if getPermissionErr != nil {
  3005. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3006. // return
  3007. // } else if headNursePermission == nil {
  3008. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3009. // return
  3010. // }
  3011. //}
  3012. dialysisRecord := &models.DialysisOrder{
  3013. ID: record_id,
  3014. UserOrgId: adminUserInfo.Org.Id,
  3015. EndTime: endDate.Unix(),
  3016. FinishNurse: nurseID,
  3017. FinishModifier: adminUserInfo.AdminUser.Id,
  3018. PuncturePointHaematoma: puncture_point_haematoma,
  3019. BloodAccessInternalFistula: blood_access_internal_fistula,
  3020. Catheter: catheter,
  3021. Cruor: cruor,
  3022. Mission: mission,
  3023. }
  3024. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  3025. redis := service.RedisClient()
  3026. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  3027. //清空key 值
  3028. redis.Set(key, "", time.Second)
  3029. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3030. //清空key 值
  3031. redis.Set(keyOne, "", time.Second)
  3032. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3033. redis.Set(keySeven, "", time.Second)
  3034. redis.Close()
  3035. if updateErr != nil {
  3036. c.ErrorLog("修改下机失败:%v", updateErr)
  3037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3038. return
  3039. }
  3040. if updateErr == nil {
  3041. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  3042. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3043. a, b := math.Modf(value)
  3044. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  3045. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  3046. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  3047. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  3048. redis := service.RedisClient()
  3049. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  3050. redis.Set(keyTen, "", time.Second)
  3051. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  3052. redis.Set(keyTwo, "", time.Second)
  3053. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  3054. redis.Set(key, "", time.Second)
  3055. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  3056. redis.Set(keyThree, "", time.Second)
  3057. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  3058. redis.Set(keySeven, "", time.Second)
  3059. defer redis.Close()
  3060. if updateAssessmentErr != nil {
  3061. utils.ErrorLog("%v", updateAssessmentErr)
  3062. }
  3063. }
  3064. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  3065. c.ServeSuccessJSON(map[string]interface{}{
  3066. "dialysis_order": dialysisRecords,
  3067. })
  3068. }
  3069. func (c *DialysisAPIController) GetLongAdvice() {
  3070. patient_id, _ := c.GetInt64("id")
  3071. adminUserInfo := c.GetMobileAdminUserInfo()
  3072. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3073. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3074. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3075. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3076. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3077. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3078. c.ServeSuccessJSON(map[string]interface{}{
  3079. "status": "1",
  3080. })
  3081. return
  3082. } else { //开启推送提醒
  3083. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3084. var advice_three []*models.DoctorAdvice
  3085. recordDateStr := time.Now().Format("2006-01-02")
  3086. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3087. nowtime := recordDate.Unix()
  3088. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  3089. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  3090. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  3091. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  3092. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  3093. for _, advice := range advices {
  3094. if advice.FrequencyType == 3 {
  3095. t := time.Now()
  3096. week := int(t.Weekday())
  3097. fmt.Println(t.Weekday())
  3098. fmt.Println(week)
  3099. switch week {
  3100. case 1:
  3101. if strings.Index(advice.WeekDay, "周一") == -1 {
  3102. advice_three = append(advice_three, advice)
  3103. }
  3104. break
  3105. case 2:
  3106. if strings.Index(advice.WeekDay, "周二") == -1 {
  3107. advice_three = append(advice_three, advice)
  3108. }
  3109. break
  3110. case 3:
  3111. if strings.Index(advice.WeekDay, "周三") == -1 {
  3112. advice_three = append(advice_three, advice)
  3113. }
  3114. break
  3115. case 4:
  3116. if strings.Index(advice.WeekDay, "周四") == -1 {
  3117. advice_three = append(advice_three, advice)
  3118. }
  3119. break
  3120. case 5:
  3121. if strings.Index(advice.WeekDay, "周五") == -1 {
  3122. advice_three = append(advice_three, advice)
  3123. }
  3124. break
  3125. case 6:
  3126. if strings.Index(advice.WeekDay, "周六") == -1 {
  3127. advice_three = append(advice_three, advice)
  3128. }
  3129. break
  3130. case 0:
  3131. if strings.Index(advice.WeekDay, "周日") == -1 {
  3132. advice_three = append(advice_three, advice)
  3133. }
  3134. break
  3135. }
  3136. }
  3137. }
  3138. for _, advice := range advices_two {
  3139. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3140. now := p.Unix()
  3141. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3142. dayStr2 := "-" + dayStr
  3143. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3144. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3145. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3146. for _, ad := range advices {
  3147. advice_three = append(advice_three, ad)
  3148. }
  3149. }
  3150. if err == nil {
  3151. c.ServeSuccessJSON(map[string]interface{}{
  3152. "status": "2",
  3153. "advices": advices,
  3154. "advices_two": RemoveRepeatedElement(advice_three),
  3155. "is_open_remind": config.IsOpenRemind,
  3156. "his_config_open": hisConfig.IsOpen,
  3157. "is_advice_open": is_advice_open.IsAdviceOpen,
  3158. "prescription_open": prescription_open.IsOpen,
  3159. })
  3160. }
  3161. }
  3162. }
  3163. func (c *DialysisAPIController) GetLongAdviceOne() {
  3164. patient_id, _ := c.GetInt64("id")
  3165. startTime := c.GetString("schedule_date")
  3166. timeLayout := "2006-01-02"
  3167. loc, _ := time.LoadLocation("Local")
  3168. var theStartTime int64
  3169. if len(startTime) > 0 {
  3170. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3171. if err != nil {
  3172. utils.ErrorLog(err.Error())
  3173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3174. return
  3175. }
  3176. theStartTime = theTime.Unix()
  3177. }
  3178. adminUserInfo := c.GetMobileAdminUserInfo()
  3179. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  3180. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  3181. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  3182. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  3183. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3184. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3185. c.ServeSuccessJSON(map[string]interface{}{
  3186. "status": "1",
  3187. })
  3188. return
  3189. } else { //开启推送提醒
  3190. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3191. var advice_three []*models.DoctorAdvice
  3192. fmt.Println("theStartTime23434343433434433443434343434334", theStartTime)
  3193. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  3194. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  3195. for _, advice := range advices {
  3196. if advice.FrequencyType == 3 {
  3197. t := time.Now()
  3198. week := int(t.Weekday())
  3199. fmt.Println(t.Weekday())
  3200. fmt.Println(week)
  3201. switch week {
  3202. case 1:
  3203. if strings.Index(advice.WeekDay, "周一") == -1 {
  3204. advice_three = append(advice_three, advice)
  3205. }
  3206. break
  3207. case 2:
  3208. if strings.Index(advice.WeekDay, "周二") == -1 {
  3209. advice_three = append(advice_three, advice)
  3210. }
  3211. break
  3212. case 3:
  3213. if strings.Index(advice.WeekDay, "周三") == -1 {
  3214. advice_three = append(advice_three, advice)
  3215. }
  3216. break
  3217. case 4:
  3218. if strings.Index(advice.WeekDay, "周四") == -1 {
  3219. advice_three = append(advice_three, advice)
  3220. }
  3221. break
  3222. case 5:
  3223. if strings.Index(advice.WeekDay, "周五") == -1 {
  3224. advice_three = append(advice_three, advice)
  3225. }
  3226. break
  3227. case 6:
  3228. if strings.Index(advice.WeekDay, "周六") == -1 {
  3229. advice_three = append(advice_three, advice)
  3230. }
  3231. break
  3232. case 0:
  3233. if strings.Index(advice.WeekDay, "周日") == -1 {
  3234. advice_three = append(advice_three, advice)
  3235. }
  3236. break
  3237. }
  3238. }
  3239. }
  3240. for _, advice := range advices_two {
  3241. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3242. now := p.Unix()
  3243. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3244. dayStr2 := "-" + dayStr
  3245. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3246. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3247. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  3248. for _, ad := range advices {
  3249. advice_three = append(advice_three, ad)
  3250. }
  3251. }
  3252. if err == nil {
  3253. c.ServeSuccessJSON(map[string]interface{}{
  3254. "status": "2",
  3255. "advices": advices,
  3256. "advices_two": RemoveRepeatedElement(advice_three),
  3257. "is_open_remind": config.IsOpenRemind,
  3258. "his_config_open": hisConfig.IsOpen,
  3259. "is_advice_open": is_advice_open.IsAdviceOpen,
  3260. "prescription_open": prescription_open.IsOpen,
  3261. })
  3262. }
  3263. }
  3264. }
  3265. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3266. newArr = make([]*models.DoctorAdvice, 0)
  3267. for i := 0; i < len(arr); i++ {
  3268. repeat := false
  3269. for j := i + 1; j < len(arr); j++ {
  3270. if arr[i].ID == arr[j].ID {
  3271. repeat = true
  3272. break
  3273. }
  3274. }
  3275. if !repeat {
  3276. newArr = append(newArr, arr[i])
  3277. }
  3278. }
  3279. return
  3280. }
  3281. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  3282. patient, _ := c.GetInt64("id", 0)
  3283. groupNo, _ := c.GetInt64("groupno", 0)
  3284. if patient <= 0 {
  3285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3286. return
  3287. }
  3288. adminUserInfo := c.GetMobileAdminUserInfo()
  3289. dataBody := make(map[string]interface{}, 0)
  3290. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3291. if err != nil {
  3292. utils.ErrorLog(err.Error())
  3293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3294. return
  3295. }
  3296. utils.ErrorLog("%v", dataBody)
  3297. timeLayout := "2006-01-02 15:04"
  3298. loc, _ := time.LoadLocation("Local")
  3299. timeLayout2 := "2006-01-02"
  3300. loc2, _ := time.LoadLocation("Local")
  3301. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3302. utils.ErrorLog("advice_type")
  3303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3304. return
  3305. }
  3306. adviceType := int64(2)
  3307. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3308. utils.ErrorLog("advice_date")
  3309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3310. return
  3311. }
  3312. adviceDate, _ := dataBody["advice_date"].(string)
  3313. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3314. AdviceDate := theTime.Unix()
  3315. RecordDate := theTime.Unix()
  3316. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3317. utils.ErrorLog("start_time")
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3319. return
  3320. }
  3321. startTime, _ := dataBody["start_time"].(string)
  3322. if len(startTime) == 0 {
  3323. utils.ErrorLog("len(start_time) == 0")
  3324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3325. return
  3326. }
  3327. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  3328. if err != nil {
  3329. utils.ErrorLog(err.Error())
  3330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3331. return
  3332. }
  3333. StartTime := theTime.Unix()
  3334. Remark := ""
  3335. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3336. remark, _ := dataBody["remark"].(string)
  3337. Remark = remark
  3338. }
  3339. var advices []*models.GroupAdvice
  3340. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3341. utils.ErrorLog("advices")
  3342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3343. return
  3344. }
  3345. adviceNames := dataBody["advices"].([]interface{})
  3346. for _, adviceNameMap := range adviceNames {
  3347. adviceNameM := adviceNameMap.(map[string]interface{})
  3348. var advice models.GroupAdvice
  3349. advice.Remark = Remark
  3350. advice.AdviceType = adviceType
  3351. advice.StartTime = StartTime
  3352. advice.AdviceDate = AdviceDate
  3353. advice.RecordDate = RecordDate
  3354. advice.Status = 1
  3355. advice.CreatedTime = time.Now().Unix()
  3356. advice.UpdatedTime = time.Now().Unix()
  3357. advice.StopState = 2
  3358. advice.ExecutionState = 2
  3359. advice.UserOrgId = adminUserInfo.Org.Id
  3360. advice.PatientId = patient
  3361. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3362. advice.IsSettle = 2
  3363. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3364. utils.ErrorLog("advice_name")
  3365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3366. return
  3367. }
  3368. adviceName, _ := adviceNameM["advice_name"].(string)
  3369. if len(adviceName) == 0 {
  3370. utils.ErrorLog("len(advice_name) == 0")
  3371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3372. return
  3373. }
  3374. advice.AdviceName = adviceName
  3375. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3376. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3377. advice.DrugSpec = drugSpec
  3378. }
  3379. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3380. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3381. advice.AdviceDesc = adviceDesc
  3382. }
  3383. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3384. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3385. advice.DrugSpecUnit = drugSpecUnit
  3386. }
  3387. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3388. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3389. // advice.SingleDose = singleDose
  3390. //}
  3391. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3392. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3393. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3394. }
  3395. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3396. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3397. advice.SingleDoseUnit = singleDoseUnit
  3398. }
  3399. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3400. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3401. // advice.PrescribingNumber = prescribingNumber
  3402. //}
  3403. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3404. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3405. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3406. }
  3407. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3408. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3409. advice.PrescribingNumberUnit = prescribingNumberUnit
  3410. }
  3411. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3412. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3413. advice.DeliveryWay = deliveryWay
  3414. }
  3415. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3416. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3417. advice.ExecutionFrequency = executionFrequency
  3418. }
  3419. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3420. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3421. advice.FrequencyType = frequency_type
  3422. }
  3423. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3424. day_count := int64(adviceNameM["day_count"].(float64))
  3425. advice.DayCount = day_count
  3426. }
  3427. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3428. week_day, _ := adviceNameM["week_day"].(string)
  3429. advice.WeekDay = week_day
  3430. }
  3431. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3432. way := int64(adviceNameM["way"].(float64))
  3433. advice.Way = way
  3434. }
  3435. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3436. drug_id := int64(adviceNameM["drug_id"].(float64))
  3437. advice.DrugId = drug_id
  3438. }
  3439. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3440. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3441. advice.DrugNameId = drug_name_id
  3442. }
  3443. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3444. template_id, _ := adviceNameM["template_id"].(string)
  3445. advice.TemplateId = template_id
  3446. }
  3447. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  3448. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3449. advice.ExecutionFrequency = executionFrequency
  3450. }
  3451. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3452. children := adviceNameM["child"].([]interface{})
  3453. if len(children) > 0 {
  3454. for _, childrenMap := range children {
  3455. childMap := childrenMap.(map[string]interface{})
  3456. var child models.GroupAdvice
  3457. child.Remark = Remark
  3458. child.AdviceType = adviceType
  3459. child.StartTime = StartTime
  3460. child.AdviceDate = AdviceDate
  3461. child.RecordDate = RecordDate
  3462. child.Status = 1
  3463. child.CreatedTime = time.Now().Unix()
  3464. child.UpdatedTime = time.Now().Unix()
  3465. child.StopState = 2
  3466. child.ExecutionState = 2
  3467. child.UserOrgId = adminUserInfo.Org.Id
  3468. child.PatientId = patient
  3469. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3470. child.IsSettle = 1
  3471. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3472. utils.ErrorLog("child advice_name")
  3473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3474. return
  3475. }
  3476. childAdviceName, _ := childMap["advice_name"].(string)
  3477. if len(childAdviceName) == 0 {
  3478. utils.ErrorLog("len(child advice_name) == 0")
  3479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3480. return
  3481. }
  3482. child.AdviceName = childAdviceName
  3483. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3484. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3485. child.AdviceDesc = childAdviceDesc
  3486. }
  3487. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3488. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3489. child.DrugSpec = childDrugSpec
  3490. }
  3491. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3492. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3493. child.DrugSpecUnit = childDrugSpecUnit
  3494. }
  3495. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3496. child.SingleDose = childMap["single_dose"].(float64)
  3497. }
  3498. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3499. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3500. child.SingleDoseUnit = childSingleDoseUnit
  3501. }
  3502. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3503. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3504. }
  3505. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3506. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3507. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3508. }
  3509. child.DeliveryWay = advice.DeliveryWay
  3510. child.ExecutionFrequency = advice.ExecutionFrequency
  3511. advice.Children = append(advice.Children, &child)
  3512. }
  3513. }
  3514. }
  3515. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  3516. if temp_advice.ID == 0 {
  3517. advices = append(advices, &advice)
  3518. }
  3519. }
  3520. if len(advices) > 0 {
  3521. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  3522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  3523. redis := service.RedisClient()
  3524. //清空key 值
  3525. redis.Set(key, "", time.Second)
  3526. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3527. redis.Set(keyOne, "", time.Second)
  3528. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3529. defer redis.Close()
  3530. redis.Set(keyThree, "", time.Second)
  3531. if err != nil {
  3532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3533. return
  3534. }
  3535. c.ServeSuccessJSON(map[string]interface{}{
  3536. "msg": "ok",
  3537. "advices": list,
  3538. })
  3539. } else {
  3540. c.ServeSuccessJSON(map[string]interface{}{
  3541. "msg": "ok",
  3542. })
  3543. }
  3544. return
  3545. }
  3546. func (c *DialysisAPIController) UploadDryWeight() {
  3547. patient_id, _ := c.GetInt64("id")
  3548. dry_weight, _ := c.GetFloat("dry_weight")
  3549. doctor_id, _ := c.GetInt64("doctor_id")
  3550. remark := c.GetString("remark")
  3551. adminUserInfo := c.GetMobileAdminUserInfo()
  3552. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  3553. if err == gorm.ErrRecordNotFound {
  3554. dryWeight := &models.SgjPatientDryweight{
  3555. PatientId: patient_id,
  3556. DryWeight: dry_weight,
  3557. Remakes: remark,
  3558. Ctime: time.Now().Unix(),
  3559. Mtime: time.Now().Unix(),
  3560. Creator: doctor_id,
  3561. Status: 1,
  3562. UserOrgId: adminUserInfo.Org.Id,
  3563. AdjustedValue: "/",
  3564. UserId: adminUserInfo.AdminUser.Id,
  3565. }
  3566. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3567. redis := service.RedisClient()
  3568. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  3569. redis.Set(keyOne, "", time.Second)
  3570. loc, _ := time.LoadLocation("Local")
  3571. nowTime := time.Now()
  3572. nowDay := nowTime.Format("2006-01-02")
  3573. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3574. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3575. redis.Set(key, "", time.Second)
  3576. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3577. redis.Set(keyTwo, "", time.Second)
  3578. redis.Close()
  3579. if createErr == nil {
  3580. c.ServeSuccessJSON(map[string]interface{}{
  3581. "msg": "提交成功",
  3582. "weight": dryWeight,
  3583. })
  3584. }
  3585. } else {
  3586. dryWeight := &models.SgjPatientDryweight{
  3587. PatientId: patient_id,
  3588. DryWeight: dry_weight,
  3589. Remakes: remark,
  3590. Ctime: time.Now().Unix(),
  3591. Mtime: time.Now().Unix(),
  3592. Creator: doctor_id,
  3593. Status: 1,
  3594. UserOrgId: adminUserInfo.Org.Id,
  3595. AdjustedValue: "/",
  3596. UserId: adminUserInfo.AdminUser.Id,
  3597. }
  3598. var value float64
  3599. value = dry_weight - weightAdjust.DryWeight
  3600. if value < 0 {
  3601. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3602. } else if value == 0 {
  3603. dryWeight.AdjustedValue = "/"
  3604. } else if value > 0 {
  3605. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3606. }
  3607. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3608. redis := service.RedisClient()
  3609. loc, _ := time.LoadLocation("Local")
  3610. nowTime := time.Now()
  3611. nowDay := nowTime.Format("2006-01-02")
  3612. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3613. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3614. redis.Set(keyOne, "", time.Second)
  3615. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3616. redis.Set(key, "", time.Second)
  3617. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3618. redis.Set(keyTwo, "", time.Second)
  3619. redis.Close()
  3620. if createErr == nil {
  3621. c.ServeSuccessJSON(map[string]interface{}{
  3622. "msg": "提交成功",
  3623. "weight": dryWeight,
  3624. })
  3625. }
  3626. }
  3627. }
  3628. func (c *DialysisAPIController) GetSolution() {
  3629. patient_id, _ := c.GetInt64("patient_id")
  3630. mode_id, _ := c.GetInt64("mode_id")
  3631. adminUserInfo := c.GetMobileAdminUserInfo()
  3632. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3633. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  3634. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  3635. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  3636. if err != nil {
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3638. return
  3639. }
  3640. c.ServeSuccessJSON(map[string]interface{}{
  3641. "solution": solution,
  3642. "prescription": prescription,
  3643. "system_prescription": system_prescription,
  3644. "dialysisPrescription": dialysisPrescription,
  3645. })
  3646. }
  3647. func (c *DialysisAPIController) GetSchedule() {
  3648. schedual_type, _ := c.GetInt64("schedual_type")
  3649. adminUserInfo := c.GetMobileAdminUserInfo()
  3650. scheduleTime, _ := c.GetInt64("record_date")
  3651. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  3652. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  3653. c.ServeSuccessJSON(map[string]interface{}{
  3654. "number": deviceNumber,
  3655. "list": list,
  3656. })
  3657. }
  3658. func (c *DialysisAPIController) GetPatientId() {
  3659. id, _ := c.GetInt64("id")
  3660. //orgid := c.GetMobileAdminUserInfo().Org.Id
  3661. patientId, _ := service.GetPatientId(id)
  3662. //获取该患者的所有传染病
  3663. list, _ := service.GetPatientInfectious(id)
  3664. c.ServeSuccessJSON(map[string]interface{}{
  3665. "patient": patientId,
  3666. "infectioulist": list,
  3667. })
  3668. }
  3669. func (this *DialysisAPIController) GetDialysisSchedule() {
  3670. schedualDate := this.GetString("date")
  3671. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3672. if parseDateErr != nil {
  3673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3674. return
  3675. }
  3676. adminInfo := this.GetMobileAdminUserInfo()
  3677. orgID := adminInfo.Org.Id
  3678. redis := service.RedisClient()
  3679. defer redis.Close()
  3680. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  3681. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  3682. if len(scheduals) > 0 {
  3683. //缓存数据
  3684. scheduals_json, err := json.Marshal(scheduals)
  3685. if err == nil {
  3686. redis.Set(key, scheduals_json, time.Second*30)
  3687. }
  3688. }
  3689. this.ServeSuccessJSON(map[string]interface{}{
  3690. "scheduals": scheduals,
  3691. })
  3692. }
  3693. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  3694. change_type, _ := this.GetInt64("type", 0)
  3695. record_date := this.GetString("record_time")
  3696. patient_id, _ := this.GetInt64("patient_id", 0)
  3697. timeLayout := "2006-01-02"
  3698. loc, _ := time.LoadLocation("Local")
  3699. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3700. record_time := theAdviceRecordTime.Unix()
  3701. adminUserInfo := this.GetMobileAdminUserInfo()
  3702. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  3703. if err == nil {
  3704. if len(advices) == 0 {
  3705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3706. return
  3707. } else {
  3708. this.ServeSuccessJSON(map[string]interface{}{
  3709. "advices": advices,
  3710. "schedule": sch,
  3711. })
  3712. return
  3713. }
  3714. } else {
  3715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3716. return
  3717. }
  3718. }
  3719. func (c *DialysisAPIController) CreateConsumables() {
  3720. record_date := c.GetString("record_time")
  3721. patient_id, _ := c.GetInt64("patient_id", 0)
  3722. active, _ := c.GetInt64("active")
  3723. adminUser := c.GetMobileAdminUserInfo()
  3724. timeLayout := "2006-01-02"
  3725. loc, _ := time.LoadLocation("Local")
  3726. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3727. record_time := theRecordTime.Unix()
  3728. dataBody := make(map[string]interface{}, 0)
  3729. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3730. if err != nil {
  3731. utils.ErrorLog(err.Error())
  3732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3733. return
  3734. }
  3735. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3736. var beforePrepares []*models.DialysisBeforePrepareGoods
  3737. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  3738. var dialysisBefor []*models.DialysisBeforePrepare
  3739. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3740. goods, _ := dataBody["goods"].([]interface{})
  3741. if len(goods) > 0 {
  3742. for _, item := range goods {
  3743. items := item.(map[string]interface{})
  3744. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3745. utils.ErrorLog("good_id")
  3746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3747. return
  3748. }
  3749. good_id := int64(items["good_id"].(float64))
  3750. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3751. utils.ErrorLog("good_type_id")
  3752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3753. return
  3754. }
  3755. good_type_id := int64(items["good_type_id"].(float64))
  3756. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3757. utils.ErrorLog("count")
  3758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3759. return
  3760. }
  3761. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3762. commdity_code := items["commdity_code"].(string)
  3763. fmt.Println("commdity", commdity_code)
  3764. prepareGoods := &models.DialysisBeforePrepareGoods{
  3765. GoodTypeId: good_type_id,
  3766. GoodId: good_id,
  3767. Count: count,
  3768. StorehouseId: houseConfig.StorehouseOutInfo,
  3769. }
  3770. beforePrepares = append(beforePrepares, prepareGoods)
  3771. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  3772. GoodTypeId: good_type_id,
  3773. GoodId: good_id,
  3774. Count: count,
  3775. StorehouseId: houseConfig.StorehouseOutInfo,
  3776. }
  3777. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  3778. prepare := &models.DialysisBeforePrepare{
  3779. GoodTypeId: good_type_id,
  3780. GoodId: good_id,
  3781. Count: count,
  3782. PatientId: patient_id,
  3783. RecordDate: record_time,
  3784. UserOrgId: adminUser.Org.Id,
  3785. Status: 1,
  3786. Ctime: time.Now().Unix(),
  3787. Creater: adminUser.AdminUser.Id,
  3788. CommdityCode: commdity_code,
  3789. StorehouseId: houseConfig.StorehouseOutInfo,
  3790. }
  3791. dialysisBefor = append(dialysisBefor, prepare)
  3792. }
  3793. }
  3794. //查询是否有库存
  3795. for _, item := range dialysisBefor {
  3796. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  3797. if err == gorm.ErrRecordNotFound {
  3798. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3799. c.ServeSuccessJSON(map[string]interface{}{
  3800. "message": "1",
  3801. "good_name": goodObj.GoodName,
  3802. "specification_name": goodObj.SpecificationName,
  3803. })
  3804. return
  3805. }
  3806. if err != nil {
  3807. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3808. c.ServeSuccessJSON(map[string]interface{}{
  3809. "message": "1",
  3810. "good_name": goodObj.GoodName,
  3811. "specification_name": goodObj.SpecificationName,
  3812. })
  3813. return
  3814. }
  3815. }
  3816. //新增
  3817. if active == 1 && len(goods) > 0 {
  3818. for _, item := range dialysisBefor {
  3819. dialyPrepareOne := models.DialysisBeforePrepare{
  3820. GoodTypeId: item.GoodTypeId,
  3821. GoodId: item.GoodId,
  3822. PatientId: item.PatientId,
  3823. RecordDate: item.RecordDate,
  3824. UserOrgId: item.UserOrgId,
  3825. Count: item.Count,
  3826. Ctime: time.Now().Unix(),
  3827. Creater: item.Creater,
  3828. CommdityCode: item.CommdityCode,
  3829. Status: 1,
  3830. StorehouseId: houseConfig.StorehouseOutInfo,
  3831. }
  3832. //先清除再插入
  3833. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3834. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  3835. //查询默认仓库
  3836. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3837. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3838. var total_count int64
  3839. for _, it := range stockList {
  3840. total_count += it.StockCount
  3841. }
  3842. //基础库插入数据
  3843. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3844. //更新库存
  3845. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  3846. var flush_count int64
  3847. for _, it := range goodList {
  3848. flush_count += it.StockCount
  3849. }
  3850. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  3851. }
  3852. if err == nil {
  3853. c.ServeSuccessJSON(map[string]interface{}{
  3854. "msg": "保存成功",
  3855. "message": "2",
  3856. })
  3857. return
  3858. } else {
  3859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3860. return
  3861. }
  3862. }
  3863. if len(beforePrepares) > 0 && active == 2 {
  3864. for _, item := range beforePrepares {
  3865. //1.查看该患者该耗材型号最后一次出库数量
  3866. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  3867. //判断当前出库数量和最后一次出库数量的大小
  3868. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  3869. if item.Count <= goodInfo.Count {
  3870. //退库
  3871. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  3872. //查询今日出库数据
  3873. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3874. for _, it := range list {
  3875. prepare := models.DialysisBeforePrepare{
  3876. UserOrgId: it.OrgId,
  3877. PatientId: patient_id,
  3878. RecordDate: it.RecordTime,
  3879. GoodId: it.GoodId,
  3880. GoodTypeId: it.GoodTypeId,
  3881. Count: it.Count,
  3882. Ctime: time.Now().Unix(),
  3883. Creater: adminUser.AdminUser.Id,
  3884. Status: 1,
  3885. StorehouseId: houseConfig.StorehouseOutInfo,
  3886. }
  3887. //删除准备表数据
  3888. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3889. service.CreateDialysisBeforePrepareOne(&prepare)
  3890. }
  3891. }
  3892. var last_total int64
  3893. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  3894. if item.Count >= goodInfo.Count {
  3895. //查询当前批次当前耗材最后一条出库数据
  3896. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3897. //计算当前出库和最后一次出库数据相差数据
  3898. last_total = item.Count - lastOutInfo.Count
  3899. //查询该批次剩余库存
  3900. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  3901. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  3902. if lastInfo.StockCount >= last_total {
  3903. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  3904. //查询今日出库数据
  3905. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3906. for _, it := range list {
  3907. prepare := models.DialysisBeforePrepare{
  3908. UserOrgId: it.OrgId,
  3909. PatientId: patient_id,
  3910. RecordDate: it.RecordTime,
  3911. GoodId: it.GoodId,
  3912. GoodTypeId: it.GoodTypeId,
  3913. Count: it.Count,
  3914. Ctime: time.Now().Unix(),
  3915. Creater: adminUser.AdminUser.Id,
  3916. Status: 1,
  3917. StorehouseId: houseConfig.StorehouseOutInfo,
  3918. }
  3919. //删除准备表数据
  3920. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3921. service.CreateDialysisBeforePrepareOne(&prepare)
  3922. //查询默认仓库
  3923. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3924. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3925. var total_count int64
  3926. for _, it := range stockList {
  3927. total_count += it.StockCount
  3928. }
  3929. //基础库插入数据
  3930. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3931. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  3932. var flush_count int64
  3933. for _, it := range goodList {
  3934. flush_count += it.StockCount
  3935. }
  3936. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  3937. }
  3938. }
  3939. //如果库存不够,则出库到下一个批次
  3940. if lastInfo.StockCount < last_total {
  3941. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  3942. //查询今日出库数据
  3943. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  3944. for _, it := range list {
  3945. prepare := models.DialysisBeforePrepare{
  3946. UserOrgId: it.OrgId,
  3947. PatientId: patient_id,
  3948. RecordDate: it.RecordTime,
  3949. GoodId: it.GoodId,
  3950. GoodTypeId: it.GoodTypeId,
  3951. Count: it.Count,
  3952. Ctime: time.Now().Unix(),
  3953. Creater: adminUser.AdminUser.Id,
  3954. Status: 1,
  3955. StorehouseId: houseConfig.StorehouseOutInfo,
  3956. }
  3957. //删除准备表数据
  3958. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  3959. service.CreateDialysisBeforePrepareOne(&prepare)
  3960. //查询默认仓库
  3961. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  3962. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  3963. var total_count int64
  3964. for _, it := range stockList {
  3965. total_count += it.StockCount
  3966. }
  3967. //基础库插入数据
  3968. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  3969. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  3970. var flush_count int64
  3971. for _, it := range goodList {
  3972. flush_count += it.StockCount
  3973. }
  3974. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  3975. }
  3976. if err != nil {
  3977. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3978. c.ServeSuccessJSON(map[string]interface{}{
  3979. "message": "1",
  3980. "good_name": goodObj.GoodName,
  3981. "specification_name": goodObj.SpecificationName,
  3982. })
  3983. return
  3984. }
  3985. }
  3986. }
  3987. if err != nil {
  3988. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  3989. c.ServeSuccessJSON(map[string]interface{}{
  3990. "message": "1",
  3991. "good_name": goodObj.GoodName,
  3992. "specification_name": goodObj.SpecificationName,
  3993. })
  3994. return
  3995. }
  3996. }
  3997. }
  3998. }
  3999. var errs error
  4000. if errs == nil {
  4001. c.ServeSuccessJSON(map[string]interface{}{
  4002. "msg": "提交成功",
  4003. "message": "2",
  4004. "good_name": "",
  4005. "specification_name": "",
  4006. })
  4007. return
  4008. } else {
  4009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4010. return
  4011. }
  4012. }
  4013. func (c *DialysisAPIController) CreateStockOutInfo() {
  4014. patient_id, _ := c.GetInt64("patient_id", 0)
  4015. record_date := c.GetString("record_time")
  4016. if patient_id <= 0 {
  4017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4018. return
  4019. }
  4020. adminInfo := c.GetMobileAdminUserInfo()
  4021. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  4022. timeLayout := "2006-01-02"
  4023. loc, _ := time.LoadLocation("Local")
  4024. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4025. record_time := theRecordTime.Unix()
  4026. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  4027. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4028. //去重
  4029. consumables = RemoveRepeatedGood(consumables)
  4030. if record.IsOpen == 1 {
  4031. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4032. //查询是否有库存
  4033. for _, item := range consumables {
  4034. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4035. if item.Count > warehouse.Count {
  4036. goodErrcode := models.XtGoodErrcode{
  4037. UserOrgId: item.UserOrgId,
  4038. Errcode: "自动出库库存不足",
  4039. GoodId: item.GoodId,
  4040. Status: 1,
  4041. Ctime: time.Now().Unix(),
  4042. Mtime: 0,
  4043. Count: 0,
  4044. StockCount: 0,
  4045. Creater: creator,
  4046. BatchNumberId: warehouse.ID,
  4047. WarehouseOutId: 0,
  4048. }
  4049. service.CreateGoodErrcode(goodErrcode)
  4050. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4051. c.ServeSuccessJSON(map[string]interface{}{
  4052. "message": "1",
  4053. "good_name": goodObj.GoodName,
  4054. "specification_name": goodObj.SpecificationName,
  4055. })
  4056. return
  4057. }
  4058. }
  4059. //查询是否有出库单
  4060. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4061. if err == gorm.ErrRecordNotFound {
  4062. //没有记录,则创建出库单
  4063. timeStr := time.Now().Format("2006-01-02")
  4064. timeArr := strings.Split(timeStr, "-")
  4065. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  4066. total = total + 1
  4067. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4068. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4069. number = number + total
  4070. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4071. creater := adminInfo.AdminUser.Id
  4072. warehouseOut := models.WarehouseOut{
  4073. WarehouseOutOrderNumber: warehousing_out_order,
  4074. OperationTime: time.Now().Unix(),
  4075. OrgId: adminInfo.Org.Id,
  4076. Creater: creater,
  4077. Ctime: time.Now().Unix(),
  4078. Status: 1,
  4079. WarehouseOutTime: record_time,
  4080. Dealer: 0,
  4081. Manufacturer: 0,
  4082. Type: 1,
  4083. IsSys: 1,
  4084. StorehouseId: houseConfig.StorehouseOutInfo,
  4085. IsCheck: 1,
  4086. }
  4087. err := service.AddSigleWarehouseOut(&warehouseOut)
  4088. if err != nil {
  4089. goodErrcode := models.XtGoodErrcode{
  4090. UserOrgId: adminInfo.Org.Id,
  4091. Errcode: "创建出库单失败",
  4092. GoodId: 0,
  4093. Status: 1,
  4094. Ctime: time.Now().Unix(),
  4095. Mtime: 0,
  4096. Count: 0,
  4097. StockCount: 0,
  4098. Creater: creator,
  4099. BatchNumberId: 0,
  4100. WarehouseOutId: 0,
  4101. }
  4102. service.CreateGoodErrcode(goodErrcode)
  4103. utils.TraceLog("创建出库单失败 err = %v", err)
  4104. } else {
  4105. for _, item := range consumables {
  4106. //出库
  4107. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  4108. if err == nil {
  4109. goodErrcode := models.XtGoodErrcode{
  4110. UserOrgId: adminInfo.Org.Id,
  4111. Errcode: "自动出库接口报错",
  4112. GoodId: 0,
  4113. Status: 1,
  4114. Ctime: time.Now().Unix(),
  4115. Mtime: 0,
  4116. Count: 0,
  4117. StockCount: 0,
  4118. Creater: creator,
  4119. BatchNumberId: 0,
  4120. WarehouseOutId: 0,
  4121. }
  4122. service.CreateGoodErrcode(goodErrcode)
  4123. utils.TraceLog("创建出库单失败 err = %v", err)
  4124. }
  4125. //查询
  4126. //出库数量相加
  4127. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4128. if errs != nil {
  4129. goodErrcode := models.XtGoodErrcode{
  4130. UserOrgId: item.UserOrgId,
  4131. Errcode: "创建剩余库存字段报错",
  4132. GoodId: item.GoodId,
  4133. Status: 1,
  4134. Ctime: time.Now().Unix(),
  4135. Mtime: 0,
  4136. Count: 0,
  4137. StockCount: 0,
  4138. Creater: creater,
  4139. BatchNumberId: 0,
  4140. WarehouseOutId: 0,
  4141. }
  4142. service.CreateGoodErrcode(goodErrcode)
  4143. }
  4144. }
  4145. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4146. if len(list) == 0 {
  4147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4148. return
  4149. }
  4150. for _, item := range list {
  4151. prepare := models.DialysisBeforePrepare{
  4152. UserOrgId: adminInfo.Org.Id,
  4153. PatientId: patient_id,
  4154. RecordDate: record_time,
  4155. GoodId: item.GoodId,
  4156. GoodTypeId: item.GoodTypeId,
  4157. Count: item.Count,
  4158. Creater: adminInfo.AdminUser.Id,
  4159. Status: 1,
  4160. Ctime: time.Now().Unix(),
  4161. StorehouseId: houseConfig.StorehouseOutInfo,
  4162. }
  4163. //清空准备表数据
  4164. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4165. if err != nil {
  4166. goodErrcode := models.XtGoodErrcode{
  4167. UserOrgId: item.OrgId,
  4168. Errcode: "自动出库清空准备表数据报错",
  4169. GoodId: item.GoodId,
  4170. Status: 1,
  4171. Ctime: time.Now().Unix(),
  4172. Mtime: 0,
  4173. Count: 0,
  4174. StockCount: 0,
  4175. Creater: creater,
  4176. BatchNumberId: 0,
  4177. WarehouseOutId: 0,
  4178. }
  4179. service.CreateGoodErrcode(goodErrcode)
  4180. }
  4181. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  4182. if errs != nil {
  4183. goodErrcode := models.XtGoodErrcode{
  4184. UserOrgId: item.OrgId,
  4185. Errcode: "自动出库创建准备表数据报错",
  4186. GoodId: item.GoodId,
  4187. Status: 1,
  4188. Ctime: time.Now().Unix(),
  4189. Mtime: 0,
  4190. Count: 0,
  4191. StockCount: 0,
  4192. Creater: creater,
  4193. BatchNumberId: 0,
  4194. WarehouseOutId: 0,
  4195. }
  4196. service.CreateGoodErrcode(goodErrcode)
  4197. }
  4198. //查询默认仓库
  4199. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4200. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4201. var total_count int64
  4202. for _, it := range stockList {
  4203. total_count += it.StockCount
  4204. }
  4205. //基础库插入数据
  4206. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4207. if errcodes != nil {
  4208. goodErrcode := models.XtGoodErrcode{
  4209. UserOrgId: item.OrgId,
  4210. Errcode: "自动出库基础库插入数据",
  4211. GoodId: item.GoodId,
  4212. Status: 1,
  4213. Ctime: time.Now().Unix(),
  4214. Mtime: 0,
  4215. Count: 0,
  4216. StockCount: 0,
  4217. Creater: creater,
  4218. BatchNumberId: 0,
  4219. WarehouseOutId: 0,
  4220. }
  4221. service.CreateGoodErrcode(goodErrcode)
  4222. }
  4223. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4224. var flush_count int64
  4225. for _, it := range goodList {
  4226. flush_count += it.StockCount
  4227. }
  4228. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4229. if errsss != nil {
  4230. goodErrcode := models.XtGoodErrcode{
  4231. UserOrgId: item.OrgId,
  4232. Errcode: "自动出库剩余库存更新数据",
  4233. GoodId: item.GoodId,
  4234. Status: 1,
  4235. Ctime: time.Now().Unix(),
  4236. Mtime: 0,
  4237. Count: 0,
  4238. StockCount: 0,
  4239. Creater: creater,
  4240. BatchNumberId: 0,
  4241. WarehouseOutId: 0,
  4242. }
  4243. service.CreateGoodErrcode(goodErrcode)
  4244. }
  4245. }
  4246. }
  4247. //
  4248. } else if err == nil {
  4249. for _, item := range consumables {
  4250. //出库
  4251. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  4252. if err != nil {
  4253. goodErrcode := models.XtGoodErrcode{
  4254. UserOrgId: adminInfo.Org.Id,
  4255. Errcode: "自动出库接口报错",
  4256. GoodId: 0,
  4257. Status: 1,
  4258. Ctime: time.Now().Unix(),
  4259. Mtime: 0,
  4260. Count: 0,
  4261. StockCount: 0,
  4262. Creater: creator,
  4263. BatchNumberId: 0,
  4264. WarehouseOutId: 0,
  4265. }
  4266. service.CreateGoodErrcode(goodErrcode)
  4267. }
  4268. //出库数量相加
  4269. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  4270. if errss != nil {
  4271. goodErrcode := models.XtGoodErrcode{
  4272. UserOrgId: item.UserOrgId,
  4273. Errcode: "创建剩余库存字段报错",
  4274. GoodId: item.GoodId,
  4275. Status: 1,
  4276. Ctime: time.Now().Unix(),
  4277. Mtime: time.Now().Unix(),
  4278. Count: 0,
  4279. StockCount: 0,
  4280. Creater: item.Creater,
  4281. BatchNumberId: 0,
  4282. WarehouseOutId: 0,
  4283. }
  4284. service.CreateGoodErrcode(goodErrcode)
  4285. }
  4286. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4287. if len(list) == 0 {
  4288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4289. return
  4290. }
  4291. for _, item := range list {
  4292. prepare := models.DialysisBeforePrepare{
  4293. UserOrgId: adminInfo.Org.Id,
  4294. PatientId: patient_id,
  4295. RecordDate: record_time,
  4296. GoodId: item.GoodId,
  4297. GoodTypeId: item.GoodTypeId,
  4298. Count: item.Count,
  4299. Creater: adminInfo.AdminUser.Id,
  4300. Status: 1,
  4301. Ctime: time.Now().Unix(),
  4302. StorehouseId: houseConfig.StorehouseOutInfo,
  4303. }
  4304. //清空准备表数据
  4305. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4306. if errs != nil {
  4307. goodErrcode := models.XtGoodErrcode{
  4308. UserOrgId: adminInfo.Org.Id,
  4309. Errcode: "自动出库清空准备表数据报错",
  4310. GoodId: 0,
  4311. Status: 1,
  4312. Ctime: time.Now().Unix(),
  4313. Mtime: 0,
  4314. Count: 0,
  4315. StockCount: 0,
  4316. Creater: creator,
  4317. BatchNumberId: 0,
  4318. WarehouseOutId: 0,
  4319. }
  4320. service.CreateGoodErrcode(goodErrcode)
  4321. }
  4322. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  4323. if errcodes != nil {
  4324. goodErrcode := models.XtGoodErrcode{
  4325. UserOrgId: adminInfo.Org.Id,
  4326. Errcode: "自动出库创建准备表数据报错",
  4327. GoodId: 0,
  4328. Status: 1,
  4329. Ctime: time.Now().Unix(),
  4330. Mtime: 0,
  4331. Count: 0,
  4332. StockCount: 0,
  4333. Creater: creator,
  4334. BatchNumberId: 0,
  4335. WarehouseOutId: 0,
  4336. }
  4337. service.CreateGoodErrcode(goodErrcode)
  4338. }
  4339. //查询默认仓库
  4340. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4341. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4342. var total_count int64
  4343. for _, it := range stockList {
  4344. total_count += it.StockCount
  4345. }
  4346. //基础库插入数据
  4347. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4348. if errcodes != nil {
  4349. goodErrcode := models.XtGoodErrcode{
  4350. UserOrgId: adminInfo.Org.Id,
  4351. Errcode: "自动出库基础库插入数据报错",
  4352. GoodId: 0,
  4353. Status: 1,
  4354. Ctime: time.Now().Unix(),
  4355. Mtime: 0,
  4356. Count: 0,
  4357. StockCount: 0,
  4358. Creater: creator,
  4359. BatchNumberId: 0,
  4360. WarehouseOutId: 0,
  4361. }
  4362. service.CreateGoodErrcode(goodErrcode)
  4363. }
  4364. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4365. var flush_count int64
  4366. for _, it := range goodList {
  4367. flush_count += it.StockCount
  4368. }
  4369. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4370. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  4371. if errss != nil {
  4372. goodErrcode := models.XtGoodErrcode{
  4373. UserOrgId: item.OrgId,
  4374. Errcode: "自动出库剩余库存更新数据",
  4375. GoodId: item.GoodId,
  4376. Status: 1,
  4377. Ctime: time.Now().Unix(),
  4378. Mtime: 0,
  4379. Count: 0,
  4380. StockCount: 0,
  4381. Creater: creater,
  4382. BatchNumberId: 0,
  4383. WarehouseOutId: 0,
  4384. }
  4385. service.CreateGoodErrcode(goodErrcode)
  4386. }
  4387. }
  4388. }
  4389. }
  4390. c.ServeSuccessJSON(map[string]interface{}{
  4391. "msg": "提交成功",
  4392. "message": "2",
  4393. "good_name": "",
  4394. "specification_name": "",
  4395. })
  4396. return
  4397. } else {
  4398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4399. return
  4400. }
  4401. }
  4402. func (c *DialysisAPIController) EditConsumables() {
  4403. patient_id, _ := c.GetInt64("patient_id", 0)
  4404. record_date := c.GetString("record_time")
  4405. if patient_id <= 0 {
  4406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4407. return
  4408. }
  4409. adminInfo := c.GetMobileAdminUserInfo()
  4410. timeLayout := "2006-01-02"
  4411. loc, _ := time.LoadLocation("Local")
  4412. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4413. record_time := theRecordTime.Unix()
  4414. dataBody := make(map[string]interface{}, 0)
  4415. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4416. if err != nil {
  4417. utils.ErrorLog(err.Error())
  4418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4419. return
  4420. }
  4421. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4422. var beforePrepares []*models.DialysisBeforePrepareGoods
  4423. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4424. var cancelbefor []*models.DialysisBeforePrepareGoods
  4425. var outbefor []*models.DialysisBeforePrepareGoods
  4426. //判断是否开启自动出库
  4427. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4428. if record.IsOpen == 1 {
  4429. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4430. goods, _ := dataBody["goods"].([]interface{})
  4431. if len(goods) > 0 {
  4432. for _, item := range goods {
  4433. items := item.(map[string]interface{})
  4434. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4435. utils.ErrorLog("good_id")
  4436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4437. return
  4438. }
  4439. good_id := int64(items["good_id"].(float64))
  4440. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4441. utils.ErrorLog("good_type_id")
  4442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4443. return
  4444. }
  4445. good_type_id := int64(items["good_type_id"].(float64))
  4446. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4447. utils.ErrorLog("count")
  4448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4449. return
  4450. }
  4451. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4452. commdity_code := items["commdity_code"].(string)
  4453. fmt.Println(commdity_code)
  4454. prepareGoods := &models.DialysisBeforePrepareGoods{
  4455. GoodTypeId: good_type_id,
  4456. GoodId: good_id,
  4457. Count: count,
  4458. StorehouseId: houseConfig.StorehouseOutInfo,
  4459. }
  4460. beforePrepares = append(beforePrepares, prepareGoods)
  4461. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4462. GoodTypeId: good_type_id,
  4463. GoodId: good_id,
  4464. Count: count,
  4465. StorehouseId: houseConfig.StorehouseOutInfo,
  4466. }
  4467. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4468. }
  4469. for _, item := range beforePrepares {
  4470. //1.查看该患者该耗材型号最后一次出库数量
  4471. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4472. //判断当前出库数量和最后一次出库数量的大小
  4473. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  4474. if item.Count < goodInfo.Count {
  4475. cancelbefor = append(cancelbefor, item)
  4476. }
  4477. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4478. if item.Count > goodInfo.Count {
  4479. outbefor = append(outbefor, item)
  4480. }
  4481. //处理编辑耗材新增不了的问题
  4482. if goodInfo.Count == item.Count {
  4483. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  4484. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  4485. }
  4486. }
  4487. fmt.Println("退库长度", len(cancelbefor))
  4488. fmt.Println("出库长度", len(outbefor))
  4489. //退库
  4490. for _, item := range cancelbefor {
  4491. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4492. creater := adminInfo.AdminUser.Id
  4493. //退库
  4494. //err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
  4495. //查询该患者当天已经出库的耗材信息
  4496. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  4497. var delete_count int64 = 0
  4498. delete_count = warehouseOutInfos.Count - item.Count
  4499. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4500. // 在出库记录表里记录退库详情
  4501. warehouseOutInfo := &models.WarehouseOutInfo{
  4502. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4503. WarehouseOutId: warehouseOut.ID,
  4504. Status: 1,
  4505. Ctime: time.Now().Unix(),
  4506. OrgId: adminInfo.Org.Id,
  4507. Type: 1,
  4508. IsSys: 1,
  4509. SysRecordTime: record_time,
  4510. GoodTypeId: item.GoodTypeId,
  4511. GoodId: item.GoodId,
  4512. PatientId: patient_id,
  4513. ConsumableType: 2,
  4514. StorehouseId: houseConfig.StorehouseOutInfo,
  4515. IsCheck: 1,
  4516. }
  4517. warehouseOutInfo.Count = item.Count
  4518. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  4519. warehouseOutInfo.Price = stockInInfo.Price
  4520. warehouseOutInfo.Dealer = stockInInfo.Dealer
  4521. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  4522. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  4523. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  4524. warehouseOutInfo.Number = warehouseOutInfos.Number
  4525. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  4526. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  4527. //查找当天是否存在出库记录
  4528. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  4529. if errcod == gorm.ErrRecordNotFound {
  4530. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4531. //插入详情明细表
  4532. stockFlow := models.VmStockFlow{
  4533. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4534. WarehouseOutId: warehouseOut.ID,
  4535. GoodId: item.GoodId,
  4536. Number: warehouseOutInfos.Number,
  4537. ProductDate: stockInInfo.ProductDate,
  4538. ExpireDate: stockInInfo.ExpiryDate,
  4539. Count: item.Count,
  4540. Price: stockInInfo.Price,
  4541. Status: 1,
  4542. Ctime: time.Now().Unix(),
  4543. UserOrgId: adminInfo.Org.Id,
  4544. Manufacturer: stockInInfo.Manufacturer,
  4545. Dealer: stockInInfo.Dealer,
  4546. LicenseNumber: stockInInfo.LicenseNumber,
  4547. IsEdit: 2,
  4548. Creator: creater,
  4549. SystemTime: record_time,
  4550. ConsumableType: 3,
  4551. WarehousingDetailId: 0,
  4552. IsSys: 1,
  4553. UpdateCreator: creater,
  4554. PatientId: patient_id,
  4555. StorehouseId: houseConfig.StorehouseOutInfo,
  4556. }
  4557. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  4558. if errflow == gorm.ErrRecordNotFound {
  4559. //创建流水表
  4560. err := service.CreateStockFlowOne(stockFlow)
  4561. fmt.Println("err", err)
  4562. } else if errflow == nil {
  4563. //插入详情明细表
  4564. stockFlow := models.VmStockFlow{
  4565. ID: exsit.ID,
  4566. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4567. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4568. WarehouseOutId: warehouseOut.ID,
  4569. GoodId: item.GoodId,
  4570. Number: warehouseOutInfos.Number,
  4571. ProductDate: stockInInfo.ProductDate,
  4572. ExpireDate: stockInInfo.ExpiryDate,
  4573. Count: exsit.Count - delete_count,
  4574. Price: stockInInfo.Price,
  4575. Status: 1,
  4576. Ctime: time.Now().Unix(),
  4577. UserOrgId: adminInfo.Org.Id,
  4578. Manufacturer: stockInInfo.Manufacturer,
  4579. Dealer: stockInInfo.Dealer,
  4580. LicenseNumber: stockInInfo.LicenseNumber,
  4581. IsEdit: 2,
  4582. Creator: creater,
  4583. SystemTime: record_time,
  4584. ConsumableType: 3,
  4585. WarehousingDetailId: 0,
  4586. IsSys: 1,
  4587. UpdateCreator: creater,
  4588. PatientId: patient_id,
  4589. StorehouseId: houseConfig.StorehouseOutInfo,
  4590. }
  4591. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  4592. }
  4593. } else if errcod == nil {
  4594. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  4595. //插入详情明细表
  4596. stockFlow := models.VmStockFlow{
  4597. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4598. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4599. WarehouseOutId: warehouseOut.ID,
  4600. GoodId: item.GoodId,
  4601. Number: warehouseOutInfos.Number,
  4602. ProductDate: stockInInfo.ProductDate,
  4603. ExpireDate: stockInInfo.ExpiryDate,
  4604. Count: item.Count,
  4605. Price: stockInInfo.Price,
  4606. Status: 1,
  4607. Ctime: time.Now().Unix(),
  4608. UserOrgId: adminInfo.Org.Id,
  4609. Manufacturer: stockInInfo.Manufacturer,
  4610. Dealer: stockInInfo.Dealer,
  4611. LicenseNumber: stockInInfo.LicenseNumber,
  4612. IsEdit: 2,
  4613. Creator: creater,
  4614. SystemTime: record_time,
  4615. ConsumableType: 3,
  4616. WarehousingDetailId: 0,
  4617. IsSys: 1,
  4618. UpdateCreator: creater,
  4619. PatientId: patient_id,
  4620. ReturnCount: delete_count,
  4621. StorehouseId: houseConfig.StorehouseOutInfo,
  4622. }
  4623. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  4624. if errflows == gorm.ErrRecordNotFound {
  4625. //创建流水表
  4626. service.CreateStockFlowOne(stockFlow)
  4627. } else if errflows == nil {
  4628. stockFlow := models.VmStockFlow{
  4629. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  4630. ID: exsit.ID,
  4631. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  4632. WarehouseOutId: warehouseOut.ID,
  4633. GoodId: item.GoodId,
  4634. Number: warehouseOutInfos.Number,
  4635. ProductDate: stockInInfo.ProductDate,
  4636. ExpireDate: stockInInfo.ExpiryDate,
  4637. Count: exsit.Count - delete_count,
  4638. Price: stockInInfo.Price,
  4639. Status: 1,
  4640. Ctime: time.Now().Unix(),
  4641. UserOrgId: adminInfo.Org.Id,
  4642. Manufacturer: stockInInfo.Manufacturer,
  4643. Dealer: stockInInfo.Dealer,
  4644. LicenseNumber: stockInInfo.LicenseNumber,
  4645. IsEdit: 2,
  4646. Creator: creater,
  4647. SystemTime: record_time,
  4648. ConsumableType: 3,
  4649. WarehousingDetailId: 0,
  4650. IsSys: 1,
  4651. UpdateCreator: creater,
  4652. PatientId: patient_id,
  4653. ReturnCount: delete_count,
  4654. StorehouseId: houseConfig.StorehouseOutInfo,
  4655. }
  4656. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  4657. }
  4658. }
  4659. //更改自动出库的表格
  4660. details := models.BloodAutomaticReduceDetail{
  4661. WarehouseOutId: warehouseOutInfo.ID,
  4662. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4663. PatientId: patient_id,
  4664. Ctime: time.Now().Unix(),
  4665. Mtime: time.Now().Unix(),
  4666. Status: 1,
  4667. RecordTime: record_time,
  4668. OrgId: adminInfo.Org.Id,
  4669. GoodId: item.GoodId,
  4670. GoodTypeId: item.GoodTypeId,
  4671. Count: item.Count,
  4672. StorehouseId: houseConfig.StorehouseOutInfo,
  4673. }
  4674. //查询当天耗材是否已经存在数据
  4675. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4676. if errcode == gorm.ErrRecordNotFound {
  4677. service.CreateAutoReduceRecord(&details)
  4678. } else if errcode == nil {
  4679. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4680. service.CreateAutoReduceRecord(&details)
  4681. }
  4682. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  4683. //增加出库库存数量
  4684. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  4685. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
  4686. fmt.Println("errOne", errOne)
  4687. // 删除出库完成后,要增加对应批次的库存数量
  4688. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  4689. //查询默认仓库
  4690. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4691. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4692. var total_count int64
  4693. for _, it := range stockList {
  4694. total_count += it.StockCount
  4695. }
  4696. //基础库插入数据
  4697. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4698. //更新剩余库存
  4699. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4700. var flush_count int64
  4701. for _, it := range goodList {
  4702. flush_count += it.StockCount
  4703. }
  4704. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4705. }
  4706. //出库
  4707. for _, item := range outbefor {
  4708. fmt.Println("出库ID", item.GoodId)
  4709. var last_total int64
  4710. //1.查看该患者该耗材型号最后一次出库数量
  4711. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4712. //计算当前出库和最后一次出库数据相差数据
  4713. last_total = item.Count - goodInfoOne.Count
  4714. //查询该批次剩余库存
  4715. lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
  4716. if lastInfo.StockCount == 0 {
  4717. //查询该耗材的总库存
  4718. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4719. if wareinfo.StockCount == 0 {
  4720. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4721. c.ServeSuccessJSON(map[string]interface{}{
  4722. "message": "1",
  4723. "good_name": goodObj.GoodName,
  4724. "specification_name": goodObj.SpecificationName,
  4725. })
  4726. return
  4727. }
  4728. }
  4729. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  4730. //查询该耗材的总库存
  4731. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  4732. // 如果库存差大于剩余库存则提示库存不足
  4733. if last_total > wareinfo.StockCount {
  4734. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4735. c.ServeSuccessJSON(map[string]interface{}{
  4736. "message": "1",
  4737. "good_name": goodObj.GoodName,
  4738. "specification_name": goodObj.SpecificationName,
  4739. })
  4740. return
  4741. } else {
  4742. fmt.Println("出库2o2o2o2o2oo2o2o2o2o2o2o", item.GoodId)
  4743. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  4744. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4745. if err == gorm.ErrRecordNotFound {
  4746. //没有记录,则创建出库单
  4747. timeStr := time.Now().Format("2006-01-02")
  4748. timeArr := strings.Split(timeStr, "-")
  4749. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  4750. total = total + 1
  4751. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4752. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4753. number = number + total
  4754. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4755. warehouseOut := models.WarehouseOut{
  4756. WarehouseOutOrderNumber: warehousing_out_order,
  4757. OperationTime: time.Now().Unix(),
  4758. OrgId: adminInfo.Org.Id,
  4759. Creater: adminInfo.AdminUser.Id,
  4760. Ctime: time.Now().Unix(),
  4761. Status: 1,
  4762. WarehouseOutTime: record_time,
  4763. Dealer: 0,
  4764. Manufacturer: 0,
  4765. Type: 1,
  4766. IsSys: 1,
  4767. StorehouseId: houseConfig.StorehouseOutInfo,
  4768. IsCheck: 1,
  4769. }
  4770. service.AddSigleWarehouseOut(&warehouseOut)
  4771. }
  4772. //出库
  4773. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  4774. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4775. //1.查看该患者该耗材型号最后一次出库数量
  4776. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4777. fmt.Println("count2323323222323wi", item.Count)
  4778. prepare := models.DialysisBeforePrepare{
  4779. UserOrgId: adminInfo.Org.Id,
  4780. PatientId: patient_id,
  4781. RecordDate: record_time,
  4782. GoodId: item.GoodId,
  4783. GoodTypeId: item.GoodTypeId,
  4784. Count: item.Count - goodInfoTwo.Count,
  4785. Ctime: time.Now().Unix(),
  4786. Mtime: 0,
  4787. Creater: adminInfo.AdminUser.Id,
  4788. Modifier: adminInfo.AdminUser.Id,
  4789. Status: 1,
  4790. CommdityCode: "",
  4791. NewCount: 0,
  4792. ProjectId: 0,
  4793. StorehouseId: houseConfig.StorehouseOutInfo,
  4794. }
  4795. fmt.Println("prepare", prepare.Count)
  4796. fmt.Println("count", item.Count)
  4797. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  4798. //增加出库数量
  4799. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  4800. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4801. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4802. var total_count int64
  4803. for _, it := range stockList {
  4804. total_count += it.StockCount
  4805. }
  4806. //基础库插入数据
  4807. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  4808. //剩余库存
  4809. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4810. var flush_count int64
  4811. for _, it := range goodList {
  4812. flush_count += it.StockCount
  4813. }
  4814. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4815. }
  4816. }
  4817. //查询今日出库数据
  4818. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  4819. for _, it := range list {
  4820. prepare := models.DialysisBeforePrepare{
  4821. UserOrgId: it.OrgId,
  4822. PatientId: patient_id,
  4823. RecordDate: it.RecordTime,
  4824. GoodId: it.GoodId,
  4825. GoodTypeId: it.GoodTypeId,
  4826. Count: it.Count,
  4827. Ctime: time.Now().Unix(),
  4828. Creater: adminInfo.AdminUser.Id,
  4829. Status: 1,
  4830. StorehouseId: houseConfig.StorehouseOutInfo,
  4831. }
  4832. //删除准备表数据
  4833. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  4834. service.CreateDialysisBeforePrepareOne(&prepare)
  4835. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  4836. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  4837. var total_count int64
  4838. for _, it := range stockList {
  4839. total_count += it.StockCount
  4840. }
  4841. //基础库插入数据
  4842. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  4843. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  4844. var flush_count int64
  4845. for _, it := range goodList {
  4846. flush_count += it.StockCount
  4847. }
  4848. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  4849. //if err != nil {
  4850. // goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
  4851. // c.ServeSuccessJSON(map[string]interface{}{
  4852. // "message": "2",
  4853. // "good_name": goodObj.GoodName,
  4854. // "specification_name": goodObj.SpecificationName,
  4855. // })
  4856. // return
  4857. //}
  4858. }
  4859. }
  4860. }
  4861. //更新自动出库的地方
  4862. var errs error
  4863. if errs == nil {
  4864. c.ServeSuccessJSON(map[string]interface{}{
  4865. "msg": "修改成功",
  4866. "message": "2",
  4867. "good_name": "",
  4868. "specification_name": "",
  4869. })
  4870. return
  4871. } else {
  4872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4873. return
  4874. }
  4875. }
  4876. }
  4877. func (c *DialysisAPIController) GetDialysisGoods() {
  4878. schedualDate := c.GetString("schedule_date")
  4879. schedule_type, _ := c.GetInt64("schedule_type")
  4880. partition_id, _ := c.GetInt64("partition_id")
  4881. page, _ := c.GetInt("page")
  4882. patient_id, _ := c.GetInt64("patient_id")
  4883. schedualEndDate := int64(0)
  4884. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4885. if parseDateErr != nil && len(schedualDate) != 0 {
  4886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4887. return
  4888. }
  4889. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4890. if parseDateErr != nil && len(schedualDate) != 0 {
  4891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4892. return
  4893. }
  4894. schedualEndDate = endDate.Unix()
  4895. adminUser := c.GetMobileAdminUserInfo()
  4896. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  4897. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  4898. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  4899. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  4900. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  4901. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  4902. //获取当天该病人的透析处方
  4903. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  4904. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  4905. if err == gorm.ErrRecordNotFound {
  4906. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  4907. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  4908. if patient_id != 0 {
  4909. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4910. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  4911. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  4912. //获取患者总的出库数据
  4913. item.LastAutomaticReduceDetail = goodUser
  4914. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4915. item.Project = project
  4916. }
  4917. }
  4918. c.ServeSuccessJSON(map[string]interface{}{
  4919. "dialysis_goods": dialysisGoods,
  4920. "good_type": goodTypes,
  4921. "total": total,
  4922. "prescribe": prescribe,
  4923. "good_info": good_info,
  4924. "warehouseOutList": warehouseOutList,
  4925. "config": config,
  4926. "outConfig": outConfig,
  4927. "settleConfig": settleConfig,
  4928. })
  4929. return
  4930. } else if err == nil {
  4931. //获取当天排班的每个患者的库存使用情况
  4932. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  4933. //获取患者总的出库数据
  4934. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  4935. if patient_id != 0 {
  4936. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4937. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  4938. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  4939. item.Project = project
  4940. item.LastAutomaticReduceDetail = goodUser
  4941. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4942. }
  4943. }
  4944. if err == nil {
  4945. c.ServeSuccessJSON(map[string]interface{}{
  4946. "dialysis_goods": dialysisGoods,
  4947. "good_type": goodTypes,
  4948. "total": total,
  4949. "prescribe": prescribe,
  4950. "good_info": good_info,
  4951. "project": project,
  4952. "warehouseOutList": warehouseOutList,
  4953. "config": config,
  4954. "outConfig": outConfig,
  4955. "settleConfig": settleConfig,
  4956. })
  4957. return
  4958. } else {
  4959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4960. return
  4961. }
  4962. } else if err != nil {
  4963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4964. return
  4965. }
  4966. }
  4967. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  4968. start_time := c.GetString("start_time")
  4969. end_time := c.GetString("end_time")
  4970. timeLayout := "2006-01-02"
  4971. loc, _ := time.LoadLocation("Local")
  4972. var theStartTime int64
  4973. if len(start_time) > 0 {
  4974. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4975. if err != nil {
  4976. utils.ErrorLog(err.Error())
  4977. }
  4978. theStartTime = theTime.Unix()
  4979. }
  4980. var theEndtTime int64
  4981. if len(end_time) > 0 {
  4982. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4983. if err != nil {
  4984. utils.ErrorLog(err.Error())
  4985. }
  4986. theEndtTime = theTime.Unix()
  4987. }
  4988. adminUser := c.GetMobileAdminUserInfo()
  4989. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  4990. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  4991. if err == nil {
  4992. c.ServeSuccessJSON(map[string]interface{}{
  4993. "stock_out": outInfo,
  4994. "stockCount": stockCount,
  4995. })
  4996. return
  4997. } else {
  4998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4999. return
  5000. }
  5001. }
  5002. func (c *DialysisAPIController) GetStockInGoodInfo() {
  5003. patient_id, _ := c.GetInt64("patient_id", 0)
  5004. record_time := c.GetString("record_time")
  5005. adminUser := c.GetMobileAdminUserInfo()
  5006. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  5007. if parseDateErr != nil && len(record_time) != 0 {
  5008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5009. return
  5010. }
  5011. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  5012. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  5013. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  5014. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  5015. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  5016. //获取今日患者的透析处方参数
  5017. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  5018. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  5019. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  5020. c.ServeSuccessJSON(map[string]interface{}{
  5021. "good_type": goodTypes,
  5022. "good_user": goodUser,
  5023. "good_info": good_info,
  5024. "last_good_user": lastGoodUserDetial,
  5025. "project": project,
  5026. "prescription": prescribe,
  5027. "outInfo": outInfo,
  5028. "configs": configs,
  5029. })
  5030. return
  5031. }
  5032. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  5033. patient_id, _ := c.GetInt64("patient_id", 0)
  5034. record_date := c.GetString("record_time")
  5035. timeLayout := "2006-01-02"
  5036. loc, _ := time.LoadLocation("Local")
  5037. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5038. record_time := theRecordTime.Unix()
  5039. adminInfo := c.GetMobileAdminUserInfo()
  5040. dataBody := make(map[string]interface{}, 0)
  5041. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5042. if err != nil {
  5043. utils.ErrorLog(err.Error())
  5044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5045. return
  5046. }
  5047. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5048. var beforePrepares []*models.DialysisBeforePrepareGoods
  5049. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5050. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5051. goods, _ := dataBody["goods"].([]interface{})
  5052. if len(goods) > 0 {
  5053. for _, item := range goods {
  5054. items := item.(map[string]interface{})
  5055. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5056. utils.ErrorLog("good_id")
  5057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5058. return
  5059. }
  5060. good_id := int64(items["good_id"].(float64))
  5061. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5062. utils.ErrorLog("good_type_id")
  5063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5064. return
  5065. }
  5066. good_type_id := int64(items["good_type_id"].(float64))
  5067. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5068. utils.ErrorLog("count")
  5069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5070. return
  5071. }
  5072. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5073. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  5074. utils.ErrorLog("project_id")
  5075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5076. return
  5077. }
  5078. project_id := int64(items["project_id"].(float64))
  5079. prepare := &models.DialysisBeforePrepareGoods{
  5080. GoodId: good_id,
  5081. GoodTypeId: good_type_id,
  5082. Count: count,
  5083. ProjectId: project_id,
  5084. StorehouseId: houseConfig.StorehouseOutInfo,
  5085. }
  5086. beforePrepares = append(beforePrepares, prepare)
  5087. newPrepare := &models.NewDialysisBeforePrepareGoods{
  5088. GoodId: good_id,
  5089. GoodTypeId: good_type_id,
  5090. Count: count,
  5091. ProjectId: project_id,
  5092. StorehouseId: houseConfig.StorehouseOutInfo,
  5093. }
  5094. newBeforePrepares = append(newBeforePrepares, newPrepare)
  5095. }
  5096. }
  5097. }
  5098. //查询是否有库存
  5099. for _, item := range beforePrepares {
  5100. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5101. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  5102. if item.Count > warehouse.Count {
  5103. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5104. c.ServeSuccessJSON(map[string]interface{}{
  5105. "message": "1",
  5106. "good_name": goodObj.GoodName,
  5107. "specification_name": goodObj.SpecificationName,
  5108. })
  5109. return
  5110. }
  5111. }
  5112. //出库逻辑
  5113. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  5114. if err != nil {
  5115. utils.ErrorLog(err.Error())
  5116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5117. return
  5118. }
  5119. //查询当天出库的数据
  5120. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5121. for _, item := range list {
  5122. prepare := models.DialysisBeforePrepare{
  5123. UserOrgId: item.OrgId,
  5124. PatientId: item.PatientId,
  5125. RecordDate: item.RecordTime,
  5126. GoodId: item.GoodId,
  5127. GoodTypeId: item.GoodTypeId,
  5128. Count: item.Count,
  5129. Creater: adminInfo.AdminUser.Id,
  5130. Status: 1,
  5131. Ctime: time.Now().Unix(),
  5132. ProjectId: item.ProjectId,
  5133. StorehouseId: houseConfig.StorehouseOutInfo,
  5134. }
  5135. //清空准备表的数据
  5136. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5137. //插入准备表数据
  5138. service.CreateDialysisBeforePrepareOne(&prepare)
  5139. //查询默认仓库
  5140. //查询默认仓库
  5141. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5142. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5143. var total_count int64
  5144. for _, it := range stockList {
  5145. total_count += it.StockCount
  5146. }
  5147. //基础库插入数据
  5148. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5149. ////更新剩余库存
  5150. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5151. var flush_count int64
  5152. for _, it := range goodList {
  5153. flush_count += it.StockCount
  5154. }
  5155. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5156. if errs != nil {
  5157. goodErrcode := models.XtGoodErrcode{
  5158. UserOrgId: item.OrgId,
  5159. Errcode: "手动出库更新剩余出库失败",
  5160. GoodId: item.GoodId,
  5161. Status: 1,
  5162. Ctime: time.Now().Unix(),
  5163. Mtime: 0,
  5164. Count: 0,
  5165. StockCount: 0,
  5166. Creater: adminInfo.AdminUser.Id,
  5167. BatchNumberId: 0,
  5168. WarehouseOutId: 0,
  5169. }
  5170. service.CreateGoodErrcode(goodErrcode)
  5171. }
  5172. }
  5173. //更新自动出库的地方
  5174. var errs error
  5175. if errs == nil {
  5176. c.ServeSuccessJSON(map[string]interface{}{
  5177. "msg": "修改成功",
  5178. "message": "2",
  5179. "good_name": "",
  5180. "specification_name": "",
  5181. })
  5182. return
  5183. } else {
  5184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5185. return
  5186. }
  5187. }
  5188. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5189. newArr = make([]*models.DialysisBeforePrepare, 0)
  5190. for i := 0; i < len(arr); i++ {
  5191. repeat := false
  5192. for j := i + 1; j < len(arr); j++ {
  5193. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  5194. repeat = true
  5195. break
  5196. }
  5197. }
  5198. if !repeat {
  5199. newArr = append(newArr, arr[i])
  5200. }
  5201. }
  5202. return
  5203. }
  5204. func (c *DialysisAPIController) GetAllDrug() {
  5205. patient_id, _ := c.GetInt64("patient_id", 0)
  5206. adminInfo := c.GetMobileAdminUserInfo()
  5207. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5208. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  5209. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  5210. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  5211. c.ServeSuccessJSON(map[string]interface{}{
  5212. "base_drug_config": drugStockConfig,
  5213. "private_drug_config": privateDrugConfig,
  5214. "base_drug_list": drugList,
  5215. "private_drug_list": privateDrugList,
  5216. })
  5217. }
  5218. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  5219. newArr = make([]*models.DialysisBeforePrepare, 0)
  5220. for i := 0; i < len(arr); i++ {
  5221. repeat := false
  5222. for j := i + 1; j < len(arr); j++ {
  5223. if arr[i].GoodId == arr[j].GoodId {
  5224. repeat = true
  5225. break
  5226. }
  5227. }
  5228. if !repeat {
  5229. newArr = append(newArr, arr[i])
  5230. }
  5231. }
  5232. return
  5233. }
  5234. func (c *DialysisAPIController) GetDepartment() {
  5235. adminInfo := c.GetMobileAdminUserInfo()
  5236. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  5237. if err == nil {
  5238. c.ServeSuccessJSON(map[string]interface{}{
  5239. "departments": departments,
  5240. })
  5241. } else {
  5242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5243. return
  5244. }
  5245. }
  5246. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  5247. types, _ := c.GetInt("type", 0)
  5248. start_time := c.GetString("start_time")
  5249. end_time := c.GetString("end_time")
  5250. orgId := c.GetMobileAdminUserInfo().Org.Id
  5251. timeLayout := "2006-01-02"
  5252. loc, _ := time.LoadLocation("Local")
  5253. var startTime int64
  5254. if len(start_time) > 0 {
  5255. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5256. if err != nil {
  5257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5258. return
  5259. }
  5260. startTime = theTime.Unix()
  5261. }
  5262. var endTime int64
  5263. if len(end_time) > 0 {
  5264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5265. if err != nil {
  5266. utils.ErrorLog(err.Error())
  5267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5268. return
  5269. }
  5270. endTime = theTime.Unix()
  5271. }
  5272. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  5273. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  5274. if err != nil {
  5275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5276. } else {
  5277. c.ServeSuccessJSON(map[string]interface{}{
  5278. "list": list,
  5279. "type": types,
  5280. "stockTotal": stockTotal,
  5281. })
  5282. }
  5283. }
  5284. func (c *DialysisAPIController) BatchDeleteMonitor() {
  5285. ids := c.GetString("ids")
  5286. //patient_id, _ := c.GetInt64("patient_id")
  5287. //monitoring_date, _ := c.GetInt64("monitoring_date")
  5288. idArray := strings.Split(ids, ",")
  5289. err := service.BatchDeleteMonitor(idArray)
  5290. fmt.Print("err", err)
  5291. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5292. //redis := service.RedisClient()
  5293. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  5294. //redis.Set(key, "", time.Second)
  5295. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  5296. //redis.Set(keyOne, "", time.Second)
  5297. //fmt.Println("keyo呢32332322332332232332",keyOne)
  5298. //redis.Close()
  5299. c.ServeSuccessJSON(map[string]interface{}{
  5300. "msg": "批量删除成功",
  5301. })
  5302. return
  5303. }
  5304. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  5305. id, _ := c.GetInt64("id")
  5306. timeLayout := "2006-01-02"
  5307. loc, _ := time.LoadLocation("Local")
  5308. start_time := time.Now().Format("2006-01-02")
  5309. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5310. nowTime := time.Now()
  5311. endTime := nowTime.AddDate(-2, 0, 0)
  5312. endTimes := endTime.Format("2006-01-02")
  5313. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  5314. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  5315. fmt.Println("endtime232332322332322323232332", endTime.Unix())
  5316. c.ServeSuccessJSON(map[string]interface{}{
  5317. "list": list,
  5318. })
  5319. return
  5320. }
  5321. func (c *DialysisAPIController) BathDeleteAdviceList() {
  5322. dataBody := make(map[string]interface{}, 0)
  5323. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5324. ids := c.GetString("ids")
  5325. idArray := strings.Split(ids, ",")
  5326. origin, _ := c.GetInt64("origin")
  5327. if origin == 1 {
  5328. err = service.BatchDeleteAdvice(idArray)
  5329. fmt.Print("err", err)
  5330. c.ServeSuccessJSON(map[string]interface{}{
  5331. "msg": "批量删除成功",
  5332. })
  5333. return
  5334. }
  5335. if origin == 2 {
  5336. service.BatchDeleteHisAdvice(idArray)
  5337. }
  5338. }
  5339. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  5340. good_id, _ := c.GetInt64("good_id")
  5341. count, _ := c.GetInt64("count")
  5342. record_time, _ := c.GetInt64("record_time")
  5343. patient_id, _ := c.GetInt64("patient_id")
  5344. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  5345. c.ServeSuccessJSON(map[string]interface{}{
  5346. "detail": detail,
  5347. })
  5348. return
  5349. }
  5350. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  5351. good_id, _ := c.GetInt64("good_id")
  5352. record_time, _ := c.GetInt64("record_time")
  5353. patient_id, _ := c.GetInt64("patient_id")
  5354. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  5355. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  5356. fmt.Print("err", err)
  5357. c.ServeSuccessJSON(map[string]interface{}{
  5358. "msg": "批量删除成功",
  5359. })
  5360. return
  5361. }
  5362. func (c *DialysisAPIController) BatchAdviceCheck() {
  5363. ids := c.GetString("ids")
  5364. idArray := strings.Split(ids, ",")
  5365. creator, _ := c.GetInt64("creator")
  5366. origin, _ := c.GetInt64("origin")
  5367. if origin == 1 {
  5368. err := service.BatchAdviceCheck(idArray, creator)
  5369. fmt.Println(err)
  5370. list, _ := service.GetAdviceExecutionById(idArray)
  5371. c.ServeSuccessJSON(map[string]interface{}{
  5372. "list": list,
  5373. })
  5374. return
  5375. }
  5376. if origin == 2 {
  5377. service.BatchHisAdviceCheck(idArray, creator)
  5378. list, _ := service.GetHisAdviceExecutionById(idArray)
  5379. c.ServeSuccessJSON(map[string]interface{}{
  5380. "list": list,
  5381. })
  5382. return
  5383. }
  5384. }
  5385. func (c *DialysisAPIController) BatchAdviceExecution() {
  5386. ids := c.GetString("ids")
  5387. idArray := strings.Split(ids, ",")
  5388. executionTime := c.GetString("execution_time")
  5389. creator, _ := c.GetInt64("creator")
  5390. timeLayout := "2006-01-02 15:04:05"
  5391. loc, _ := time.LoadLocation("Local")
  5392. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  5393. orgin, _ := c.GetInt64("origin")
  5394. if orgin == 1 {
  5395. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  5396. list, _ := service.GetAdviceExecutionById(idArray)
  5397. fmt.Println(err)
  5398. c.ServeSuccessJSON(map[string]interface{}{
  5399. "list": list,
  5400. })
  5401. return
  5402. }
  5403. if orgin == 2 {
  5404. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  5405. list, _ := service.GetHisAdviceExecutionById(idArray)
  5406. fmt.Println(err)
  5407. c.ServeSuccessJSON(map[string]interface{}{
  5408. "list": list,
  5409. })
  5410. return
  5411. }
  5412. }
  5413. func (c *DialysisAPIController) UpdateStockGoods() {
  5414. good_id, _ := c.GetInt64("good_id")
  5415. record_time, _ := c.GetInt64("record_time")
  5416. patient_id, _ := c.GetInt64("patient_id")
  5417. count, _ := c.GetInt64("count")
  5418. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  5419. fmt.Print("err", err)
  5420. c.ServeSuccessJSON(map[string]interface{}{
  5421. "msg": "更新成功",
  5422. })
  5423. return
  5424. }
  5425. //当前数据比上一次出库数据少
  5426. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  5427. //查询该患者当天已经出库的耗材信息
  5428. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5429. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5430. for i := len(goods_yc) - 1; i >= 0; i-- {
  5431. goods_yc_temp := goods_yc[i]
  5432. for j := len(goods) - 1; j >= 0; j-- {
  5433. goods_temp := goods[j]
  5434. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5435. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5436. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5437. if goods_yc_temp.Count == goods_temp.Count {
  5438. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5439. goods = append(goods[:j], goods[j+1:]...)
  5440. break
  5441. }
  5442. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5443. if goods_yc_temp.Count > goods_temp.Count {
  5444. temp_count := goods_yc_temp.Count - goods_temp.Count
  5445. goods_yc[i].Count = temp_count
  5446. goods = append(goods[:j], goods[j+1:]...)
  5447. break
  5448. }
  5449. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5450. if goods_yc_temp.Count < goods_temp.Count {
  5451. temp_count := goods_temp.Count - goods_yc_temp.Count
  5452. goods[j].Count = temp_count
  5453. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5454. break
  5455. }
  5456. }
  5457. }
  5458. }
  5459. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5460. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5461. //退库
  5462. if len(goods_yc) > 0 {
  5463. for _, good_yc := range goods_yc {
  5464. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5465. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  5466. }
  5467. }
  5468. return nil
  5469. }
  5470. //耗材出库删除
  5471. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  5472. // 先根据相关信息查询当天该耗材的出库信息
  5473. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  5474. if err != nil {
  5475. return err
  5476. }
  5477. var delete_count int64 = 0
  5478. delete_count = warehouseOutInfos.Count - count
  5479. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5480. // 在出库记录表里记录退库详情
  5481. warehouseOutInfo := &models.WarehouseOutInfo{
  5482. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5483. WarehouseOutId: warehouseOut.ID,
  5484. Status: 1,
  5485. Ctime: time.Now().Unix(),
  5486. OrgId: orgID,
  5487. Type: 1,
  5488. IsSys: 1,
  5489. SysRecordTime: record_time,
  5490. GoodTypeId: good_yc.GoodTypeId,
  5491. GoodId: good_yc.GoodId,
  5492. PatientId: good_yc.PatientId,
  5493. ConsumableType: 2,
  5494. StorehouseId: houseConfig.StorehouseOutInfo,
  5495. IsCheck: 1,
  5496. }
  5497. warehouseOutInfo.Count = count
  5498. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5499. warehouseOutInfo.Price = stockInInfo.Price
  5500. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5501. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5502. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5503. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5504. warehouseOutInfo.Number = warehouseOutInfos.Number
  5505. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5506. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5507. //查找当天是否存在出库记录
  5508. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5509. if errcod == gorm.ErrRecordNotFound {
  5510. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5511. //插入详情明细表
  5512. stockFlow := models.VmStockFlow{
  5513. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5514. WarehouseOutId: warehouseOut.ID,
  5515. GoodId: good_yc.GoodId,
  5516. Number: warehouseOutInfos.Number,
  5517. ProductDate: stockInInfo.ProductDate,
  5518. ExpireDate: stockInInfo.ExpiryDate,
  5519. Count: count,
  5520. Price: stockInInfo.Price,
  5521. Status: 1,
  5522. Ctime: time.Now().Unix(),
  5523. UserOrgId: good_yc.OrgId,
  5524. Manufacturer: stockInInfo.Manufacturer,
  5525. Dealer: stockInInfo.Dealer,
  5526. LicenseNumber: stockInInfo.LicenseNumber,
  5527. IsEdit: 2,
  5528. Creator: creater,
  5529. SystemTime: record_time,
  5530. ConsumableType: 3,
  5531. WarehousingDetailId: 0,
  5532. IsSys: 1,
  5533. UpdateCreator: creater,
  5534. PatientId: patient_id,
  5535. StorehouseId: houseConfig.StorehouseOutInfo,
  5536. }
  5537. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  5538. if errflow == gorm.ErrRecordNotFound {
  5539. //创建流水表
  5540. err := service.CreateStockFlowOne(stockFlow)
  5541. fmt.Println("err", err)
  5542. } else if errflow == nil {
  5543. //插入详情明细表
  5544. stockFlow := models.VmStockFlow{
  5545. ID: exsit.ID,
  5546. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5547. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5548. WarehouseOutId: warehouseOut.ID,
  5549. GoodId: good_yc.GoodId,
  5550. Number: warehouseOutInfos.Number,
  5551. ProductDate: stockInInfo.ProductDate,
  5552. ExpireDate: stockInInfo.ExpiryDate,
  5553. Count: exsit.Count - delete_count,
  5554. Price: stockInInfo.Price,
  5555. Status: 1,
  5556. Ctime: time.Now().Unix(),
  5557. UserOrgId: good_yc.OrgId,
  5558. Manufacturer: stockInInfo.Manufacturer,
  5559. Dealer: stockInInfo.Dealer,
  5560. LicenseNumber: stockInInfo.LicenseNumber,
  5561. IsEdit: 2,
  5562. Creator: creater,
  5563. SystemTime: record_time,
  5564. ConsumableType: 3,
  5565. WarehousingDetailId: 0,
  5566. IsSys: 1,
  5567. UpdateCreator: creater,
  5568. PatientId: patient_id,
  5569. StorehouseId: houseConfig.StorehouseOutInfo,
  5570. }
  5571. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  5572. }
  5573. if errOne != nil {
  5574. return errOne
  5575. }
  5576. } else if errcod == nil {
  5577. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5578. //插入详情明细表
  5579. stockFlow := models.VmStockFlow{
  5580. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5581. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5582. WarehouseOutId: warehouseOut.ID,
  5583. GoodId: good_yc.GoodId,
  5584. Number: warehouseOutInfos.Number,
  5585. ProductDate: stockInInfo.ProductDate,
  5586. ExpireDate: stockInInfo.ExpiryDate,
  5587. Count: count,
  5588. Price: stockInInfo.Price,
  5589. Status: 1,
  5590. Ctime: time.Now().Unix(),
  5591. UserOrgId: good_yc.OrgId,
  5592. Manufacturer: stockInInfo.Manufacturer,
  5593. Dealer: stockInInfo.Dealer,
  5594. LicenseNumber: stockInInfo.LicenseNumber,
  5595. IsEdit: 2,
  5596. Creator: creater,
  5597. SystemTime: record_time,
  5598. ConsumableType: 3,
  5599. WarehousingDetailId: 0,
  5600. IsSys: 1,
  5601. UpdateCreator: creater,
  5602. PatientId: patient_id,
  5603. ReturnCount: delete_count,
  5604. StorehouseId: houseConfig.StorehouseOutInfo,
  5605. }
  5606. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  5607. if errflows == gorm.ErrRecordNotFound {
  5608. //创建流水表
  5609. service.CreateStockFlowOne(stockFlow)
  5610. } else if errflows == nil {
  5611. stockFlow := models.VmStockFlow{
  5612. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5613. ID: exsit.ID,
  5614. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5615. WarehouseOutId: warehouseOut.ID,
  5616. GoodId: good_yc.GoodId,
  5617. Number: warehouseOutInfos.Number,
  5618. ProductDate: stockInInfo.ProductDate,
  5619. ExpireDate: stockInInfo.ExpiryDate,
  5620. Count: exsit.Count - delete_count,
  5621. Price: stockInInfo.Price,
  5622. Status: 1,
  5623. Ctime: time.Now().Unix(),
  5624. UserOrgId: good_yc.OrgId,
  5625. Manufacturer: stockInInfo.Manufacturer,
  5626. Dealer: stockInInfo.Dealer,
  5627. LicenseNumber: stockInInfo.LicenseNumber,
  5628. IsEdit: 2,
  5629. Creator: creater,
  5630. SystemTime: record_time,
  5631. ConsumableType: 3,
  5632. WarehousingDetailId: 0,
  5633. IsSys: 1,
  5634. UpdateCreator: creater,
  5635. PatientId: patient_id,
  5636. ReturnCount: delete_count,
  5637. StorehouseId: houseConfig.StorehouseOutInfo,
  5638. }
  5639. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  5640. }
  5641. }
  5642. //更改自动出库的表格
  5643. details := models.BloodAutomaticReduceDetail{
  5644. WarehouseOutId: warehouseOutInfo.ID,
  5645. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5646. PatientId: patient_id,
  5647. Ctime: time.Now().Unix(),
  5648. Mtime: time.Now().Unix(),
  5649. Status: 1,
  5650. RecordTime: record_time,
  5651. OrgId: orgID,
  5652. GoodId: good_yc.GoodId,
  5653. GoodTypeId: good_yc.GoodTypeId,
  5654. Count: count,
  5655. StorehouseId: houseConfig.StorehouseOutInfo,
  5656. }
  5657. //查询当天耗材是否已经存在数据
  5658. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  5659. if errcode == gorm.ErrRecordNotFound {
  5660. errTwo := service.CreateAutoReduceRecord(&details)
  5661. if errTwo != nil {
  5662. return errTwo
  5663. }
  5664. } else if errcode == nil {
  5665. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  5666. service.CreateAutoReduceRecord(&details)
  5667. }
  5668. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  5669. //增加出库库存数量
  5670. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  5671. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  5672. fmt.Println("errOne", errOne)
  5673. // 删除出库完成后,要增加对应批次的库存数量
  5674. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  5675. if errThree != nil {
  5676. return errThree
  5677. }
  5678. if good_yc.Count == 0 {
  5679. return nil
  5680. } else {
  5681. return errors.New("退库和出库数据不匹配")
  5682. }
  5683. }
  5684. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  5685. //查询该患者当天已经出库的耗材信息
  5686. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  5687. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  5688. for i := len(goods_yc) - 1; i >= 0; i-- {
  5689. goods_yc_temp := goods_yc[i]
  5690. for j := len(goods) - 1; j >= 0; j-- {
  5691. goods_temp := goods[j]
  5692. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  5693. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  5694. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  5695. if goods_yc_temp.Count == goods_temp.Count {
  5696. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5697. goods = append(goods[:j], goods[j+1:]...)
  5698. break
  5699. }
  5700. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  5701. if goods_yc_temp.Count > goods_temp.Count {
  5702. temp_count := goods_yc_temp.Count - goods_temp.Count
  5703. goods_yc[i].Count = temp_count
  5704. goods = append(goods[:j], goods[j+1:]...)
  5705. break
  5706. }
  5707. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  5708. if goods_yc_temp.Count < goods_temp.Count {
  5709. temp_count := goods_temp.Count - goods_yc_temp.Count
  5710. goods[j].Count = temp_count
  5711. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  5712. break
  5713. }
  5714. }
  5715. }
  5716. }
  5717. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  5718. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  5719. fmt.Println("剩余需要出库的", len(goods))
  5720. if len(goods) > 0 {
  5721. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  5722. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5723. if err == gorm.ErrRecordNotFound {
  5724. //没有记录,则创建出库单
  5725. timeStr := time.Now().Format("2006-01-02")
  5726. timeArr := strings.Split(timeStr, "-")
  5727. total, _ := service.FindAllWarehouseOut(orgID)
  5728. total = total + 1
  5729. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5730. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5731. number = number + total
  5732. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5733. warehouseOut := models.WarehouseOut{
  5734. WarehouseOutOrderNumber: warehousing_out_order,
  5735. OperationTime: time.Now().Unix(),
  5736. OrgId: orgID,
  5737. Creater: creater,
  5738. Ctime: time.Now().Unix(),
  5739. Status: 1,
  5740. WarehouseOutTime: record_time,
  5741. Dealer: 0,
  5742. Manufacturer: 0,
  5743. Type: 1,
  5744. IsSys: 1,
  5745. StorehouseId: houseConfig.StorehouseOutInfo,
  5746. IsCheck: 1,
  5747. }
  5748. err := service.AddSigleWarehouseOut(&warehouseOut)
  5749. if err != nil {
  5750. utils.TraceLog("创建出库单失败 err = %v", err)
  5751. return err
  5752. } else {
  5753. out = warehouseOut
  5754. }
  5755. }
  5756. for _, item := range goods {
  5757. var newCount int64 = 0
  5758. for _, it := range goodOne {
  5759. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  5760. newCount = it.Count
  5761. }
  5762. }
  5763. prepare := models.DialysisBeforePrepare{
  5764. GoodTypeId: item.GoodTypeId,
  5765. GoodId: item.GoodId,
  5766. Count: item.Count,
  5767. StorehouseId: houseConfig.StorehouseOutInfo,
  5768. }
  5769. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  5770. //增加出库数量
  5771. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  5772. }
  5773. }
  5774. if len(goods_yc) > 0 {
  5775. for _, good_yc := range goods_yc {
  5776. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  5777. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  5778. }
  5779. }
  5780. return nil
  5781. }
  5782. //耗材出库删除
  5783. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  5784. // 先根据相关信息查询当天该耗材的出库信息
  5785. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  5786. if err != nil {
  5787. return err
  5788. }
  5789. var delete_count int64 = 0
  5790. for _, ware := range warehouseOutInfos {
  5791. // 判断当前出库的数据和删除出库数量
  5792. if good_yc.Count <= ware.Count {
  5793. delete_count = good_yc.Count
  5794. } else {
  5795. delete_count = ware.Count
  5796. }
  5797. warehouseOutInfo := &models.WarehouseOutInfo{
  5798. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5799. WarehouseOutId: warehouseOut.ID,
  5800. Status: 1,
  5801. Ctime: time.Now().Unix(),
  5802. Remark: "",
  5803. OrgId: orgID,
  5804. Type: 1,
  5805. Manufacturer: 0,
  5806. Dealer: 0,
  5807. IsSys: 0,
  5808. SysRecordTime: record_time,
  5809. GoodTypeId: good_yc.GoodTypeId,
  5810. GoodId: good_yc.GoodId,
  5811. StorehouseId: warehouseOut.StorehouseId,
  5812. IsCheck: 1,
  5813. }
  5814. warehouseOutInfo.Count = delete_count
  5815. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5816. warehouseOutInfo.Price = stockInInfo.Price
  5817. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5818. if errOne != nil {
  5819. return errOne
  5820. }
  5821. // 删除出库完成后,要改变流水库存(有疑问)
  5822. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  5823. fmt.Println("errOne", errOne)
  5824. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  5825. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  5826. //扣减出库数量
  5827. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  5828. if errThree != nil {
  5829. return errThree
  5830. }
  5831. }
  5832. if good_yc.Count == 0 {
  5833. return nil
  5834. } else {
  5835. return errors.New("退库和出库数据不匹配")
  5836. }
  5837. }
  5838. func (this *DialysisAPIController) GetMobileScheduleList() {
  5839. limit, _ := this.GetInt64("limit")
  5840. page, _ := this.GetInt64("page")
  5841. type_options_visible, _ := this.GetInt64("type_options_visible")
  5842. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  5843. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  5844. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  5845. }
  5846. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  5847. newArr = make([]*models.HisPrescriptionProject, 0)
  5848. for i := 0; i < len(arr); i++ {
  5849. repeat := false
  5850. for j := i + 1; j < len(arr); j++ {
  5851. if arr[i].TeamId == arr[j].TeamId {
  5852. repeat = true
  5853. break
  5854. }
  5855. }
  5856. if !repeat {
  5857. newArr = append(newArr, arr[i])
  5858. }
  5859. }
  5860. return
  5861. }
  5862. func (this *DialysisAPIController) GetRoleList() {
  5863. admin_user_id, _ := this.GetInt64("admin_user_id")
  5864. orgid := this.GetMobileAdminUserInfo().Org.Id
  5865. list, err := service.GetRoleList(orgid, admin_user_id)
  5866. fmt.Println(err)
  5867. this.ServeSuccessJSON(map[string]interface{}{
  5868. "list": list,
  5869. })
  5870. return
  5871. }
  5872. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  5873. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  5874. // 先根据相关信息查询当天该耗材的出库信息
  5875. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  5876. if err != nil {
  5877. return err
  5878. }
  5879. var delete_count int64 = 0
  5880. delete_count = warehouseOutInfos.Count - count
  5881. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  5882. // 删除出库完成后,要增加对应批次的库存数量
  5883. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  5884. if errThree != nil {
  5885. return errThree
  5886. }
  5887. //增加退库数量
  5888. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  5889. //扣减出库数量
  5890. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  5891. //查询剩余库存
  5892. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  5893. var sum_count int64
  5894. for _, item := range goodList {
  5895. sum_count += item.StockCount
  5896. }
  5897. // 在出库记录表里记录退库详情
  5898. warehouseOutInfo := &models.WarehouseOutInfo{
  5899. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5900. WarehouseOutId: warehouseOut.ID,
  5901. Status: 1,
  5902. Ctime: time.Now().Unix(),
  5903. OrgId: orgID,
  5904. Type: 1,
  5905. IsSys: 1,
  5906. SysRecordTime: record_time,
  5907. GoodTypeId: good_yc.GoodTypeId,
  5908. GoodId: good_yc.GoodId,
  5909. PatientId: good_yc.PatientId,
  5910. ConsumableType: 2,
  5911. StorehouseId: houseConfig.StorehouseOutInfo,
  5912. IsCheck: 1,
  5913. OverCount: sum_count,
  5914. }
  5915. warehouseOutInfo.Count = count
  5916. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  5917. warehouseOutInfo.Price = stockInInfo.Price
  5918. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5919. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5920. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5921. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5922. warehouseOutInfo.Number = warehouseOutInfos.Number
  5923. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5924. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5925. //查找当天是否存在出库记录
  5926. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5927. if errcod == gorm.ErrRecordNotFound {
  5928. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5929. //插入详情明细表
  5930. if errOne != nil {
  5931. return errOne
  5932. }
  5933. //插入详情明细表
  5934. stockFlow := models.VmStockFlow{
  5935. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5936. WarehouseOutId: warehouseOut.ID,
  5937. GoodId: good_yc.GoodId,
  5938. Number: warehouseOutInfos.Number,
  5939. ProductDate: stockInInfo.ProductDate,
  5940. ExpireDate: stockInInfo.ExpiryDate,
  5941. Count: count,
  5942. Price: stockInInfo.Price,
  5943. Status: 1,
  5944. Ctime: time.Now().Unix(),
  5945. UserOrgId: good_yc.OrgId,
  5946. Manufacturer: stockInInfo.Manufacturer,
  5947. Dealer: stockInInfo.Dealer,
  5948. LicenseNumber: stockInInfo.LicenseNumber,
  5949. IsEdit: 2,
  5950. Creator: creater,
  5951. SystemTime: record_time,
  5952. ConsumableType: 3,
  5953. WarehousingDetailId: 0,
  5954. IsSys: 1,
  5955. UpdateCreator: creater,
  5956. PatientId: patient_id,
  5957. StorehouseId: houseConfig.StorehouseOutInfo,
  5958. OverCount: sum_count,
  5959. ProjectId: good_yc.ProjectId,
  5960. }
  5961. err := service.CreateStockFlowOne(stockFlow)
  5962. fmt.Println("err", err)
  5963. } else if errcod == nil {
  5964. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  5965. }
  5966. //创建退库单
  5967. operation_time := time.Now().Unix()
  5968. //创建退库单
  5969. timeStr := time.Now().Format("2006-01-02")
  5970. timeArr := strings.Split(timeStr, "-")
  5971. total, _ := service.FindAllCancelStockTotal(orgID)
  5972. total = total + 1
  5973. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5974. cancelStock := models.CancelStock{
  5975. OrderNumber: orderNumber,
  5976. OperaTime: operation_time,
  5977. OrgId: orgID,
  5978. Creater: warehouseOut.Creater,
  5979. Ctime: time.Now().Unix(),
  5980. Status: 1,
  5981. ReturnTime: record_time,
  5982. Type: 1,
  5983. StorehouseId: stockInInfo.StorehouseId,
  5984. IsCheck: 1,
  5985. }
  5986. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  5987. if msgerrkonde == gorm.ErrRecordNotFound {
  5988. service.AddSigleCancelStock(&cancelStock)
  5989. }
  5990. cancel, _ := service.GetLastCancelStockById(orgID)
  5991. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  5992. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  5993. cancelStockInfo := models.CancelStockInfo{
  5994. GoodId: stockInInfo.GoodId,
  5995. CancelStockId: cancel.ID,
  5996. GoodTypeId: stockInInfo.GoodTypeId,
  5997. Count: delete_count,
  5998. Price: stockInInfo.PackingPrice,
  5999. Total: 0,
  6000. ProductDate: stockInInfo.ProductDate,
  6001. ExpiryDate: stockInInfo.ExpiryDate,
  6002. Ctime: time.Now().Unix(),
  6003. Status: 1,
  6004. OrgId: orgID,
  6005. OrderNumber: cancel.OrderNumber,
  6006. Type: 0,
  6007. Dealer: deaerler.DealerName,
  6008. Manufacturer: manufacturer.ManufacturerName,
  6009. Number: stockInInfo.Number,
  6010. RegisterAccount: "",
  6011. Remark: "",
  6012. WarehouseInfoId: stockInInfo.ID,
  6013. PatientId: patient_id,
  6014. RecordDate: record_time,
  6015. StorehouseId: stockInInfo.StorehouseId,
  6016. IsCheck: 1,
  6017. }
  6018. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6019. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  6020. flow := models.VmStockFlow{
  6021. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  6022. GoodId: good_yc.GoodId,
  6023. Number: warehouseOutInfos.Number,
  6024. LicenseNumber: stockInInfo.LicenseNumber,
  6025. Count: delete_count,
  6026. UserOrgId: orgID,
  6027. PatientId: patient_id,
  6028. SystemTime: record_time,
  6029. ConsumableType: 7,
  6030. IsSys: 0,
  6031. WarehousingOrder: "",
  6032. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  6033. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6034. IsEdit: 0,
  6035. CancelStockId: cancel.ID,
  6036. CancelOrderNumber: cancel.OrderNumber,
  6037. Manufacturer: manufacturer.ID,
  6038. Dealer: 0,
  6039. Creator: warehouseOut.Creater,
  6040. UpdateCreator: 0,
  6041. Status: 1,
  6042. Ctime: time.Now().Unix(),
  6043. Mtime: 0,
  6044. Price: stockInInfo.Price,
  6045. WarehousingDetailId: stockInInfo.ID,
  6046. WarehouseOutDetailId: warehouseOutInfos.ID,
  6047. CancelOutDetailId: cancelInfo.ID,
  6048. ProductDate: stockInInfo.ProductDate,
  6049. ExpireDate: stockInInfo.ExpiryDate,
  6050. StorehouseId: houseConfig.StorehouseOutInfo,
  6051. OverCount: sum_count,
  6052. }
  6053. service.CreateStockFlowOne(flow)
  6054. //更改自动出库的表格
  6055. details := models.BloodAutomaticReduceDetail{
  6056. WarehouseOutId: warehouseOutInfo.ID,
  6057. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6058. PatientId: patient_id,
  6059. Ctime: time.Now().Unix(),
  6060. Mtime: time.Now().Unix(),
  6061. Status: 1,
  6062. RecordTime: record_time,
  6063. OrgId: orgID,
  6064. GoodId: good_yc.GoodId,
  6065. GoodTypeId: good_yc.GoodTypeId,
  6066. Count: count,
  6067. StorehouseId: houseConfig.StorehouseOutInfo,
  6068. }
  6069. //查询当天耗材是否已经存在数据
  6070. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6071. if errcode == gorm.ErrRecordNotFound {
  6072. errTwo := service.CreateAutoReduceRecord(&details)
  6073. if errTwo != nil {
  6074. return errTwo
  6075. }
  6076. } else if errcode == nil {
  6077. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6078. service.CreateAutoReduceRecord(&details)
  6079. }
  6080. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6081. //增加出库库存数量
  6082. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  6083. if good_yc.Count == 0 {
  6084. return nil
  6085. } else {
  6086. return errors.New("退库和出库数据不匹配")
  6087. }
  6088. }
  6089. func (this *DialysisAPIController) SavePatientSign() {
  6090. adminUserInfo := this.GetMobileAdminUserInfo()
  6091. patient_id, _ := this.GetInt64("patient_id")
  6092. dialysis_date, _ := this.GetInt64("dialysis_date")
  6093. orgid := adminUserInfo.Org.Id
  6094. var esdata models.DialysisOrder
  6095. var err error
  6096. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  6097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6098. return
  6099. }
  6100. esdata.Hash = esdata.Hash
  6101. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  6102. order := models.DialysisOrder{
  6103. Hash: esdata.Hash,
  6104. Url: esdata.Url,
  6105. }
  6106. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  6107. redis := service.RedisClient()
  6108. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6109. redis.Set(key, "", time.Second)
  6110. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6111. //清空key 值
  6112. redis.Set(keyOne, "", time.Second)
  6113. //scheduleDateStartOne := startDate.Format("2006-01-02")
  6114. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6115. //redis.Set(keyTwo, "", time.Second)
  6116. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6117. redis.Set(keyThree, "", time.Second)
  6118. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6119. redis.Set(keyFour, "", time.Second)
  6120. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6121. redis.Set(keyFive, "", time.Second)
  6122. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6123. redis.Set(keySix, "", time.Second)
  6124. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  6125. redis.Set(keySeven, "", time.Second)
  6126. if err != nil {
  6127. fmt.Println(err)
  6128. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6129. return
  6130. }
  6131. this.ServeSuccessJSON(map[string]interface{}{
  6132. "electronic_signature": esdata,
  6133. })
  6134. }
  6135. func (this *DialysisAPIController) GetPatientSign() {
  6136. patient_id, _ := this.GetInt64("patient_id")
  6137. dialysis_date, _ := this.GetInt64("dialysis_date")
  6138. adminUserInfo := this.GetMobileAdminUserInfo()
  6139. orgId := adminUserInfo.Org.Id
  6140. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  6141. if err != nil {
  6142. fmt.Println(err)
  6143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6144. return
  6145. }
  6146. this.ServeSuccessJSON(map[string]interface{}{
  6147. "dialysisOrder": dialysisOrder,
  6148. })
  6149. }
  6150. func (this *DialysisAPIController) GetScheduleByPatient() {
  6151. patient_id, _ := this.GetInt64("patient_id")
  6152. schedule_date, _ := this.GetInt64("schedule_date")
  6153. orgid := this.GetMobileAdminUserInfo().Org.Id
  6154. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  6155. this.ServeSuccessJSON(map[string]interface{}{
  6156. "schedule": schedule,
  6157. })
  6158. }
  6159. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  6160. org_id := this.GetMobileAdminUserInfo().Org.Id
  6161. patient_id, _ := this.GetInt64("patient_id")
  6162. schedule_date, _ := this.GetInt64("schedule_date")
  6163. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  6164. this.ServeSuccessJSON(map[string]interface{}{
  6165. "order": order,
  6166. })
  6167. }
  6168. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  6169. org_id := this.GetMobileAdminUserInfo().Org.Id
  6170. schedule_date := this.GetString("schedule_date")
  6171. schedule_type, _ := this.GetInt64("schedule_type")
  6172. timeLayout := "2006-01-02"
  6173. loc, _ := time.LoadLocation("Local")
  6174. var startdateunix int64
  6175. if len(schedule_date) > 0 {
  6176. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  6177. if err != nil {
  6178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6179. return
  6180. }
  6181. startdateunix = theTime.Unix()
  6182. }
  6183. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  6184. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  6185. devices, _ := service.GetAllDevicetByListSix(org_id)
  6186. for key, item := range scheduals {
  6187. // 床位信息
  6188. for _, device := range devices {
  6189. if item.BedId == device.ID {
  6190. scheduals[key].DeviceNumber = device
  6191. break
  6192. }
  6193. }
  6194. }
  6195. this.ServeSuccessJSON(map[string]interface{}{
  6196. "list": list,
  6197. "scheduals": scheduals,
  6198. })
  6199. }
  6200. func (this *DialysisAPIController) SavePatientPicture() {
  6201. patient_id, _ := this.GetInt64("patient_id")
  6202. dialysis_date, _ := this.GetInt64("schedule_date")
  6203. avatar := this.GetString("avatar")
  6204. fmt.Println("patient_id", patient_id)
  6205. orgId := this.GetMobileAdminUserInfo().Org.Id
  6206. order := models.DialysisOrder{
  6207. Url: avatar,
  6208. }
  6209. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  6210. redis := service.RedisClient()
  6211. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  6212. redis.Set(key, "", time.Second)
  6213. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  6214. //清空key 值
  6215. redis.Set(keyOne, "", time.Second)
  6216. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  6217. redis.Set(keyThree, "", time.Second)
  6218. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  6219. redis.Set(keyFour, "", time.Second)
  6220. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  6221. redis.Set(keyFive, "", time.Second)
  6222. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  6223. redis.Set(keySix, "", time.Second)
  6224. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  6225. redis.Set(keySeven, "", time.Second)
  6226. if err != nil {
  6227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  6228. return
  6229. }
  6230. this.ServeSuccessJSON(map[string]interface{}{
  6231. "order": order,
  6232. })
  6233. }
  6234. func (this *DialysisAPIController) ExectionMobileAdvice() {
  6235. ids := this.GetString("ids")
  6236. idSplit := strings.Split(ids, ",")
  6237. orgId := this.GetMobileAdminUserInfo().Org.Id
  6238. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6239. execution_time := this.GetString("exce_time")
  6240. timeLayout2 := "2006-01-02 15:04:05"
  6241. loc, _ := time.LoadLocation("Local")
  6242. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  6243. if errs != nil {
  6244. utils.ErrorLog(errs.Error())
  6245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6246. return
  6247. }
  6248. //his客户
  6249. if config.IsOpen == 1 {
  6250. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  6251. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  6252. for _, item := range list {
  6253. for _, it := range adviceList {
  6254. if item.DrugId == it.DrugId {
  6255. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6256. }
  6257. }
  6258. }
  6259. for _, item := range list {
  6260. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6261. var sum_out_count int64
  6262. for _, itemThree := range item.ChildDoctorAdvice {
  6263. var prescribing_number int64
  6264. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6265. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6266. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6267. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6268. }
  6269. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6270. prescribing_number = parseIntPrescribingNumber
  6271. }
  6272. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6273. prescribing_number = parseIntPrescribingNumber
  6274. }
  6275. sum_out_count += prescribing_number
  6276. }
  6277. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6278. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6279. //库存不足
  6280. if sum_out_count > drugStockOut.FlushCount {
  6281. this.ServeSuccessJSON(map[string]interface{}{
  6282. "msg": "2",
  6283. "drug": medical,
  6284. "ids": ids,
  6285. })
  6286. return
  6287. }
  6288. }
  6289. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6290. //执行医嘱
  6291. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6292. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  6293. for _, item := range advices {
  6294. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6295. redis := service.RedisClient()
  6296. //清空key 值
  6297. redis.Set(key, "", time.Second)
  6298. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6299. redis.Set(keyTwo, "", time.Second)
  6300. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6301. redis.Set(keyThree, "", time.Second)
  6302. recordDate := theTime.Format("2006-01-02")
  6303. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6304. redis.Set(keyFour, "", time.Second)
  6305. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6306. redis.Set(keyFive, "", time.Second)
  6307. defer redis.Close()
  6308. }
  6309. if errs == nil {
  6310. //药品管理信息
  6311. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6312. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6313. if drugStockConfig.IsOpen == 1 {
  6314. for _, item := range advices {
  6315. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  6316. config, _ := service.GetDrugOpenConfigOne(orgId)
  6317. if config.IsOpen != 1 {
  6318. //查询该药品是否有库存
  6319. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6320. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  6321. if medical.IsUse == 2 {
  6322. if config.IsOpen != 1 {
  6323. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6324. service.HisDrugsDelivery(orgId, creater, &advice)
  6325. }
  6326. if pharmacyConfig.IsOpen != 1 {
  6327. service.HisDrugsDelivery(orgId, creater, &advice)
  6328. }
  6329. //更新字典里面的库存
  6330. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6331. var sum_count int64
  6332. for _, its := range stockInfo {
  6333. if its.MaxUnit == medical.MaxUnit {
  6334. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6335. }
  6336. sum_count += its.StockMaxNumber + its.StockMinNumber
  6337. }
  6338. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6339. //剩余库存
  6340. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6341. }
  6342. }
  6343. }
  6344. }
  6345. }
  6346. this.ServeSuccessJSON(map[string]interface{}{
  6347. "msg": "1",
  6348. "ids": ids,
  6349. })
  6350. return
  6351. } else {
  6352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6353. }
  6354. }
  6355. fmt.Println("config233322333223", config.IsOpen)
  6356. //血透客户
  6357. if config.IsOpen == 2 || config.IsOpen == 0 {
  6358. //药品管理信息
  6359. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  6360. if drugStockConfig.IsOpen == 1 {
  6361. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  6362. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  6363. for _, item := range list {
  6364. for _, it := range adviceList {
  6365. if item.DrugId == it.DrugId {
  6366. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6367. }
  6368. }
  6369. }
  6370. for _, item := range list {
  6371. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6372. var sum_out_count int64
  6373. for _, itemThree := range item.ChildDoctorAdvice {
  6374. var prescribing_number int64
  6375. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6376. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6377. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6378. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6379. }
  6380. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6381. prescribing_number = parseIntPrescribingNumber
  6382. }
  6383. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6384. prescribing_number = parseIntPrescribingNumber
  6385. }
  6386. sum_out_count += prescribing_number
  6387. }
  6388. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6389. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6390. //库存不足
  6391. if sum_out_count > drugStockOut.FlushCount {
  6392. this.ServeSuccessJSON(map[string]interface{}{
  6393. "msg": "2",
  6394. "drug": medical,
  6395. "ids": ids,
  6396. })
  6397. return
  6398. }
  6399. }
  6400. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6401. fmt.Println("creater2332243244224242424", creater)
  6402. //执行医嘱
  6403. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6404. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6405. for _, item := range advices {
  6406. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6407. redis := service.RedisClient()
  6408. //清空key 值
  6409. redis.Set(key, "", time.Second)
  6410. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6411. redis.Set(keyTwo, "", time.Second)
  6412. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6413. redis.Set(keyThree, "", time.Second)
  6414. recordDate := theTime.Format("2006-01-02")
  6415. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6416. redis.Set(keyFour, "", time.Second)
  6417. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6418. redis.Set(keyFive, "", time.Second)
  6419. defer redis.Close()
  6420. }
  6421. if errs == nil {
  6422. for _, item := range advices {
  6423. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6424. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6425. //查询是否出库按钮开启
  6426. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  6427. if adviceSetting.IsAdviceOpen == 1 {
  6428. //查询是否出库按钮开启
  6429. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  6430. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6431. if prescriptionConfig.IsOpen == 1 {
  6432. if medical.IsUse == 2 {
  6433. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6434. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6435. }
  6436. if pharmacyConfig.IsOpen != 1 {
  6437. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6438. }
  6439. //更新字典里面的库存
  6440. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6441. var sum_count int64
  6442. for _, its := range stockInfo {
  6443. if its.MaxUnit == medical.MaxUnit {
  6444. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6445. }
  6446. sum_count += its.StockMaxNumber + its.StockMinNumber
  6447. }
  6448. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6449. //剩余库存
  6450. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6451. }
  6452. }
  6453. } else {
  6454. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  6455. if medical.IsUse == 2 {
  6456. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6457. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6458. }
  6459. if pharmacyConfig.IsOpen != 1 {
  6460. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  6461. }
  6462. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6463. var sum_count int64
  6464. for _, its := range stockInfo {
  6465. if its.MaxUnit == medical.MaxUnit {
  6466. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6467. }
  6468. sum_count += its.StockMaxNumber + its.StockMinNumber
  6469. }
  6470. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6471. //剩余库存
  6472. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6473. }
  6474. }
  6475. }
  6476. }
  6477. this.ServeSuccessJSON(map[string]interface{}{
  6478. "msg": "1",
  6479. "ids": ids,
  6480. })
  6481. return
  6482. } else {
  6483. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  6484. //执行医嘱
  6485. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  6486. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  6487. for _, item := range advices {
  6488. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6489. redis := service.RedisClient()
  6490. //清空key 值
  6491. redis.Set(key, "", time.Second)
  6492. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6493. redis.Set(keyTwo, "", time.Second)
  6494. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6495. redis.Set(keyThree, "", time.Second)
  6496. recordDate := theTime.Format("2006-01-02")
  6497. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6498. redis.Set(keyFour, "", time.Second)
  6499. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6500. redis.Set(keyFive, "", time.Second)
  6501. defer redis.Close()
  6502. }
  6503. this.ServeSuccessJSON(map[string]interface{}{
  6504. "msg": "1",
  6505. "ids": ids,
  6506. })
  6507. return
  6508. }
  6509. }
  6510. }
  6511. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  6512. ids := this.GetString("ids")
  6513. idSplit := strings.Split(ids, ",")
  6514. orgId := this.GetMobileAdminUserInfo().Org.Id
  6515. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6516. if config.IsOpen == 1 {
  6517. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  6518. this.ServeSuccessJSON(map[string]interface{}{
  6519. "msg": "1",
  6520. "ids": ids,
  6521. })
  6522. return
  6523. }
  6524. if config.IsOpen == 0 || config.IsOpen == 2 {
  6525. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  6526. this.ServeSuccessJSON(map[string]interface{}{
  6527. "msg": "1",
  6528. "ids": ids,
  6529. })
  6530. return
  6531. }
  6532. }
  6533. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  6534. ids := this.GetString("ids")
  6535. idSplit := strings.Split(ids, ",")
  6536. orgId := this.GetMobileAdminUserInfo().Org.Id
  6537. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6538. //his
  6539. if config.IsOpen == 1 {
  6540. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6541. theTime := time.Now()
  6542. advices := models.HisDoctorAdviceThirty{
  6543. CheckTime: theTime.Unix(),
  6544. Checker: checker,
  6545. UpdatedTime: time.Now().Unix(),
  6546. }
  6547. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  6548. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6549. for _, item := range list {
  6550. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6551. redis := service.RedisClient()
  6552. //清空key 值
  6553. redis.Set(key, "", time.Second)
  6554. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6555. redis.Set(keyTwo, "", time.Second)
  6556. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6557. redis.Set(keyThree, "", time.Second)
  6558. recordDate := theTime.Format("2006-01-02")
  6559. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6560. redis.Set(keyFour, "", time.Second)
  6561. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6562. redis.Set(keyFive, "", time.Second)
  6563. defer redis.Close()
  6564. }
  6565. this.ServeSuccessJSON(map[string]interface{}{
  6566. "msg": "1",
  6567. "ids": ids,
  6568. })
  6569. return
  6570. }
  6571. //血透
  6572. if config.IsOpen == 0 || config.IsOpen == 2 {
  6573. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  6574. theTime := time.Now()
  6575. advices := models.DoctorAdvice{
  6576. CheckTime: theTime.Unix(),
  6577. Checker: checker,
  6578. UpdatedTime: time.Now().Unix(),
  6579. }
  6580. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  6581. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  6582. for _, item := range list {
  6583. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6584. redis := service.RedisClient()
  6585. //清空key 值
  6586. redis.Set(key, "", time.Second)
  6587. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6588. redis.Set(keyTwo, "", time.Second)
  6589. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6590. redis.Set(keyThree, "", time.Second)
  6591. recordDate := theTime.Format("2006-01-02")
  6592. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6593. redis.Set(keyFour, "", time.Second)
  6594. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6595. redis.Set(keyFive, "", time.Second)
  6596. defer redis.Close()
  6597. }
  6598. this.ServeSuccessJSON(map[string]interface{}{
  6599. "msg": "1",
  6600. "ids": ids,
  6601. })
  6602. return
  6603. }
  6604. }
  6605. func (this *DialysisAPIController) CheckSchedule() {
  6606. patientID, _ := this.GetInt64("patient_id")
  6607. recordDateStr := this.GetString("record_date")
  6608. nurseID, _ := this.GetInt64("nurse")
  6609. schedual_type, _ := this.GetInt64("schedual_type")
  6610. bedID, _ := this.GetInt64("bed")
  6611. start_time := this.GetString("start_time")
  6612. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  6613. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6614. return
  6615. }
  6616. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6617. if parseStartDateErr != nil {
  6618. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  6619. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6620. return
  6621. }
  6622. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6623. if parseErr != nil {
  6624. this.ErrorLog("时间解析失败:%v", parseErr)
  6625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6626. return
  6627. }
  6628. adminUserInfo := this.GetMobileAdminUserInfo()
  6629. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  6630. if getPatientErr != nil {
  6631. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  6632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6633. return
  6634. } else if patient == nil {
  6635. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6636. return
  6637. }
  6638. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  6639. if getNurseErr != nil {
  6640. this.ErrorLog("获取护士失败:%v", getNurseErr)
  6641. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6642. return
  6643. } else if nurse == nil {
  6644. this.ErrorLog("护士不存在")
  6645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6646. return
  6647. }
  6648. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  6649. if getDeviceNumberErr != nil {
  6650. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  6651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6652. return
  6653. } else if deviceNumber == nil {
  6654. this.ErrorLog("床位号不存在")
  6655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6656. return
  6657. }
  6658. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  6659. if getRecordErr != nil {
  6660. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  6661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6662. return
  6663. } else if dialysisRecord != nil {
  6664. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  6665. return
  6666. }
  6667. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  6668. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  6669. timeLayout := "2006-01-02 15:04:05"
  6670. loc, _ := time.LoadLocation("Local")
  6671. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  6672. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  6673. schedulestartTime := theStartTime.Unix()
  6674. scheduleendTime := theEndTime.Unix()
  6675. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  6676. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  6677. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  6678. //查询该床位是否有人用了
  6679. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  6680. if err == nil {
  6681. if schedule.ID == 0 {
  6682. this.ServeSuccessJSON(map[string]interface{}{
  6683. "status": 0,
  6684. "msg": "请求失败",
  6685. })
  6686. } else {
  6687. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  6688. if order.ID > 0 { //该机位被其他人占用了
  6689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  6690. return
  6691. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  6692. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  6693. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  6694. this.ServeSuccessJSON(map[string]interface{}{
  6695. "status": 1,
  6696. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  6697. })
  6698. return
  6699. } else {
  6700. this.ServeSuccessJSON(map[string]interface{}{
  6701. "status": 0,
  6702. "msg": "",
  6703. })
  6704. }
  6705. }
  6706. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  6707. this.ServeSuccessJSON(map[string]interface{}{
  6708. "status": 2,
  6709. "msg": "当前机位已有患者在使用,请重新选择!",
  6710. })
  6711. }
  6712. }
  6713. } else {
  6714. this.ServeSuccessJSON(map[string]interface{}{
  6715. "status": 0,
  6716. "msg": "",
  6717. })
  6718. }
  6719. }