dialysis_api_controller.go 316KB

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