dialysis_api_controller.go 261KB

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