dialysis_api_controller.go 287KB

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