123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698 |
- package mobile_api_controllers
-
- import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/jinzhu/gorm"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/astaxie/beego"
- "math"
- "net/http"
- "net/url"
- )
-
- // type DialysisTestAPIController struct {
- // MobileBaseAPIController
- // }
-
- // [get]/m/api/test
- // func (this *DialysisTestAPIController) Test() {
- // orgID := int64(3907)
-
- // now := time.Now()
- // nextWeek := now.AddDate(0, 0, 7)
- // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
- // nextTwoWeek := now.AddDate(0, 0, 14)
- // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
- // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
- // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
-
- // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
- // if exchangeErr != nil {
- // this.ErrorLog("%v", exchangeErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // this.ServeSuccessJSON(map[string]interface{}{
- // // "now": now,
- // // "next_week": nextWeek,f
- // // "next_week_mon": nextWeekMon,
- // // "next_week_sun": nextWeekSun,
- // // "next_two_week_mon": nextTwoWeekMon,
- // // "next_two_week_sun": nextTwoWeekSun,
- // "next_week_schs": nextWeekSchs,
- // "next_two_week_schs": nextTwoWeekSchs,
- // })
- // }
-
- type DialysisAPIController struct {
- MobileBaseAPIAuthController
- }
-
- // /m/api/scheduals [get]
- // @param type:int
- // @param date:string
- func (this *DialysisAPIController) Scheduals() {
- schedualType, _ := this.GetInt64("type")
- schedualDate := this.GetString("date")
-
- if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
- schedualType = 0
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
-
- redis := service.RedisClient()
- defer redis.Close()
-
- key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
- scheduals_json_str, _ := redis.Get(key).Result()
- redis.Set(key, "", time.Second)
- patients, _ := service.GetAllPatientListSix(orgID)
- if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
-
- if err != nil {
- this.ErrorLog("获取排班信息失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- if len(scheduals) > 0 {
- devices, _ := service.GetAllDevicetByListSix(orgID)
- advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
- prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
- assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
- dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
- treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
- AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
- dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
- hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
- for key, item := range scheduals {
- // 获取患者信息
- for _, patient := range patients {
- if item.PatientId == patient.ID {
- scheduals[key].SchedualPatient = patient
- break
- }
- }
- // 床位信息
- for _, device := range devices {
- if item.BedId == device.ID {
- scheduals[key].DeviceNumber = device
- break
- }
- }
-
- // 医嘱信息
- scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
- for _, advice := range advices {
- if item.PatientId == advice.PatientId {
- scheduals[key].Advices = append(scheduals[key].Advices, advice)
- }
- }
-
- // 医嘱信息
- scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
- for _, hisAdvice := range hisAdvices {
- if item.PatientId == hisAdvice.PatientId {
- scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
- }
- }
-
- // 医嘱信息
- for _, prescription := range prescriptions {
- if item.PatientId == prescription.PatientId {
- scheduals[key].Prescription = prescription
- break
- }
- }
-
- // 透前评估
- for _, assessmentBefore := range assessmentBefores {
- if item.PatientId == assessmentBefore.PatientId {
- scheduals[key].AssessmentBeforeDislysis = assessmentBefore
- break
- }
- }
-
- // 透析上下机
- for _, dialysisOrder := range dialysisOrders {
- if item.PatientId == dialysisOrder.PatientId {
- scheduals[key].DialysisOrder = dialysisOrder
- break
- }
- }
-
- // 治疗小节
- for _, afterDislysis := range AssessmentAfterDislysis {
- if item.PatientId == afterDislysis.PatientId {
- scheduals[key].AssessmentAfterDislysis = afterDislysis
- break
- }
- }
-
- // 透后评估
- for _, treatmentSummary := range treatmentSummarys {
- if item.PatientId == treatmentSummary.PatientId {
- scheduals[key].TreatmentSummary = treatmentSummary
- break
- }
- }
-
- for _, check := range dobulecheck {
- if item.PatientId == check.PatientId {
- scheduals[key].DoubleCheck = check
- break
- }
- }
- }
- //缓存数据
- scheduals_json, err := json.Marshal(&scheduals)
- if err == nil {
- redis.Set(key, scheduals_json, time.Second*60)
- }
- }
-
- //获取今日所有的处方开的耗材
- _, configs := service.FindXTHisProjectByOrgId(orgID)
- project := make([]*models.HisPrescriptionProjectTwo, 0)
-
- if configs.ID > 0 && configs.IsOpen == 1 {
- project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
- }
-
- //list, _ := service.GetZoneCountList(orgID, date.Unix())
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- "project": project,
- })
- }
-
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- var dat []map[string]interface{}
-
- if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
-
- } else {
-
- }
- //获取今日所有的处方开的耗材
- _, configs := service.FindXTHisProjectByOrgId(orgID)
- project := make([]*models.HisPrescriptionProjectTwo, 0)
-
- if configs.ID > 0 && configs.IsOpen == 1 {
- project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": dat,
- "redis": "true",
- "date": schedualDate,
- "project": project,
- })
-
- }
-
- }
-
- // /m/api/waiting_scheduals [get]
- // @param date:string
- func (this *DialysisAPIController) WaitingScheduals() {
- schedualDate := this.GetString("date")
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil && len(schedualDate) != 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
- redis := service.RedisClient()
- defer redis.Close()
-
- // cur_date := time.Now().Format("2006-01-02")
- key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
-
- wait_scheduals, _ := redis.Get(key).Result()
-
- if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
- scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
- if err != nil {
- this.ErrorLog("获取排班信息失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
- for _, s := range scheduals {
- returnScheduals = append(returnScheduals, s)
- }
-
- if len(returnScheduals) > 0 {
- //缓存数据
- wait_scheduals_json, err := json.Marshal(scheduals)
- if err == nil {
- redis.Set(key, wait_scheduals_json, time.Second*30)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- })
- }
-
- } else { //缓存数据了数据,将redis缓存的json字符串转为map
- var dat []map[string]interface{}
- if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
-
- } else {
-
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": dat,
- "redis": "true",
- "date": schedualDate,
- })
- }
-
- }
-
- //else{
- // fmt.Println("33333333")
- //
- // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
- // if err != nil {
- // this.ErrorLog("获取排班信息失败:%v", err)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // } else {
- // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
- // for _, s := range scheduals {
- //
- // returnScheduals = append(returnScheduals, s)
- // }
- //
- // this.ServeSuccessJSON(map[string]interface{}{
- // "scheduals": returnScheduals,
- // })
- // }
- //
- // }
-
- //if err == nil{
- //
- //
- //
- //
- //
- //}else{
-
- //}
-
- // /m/api/dialysis/record [get]
- // @param patient_id:int
- // @param date:string (yyyy-MM-dd)
- func (this *DialysisAPIController) DialysisRecord() {
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("date")
- if patientID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := this.GetMobileAdminUserInfo()
-
- ch := make(chan struct{})
- count := 24 // count 表示活动的协程个数
- var patient models.Patients
- var receiverTreatmentAccess *models.ReceiveTreatmentAsses
- var predialysisEvaluation *models.PredialysisEvaluation
- var lastPredialysisEvaluation *models.PredialysisEvaluation
- var doctorAdvices []*models.DoctorAdvice
- var dialysisOrder *models.DialysisOrder
- var doubleCheck *models.DoubleCheck
- var monitorRecords []*models.MonitoringRecord
- var lastMonitorRecord *models.MonitoringRecord
- var assessmentAfterDislysis *models.AssessmentAfterDislysis
- var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
- var treatmentSummary *models.TreatmentSummary
- var dialysisPrescribe *models.DialysisPrescription
- var dialysisSolution *models.DialysisSolution
- var lastDialysisPrescribe *models.DialysisPrescription
- var systemDialysisPrescribe *models.SystemPrescription
- var is_project_open_config models.XtHisProjectConfig
- var projects []*models.HisPrescriptionProject
- var stockType []*models.GoodsTypeOne
- var prepare []*models.XtDialysisBeforePrepare
- var lastAssessment models.XtPatientVascularAccess
-
- var lastDryWeightDislysis *models.SgjPatientDryweight
- var gobalConfig models.GobalConfig
- var operators []*models.SgjUserAdminRoles
-
- // 先走redis,没有走数据库
- schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
- go func() {
- patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
-
- ch <- struct{}{}
- }()
-
- go func() {
- receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
-
- ch <- struct{}{}
- }()
-
- go func() {
- dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
-
- ch <- struct{}{}
- }()
-
- go func() {
- doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
-
- ch <- struct{}{}
- }()
-
- go func() {
- lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
- ch <- struct{}{}
- }()
-
- go func() {
- dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
- ch <- struct{}{}
- }()
-
- go func() {
- lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
-
- ch <- struct{}{}
- }()
-
- go func() {
- systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
- ch <- struct{}{}
- }()
-
- go func() {
- // // 先走redis,没有走数据库
- stockType, _ = service.GetStockType(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
- ch <- struct{}{}
- }()
-
- go func() {
- // //获取最后一次血管通路
- // 先走redis,没有走数据库
- lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- go func() {
- // 先走redis,没有走数据库
- operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
- ch <- struct{}{}
- }()
-
- for range ch {
- // 每次从ch中接收数据,表明一个活动的协程结束
- count--
- // 当所有活动的协程都结束时,关闭管道
- if count == 0 {
- close(ch)
- }
- }
-
- prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
- _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
-
- _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
-
- projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
- temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
-
- prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
- var team_projects []*models.HisPrescriptionProject
- //var index int64 = 0
- for _, item := range temp_team_projects {
- //组套里面非检验项目的
- if item.HisProject.CostClassify != 3 {
- projects = append(projects, item)
- }
- //组套里面检验项目的
- if item.HisProject.CostClassify == 3 {
- team_projects = append(team_projects, item)
- }
- }
-
- team_projects = RemoveRepeatedCheckRecod(team_projects)
-
- stockType, _ = service.GetStockType(adminInfo.Org.Id)
-
- prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
-
- prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
- var his_advices []*models.HisDoctorAdviceInfo
-
- if is_open_config.IsOpen == 1 {
- // 先走redis,没有走数据库
- his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
- }
-
- is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
-
- if is_advice_open.IsAdviceOpen == 1 {
- his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
- }
-
- lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
- returnData := map[string]interface{}{
- "patient": patient,
- "schedual": schedual,
- "prescription": dialysisPrescribe,
- "solution": dialysisSolution,
- "last_prescription": lastDialysisPrescribe,
- "receiver_treatment_access": receiverTreatmentAccess,
- "predialysis_evaluation": predialysisEvaluation,
- "doctor_advices": doctorAdvices,
- "double_check": doubleCheck,
- "assessment_after_dislysis": assessmentAfterDislysis,
- "treatment_summary": treatmentSummary,
- "monitor_records": monitorRecords,
- "dialysis_order": dialysisOrder,
- "operators": operators,
- "last_predialysis_evaluation": lastPredialysisEvaluation,
- "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
- "last_monitor_record": lastMonitorRecord,
- "config": gobalConfig,
- "dry_weight": lastDryWeightDislysis,
- "system_prescription": systemDialysisPrescribe,
- "his_advices": his_advices,
- "is_open_config": is_open_config,
- "stockType": stockType,
- "prepare": prepare,
- "lastAssessment": lastAssessment,
- "prescribeOne": prescribeOne,
- "is_project_open_config": is_project_open_config,
- "project": projects,
- "team_projects": team_projects,
- "is_advice_open": is_advice_open,
- "prescription_open": prescriptionConfig.IsOpen,
- "lastOrder": lastOrder,
- }
- this.ServeSuccessJSON(returnData)
- }
-
- func (c *DialysisAPIController) GetDialysisGlobalConfig() {
- adminInfo := c.GetMobileAdminUserInfo()
-
- adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
- devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
- device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
-
- returnData := map[string]interface{}{
- "admin_users": adminUsers,
- "devices": devices,
- "device_numbers": device_numbers,
- }
- c.ServeSuccessJSON(returnData)
-
- }
-
- func (c *DialysisAPIController) PostAtreatmentInfo() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
- summaryContent := c.GetString("summaryContent")
- changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
- treatNurseId, _ := c.GetInt64("treatNurse", 0)
- checkStaffId, _ := c.GetInt64("checkStaff", 0)
- deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
- treatDoctor, _ := c.GetInt64("treatDoctor", 0)
- nursingRecord := c.GetString("nursing_record")
- fmt.Println("护理记录", nursingRecord)
- specialRecord := c.GetString("special_record")
- fmt.Println("特殊记录", specialRecord)
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- changeMedicalNurseId = adminUserInfo.AdminUser.Id
- checkStaffId = adminUserInfo.AdminUser.Id
- deboardNurseId = adminUserInfo.AdminUser.Id
- treatDoctor = adminUserInfo.AdminUser.Id
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- summary := models.TreatmentSummary{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- AssessmentDate: recordDate.Unix(),
- Mission: propagandaAndEducationContent,
- DialysisSummary: summaryContent,
- SjNurse: changeMedicalNurseId,
- ZlNurse: treatNurseId,
- HdNurse: checkStaffId,
- XjNurse: deboardNurseId,
- ZlDoctor: treatDoctor,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- NursingRecord: nursingRecord,
- SpecialRecord: specialRecord,
- }
- _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if treatmentSummary.ID == 0 { //新增
- summary.Creater = adminUserInfo.AdminUser.Id
- service.AddSigleSummaryRecord(&summary)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
- redis.Set(keyOne, "", time.Second)
- keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": summary,
- })
- } else { //修改
-
- summary.Creater = treatmentSummary.Creater
- summary.CreatedTime = treatmentSummary.CreatedTime
-
- summary.Modifier = adminUserInfo.AdminUser.Id
- summary.ID = treatmentSummary.ID
- service.UpdateSummeRecord(&summary)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
- redis.Set(keyOne, "", time.Second)
- keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyThree, "", time.Second)
- defer redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "summary": summary,
- })
- }
- }
-
- func (c *DialysisAPIController) PostDoubleCheck() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- checkTimeStr := c.GetString("check_time")
- firstCheckTimeStr := c.GetString("first_check_time")
-
- creater, _ := c.GetInt64("creater", 0)
- modifier, _ := c.GetInt64("modifier", 0)
-
- dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
- dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
- vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
- pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
- dialysis_item_desc := c.GetString("dialysis_item_desc")
- dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
- vascular_access_desc := c.GetString("vascular_access_desc")
- pipeline_connection_desc := c.GetString("pipeline_connection_desc")
- collator, _ := c.GetInt64("collator", 0)
- employee_number := c.GetString("employee_number")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var checkDate int64
-
- if len(checkTimeStr) == 0 {
- checkDate = 0
- } else {
- checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
- checkDate = checkDateUnix.Unix()
-
- }
-
- var firstCheckDate int64
-
- if len(firstCheckTimeStr) == 0 {
- firstCheckDate = 0
- } else {
- firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
- firstCheckDate = firstCheckDateUnix.Unix()
- }
-
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
-
- list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
- _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if check.ID == 0 {
- if employee_number != list.JobNumber {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": check,
- "msg": "2",
- })
- return
- }
- }
- if check.ID > 0 {
- if employee_number != list.JobNumber {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": check,
- "msg": "2",
- })
- return
- }
- }
-
- }
-
- doubleCheck := models.DoubleCheck{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- DialysisItemCheck: dialysis_item_check,
- DialysisParameterCheck: dialysis_parameter_check,
- VascularAccessVerification: vascular_access_verification,
- PipelineConnectionCheck: pipeline_connection_check,
- DialysisItemDesc: dialysis_item_desc,
- DialysisParameterDesc: dialysis_parameter_desc,
- VascularAccessDesc: vascular_access_desc,
- PipelineConnectionDesc: pipeline_connection_desc,
- Collator: collator,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- CheckDate: recordDate.Unix(),
- UpdatedTime: time.Now().Unix(),
- EmployeeNumber: employee_number,
- }
-
- _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if check.ID == 0 { //新增
- doubleCheck.FirstCheckTime = firstCheckDate
- doubleCheck.CheckTime = checkDate
- doubleCheck.Creater = creater
- doubleCheck.Modifier = modifier
-
- err := service.AddSigleDoubleCheck(&doubleCheck)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
- redis := service.RedisClient()
-
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": &doubleCheck,
- })
- }
- } else { //修改
-
- doubleCheck.FirstCheckTime = firstCheckDate
- doubleCheck.CheckTime = checkDate
- doubleCheck.Creater = creater
- doubleCheck.Modifier = modifier
- doubleCheck.CreatedTime = check.CreatedTime
- doubleCheck.ID = check.ID
- doubleCheck.EmployeeNumber = employee_number
- err := service.UpdateDoubleCheck(&doubleCheck)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "doubleCheck": &doubleCheck,
- "msg": "1",
- })
- }
-
- }
-
- }
- func (c *DialysisAPIController) PostAcceptsAssessment() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- way, _ := c.GetInt64("way", 0)
- consciousness, _ := c.GetInt64("consciousness", 0)
- appetite, _ := c.GetInt64("appetite", 0)
- condition, _ := c.GetInt64("condition", 0)
- posture, _ := c.GetInt64("posture")
- sick_condition, _ := c.GetInt64("sick_condition", 0)
- danger_level, _ := c.GetInt64("danger_level", 0)
- intake, _ := c.GetInt64("intake", 0)
- nutrition, _ := c.GetInt64("nutrition", 0)
- psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
- psychological_assessment_other := c.GetString("psychological_assessment_other")
- score := c.GetString("score")
- sick_condition_other := c.GetString("sick_condition_other")
-
- //precaution, _ := c.GetInt64("precaution", 0)
- precaution := c.GetString("precaution")
- precaution_other := c.GetString("precaution_other")
- psychological_other := c.GetString("psychological_other")
-
- admission_number := c.GetString("admission_number")
- tumble, _ := c.GetInt64("tumble")
- diacrisis := c.GetString("diacrisis")
- his_department := c.GetString("his_department")
- his_bed := c.GetString("his_bed")
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- receiveTreatmentAsses := models.ReceiveTreatmentAsses{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- Way: way,
- Consciousness: consciousness,
- Appetite: appetite,
- Condition: condition,
- SickCondition: sick_condition,
- DangerLevel: danger_level,
- Intake: intake,
- Nutrition: nutrition,
- PsychologicalAssessment: psychological_assessment,
- PsychologicalAssessmentOther: psychological_assessment_other,
- SickConditionOther: sick_condition_other,
- Posture: posture,
- CreatedTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- Status: 1,
- Score: score,
- Precaution: precaution,
- PrecautionOther: precaution_other,
- PsychologicalOther: psychological_other,
- AdmissionNumber: admission_number,
- Tumble: tumble,
- Diacrisis: diacrisis,
- HisBed: his_bed,
- HisDepartment: his_department,
- }
-
- if receiveTreatment.ID == 0 { //新增
- receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
- err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
-
- } else { //修改
- //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- receiveTreatmentAsses.Creater = receiveTreatment.Creater
- receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
-
- receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
- receiveTreatmentAsses.ID = receiveTreatment.ID
- err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
- }
-
- }
- func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- weightAfter, _ := c.GetFloat("weight_after", 0)
- additionalWeight, _ := c.GetFloat("additional_weight", 0)
- weightReduce, _ := c.GetFloat("weight_loss", 0)
- temperature, _ := c.GetFloat("temperature", 0)
- pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
- breathing_rate := c.GetString("breathing_rate")
- systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
-
- diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
- actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
- actual_displacement, _ := c.GetFloat("actual_displacement", 0)
- actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
- actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
- cruor := c.GetString("cruor")
- symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
- internalFistula := c.GetString("internal_fistula")
- catheter := c.GetString("catheter")
- complications := c.GetString("complication")
- remark := c.GetString("remark")
- //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
- dialysis_intakes := c.GetString("dialysis_intakes")
- dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
- fmt.Println("dialysateVolumewode 23323233223232wode", dialysateVolume)
- dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
-
- blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
- blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
-
- puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
- puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
- internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
- patientGose, _ := c.GetInt64("patient_gose", 0)
- inpatientDepartment := c.GetString("inpatient_department")
- observationContent := c.GetString("observation_content")
- observationContentOther := c.GetString("observation_content_other")
- dialysis_process, _ := c.GetInt64("dialysis_process", 0)
-
- in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
- in_advance_reason := c.GetString("in_advance_reason")
- hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
- hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
- tremor_noise, _ := c.GetInt64("tremor_noise", 0)
- disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
- disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
-
- arterial_tube, _ := c.GetInt64("arterial_tube", 0)
- intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- in_advance_reason_other := c.GetString("in_advance_reason_other")
- is_eat, _ := c.GetInt64("is_eat", 0)
-
- cvc_a, _ := c.GetFloat("cvc_a", 0)
- cvc_v, _ := c.GetFloat("cvc_v", 0)
- channels, _ := c.GetInt64("channel", 0)
- return_blood, _ := c.GetInt64("return_blood", 0)
- rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
- dialysis_during, _ := c.GetInt64("dialysis_during", 0)
- stroke_volume, _ := c.GetInt64("stroke_volume", 0)
- blood_flow, _ := c.GetInt64("blood_flow", 0)
- //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
- sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
- sealing_fluid_special := c.GetString("sealing_fluid_special")
- dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
- supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
- setting_pressure := c.GetString("setting_pressure")
- supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
- diastolic_pressure := c.GetString("diastolic_pressure")
- other_complication := c.GetString("other_complication")
- ktv := c.GetString("ktv")
- urr := c.GetString("urr")
- hypertenison, _ := c.GetInt64("hypertenison")
- hypopiesia, _ := c.GetInt64("hypopiesia")
- leave_office_method, _ := c.GetInt64("leave_office_method")
- lapse, _ := c.GetInt64("lapse")
- consciousness, _ := c.GetInt64("consciousness")
- fallrisk, _ := c.GetInt64("fallrisk")
- machine_run := c.GetString("machine_run")
- after_urea := c.GetString("after_urea")
- pip_coagulation := c.GetString("pip_coagulation")
- accumulated_blood_volume := c.GetString("accumulated_blood_volume")
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
-
- assessmentAfterDislysis := models.AssessmentAfterDislysis{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- AssessmentDate: recordDate.Unix(),
- Temperature: temperature,
- PulseFrequency: pulse_frequency,
- BreathingRate: breathing_rate,
- SystolicBloodPressure: systolic_blood_pressure,
- DiastolicBloodPressure: diastolic_blood_pressure,
- ActualUltrafiltration: actual_ultrafiltration,
- ActualDisplacement: actual_displacement,
- ActualTreatmentHour: actualtreatHour,
- ActualTreatmentMinute: actualtreatmin,
- WeightAfter: weightAfter,
- AdditionalWeight: additionalWeight,
- WeightLoss: weightReduce,
- Cruor: cruor,
- SymptomAfterDialysis: symptomsAfterDialysi,
- InternalFistula: internalFistula,
- Catheter: catheter,
- Complication: complications,
- DialysisIntakes: dialysateVolume,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- Status: 1,
- Remark: remark,
- BloodAccessPartId: blood_access_part_id,
- BloodAccessPartOperaId: blood_access_part_opera_id,
- DialysisIntakesUnit: dialysis_intakes_unit,
- PuncturePointOozingBlood: puncturePointOozingBlood,
- PuncturePointHaematoma: puncturePointHaematoma,
- InternalFistulaTremorAc: internalFistulaTremorAc,
- PatientGose: patientGose,
- InpatientDepartment: inpatientDepartment,
- ObservationContent: observationContent,
- ObservationContentOther: observationContentOther,
- DialysisProcess: dialysis_process,
- InAdvanceMinute: in_advance_minute,
- InAdvanceReason: in_advance_reason,
- HemostasisMinute: hemostasis_minute,
- HemostasisOpera: hemostasis_opera,
- TremorNoise: tremor_noise,
- DisequilibriumSyndrome: disequilibrium_syndrome,
- DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
- ArterialTube: arterial_tube,
- IntravenousTube: intravenous_tube,
- Dialyzer: dialyzer,
- InAdvanceReasonOther: in_advance_reason_other,
- IsEat: is_eat,
- CvcA: cvc_a,
- CvcV: cvc_v,
- Channel: channels,
- ReturnBlood: return_blood,
- RehydrationVolume: rehydration_volume,
- DialysisDuring: dialysis_during,
- StrokeVolume: stroke_volume,
- BloodFlow: blood_flow,
- SealingFluidDispose: sealing_fluid_dispose,
- SealingFluidSpecial: sealing_fluid_special,
- DosageOfAnticoagulants: dosage_of_anticoagulants,
- SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
- SupineSystolicBloodPressure: supine_systolic_blood_pressure,
- SettingPressure: setting_pressure,
- DiastolicPressure: diastolic_pressure,
- OtherComplication: other_complication,
- Ktv: ktv,
- Urr: urr,
- Hypopiesia: hypopiesia,
- Hypertenison: hypertenison,
- Lapse: lapse,
- LeaveOfficeMethod: leave_office_method,
- Consciousness: consciousness,
- Fallrisk: fallrisk,
- MachineRun: machine_run,
- AfterUrea: after_urea,
- PipCoagulation: pip_coagulation,
- AccumulatedBloodVolume: accumulated_blood_volume,
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if assessmentAfter.ID == 0 { //新增
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
-
- } else {
- assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
-
- }
-
- err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
- redis := service.RedisClient()
- keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyTwo, "", time.Second)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": assessmentAfterDislysis,
- })
- }
- } else { //修改
-
- if appRole.UserType == 2 || appRole.UserType == 1 {
- assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
- assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
- } else {
- assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
- if assessmentAfterDislysis.Creater == 0 {
- assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
- }
- }
-
- assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
- assessmentAfterDislysis.ID = assessmentAfter.ID
-
- err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
- redis := service.RedisClient()
- keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyTwo, "", time.Second)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyOne, "", time.Second)
- fmt.Println("err233332323232232323", err)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "assessmentAfterDislysis": assessmentAfterDislysis,
- })
- }
- }
- }
-
- func (c *DialysisAPIController) PostDialysisPrescription() {
- id, _ := c.GetInt64("patient", 0)
-
- recordDateStr := c.GetString("record_date")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_total, _ := c.GetFloat("replacement_total", 0)
-
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
-
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- glucose, _ := c.GetFloat("glucose", 0)
- // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
-
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
- pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
- fmt.Println("预冲量", pre_impulse)
- anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
- anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
- blood := c.GetString("blood")
- dialysis_dialyszers := c.GetString("dialysis_dialyszers")
- dialysis_irrigation := c.GetString("dialysis_irrigation")
- antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
- displace_speed := c.GetString("displace_speed")
- illness, _ := c.GetInt64("illness")
- amylaceum := c.GetString("amylaceum")
- single_time := c.GetString("single_time")
- single_water := c.GetString("single_water")
- replacement_flow := c.GetString("replacement_flow")
- plasma_separator := c.GetString("plasma_separator")
- bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
- oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
- oxygen_flow := c.GetString("oxygen_flow")
- oxygen_time := c.GetString("oxygen_time")
-
- hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
- hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
-
- puncture_needle := c.GetString("puncture_needle")
- puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
-
- epo := c.GetString("epo")
- epo_count, _ := c.GetFloat("epo_count", 0)
-
- max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
- admin_user_id, _ := c.GetInt64("admin_user_id")
-
- is_water := c.GetString("is_water")
- var is_war int64
- if is_water == "是" {
- is_war = 1
- }
- if is_water == "否" {
- is_war = 2
- }
- if is_water == "请选择" {
- is_war = 0
- }
- drhy_water := c.GetString("drhy_water")
-
- dry_water_hour := c.GetString("dry_water_hour")
-
- water_machine := c.GetString("water_machine")
- add_amount, _ := c.GetFloat("add_amount")
- reduce_amount, _ := c.GetFloat("reduce_amount")
- dialysis_remark := c.GetString("dialysis_remark")
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- //
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- //TODO 需要根据角色去判断
-
- prescription := models.DialysisPrescription{
-
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- // PrescriptionDoctor: prescription_doctor,
- ReplacementTotal: replacement_total,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- TargetKtv: target_ktv,
- PreImpulse: pre_impulse,
- AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
- AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
- Blood: blood,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- AntioxidantCommodityName: antioxidant_commodity_name,
- DisplaceSpeed: displace_speed,
- Illness: illness,
- Amylaceum: amylaceum,
- SingleTime: single_time,
- SingleWater: single_water,
- ReplacementFlow: replacement_flow,
- PlasmaSeparator: plasma_separator,
- BilirubinAdsorptionColumn: bilirubin_adsorption_column,
- OxygenUptake: oxygen_uptake,
- OxygenFlow: oxygen_flow,
- OxygenTime: oxygen_time,
- HemodialysisPipelines: hemodialysis_pipelines,
- HemodialysisPipelinesCount: hemodialysis_pipelines_count,
- PunctureNeedle: puncture_needle,
- PunctureNeedleCount: puncture_needle_count,
- Epo: epo,
- EpoCount: epo_count,
- MaxUltrafiltrationRate: max_ultrafiltration_rate,
- AdminUserId: admin_user_id,
- IsWater: is_war,
- DrhyWater: drhy_water,
- DryWaterHour: dry_water_hour,
- WaterMachine: water_machine,
- AddAmount: add_amount,
- ReduceAmount: reduce_amount,
- DialysisRemark: dialysis_remark,
- }
-
- //查询最近透析准备表里是否存在 透析器 灌流器
-
- //
- //splitStr := strings.Split(dialysis_dialyszers, ",")
- //
- //splitIrrigation := strings.Split(dialysis_irrigation, ",")
- //
- //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
- //if len(mation)>0{
- // for _, item := range splitStr {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- //
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- //
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println("",errcode)
- // }
- // }
- // }
- //
- // }
- //
- // for _, item := range splitIrrigation {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println(errcode)
- // }
- // }
- // }
- // }
- //}
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- if dialysisPrescription.ID == 0 { //新增
-
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
- }
-
- prescription.Creater = adminUserInfo.AdminUser.Id
-
- //针对河间咸得
- if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
-
- if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
-
- prescription.DisplaceLiquiPart = 0
- prescription.DisplaceLiquiValue = 0
- }
- }
-
- err := service.AddSigleRecord(&prescription)
-
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
-
- if err == nil {
- updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
-
- //清空key 值
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
- //清空key 值
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
- defer redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": prescription,
- })
-
- }
- } else { //修改
-
- //if mode_id > 0 {
- // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
- //}
- //if template.TemplateId == 1 {
- // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.Modifier = adminUserInfo.AdminUser.Id
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor := adminUserInfo.AdminUser.Id
- prescription.PrescriptionDoctor = prescription_doctor
- } else {
- prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
- }
-
- if dialysisPrescription.Creater == 0 { //体重称
- prescription.Creater = adminUserInfo.AdminUser.Id
-
- } else {
- prescription.Creater = dialysisPrescription.Creater
- }
-
- prescription.ID = dialysisPrescription.ID
-
- err := service.UpDateDialysisPrescription(&prescription)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
-
- if err == nil {
- updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if updateErr != nil {
- utils.ErrorLog("%v", updateErr)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescription": prescription,
- })
- }
- }
-
- }
-
- func (c *DialysisAPIController) Finish() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
- nurseID, _ := c.GetInt64("nurse")
- end_time := c.GetString("end_time")
- puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
- internal_fistula := c.GetString("blood_access_internal_fistula")
- catheter := c.GetString("catheter")
- cruor := c.GetString("cruor")
- mission := c.GetString("mission")
- if id <= 0 || nurseID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- c.ErrorLog("获取护士失败:%v", getNurseErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- c.ErrorLog("护士不存在")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
- if parseEndDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- //now := time.Now()
- //year, month, day := now.Date()
- //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- //todayTimeStamp := today_time.Unix()
-
- // 获取当天的第一条透析纪录
- fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getMonitorRecordsErr != nil {
- c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- // 获取当前的最后一条透析纪录
- endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getMonitorRecordsErr != nil {
- c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- fmt.Println(endmonitorRecords.UltrafiltrationVolume)
-
- assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
- if getAADErr != nil {
- c.ErrorLog("获取透后评估失败:%v", getAADErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
-
- var tempassessmentAfterDislysis models.AssessmentAfterDislysis
-
- if assessmentAfterDislysis != nil {
- tempassessmentAfterDislysis = *assessmentAfterDislysis
- tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
- } else {
- tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
- tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
- tempassessmentAfterDislysis.Status = 1
- tempassessmentAfterDislysis.PatientId = id
- tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
- }
-
- //长沙南雅
- if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
- //获取最后一条透析处方数据
- prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
- evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
- tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
- }
-
- if dialysisOrder.Stage == 1 {
- temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- fmt.Println(value)
- a, b := math.Modf(value)
- c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
-
- tempassessmentAfterDislysis.ActualTreatmentHour = hour
- tempassessmentAfterDislysis.ActualTreatmentMinute = minute
- }
-
- if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
- //var num1 int64
- //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
- //fmt.Println(num1)
- //sub := float64(num1 / 3600)
- //fmt.Println(sub)
- //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
- //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
- //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
-
- tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
- tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
- tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
- tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
- tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
- if adminUserInfo.Org.Id != 10445 {
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
- }
-
- tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
-
- }
-
- 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 {
- evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
- if evaluation.SystolicBloodPressure == 0 {
- evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
- pre := models.PredialysisEvaluation{
- SystolicBloodPressure: evaluation.SystolicBloodPressure,
- }
- fmt.Println("prew", pre)
- getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
-
- if evaluation.DiastolicBloodPressure == 0 {
- evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
- pres := models.PredialysisEvaluation{
- DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
- }
- getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
- if evaluation.PulseFrequency == 0 {
- evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
- press := models.PredialysisEvaluation{
- PulseFrequency: evaluation.PulseFrequency,
- }
- getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
-
- if evaluation.Temperature == 0 {
- evaluation.Temperature = fmonitorRecords.Temperature
- press := models.PredialysisEvaluation{
- Temperature: evaluation.Temperature,
- }
- getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
-
- redis := service.RedisClient()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- fmt.Println(getNurseErr)
- }
- }
-
- if adminUserInfo.Org.Id == 9583 {
- //获取透析处方的最后一条数据
- diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
- if diaerr != nil {
- c.ErrorLog("获取透析处方失败:%v", diaerr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
-
- tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
- }
-
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
-
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
-
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
- }
-
- if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
- tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
- }
-
- if lastAssessmentAfterDislysis != nil {
- tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
-
- tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
-
- tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
- tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
- tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
- tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
- tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
- tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
- tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
- tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
- tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
-
- tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
-
- tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
- tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
-
- tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
- tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
- tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
- tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
-
- tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
- tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
- tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
- tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
-
- tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
- tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
- tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
-
- tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
- tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
- tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
-
- tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
- tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
- tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
-
- tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
- tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
- tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
- tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
-
- tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
- tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
- tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
- tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
- tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
- tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
- tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
- tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
- tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
- tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
- tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
-
- }
-
- err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
- redis := service.RedisClient()
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
- redis.Set(keyTwo, "", time.Second)
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if dialysisOrder == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
- return
- }
- if dialysisOrder.Stage == 2 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
- return
- }
- if dialysisOrder.Stage == 1 {
- err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
- redis.Set(keyOne, "", time.Second)
- //结束时候透析次数加1
- service.UpdateSolutionByPatientId(id)
-
- dialysisOrder.Stage = 2
- dialysisOrder.FinishNurse = nurseID
- dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
- dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
- dialysisOrder.EndTime = endDate.Unix()
-
- go func() {
- ssoDomain := beego.AppConfig.String("call_domain")
- api := ssoDomain + "/index/downpatient"
- values := make(url.Values)
- values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
- values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
- values.Set("patient_id", strconv.FormatInt(id, 10))
- http.PostForm(api, values)
- }()
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysisOrder": dialysisOrder,
- "assessmentAfterDislysis": tempassessmentAfterDislysis,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- }
-
- func (c *DialysisAPIController) GetAllZone() {
- adminUserInfo := c.GetMobileAdminUserInfo()
- err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "zone": zone,
- })
- }
-
- }
-
- func (c *DialysisAPIController) GetSchedualPatientsList() {
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- schedulType, _ := c.GetInt64("schedul_type", 0)
- startTime, _ := c.GetInt64("schedul_time", 0)
- partitionType, _ := c.GetInt64("partition_type", 0)
- keywords := c.GetString("keywords")
- dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": dialysisSchedule,
- })
- }
- return
- }
-
- // /m/api/dialysis/start [post]
- // @param patient_id:int
- // @param record_date:string 排班时间 (yyyy-mm-dd)
- // @param nurse:int 上机护士
- // @param bed:int 床位号
- func (this *DialysisAPIController) StartDialysis() {
-
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("record_date")
- nurseID, _ := this.GetInt64("nurse")
- puncture_nurse, _ := this.GetInt64("puncture_nurse")
- blood_drawing, _ := this.GetInt64("blood_drawing")
- schedual_type, _ := this.GetInt64("schedual_type")
-
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
- washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
- change_nurse, _ := this.GetInt64("change_nurse")
- difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
- new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
- quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
- puncture_needle := this.GetString("puncture_needle")
- puncture_way := this.GetString("puncture_way")
- dialysis_dialyszers := this.GetString("dialysis_dialyszers")
- dialysis_irrigation := this.GetString("dialysis_irrigation")
- blood_access_id, _ := this.GetInt64("blood_access_id")
- zone_id, _ := this.GetInt64("zone_id")
- elecsign := this.GetString("url")
- nuclein_date_str := this.GetString("nuclein_date_str")
- schedule_remark := this.GetString("schedule_remark")
- order_remark := this.GetString("order_remark")
- if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseErr != nil {
- this.ErrorLog("时间解析失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- if getRecordErr != nil {
- this.ErrorLog("获取透析记录失败:%v", getRecordErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if dialysisRecord != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
- return
- }
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- var theNucleinDate int64
- timeLayoutOne := "2006-01-02"
- if len(nuclein_date_str) > 0 {
- theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theNucleinDate = theTime.Unix()
- }
-
- template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
- //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- //查询该床位是否有人用了
- order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- if err == gorm.ErrRecordNotFound { //空床位
- // 修改了床位逻辑
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 {
- daySchedule.PartitionId = deviceNumber.ZoneID
- daySchedule.BedId = bedID
- daySchedule.ScheduleType = schedual_type
- daySchedule.UpdatedTime = time.Now().Unix()
- xtSchedule := models.Schedule{
- PartitionId: deviceNumber.ZoneID,
- BedId: bedID,
- ScheduleType: schedual_type,
- UpdatedTime: time.Now().Unix(),
- }
- err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- } else if err == nil {
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
-
- if order.ID > 0 { //该机位被其他人占用了
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 {
- //daySchedule.PartitionId = deviceNumber.ZoneID
- //daySchedule.BedId = bedID
- //daySchedule.ScheduleType = schedual_type
- //daySchedule.UpdatedTime = time.Now().Unix()
- //err := service.UpdateSchedule(&daySchedule)
- //xtSchedule := models.Schedule{
- // PartitionId: deviceNumber.ZoneID,
- // BedId: bedID,
- // ScheduleType: schedual_type,
- // UpdatedTime: time.Now().Unix(),
- //}
- //err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- service.UpdateScheduleTwo(daySchedule, schedule)
-
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- }
- //else if order.ID == 0 { //该床位没被占用
- // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- // if daySchedule.ID > 0 {
- // //daySchedule.PartitionId = deviceNumber.ZoneID
- // //daySchedule.BedId = bedID
- // //daySchedule.ScheduleType = schedual_type
- // //daySchedule.UpdatedTime = time.Now().Unix()
- // //err := service.UpdateSchedule(&daySchedule)
- // xtSchedule := models.Schedule{
- // PartitionId: deviceNumber.ZoneID,
- // BedId: bedID,
- // ScheduleType: schedual_type,
- // UpdatedTime: time.Now().Unix(),
- // }
- // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- // if err != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- // }
- //}
- //}
-
- } else if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- dialysisRecord = &models.DialysisOrder{
- DialysisDate: recordDate.Unix(),
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patientID,
- Stage: 1,
- BedID: bedID,
- StartNurse: nurseID,
- Status: 1,
- StartTime: startDate.Unix(),
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- PunctureNurse: puncture_nurse,
- Creator: adminUserInfo.AdminUser.Id,
- Modifier: adminUserInfo.AdminUser.Id,
- SchedualType: schedual_type,
- WashpipeNurse: washpipe_nurse,
- ChangeNurse: change_nurse,
- DifficultPunctureNurse: difficult_puncture_nurse,
- NewFistulaNurse: new_fistula_nurse,
- ZoneId: zone_id,
- QualityNurseId: quality_nurse_id,
- PunctureNeedle: puncture_needle,
- PunctureWay: puncture_way,
- DialysisIrrigation: dialysis_irrigation,
- DialysisDialyszers: dialysis_dialyszers,
- BloodAccessId: blood_access_id,
- Url: elecsign,
- NucleinDate: theNucleinDate,
- ScheduleRemark: schedule_remark,
- OrderRemark: order_remark,
- }
- //查询该床位是否有人用了
- _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
- if errorscode == gorm.ErrRecordNotFound {
-
- createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
- service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
-
- if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
- //统计该患者总次数
- dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
- service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
- }
-
- if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
- //统计该患者总次数
- dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
- service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
- }
-
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- if createErr != nil {
- this.ErrorLog("上机失败:%v", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
-
- var tempdispose string
- // 只针对中能建
- if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
- tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
- }
-
- if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
- tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
- }
-
- var ultrafiltration_rate float64
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
- //后期预增脱水量
- _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
-
- if prescription.ID > 0 {
- if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
-
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- if (template.TemplateId == 6 || template.TemplateId == 32) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- }
-
- //针对医师汇
- if adminUserInfo.Org.Id == 10121 {
- dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
- ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
- }
-
- //针对通道
-
- if adminUserInfo.Org.Id == 10234 {
- ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
- }
-
- //针对监利大垸医院
- if template.TemplateId == 41 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
- }
-
- //针对肇庆三鹤血液透析中心
-
- if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
- }
-
- if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
- }
-
- // 只针对方济医院
- if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
- ultrafiltration_rate = value
- }
- }
- }
-
- record := models.MonitoringRecord{
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: patientID,
- DialysisOrderId: dialysisRecord.ID,
- MonitoringDate: schedulestartTime,
- OperateTime: startDate.Unix(),
- // MonitoringTime: recordTime,
- MonitoringNurse: nurseID,
- Dispose: tempdispose,
- UltrafiltrationRate: ultrafiltration_rate,
- UltrafiltrationVolume: 0,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- }
-
- //只针对广慈医院
- 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 {
- // 查询病人是否有透前评估数据
- befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
-
- //如果有数据就插入
- if errcode == nil {
- record.SystolicBloodPressure = befor.SystolicBloodPressure
- record.DiastolicBloodPressure = befor.DiastolicBloodPressure
-
- record.BreathingRate = befor.BreathingRate
- record.PulseFrequency = befor.PulseFrequency
- record.Temperature = befor.Temperature
- }
- }
-
- // 如果当天有插入数据,则不再往透析纪录里插入数据
- if newdialysisRecord.ID > 0 {
- if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 {
- record.Temperature = 36.5
- record.ArterialPressure = -100
- record.DialysateTemperature = 36.5
- record.Conductivity = 14
- record.BreathingRate = "20"
- record.VenousPressure = 80
- record.TransmembranePressure = 60
- }
- //针对兰溪人民医院的需求
- if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
- befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- record.SystolicBloodPressure = befor.SystolicBloodPressure
- record.DiastolicBloodPressure = befor.DiastolicBloodPressure
- record.Temperature = befor.Temperature
- record.PulseFrequency = befor.PulseFrequency
- record.BreathingRate = befor.BreathingRate
- }
- err := service.CreateMonitor(&record)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
-
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
- return
- }
- }
-
- go func() {
- ssoDomain := beego.AppConfig.String("call_domain")
- api := ssoDomain + "/index/uppatient"
- values := make(url.Values)
- values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
- values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
- values.Set("patient_id", strconv.FormatInt(patientID, 10))
- values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
- http.PostForm(api, values)
- }()
-
- this.ServeSuccessJSON(map[string]interface{}{
-
- "dialysis_order": newdialysisRecord,
- "monitor": record,
- })
- return
- }
-
- func (c *DialysisAPIController) PostSolution() {
- id, _ := c.GetInt64("patient", 0)
- recordDateStr := c.GetString("record_date")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- mode_id, _ := c.GetInt64("mode_id", 0)
- dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
- dialyzer, _ := c.GetInt64("dialyzer", 0)
- perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
- blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
- dewater_amount, _ := c.GetFloat("dewater_amount", 0)
- displace_liqui, _ := c.GetFloat("displace_liqui", 0)
- replacement_way, _ := c.GetInt64("replacement_way", 0)
- anticoagulant, _ := c.GetInt64("anticoagulant", 0)
- anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
- anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
- anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
- anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
- anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
- kalium, _ := c.GetFloat("kalium", 0)
- sodium, _ := c.GetFloat("sodium", 0)
- calcium, _ := c.GetFloat("calcium", 0)
- bicarbonate, _ := c.GetFloat("bicarbonate", 0)
- prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
- dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
-
- glucose, _ := c.GetFloat("glucose", 0)
- // dry_weight, _ := c.GetFloat("dry_weight", 0)
- dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
- dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
- conductivity, _ := c.GetFloat("conductivity", 0)
- remark := c.GetString("remark")
- dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
- dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
- targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
- dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
- body_fluid, _ := c.GetInt64("body_fluid", 0)
- special_medicine, _ := c.GetInt64("special_medicine", 0)
- special_medicine_other := c.GetString("special_medicine_other")
- displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
- displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
- blood_access, _ := c.GetInt64("blood_access", 0)
- ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
- body_fluid_other := c.GetString("body_fluid_other")
- replacement_total, _ := c.GetFloat("replacement_total", 0)
-
- niprocart, _ := c.GetInt64("niprocart", 0)
- jms, _ := c.GetInt64("jms", 0)
- fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
- fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
- hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
- dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
- filtryzer, _ := c.GetInt64("filtryzer", 0)
-
- target_ktv, _ := c.GetFloat("target_ktv", 0)
-
- dialyzers, _ := c.GetInt64("dialyzers", 0)
- injector, _ := c.GetInt64("injector", 0)
- bloodlines, _ := c.GetInt64("bloodlines", 0)
- tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
- safe_package, _ := c.GetInt64("package", 0)
- a_liquid, _ := c.GetInt64("a_liquid", 0)
-
- anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
- anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
- blood := c.GetString("blood")
- dialysis_dialyszers := c.GetString("dialysis_dialyszers")
- dialysis_irrigation := c.GetString("dialysis_irrigation")
- antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
- displace_speed := c.GetString("displace_speed")
- illness, _ := c.GetInt64("illness")
- amylaceum := c.GetString("amylaceum")
- single_time := c.GetString("single_time")
- single_water := c.GetString("single_water")
- replacement_flow := c.GetString("replacement_flow")
- plasma_separator := c.GetString("plasma_separator")
- bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
- oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
- oxygen_flow := c.GetString("oxygen_flow")
- oxygen_time := c.GetString("oxygen_time")
-
- hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
- hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
-
- puncture_needle := c.GetString("puncture_needle")
- puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
-
- epo := c.GetString("epo")
- epo_count, _ := c.GetFloat("epo_count", 0)
- max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
- pre_impulse := c.GetString("pre_impulse")
- impulse, _ := strconv.ParseFloat(pre_impulse, 64)
- admin_user_id, _ := c.GetInt64("admin_user_id")
-
- is_water := c.GetString("is_water")
- add_amount, _ := c.GetFloat("add_amount")
- reduce_amount, _ := c.GetFloat("reduce_amount")
- var is_war int64
- if is_water == "是" {
- is_war = 1
- }
- if is_water == "否" {
- is_war = 2
- }
- if is_water == "请选择" {
- is_war = 0
- }
- drhy_water := c.GetString("drhy_water")
- dry_water_hour := c.GetString("dry_water_hour")
- water_machine := c.GetString("water_machine")
- dialysis_remark := c.GetString("dialysis_remark")
- if mode_id > 0 {
- service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
- }
-
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- //
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- prescription := models.DialysisPrescription{
-
- UserOrgId: adminUserInfo.Org.Id,
- PatientId: id,
- RecordDate: recordDate.Unix(),
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- Dialyzer: dialyzer,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- DewaterAmount: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
-
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
-
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- ReplacementTotal: replacement_total,
- Niprocart: niprocart,
- Jms: jms,
- FistulaNeedleSet: fistula_needle_set,
- FistulaNeedleSet16: fistula_needle_set_16,
- Hemoperfusion: hemoperfusion,
- DialyserSterilised: dialyser_sterilised,
- Filtryzer: filtryzer,
- TargetKtv: target_ktv,
- Dialyzers: dialyzers,
- Injector: injector,
- Bloodlines: bloodlines,
- TubingHemodialysis: tubing_hemodialysis,
- Package: safe_package,
- ALiquid: a_liquid,
- AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
- AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
- Blood: blood,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- AntioxidantCommodityName: antioxidant_commodity_name,
- DisplaceSpeed: displace_speed,
- Illness: illness,
- Amylaceum: amylaceum,
- SingleWater: single_water,
- SingleTime: single_time,
- ReplacementFlow: replacement_flow,
- PlasmaSeparator: plasma_separator,
- BilirubinAdsorptionColumn: bilirubin_adsorption_column,
- OxygenUptake: oxygen_uptake,
- OxygenTime: oxygen_time,
- OxygenFlow: oxygen_flow,
- HemodialysisPipelines: hemodialysis_pipelines,
- HemodialysisPipelinesCount: hemodialysis_pipelines_count,
- PunctureNeedle: puncture_needle,
- PunctureNeedleCount: puncture_needle_count,
- Epo: epo,
- EpoCount: epo_count,
- MaxUltrafiltrationRate: max_ultrafiltration_rate,
- PreImpulse: impulse,
- AdminUserId: admin_user_id,
- IsWater: is_war,
- DrhyWater: drhy_water,
- DryWaterHour: dry_water_hour,
- WaterMachine: water_machine,
- AddAmount: add_amount,
- ReduceAmount: reduce_amount,
- DialysisRemark: dialysis_remark,
- }
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //
- if appRole.UserType == 2 || appRole.UserType == 1 {
- prescription_doctor = adminUserInfo.AdminUser.Id
- prescription.PrescriptionDoctor = prescription_doctor
-
- }
-
- if dialysisPrescription.ID == 0 { //新增
- prescription.Creater = adminUserInfo.AdminUser.Id
-
- } else { //修改
- if dialysisPrescription.Creater == 0 {
- prescription.Creater = adminUserInfo.AdminUser.Id
- } else {
- prescription.Creater = dialysisPrescription.Creater
- }
-
- //if/**/
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- //prescription.Creater = dialysisPrescription.Creater
- prescription.CreatedTime = dialysisPrescription.CreatedTime
- prescription.Modifier = adminUserInfo.AdminUser.Id
- prescription.ID = dialysisPrescription.ID
- }
-
- solution := models.DialysisSolution{
- RegistrarsId: adminUserInfo.AdminUser.Id,
- UserOrgId: adminUserInfo.Org.Id,
- Doctor: prescription_doctor,
- PatientId: id,
- ModeId: mode_id,
- DialysisDuration: dialysis_duration,
- PerfusionApparatus: perfusion_apparatus,
- BloodFlowVolume: blood_flow_volume,
- Dewater: dewater_amount,
- DisplaceLiqui: displace_liqui,
- ReplacementWay: replacement_way,
- Anticoagulant: anticoagulant,
- AnticoagulantShouji: anticoagulant_shouji,
- AnticoagulantWeichi: anticoagulant_weichi,
- AnticoagulantZongliang: anticoagulant_zongliang,
- AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
- AnticoagulantGaijiliang: anticoagulant_gaijiliang,
- Kalium: kalium,
- Sodium: sodium,
- Calcium: calcium,
- Bicarbonate: bicarbonate,
- Glucose: glucose,
- // DryWeight: dry_weight,
- DialysateFlow: dialysate_flow,
- DialysateTemperature: dialysate_temperature,
- Conductivity: conductivity,
- Remark: remark,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DialysisDurationMinute: dialysisDurationMinute,
- DialysisDurationHour: dialysisDurationHour,
- TargetUltrafiltration: targetUltrafiltration,
- DialysateFormulation: dialysateFormulation,
- DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
- BodyFluid: body_fluid,
- SpecialMedicine: special_medicine,
- SpecialMedicineOther: special_medicine_other,
- DisplaceLiquiPart: displace_liqui_part,
- DisplaceLiquiValue: displace_liqui_value,
- BloodAccess: blood_access,
- Ultrafiltration: ultrafiltration,
- BodyFluidOther: body_fluid_other,
- ReplacementTotal: replacement_total,
- TargetKtv: target_ktv,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- HemodialysisPipelines: hemodialysis_pipelines,
- HemodialysisPipelinesCount: hemodialysis_pipelines_count,
- PunctureNeedle: puncture_needle,
- PunctureNeedleCount: puncture_needle_count,
- Epo: epo,
- EpoCount: epo_count,
- MaxUltrafiltrationRate: max_ultrafiltration_rate,
- PreImpulse: impulse,
- SolutionStatus: 1,
- DialysisRemark: dialysis_remark,
- }
-
- //针对河间咸的
- if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
-
- if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
- solution.DisplaceLiquiPart = 0
- solution.DisplaceLiquiValue = 0
- }
-
- if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
- prescription.DisplaceLiquiPart = 0
- prescription.DisplaceLiquiValue = 0
- }
- }
-
- service.SavePrescriptionAndCreateSolution(&solution, &prescription)
- //获取最新1条
- dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
- //更新状态
- service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
-
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- //清空长期医嘱的key
- soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- redis.Set(soulution_key, "", time.Second)
- //查询最近透析准备表里是否存在 透析器 灌流器
-
- keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
- redis.Set(keyTwo, "", time.Second)
-
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keyFour, "", time.Second)
- //splitStr := strings.Split(dialysis_dialyszers, ",")
- //
- //splitIrrigation := strings.Split(dialysis_irrigation, ",")
- //
- //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
- //if len(mation)>0{
- // for _, item := range splitStr {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- //
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- //
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println("",errcode)
- // }
- // }
- // }
- //
- // }
- //
- // for _, item := range splitIrrigation {
- // for _,it := range mation{
- // if(item == it.SpecificationName){
- // //查询最近一次的透析器
- // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
- // if errcode == gorm.ErrRecordNotFound{
- // //插入数据
- // prepare := models.DialysisBeforePrepare{
- // UserOrgId: adminUserInfo.Org.Id,
- // PatientId: id,
- // RecordDate: recordDate.Unix(),
- // GoodTypeId: it.GoodTypeId,
- // GoodId: it.ID,
- // Count: 1,
- // Ctime: time.Now().Unix(),
- // Creater: adminUserInfo.AdminUser.Id,
- // Status:1,
- //
- // }
- // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
- // fmt.Println(errcode)
- // }
- // }
- // }
- // }
- //}
-
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": &solution,
- "prescription": &prescription,
- })
-
- }
-
- func (c *DialysisAPIController) GetAcceptsAssessment() {
- patient, _ := c.GetInt64("patient", 0)
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "receiveTreatmentAsses": receiveTreatmentAsses,
- })
- }
-
- func (this *DialysisAPIController) PostSignInfo() {
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("date")
- if patientID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02")
- }
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseDateErr != nil {
- this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := this.GetMobileAdminUserInfo()
- err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
-
- if err != nil {
- this.ErrorLog("签名失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "doctor_id": adminInfo.AdminUser.Id,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastMonitorRecord() {
- patientID, _ := this.GetInt64("patient_id")
- adminInfo := this.GetMobileAdminUserInfo()
- record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": record,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastMonitorRecordTody() {
-
- thisTime := time.Now()
- scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theAssessmentDateTime := theStartTime.Unix()
-
- patientID, _ := this.GetInt64("patient_id")
- monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
- adminInfo := this.GetMobileAdminUserInfo()
- record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
- fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
-
- template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
-
- var ultrafiltration_rate float64
- _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
-
- _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
- fmt.Println(evaluation)
- if prescription.ID > 0 {
-
- if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
-
- totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
- if template.TemplateId == 6 && adminInfo.Org.Id != 9538 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate
-
- }
-
- if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
-
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if template.TemplateId == 20 || template.TemplateId == 22 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- // 只针对方济医院
- if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
- ultrafiltration_rate = value
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if template.TemplateId == 41 || template.TemplateId == 47 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- if template.TemplateId == 43 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
-
- record.UltrafiltrationRate = ultrafiltration_rate
- }
- if template.TemplateId == 46 || template.TemplateId == 54 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
- record.UltrafiltrationRate = ultrafiltration_rate
- }
-
- 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 {
- ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
- record.UltrafiltrationRate = ultrafiltration_rate
- }
- //if template.TemplateId == 47 {
- // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
- // record.UltrafiltrationRate = ultrafiltration_rate
- //}
- }
- }
- // record.UltrafiltrationRate = ultrafiltration_rate
-
- record.UltrafiltrationVolume = 0
-
- 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
- if ultrafiltration_rate > 0 {
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
- record.UltrafiltrationVolume = value
- }
- }
-
- 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
- if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
- record.UltrafiltrationVolume = ultrafiltration_volume
-
- }
- }
-
- 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 {
-
- if ultrafiltration_rate > 0 {
- ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
-
- record.UltrafiltrationVolume = ultrafiltration_volume
- }
-
- }
-
- if template.TemplateId == 47 || template.TemplateId == 54 {
- record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": record,
- })
-
- }
-
- func (this *DialysisAPIController) ModifyStartDialysisOrder() {
- record_id, _ := this.GetInt64("id")
- nurseID, _ := this.GetInt64("nurse")
- puncture_nurse, _ := this.GetInt64("puncture_nurse")
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
- schedual_type, _ := this.GetInt64("schedual_type")
- washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
- change_nurse, _ := this.GetInt64("change_nurse")
- difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
- new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
- quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
- patient_id, _ := this.GetInt64("patient_id")
- record_date, _ := this.GetInt64("record_date")
- puncture_needle := this.GetString("puncture_needle")
- puncture_way := this.GetString("puncture_way")
- dialysis_dialyszers := this.GetString("dialysis_dialyszers")
- dialysis_irrigation := this.GetString("dialysis_irrigation")
- blood_access_id, _ := this.GetInt64("blood_access_id")
- nuclein_date_str := this.GetString("nuclein_date_str")
- order_remark := this.GetString("order_remark")
- schedule_remark := this.GetString("schedule_remark")
- if record_id == 0 {
- this.ErrorLog("id:%v", record_id)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
- //if getNurseErr != nil {
- // this.ErrorLog("获取护士失败:%v", getNurseErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- //} else if nurse == nil {
- // this.ErrorLog("护士不存在")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
- //
- //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- var theNucleinDate int64
- timeLayoutOne := "2006-01-02"
- if len(nuclein_date_str) > 0 {
- theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theNucleinDate = theTime.Unix()
- }
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
-
- if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
-
- if err == gorm.ErrRecordNotFound { //空床位
- // 修改了床位逻辑
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
- if daySchedule.ID > 0 {
- //daySchedule.BedId = bedID
- //daySchedule.PartitionId = deviceNumber.ZoneID
- //daySchedule.ScheduleType = schedual_type
- //daySchedule.UpdatedTime = time.Now().Unix()
- //err := service.UpdateSchedule(&daySchedule)
- xtSchedule := models.Schedule{
- PartitionId: deviceNumber.ZoneID,
- BedId: bedID,
- ScheduleType: schedual_type,
- UpdatedTime: time.Now().Unix(),
- }
- err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- } else if err == nil {
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
- if daySchedule.ID > 0 {
- //daySchedule.BedId = bedID
- //daySchedule.PartitionId = deviceNumber.ZoneID
- //
- //daySchedule.ScheduleType = schedual_type
- //daySchedule.UpdatedTime = time.Now().Unix()
- //err := service.UpdateSchedule(&daySchedule)
- xtSchedule := models.Schedule{
- PartitionId: deviceNumber.ZoneID,
- BedId: bedID,
- ScheduleType: schedual_type,
- UpdatedTime: time.Now().Unix(),
- }
- err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- }
- } else if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
- dialysisRecord := &models.DialysisOrder{
- ID: record_id,
- UserOrgId: adminUserInfo.Org.Id,
- BedID: bedID,
- StartNurse: nurseID,
- StartTime: startDate.Unix(),
- PunctureNurse: puncture_nurse,
- Creator: adminUserInfo.AdminUser.Id,
- Modifier: adminUserInfo.AdminUser.Id,
- WashpipeNurse: washpipe_nurse,
- SchedualType: schedual_type,
- ChangeNurse: change_nurse,
- DifficultPunctureNurse: difficult_puncture_nurse,
- NewFistulaNurse: new_fistula_nurse,
- QualityNurseId: quality_nurse_id,
- PunctureNeedle: puncture_needle,
- PunctureWay: puncture_way,
- DialysisDialyszers: dialysis_dialyszers,
- DialysisIrrigation: dialysis_irrigation,
- BloodAccessId: blood_access_id,
- NucleinDate: theNucleinDate,
- OrderRemark: order_remark,
- ScheduleRemark: schedule_remark,
- }
-
- updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
- order, _ := service.GetLastPatientOrder(record_id)
- service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- scheduleDateStartOne := startDate.Format("2006-01-02")
- keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyTwo, "", time.Second)
-
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
- redis.Set(keyThree, "", time.Second)
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
- redis.Set(keySeven, "", time.Second)
-
- if updateErr != nil {
- this.ErrorLog("修改上机失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if updateErr == nil {
- if tempDialysisRecord.Stage == 2 {
- temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- fmt.Println(value)
- a, b := math.Modf(value)
- tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
- updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
- redis.Set(keyOne, "", time.Second)
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
- redis.Set(keySeven, "", time.Second)
- redis.Close()
- if updateAssessmentErr != nil {
- utils.ErrorLog("%v", updateAssessmentErr)
- }
- }
- }
-
- _, dialysisRecords := service.FindDialysisOrderById(record_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "dialysis_order": dialysisRecords,
- })
-
- }
- func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
- record_id, _ := c.GetInt64("id")
- nurseID, _ := c.GetInt64("nurse")
- end_time := c.GetString("end_time")
-
- puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
- blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
- catheter := c.GetString("catheter")
- cruor := c.GetString("cruor")
- mission := c.GetString("mission")
- if record_id <= 0 || nurseID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- c.ErrorLog("获取护士失败:%v", getNurseErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- c.ErrorLog("护士不存在")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
- if parseEndDateErr != nil {
- c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
-
- //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- dialysisRecord := &models.DialysisOrder{
- ID: record_id,
- UserOrgId: adminUserInfo.Org.Id,
- EndTime: endDate.Unix(),
- FinishNurse: nurseID,
- FinishModifier: adminUserInfo.AdminUser.Id,
- PuncturePointHaematoma: puncture_point_haematoma,
- BloodAccessInternalFistula: blood_access_internal_fistula,
- Catheter: catheter,
- Cruor: cruor,
- Mission: mission,
- }
-
- updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
- redis.Set(keySeven, "", time.Second)
- redis.Close()
- if updateErr != nil {
- c.ErrorLog("修改下机失败:%v", updateErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if updateErr == nil {
- temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
- value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
- a, b := math.Modf(value)
- tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
- hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
- minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
- updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
-
- redis := service.RedisClient()
- keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
- redis.Set(keyTen, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
- redis.Set(keyTwo, "", time.Second)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
-
- redis.Set(key, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
- redis.Set(keyThree, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
- redis.Set(keySeven, "", time.Second)
- defer redis.Close()
- if updateAssessmentErr != nil {
- utils.ErrorLog("%v", updateAssessmentErr)
- }
- }
-
- _, dialysisRecords := service.FindDialysisOrderById(record_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_order": dialysisRecords,
- })
- }
-
- func (c *DialysisAPIController) GetLongAdvice() {
- patient_id, _ := c.GetInt64("id")
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
- _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
- is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
-
- prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
- //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
- if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "1",
- })
- return
- } else { //开启推送提醒
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- recordDateStr := time.Now().Format("2006-01-02")
- recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
-
- nowtime := recordDate.Unix()
- //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
- //fmt.Println("advices232333232323323233232333223233232322332",advices)
- //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
- advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
- advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
- for _, advice := range advices {
- if advice.FrequencyType == 3 {
- t := time.Now()
- week := int(t.Weekday())
- fmt.Println(t.Weekday())
-
- fmt.Println(week)
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- }
- }
-
- for _, advice := range advices_two {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
-
- for _, ad := range advices {
- advice_three = append(advice_three, ad)
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "2",
- "advices": advices,
- "advices_two": RemoveRepeatedElement(advice_three),
- "is_open_remind": config.IsOpenRemind,
- "his_config_open": hisConfig.IsOpen,
- "is_advice_open": is_advice_open.IsAdviceOpen,
- "prescription_open": prescription_open.IsOpen,
- })
- }
- }
-
- }
-
- func (c *DialysisAPIController) GetLongAdviceOne() {
- patient_id, _ := c.GetInt64("id")
- startTime := c.GetString("schedule_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theStartTime = theTime.Unix()
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
- _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
- is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
-
- prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
- //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
- if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "1",
- })
- return
- } else { //开启推送提醒
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
-
- fmt.Println("theStartTime23434343433434433443434343434334", theStartTime)
- advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
- advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
- for _, advice := range advices {
- if advice.FrequencyType == 3 {
- t := time.Now()
- week := int(t.Weekday())
- fmt.Println(t.Weekday())
-
- fmt.Println(week)
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") == -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- }
- }
-
- for _, advice := range advices_two {
- p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- now := p.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
- advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
-
- for _, ad := range advices {
- advice_three = append(advice_three, ad)
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "status": "2",
- "advices": advices,
- "advices_two": RemoveRepeatedElement(advice_three),
- "is_open_remind": config.IsOpenRemind,
- "his_config_open": hisConfig.IsOpen,
- "is_advice_open": is_advice_open.IsAdviceOpen,
- "prescription_open": prescription_open.IsOpen,
- })
- }
- }
-
- }
-
- func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
- newArr = make([]*models.DoctorAdvice, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].ID == arr[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
-
- patient, _ := c.GetInt64("id", 0)
- groupNo, _ := c.GetInt64("groupno", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- utils.ErrorLog("%v", dataBody)
-
- timeLayout := "2006-01-02 15:04"
- loc, _ := time.LoadLocation("Local")
-
- timeLayout2 := "2006-01-02"
- loc2, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceType := int64(2)
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
- AdviceDate := theTime.Unix()
- RecordDate := theTime.Unix()
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- Remark := ""
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- Remark = remark
- }
-
- var advices []*models.GroupAdvice
- if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
- utils.ErrorLog("advices")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceNames := dataBody["advices"].([]interface{})
- for _, adviceNameMap := range adviceNames {
- adviceNameM := adviceNameMap.(map[string]interface{})
- var advice models.GroupAdvice
- advice.Remark = Remark
- advice.AdviceType = adviceType
- advice.StartTime = StartTime
- advice.AdviceDate = AdviceDate
-
- advice.RecordDate = RecordDate
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.Org.Id
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
- advice.IsSettle = 2
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- // advice.SingleDose = singleDose
- //}
-
- if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
- //single_dose := int64(adviceNameM["single_dose"].(float64))
- advice.SingleDose = adviceNameM["single_dose"].(float64)
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- // advice.PrescribingNumber = prescribingNumber
- //}
-
- if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
- //single_dose := int64(adviceNameM["single_dose"].(float64))
- advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
- frequency_type := int64(adviceNameM["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
- day_count := int64(adviceNameM["day_count"].(float64))
- advice.DayCount = day_count
- }
-
- if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
- week_day, _ := adviceNameM["week_day"].(string)
- advice.WeekDay = week_day
- }
-
- if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
- way := int64(adviceNameM["way"].(float64))
- advice.Way = way
- }
-
- if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
- drug_id := int64(adviceNameM["drug_id"].(float64))
- advice.DrugId = drug_id
- }
-
- if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
- advice.DrugNameId = drug_name_id
- }
-
- if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
- template_id, _ := adviceNameM["template_id"].(string)
- advice.TemplateId = template_id
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
- children := adviceNameM["child"].([]interface{})
- if len(children) > 0 {
- for _, childrenMap := range children {
- childMap := childrenMap.(map[string]interface{})
- var child models.GroupAdvice
- child.Remark = Remark
- child.AdviceType = adviceType
- child.StartTime = StartTime
- child.AdviceDate = AdviceDate
- child.RecordDate = RecordDate
- child.Status = 1
- child.CreatedTime = time.Now().Unix()
- child.UpdatedTime = time.Now().Unix()
- child.StopState = 2
- child.ExecutionState = 2
- child.UserOrgId = adminUserInfo.Org.Id
- child.PatientId = patient
- child.AdviceDoctor = adminUserInfo.AdminUser.Id
- child.IsSettle = 1
- if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
- utils.ErrorLog("child advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- childAdviceName, _ := childMap["advice_name"].(string)
- if len(childAdviceName) == 0 {
- utils.ErrorLog("len(child advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- child.AdviceName = childAdviceName
-
- if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
- childAdviceDesc, _ := childMap["advice_desc"].(string)
- child.AdviceDesc = childAdviceDesc
- }
-
- if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
- childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
- child.DrugSpec = childDrugSpec
- }
-
- if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
- childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
- child.DrugSpecUnit = childDrugSpecUnit
- }
-
- if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
- child.SingleDose = childMap["single_dose"].(float64)
- }
-
- if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
- childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
- child.SingleDoseUnit = childSingleDoseUnit
- }
-
- if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
- child.PrescribingNumber = childMap["prescribing_number"].(float64)
- }
-
- if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
- childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
- child.PrescribingNumberUnit = childPrescribingNumberUnit
- }
-
- child.DeliveryWay = advice.DeliveryWay
- child.ExecutionFrequency = advice.ExecutionFrequency
- advice.Children = append(advice.Children, &child)
- }
- }
- }
-
- temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
- if temp_advice.ID == 0 {
- advices = append(advices, &advice)
- }
- }
-
- if len(advices) > 0 {
- list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- defer redis.Close()
- redis.Set(keyThree, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
-
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
-
- }
-
- return
-
- }
-
- func (c *DialysisAPIController) UploadDryWeight() {
- patient_id, _ := c.GetInt64("id")
- dry_weight, _ := c.GetFloat("dry_weight")
- doctor_id, _ := c.GetInt64("doctor_id")
- remark := c.GetString("remark")
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
- if err == gorm.ErrRecordNotFound {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.Org.Id,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- createErr := service.CreatePatientWeightAdjust(dryWeight)
- redis := service.RedisClient()
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- loc, _ := time.LoadLocation("Local")
- nowTime := time.Now()
- nowDay := nowTime.Format("2006-01-02")
- dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
- redis.Set(keyTwo, "", time.Second)
- redis.Close()
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
-
- } else {
- dryWeight := &models.SgjPatientDryweight{
- PatientId: patient_id,
- DryWeight: dry_weight,
- Remakes: remark,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Creator: doctor_id,
- Status: 1,
- UserOrgId: adminUserInfo.Org.Id,
- AdjustedValue: "/",
- UserId: adminUserInfo.AdminUser.Id,
- }
- var value float64
- value = dry_weight - weightAdjust.DryWeight
-
- if value < 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
- } else if value == 0 {
- dryWeight.AdjustedValue = "/"
- } else if value > 0 {
- dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
- }
-
- createErr := service.CreatePatientWeightAdjust(dryWeight)
- redis := service.RedisClient()
- loc, _ := time.LoadLocation("Local")
- nowTime := time.Now()
- nowDay := nowTime.Format("2006-01-02")
- dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
- redis.Set(keyTwo, "", time.Second)
- redis.Close()
- if createErr == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "weight": dryWeight,
- })
- }
- }
-
- }
-
- func (c *DialysisAPIController) GetSolution() {
- patient_id, _ := c.GetInt64("patient_id")
- mode_id, _ := c.GetInt64("mode_id")
- adminUserInfo := c.GetMobileAdminUserInfo()
- solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
- prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
- system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
- dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": solution,
- "prescription": prescription,
- "system_prescription": system_prescription,
- "dialysisPrescription": dialysisPrescription,
- })
-
- }
-
- func (c *DialysisAPIController) GetSchedule() {
- schedual_type, _ := c.GetInt64("schedual_type")
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- scheduleTime, _ := c.GetInt64("record_date")
- deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
- list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "number": deviceNumber,
- "list": list,
- })
-
- }
-
- func (c *DialysisAPIController) GetPatientId() {
-
- id, _ := c.GetInt64("id")
- //orgid := c.GetMobileAdminUserInfo().Org.Id
- patientId, _ := service.GetPatientId(id)
- //获取该患者的所有传染病
- list, _ := service.GetPatientInfectious(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patientId,
- "infectioulist": list,
- })
- }
-
- func (this *DialysisAPIController) GetDialysisSchedule() {
- schedualDate := this.GetString("date")
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := this.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
- redis := service.RedisClient()
- defer redis.Close()
- key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
- scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
- if len(scheduals) > 0 {
- //缓存数据
- scheduals_json, err := json.Marshal(scheduals)
- if err == nil {
- redis.Set(key, scheduals_json, time.Second*30)
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "scheduals": scheduals,
- })
-
- }
-
- func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
- change_type, _ := this.GetInt64("type", 0)
- record_date := this.GetString("record_time")
- patient_id, _ := this.GetInt64("patient_id", 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theAdviceRecordTime.Unix()
- adminUserInfo := this.GetMobileAdminUserInfo()
- advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
- if err == nil {
- if len(advices) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "schedule": sch,
- })
- return
- }
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *DialysisAPIController) CreateConsumables() {
- record_date := c.GetString("record_time")
- patient_id, _ := c.GetInt64("patient_id", 0)
- active, _ := c.GetInt64("active")
- adminUser := c.GetMobileAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
-
- var beforePrepares []*models.DialysisBeforePrepareGoods
- var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
- var dialysisBefor []*models.DialysisBeforePrepare
- if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
- goods, _ := dataBody["goods"].([]interface{})
-
- if len(goods) > 0 {
- for _, item := range goods {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
- commdity_code := items["commdity_code"].(string)
- fmt.Println("commdity", commdity_code)
-
- prepareGoods := &models.DialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- beforePrepares = append(beforePrepares, prepareGoods)
-
- newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
-
- prepare := &models.DialysisBeforePrepare{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- PatientId: patient_id,
- RecordDate: record_time,
- UserOrgId: adminUser.Org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- CommdityCode: commdity_code,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- dialysisBefor = append(dialysisBefor, prepare)
-
- }
- }
-
- //查询是否有库存
- for _, item := range dialysisBefor {
- _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
-
- if err == gorm.ErrRecordNotFound {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- if err != nil {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- //新增
- if active == 1 && len(goods) > 0 {
- for _, item := range dialysisBefor {
- dialyPrepareOne := models.DialysisBeforePrepare{
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- PatientId: item.PatientId,
- RecordDate: item.RecordDate,
- UserOrgId: item.UserOrgId,
- Count: item.Count,
- Ctime: time.Now().Unix(),
- Creater: item.Creater,
- CommdityCode: item.CommdityCode,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //先清除再插入
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
-
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
-
- //更新库存
- goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
-
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- "message": "2",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- if len(beforePrepares) > 0 && active == 2 {
-
- for _, item := range beforePrepares {
-
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
-
- //判断当前出库数量和最后一次出库数量的大小
- //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
-
- if item.Count <= goodInfo.Count {
- //退库
- err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
-
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
-
- }
- }
-
- var last_total int64
-
- //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
- if item.Count >= goodInfo.Count {
-
- //查询当前批次当前耗材最后一条出库数据
- lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- //计算当前出库和最后一次出库数据相差数据
- last_total = item.Count - lastOutInfo.Count
-
- //查询该批次剩余库存
- lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
-
- //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
- if lastInfo.StockCount >= last_total {
-
- err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
-
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
- //查询默认仓库
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
-
- goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
- }
-
- //如果库存不够,则出库到下一个批次
- if lastInfo.StockCount < last_total {
-
- err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminUser.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
- //查询默认仓库
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
-
- goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
- if err != nil {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- }
-
- if err != nil {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- }
- }
-
- var errs error
-
- if errs == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *DialysisAPIController) CreateStockOutInfo() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_date := c.GetString("record_time")
-
- if patient_id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := c.GetMobileAdminUserInfo()
- creator := c.GetMobileAdminUserInfo().AdminUser.Id
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
-
- consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
-
- _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
-
- //去重
- consumables = RemoveRepeatedGood(consumables)
-
- if record.IsOpen == 1 {
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- //查询是否有库存
- for _, item := range consumables {
- warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
-
- if item.Count > warehouse.Count {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "自动出库库存不足",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: warehouse.ID,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
-
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
- }
-
- //查询是否有出库单
- out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- creater := adminInfo.AdminUser.Id
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: adminInfo.Org.Id,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_time,
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- err := service.AddSigleWarehouseOut(&warehouseOut)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "创建出库单失败",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- utils.TraceLog("创建出库单失败 err = %v", err)
-
- } else {
-
- for _, item := range consumables {
- //出库
- err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
- if err == nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库接口报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- utils.TraceLog("创建出库单失败 err = %v", err)
- }
-
- //查询
-
- //出库数量相加
- errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "创建剩余库存字段报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
-
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
- if len(list) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //清空准备表数据
- err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库清空准备表数据报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- errs := service.CreateDialysisBeforePrepareOne(&prepare)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库创建准备表数据报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库基础库插入数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- if errsss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库剩余库存更新数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- }
- }
- //
- } else if err == nil {
- for _, item := range consumables {
- //出库
- err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
- if err != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库接口报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //出库数量相加
- errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
- if errss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.UserOrgId,
- Errcode: "创建剩余库存字段报错",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Count: 0,
- StockCount: 0,
- Creater: item.Creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
- if len(list) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- //清空准备表数据
- errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库清空准备表数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
- errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库创建准备表数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- if errcodes != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: adminInfo.Org.Id,
- Errcode: "自动出库基础库插入数据报错",
- GoodId: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creator,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
-
- errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- creater := c.GetMobileAdminUserInfo().AdminUser.Id
- if errss != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "自动出库剩余库存更新数据",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: creater,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "提交成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
- return
- }
-
- }
-
- func (c *DialysisAPIController) EditConsumables() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_date := c.GetString("record_time")
-
- if patient_id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminInfo := c.GetMobileAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- var beforePrepares []*models.DialysisBeforePrepareGoods
-
- var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
-
- var cancelbefor []*models.DialysisBeforePrepareGoods
- var outbefor []*models.DialysisBeforePrepareGoods
-
- //判断是否开启自动出库
- _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
-
- if record.IsOpen == 1 {
-
- if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
-
- goods, _ := dataBody["goods"].([]interface{})
-
- if len(goods) > 0 {
- for _, item := range goods {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- commdity_code := items["commdity_code"].(string)
- fmt.Println(commdity_code)
-
- prepareGoods := &models.DialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- beforePrepares = append(beforePrepares, prepareGoods)
-
- newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
- GoodTypeId: good_type_id,
- GoodId: good_id,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
- }
-
- for _, item := range beforePrepares {
-
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
- //判断当前出库数量和最后一次出库数量的大小
- //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
- if item.Count < goodInfo.Count {
- cancelbefor = append(cancelbefor, item)
- }
-
- //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
- if item.Count > goodInfo.Count {
-
- outbefor = append(outbefor, item)
- }
-
- //处理编辑耗材新增不了的问题
- if goodInfo.Count == item.Count {
- lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
- service.UpdateLastAutoCount(lastCount.ID, item.Count)
- }
-
- }
-
- fmt.Println("退库长度", len(cancelbefor))
- fmt.Println("出库长度", len(outbefor))
- //退库
- for _, item := range cancelbefor {
- warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
- creater := adminInfo.AdminUser.Id
- //退库
- //err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
- //查询该患者当天已经出库的耗材信息
-
- warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
-
- var delete_count int64 = 0
-
- delete_count = warehouseOutInfos.Count - item.Count
-
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
-
- // 在出库记录表里记录退库详情
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- OrgId: adminInfo.Org.Id,
- Type: 1,
- IsSys: 1,
- SysRecordTime: record_time,
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- PatientId: patient_id,
- ConsumableType: 2,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- warehouseOutInfo.Count = item.Count
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.Dealer = stockInInfo.Dealer
- warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
- warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
- warehouseOutInfo.ProductDate = stockInInfo.ProductDate
- warehouseOutInfo.Number = warehouseOutInfos.Number
- warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
- warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
- //查找当天是否存在出库记录
-
- _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
-
- if errcod == gorm.ErrRecordNotFound {
- service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: item.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: item.Count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: adminInfo.Org.Id,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
- if errflow == gorm.ErrRecordNotFound {
- //创建流水表
- err := service.CreateStockFlowOne(stockFlow)
- fmt.Println("err", err)
- } else if errflow == nil {
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- ID: exsit.ID,
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: item.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: exsit.Count - delete_count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: adminInfo.Org.Id,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
- }
-
- } else if errcod == nil {
- service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: item.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: item.Count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: adminInfo.Org.Id,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- ReturnCount: delete_count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
- if errflows == gorm.ErrRecordNotFound {
- //创建流水表
- service.CreateStockFlowOne(stockFlow)
- } else if errflows == nil {
- stockFlow := models.VmStockFlow{
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- ID: exsit.ID,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: item.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: exsit.Count - delete_count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: adminInfo.Org.Id,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- ReturnCount: delete_count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
- }
-
- }
-
- //更改自动出库的表格
- details := models.BloodAutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: record_time,
- OrgId: adminInfo.Org.Id,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //查询当天耗材是否已经存在数据
- _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
-
- if errcode == gorm.ErrRecordNotFound {
- service.CreateAutoReduceRecord(&details)
-
- } else if errcode == nil {
- service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- service.CreateAutoReduceRecord(&details)
-
- }
-
- service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
-
- //增加出库库存数量
- service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
-
- errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
- fmt.Println("errOne", errOne)
- // 删除出库完成后,要增加对应批次的库存数量
-
- service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- //更新剩余库存
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
-
- //出库
- for _, item := range outbefor {
- fmt.Println("出库ID", item.GoodId)
- var last_total int64
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
- //计算当前出库和最后一次出库数据相差数据
- last_total = item.Count - goodInfoOne.Count
-
- //查询该批次剩余库存
- lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
-
- if lastInfo.StockCount == 0 {
- //查询该耗材的总库存
- wareinfo, _ := service.GetStockGoodCount(item.GoodId)
- if wareinfo.StockCount == 0 {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
-
- }
-
- //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
-
- //查询该耗材的总库存
- wareinfo, _ := service.GetStockGoodCount(item.GoodId)
- // 如果库存差大于剩余库存则提示库存不足
- if last_total > wareinfo.StockCount {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- } else {
-
- fmt.Println("出库2o2o2o2o2oo2o2o2o2o2o2o", item.GoodId)
-
- out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: adminInfo.Org.Id,
- Creater: adminInfo.AdminUser.Id,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_time,
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- service.AddSigleWarehouseOut(&warehouseOut)
-
- }
- //出库
- //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
- //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- //1.查看该患者该耗材型号最后一次出库数量
- goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
-
- fmt.Println("count2323323222323wi", item.Count)
- prepare := models.DialysisBeforePrepare{
- UserOrgId: adminInfo.Org.Id,
- PatientId: patient_id,
- RecordDate: record_time,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count - goodInfoTwo.Count,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Creater: adminInfo.AdminUser.Id,
- Modifier: adminInfo.AdminUser.Id,
- Status: 1,
- CommdityCode: "",
- NewCount: 0,
- ProjectId: 0,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- fmt.Println("prepare", prepare.Count)
- fmt.Println("count", item.Count)
- service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
- //增加出库数量
- service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
- //剩余库存
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- }
- }
-
- //查询今日出库数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
-
- for _, it := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: it.OrgId,
- PatientId: patient_id,
- RecordDate: it.RecordTime,
- GoodId: it.GoodId,
- GoodTypeId: it.GoodTypeId,
- Count: it.Count,
- Ctime: time.Now().Unix(),
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //删除准备表数据
- service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
-
- service.CreateDialysisBeforePrepareOne(&prepare)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
- //if err != nil {
- // goodObj, _ := service.GetGoodInformationByGoodId(it.GoodId)
- // c.ServeSuccessJSON(map[string]interface{}{
- // "message": "2",
- // "good_name": goodObj.GoodName,
- // "specification_name": goodObj.SpecificationName,
- // })
- // return
- //}
- }
- }
- }
-
- //更新自动出库的地方
- var errs error
- if errs == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- }
-
- func (c *DialysisAPIController) GetDialysisGoods() {
- schedualDate := c.GetString("schedule_date")
- schedule_type, _ := c.GetInt64("schedule_type")
- partition_id, _ := c.GetInt64("partition_id")
- page, _ := c.GetInt("page")
- patient_id, _ := c.GetInt64("patient_id")
-
- schedualEndDate := int64(0)
-
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
- if parseDateErr != nil && len(schedualDate) != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
- if parseDateErr != nil && len(schedualDate) != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- schedualEndDate = endDate.Unix()
-
- adminUser := c.GetMobileAdminUserInfo()
-
- _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
-
- goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
-
- project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
-
- _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
-
- outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
-
- settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
-
- //获取当天该病人的透析处方
- prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
- good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
- if err == gorm.ErrRecordNotFound {
- dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
- warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
- if patient_id != 0 {
- for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
- goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
- lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
- //获取患者总的出库数据
- item.LastAutomaticReduceDetail = goodUser
- item.LastDialysisBeforePrepare = lastGoodUserDetial
- item.Project = project
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_goods": dialysisGoods,
- "good_type": goodTypes,
- "total": total,
- "prescribe": prescribe,
- "good_info": good_info,
- "warehouseOutList": warehouseOutList,
- "config": config,
- "outConfig": outConfig,
- "settleConfig": settleConfig,
- })
- return
-
- } else if err == nil {
- //获取当天排班的每个患者的库存使用情况
- dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
- //获取患者总的出库数据
- warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
- if patient_id != 0 {
- for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
- goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
- lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
- item.Project = project
- item.LastAutomaticReduceDetail = goodUser
- item.LastDialysisBeforePrepare = lastGoodUserDetial
- }
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_goods": dialysisGoods,
- "good_type": goodTypes,
- "total": total,
- "prescribe": prescribe,
- "good_info": good_info,
- "project": project,
- "warehouseOutList": warehouseOutList,
- "config": config,
- "outConfig": outConfig,
- "settleConfig": settleConfig,
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- } else if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
- func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var theStartTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theStartTime = theTime.Unix()
- }
- var theEndtTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- }
- theEndtTime = theTime.Unix()
- }
-
- adminUser := c.GetMobileAdminUserInfo()
- outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
- stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "stock_out": outInfo,
- "stockCount": stockCount,
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
- func (c *DialysisAPIController) GetStockInGoodInfo() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_time := c.GetString("record_time")
- adminUser := c.GetMobileAdminUserInfo()
- date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
- if parseDateErr != nil && len(record_time) != 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
- good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
-
- goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
- lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
-
- project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
-
- //获取今日患者的透析处方参数
- prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
-
- outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
-
- _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "good_type": goodTypes,
- "good_user": goodUser,
- "good_info": good_info,
- "last_good_user": lastGoodUserDetial,
- "project": project,
- "prescription": prescribe,
- "outInfo": outInfo,
- "configs": configs,
- })
- return
-
- }
-
- func (c *DialysisAPIController) CreateOtherStockOutInfo() {
-
- patient_id, _ := c.GetInt64("patient_id", 0)
- record_date := c.GetString("record_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
- record_time := theRecordTime.Unix()
- adminInfo := c.GetMobileAdminUserInfo()
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
-
- var beforePrepares []*models.DialysisBeforePrepareGoods
-
- var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
-
- if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
- goods, _ := dataBody["goods"].([]interface{})
- if len(goods) > 0 {
- for _, item := range goods {
- items := item.(map[string]interface{})
-
- if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
- utils.ErrorLog("good_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- good_id := int64(items["good_id"].(float64))
-
- if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
- utils.ErrorLog("good_type_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- good_type_id := int64(items["good_type_id"].(float64))
-
- if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
- utils.ErrorLog("count")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
-
- if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
- utils.ErrorLog("project_id")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- project_id := int64(items["project_id"].(float64))
-
- prepare := &models.DialysisBeforePrepareGoods{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- ProjectId: project_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- beforePrepares = append(beforePrepares, prepare)
-
- newPrepare := &models.NewDialysisBeforePrepareGoods{
- GoodId: good_id,
- GoodTypeId: good_type_id,
- Count: count,
- ProjectId: project_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- newBeforePrepares = append(newBeforePrepares, newPrepare)
- }
- }
- }
-
- //查询是否有库存
- for _, item := range beforePrepares {
- storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
-
- if item.Count > warehouse.Count {
- goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
- c.ServeSuccessJSON(map[string]interface{}{
- "message": "1",
- "good_name": goodObj.GoodName,
- "specification_name": goodObj.SpecificationName,
- })
- return
- }
-
- }
-
- //出库逻辑
- err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
- //查询当天出库的数据
- list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
-
- for _, item := range list {
- prepare := models.DialysisBeforePrepare{
- UserOrgId: item.OrgId,
- PatientId: item.PatientId,
- RecordDate: item.RecordTime,
- GoodId: item.GoodId,
- GoodTypeId: item.GoodTypeId,
- Count: item.Count,
- Creater: adminInfo.AdminUser.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- ProjectId: item.ProjectId,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //清空准备表的数据
- err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
- //插入准备表数据
- service.CreateDialysisBeforePrepareOne(&prepare)
-
- //查询默认仓库
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
- var total_count int64
- for _, it := range stockList {
- total_count += it.StockCount
- }
- //基础库插入数据
- service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
-
- ////更新剩余库存
-
- goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
- var flush_count int64
- for _, it := range goodList {
- flush_count += it.StockCount
- }
- errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
- if errs != nil {
- goodErrcode := models.XtGoodErrcode{
- UserOrgId: item.OrgId,
- Errcode: "手动出库更新剩余出库失败",
- GoodId: item.GoodId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Count: 0,
- StockCount: 0,
- Creater: adminInfo.AdminUser.Id,
- BatchNumberId: 0,
- WarehouseOutId: 0,
- }
- service.CreateGoodErrcode(goodErrcode)
- }
-
- }
-
- //更新自动出库的地方
- var errs error
- if errs == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "修改成功",
- "message": "2",
- "good_name": "",
- "specification_name": "",
- })
- return
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- }
-
- func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
- newArr = make([]*models.DialysisBeforePrepare, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisAPIController) GetAllDrug() {
- patient_id, _ := c.GetInt64("patient_id", 0)
- adminInfo := c.GetMobileAdminUserInfo()
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
- drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
- privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "base_drug_config": drugStockConfig,
- "private_drug_config": privateDrugConfig,
- "base_drug_list": drugList,
- "private_drug_list": privateDrugList,
- })
-
- }
-
- func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
- newArr = make([]*models.DialysisBeforePrepare, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].GoodId == arr[j].GoodId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (c *DialysisAPIController) GetDepartment() {
- adminInfo := c.GetMobileAdminUserInfo()
- departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "departments": departments,
- })
- } else {
-
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- }
-
- func (c *DialysisAPIController) GetMobilePrintStockGood() {
-
- types, _ := c.GetInt("type", 0)
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- orgId := c.GetMobileAdminUserInfo().Org.Id
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
- stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "type": types,
- "stockTotal": stockTotal,
- })
- }
- }
-
- func (c *DialysisAPIController) BatchDeleteMonitor() {
-
- ids := c.GetString("ids")
- //patient_id, _ := c.GetInt64("patient_id")
- //monitoring_date, _ := c.GetInt64("monitoring_date")
- idArray := strings.Split(ids, ",")
- err := service.BatchDeleteMonitor(idArray)
- fmt.Print("err", err)
- //orgid := c.GetMobileAdminUserInfo().Org.Id
- //redis := service.RedisClient()
- //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
- //redis.Set(key, "", time.Second)
- //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
- //redis.Set(keyOne, "", time.Second)
- //fmt.Println("keyo呢32332322332332232332",keyOne)
- //redis.Close()
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "批量删除成功",
- })
- return
- }
-
- func (c *DialysisAPIController) GetPatientDialysisRecordList() {
-
- id, _ := c.GetInt64("id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- start_time := time.Now().Format("2006-01-02")
-
- startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
-
- nowTime := time.Now()
- endTime := nowTime.AddDate(-2, 0, 0)
- endTimes := endTime.Format("2006-01-02")
- endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
-
- list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
- fmt.Println("endtime232332322332322323232332", endTime.Unix())
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- func (c *DialysisAPIController) BathDeleteAdviceList() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- ids := c.GetString("ids")
-
- idArray := strings.Split(ids, ",")
- origin, _ := c.GetInt64("origin")
- if origin == 1 {
- err = service.BatchDeleteAdvice(idArray)
- fmt.Print("err", err)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "批量删除成功",
- })
- return
- }
-
- if origin == 2 {
- service.BatchDeleteHisAdvice(idArray)
- }
- }
-
- func (c *DialysisAPIController) UpdateAutoReduceDetail() {
-
- good_id, _ := c.GetInt64("good_id")
- count, _ := c.GetInt64("count")
- record_time, _ := c.GetInt64("record_time")
- patient_id, _ := c.GetInt64("patient_id")
- detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "detail": detail,
- })
- return
- }
-
- func (c *DialysisAPIController) DeleteAutoReduceDetail() {
-
- good_id, _ := c.GetInt64("good_id")
- record_time, _ := c.GetInt64("record_time")
- patient_id, _ := c.GetInt64("patient_id")
- service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
-
- err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
- fmt.Print("err", err)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "批量删除成功",
- })
- return
- }
-
- func (c *DialysisAPIController) BatchAdviceCheck() {
-
- ids := c.GetString("ids")
- idArray := strings.Split(ids, ",")
- creator, _ := c.GetInt64("creator")
- origin, _ := c.GetInt64("origin")
- if origin == 1 {
- err := service.BatchAdviceCheck(idArray, creator)
- fmt.Println(err)
- list, _ := service.GetAdviceExecutionById(idArray)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
- if origin == 2 {
- service.BatchHisAdviceCheck(idArray, creator)
- list, _ := service.GetHisAdviceExecutionById(idArray)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- }
-
- func (c *DialysisAPIController) BatchAdviceExecution() {
-
- ids := c.GetString("ids")
-
- idArray := strings.Split(ids, ",")
- executionTime := c.GetString("execution_time")
-
- creator, _ := c.GetInt64("creator")
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
-
- orgin, _ := c.GetInt64("origin")
- if orgin == 1 {
- err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
- list, _ := service.GetAdviceExecutionById(idArray)
- fmt.Println(err)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- if orgin == 2 {
- err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
- list, _ := service.GetHisAdviceExecutionById(idArray)
- fmt.Println(err)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- }
-
- func (c *DialysisAPIController) UpdateStockGoods() {
-
- good_id, _ := c.GetInt64("good_id")
- record_time, _ := c.GetInt64("record_time")
- patient_id, _ := c.GetInt64("patient_id")
- count, _ := c.GetInt64("count")
-
- err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
-
- fmt.Print("err", err)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "更新成功",
- })
- return
- }
-
- //当前数据比上一次出库数据少
- func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
-
- //查询该患者当天已经出库的耗材信息
- goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
- // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
- for i := len(goods_yc) - 1; i >= 0; i-- {
- goods_yc_temp := goods_yc[i]
- for j := len(goods) - 1; j >= 0; j-- {
- goods_temp := goods[j]
- // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
- if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
- // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
- if goods_yc_temp.Count == goods_temp.Count {
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
- if goods_yc_temp.Count > goods_temp.Count {
-
- temp_count := goods_yc_temp.Count - goods_temp.Count
- goods_yc[i].Count = temp_count
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
- if goods_yc_temp.Count < goods_temp.Count {
- temp_count := goods_temp.Count - goods_yc_temp.Count
-
- goods[j].Count = temp_count
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
-
- break
- }
- }
- }
- }
-
- // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
- // goods 这个数据就是需要出库的耗材的数据(新增的数据)
-
- //退库
- if len(goods_yc) > 0 {
- for _, good_yc := range goods_yc {
- out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
- ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
- }
- }
-
- return nil
- }
-
- //耗材出库删除
- func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
-
- // 先根据相关信息查询当天该耗材的出库信息
- warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
-
- if err != nil {
- return err
- }
-
- var delete_count int64 = 0
-
- delete_count = warehouseOutInfos.Count - count
-
- houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
-
- // 在出库记录表里记录退库详情
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- OrgId: orgID,
- Type: 1,
- IsSys: 1,
- SysRecordTime: record_time,
- GoodTypeId: good_yc.GoodTypeId,
- GoodId: good_yc.GoodId,
- PatientId: good_yc.PatientId,
- ConsumableType: 2,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- warehouseOutInfo.Count = count
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.Dealer = stockInInfo.Dealer
- warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
- warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
- warehouseOutInfo.ProductDate = stockInInfo.ProductDate
- warehouseOutInfo.Number = warehouseOutInfos.Number
- warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
- warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
- //查找当天是否存在出库记录
-
- _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
-
- if errcod == gorm.ErrRecordNotFound {
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
- if errflow == gorm.ErrRecordNotFound {
- //创建流水表
- err := service.CreateStockFlowOne(stockFlow)
- fmt.Println("err", err)
- } else if errflow == nil {
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- ID: exsit.ID,
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: exsit.Count - delete_count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
- }
-
- if errOne != nil {
- return errOne
- }
- } else if errcod == nil {
- service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- ReturnCount: delete_count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
- if errflows == gorm.ErrRecordNotFound {
- //创建流水表
- service.CreateStockFlowOne(stockFlow)
- } else if errflows == nil {
- stockFlow := models.VmStockFlow{
- WarehousingId: warehouseOutInfos.WarehouseInfotId,
- ID: exsit.ID,
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: exsit.Count - delete_count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- ReturnCount: delete_count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
- }
-
- }
-
- //更改自动出库的表格
- details := models.BloodAutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: record_time,
- OrgId: orgID,
- GoodId: good_yc.GoodId,
- GoodTypeId: good_yc.GoodTypeId,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //查询当天耗材是否已经存在数据
- _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
-
- if errcode == gorm.ErrRecordNotFound {
- errTwo := service.CreateAutoReduceRecord(&details)
- if errTwo != nil {
- return errTwo
- }
- } else if errcode == nil {
- service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
- service.CreateAutoReduceRecord(&details)
-
- }
-
- service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
-
- //增加出库库存数量
- service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
-
- errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
- fmt.Println("errOne", errOne)
- // 删除出库完成后,要增加对应批次的库存数量
-
- errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
- if errThree != nil {
- return errThree
- }
-
- if good_yc.Count == 0 {
- return nil
- } else {
- return errors.New("退库和出库数据不匹配")
- }
- }
-
- func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
-
- //查询该患者当天已经出库的耗材信息
- goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
- // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
- for i := len(goods_yc) - 1; i >= 0; i-- {
- goods_yc_temp := goods_yc[i]
- for j := len(goods) - 1; j >= 0; j-- {
- goods_temp := goods[j]
- // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
- if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
- // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
- if goods_yc_temp.Count == goods_temp.Count {
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
- if goods_yc_temp.Count > goods_temp.Count {
-
- temp_count := goods_yc_temp.Count - goods_temp.Count
- goods_yc[i].Count = temp_count
- goods = append(goods[:j], goods[j+1:]...)
- break
- }
- // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
- if goods_yc_temp.Count < goods_temp.Count {
- temp_count := goods_temp.Count - goods_yc_temp.Count
- goods[j].Count = temp_count
- goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
- break
- }
- }
- }
- }
-
- // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
- // goods 这个数据就是需要出库的耗材的数据(新增的数据)
-
- fmt.Println("剩余需要出库的", len(goods))
- if len(goods) > 0 {
- out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
- houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
- if err == gorm.ErrRecordNotFound {
- //没有记录,则创建出库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllWarehouseOut(orgID)
- total = total + 1
- warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- warehouseOut := models.WarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: time.Now().Unix(),
- OrgId: orgID,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: record_time,
- Dealer: 0,
- Manufacturer: 0,
- Type: 1,
- IsSys: 1,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- }
- err := service.AddSigleWarehouseOut(&warehouseOut)
- if err != nil {
- utils.TraceLog("创建出库单失败 err = %v", err)
- return err
- } else {
- out = warehouseOut
- }
- }
-
- for _, item := range goods {
- var newCount int64 = 0
- for _, it := range goodOne {
- if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
- newCount = it.Count
- }
- }
- prepare := models.DialysisBeforePrepare{
- GoodTypeId: item.GoodTypeId,
- GoodId: item.GoodId,
- Count: item.Count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
-
- service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
-
- //增加出库数量
- service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
- }
-
- }
-
- if len(goods_yc) > 0 {
-
- for _, good_yc := range goods_yc {
- out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
- ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
- }
- }
-
- return nil
- }
-
- //耗材出库删除
- func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
- // 先根据相关信息查询当天该耗材的出库信息
- warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
- if err != nil {
- return err
- }
-
- var delete_count int64 = 0
-
- for _, ware := range warehouseOutInfos {
- // 判断当前出库的数据和删除出库数量
- if good_yc.Count <= ware.Count {
- delete_count = good_yc.Count
- } else {
- delete_count = ware.Count
- }
-
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Remark: "",
- OrgId: orgID,
- Type: 1,
- Manufacturer: 0,
- Dealer: 0,
- IsSys: 0,
- SysRecordTime: record_time,
- GoodTypeId: good_yc.GoodTypeId,
- GoodId: good_yc.GoodId,
- StorehouseId: warehouseOut.StorehouseId,
- IsCheck: 1,
- }
- warehouseOutInfo.Count = delete_count
- stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
- warehouseOutInfo.Price = stockInInfo.Price
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- if errOne != nil {
- return errOne
- }
-
- // 删除出库完成后,要改变流水库存(有疑问)
- errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
-
- fmt.Println("errOne", errOne)
- errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
-
- service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
-
- //扣减出库数量
- service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
- if errThree != nil {
- return errThree
- }
- }
-
- if good_yc.Count == 0 {
- return nil
- } else {
- return errors.New("退库和出库数据不匹配")
- }
- }
-
- func (this *DialysisAPIController) GetMobileScheduleList() {
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- type_options_visible, _ := this.GetInt64("type_options_visible")
- sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
- zone_options_visible, _ := this.GetInt64("zone_options_visible")
- fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
- }
-
- func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
- newArr = make([]*models.HisPrescriptionProject, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].TeamId == arr[j].TeamId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (this *DialysisAPIController) GetRoleList() {
-
- admin_user_id, _ := this.GetInt64("admin_user_id")
- orgid := this.GetMobileAdminUserInfo().Org.Id
- list, err := service.GetRoleList(orgid, admin_user_id)
- fmt.Println(err)
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- return
- }
-
- func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
-
- fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
- // 先根据相关信息查询当天该耗材的出库信息
- warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
-
- if err != nil {
- return err
- }
-
- var delete_count int64 = 0
-
- delete_count = warehouseOutInfos.Count - count
-
- houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
-
- // 删除出库完成后,要增加对应批次的库存数量
-
- errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
- if errThree != nil {
- return errThree
- }
-
- //增加退库数量
- service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
-
- //扣减出库数量
- service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
- //查询剩余库存
- goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
- var sum_count int64
- for _, item := range goodList {
- sum_count += item.StockCount
- }
-
- // 在出库记录表里记录退库详情
- warehouseOutInfo := &models.WarehouseOutInfo{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- OrgId: orgID,
- Type: 1,
- IsSys: 1,
- SysRecordTime: record_time,
- GoodTypeId: good_yc.GoodTypeId,
- GoodId: good_yc.GoodId,
- PatientId: good_yc.PatientId,
- ConsumableType: 2,
- StorehouseId: houseConfig.StorehouseOutInfo,
- IsCheck: 1,
- OverCount: sum_count,
- }
- warehouseOutInfo.Count = count
-
- stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
- warehouseOutInfo.Price = stockInInfo.Price
- warehouseOutInfo.Dealer = stockInInfo.Dealer
- warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
- warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
- warehouseOutInfo.ProductDate = stockInInfo.ProductDate
- warehouseOutInfo.Number = warehouseOutInfos.Number
- warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
- warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
- //查找当天是否存在出库记录
-
- _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
-
- if errcod == gorm.ErrRecordNotFound {
- errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
-
- //插入详情明细表
- if errOne != nil {
- return errOne
- }
- //插入详情明细表
- stockFlow := models.VmStockFlow{
- WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
- WarehouseOutId: warehouseOut.ID,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- Count: count,
- Price: stockInInfo.Price,
- Status: 1,
- Ctime: time.Now().Unix(),
- UserOrgId: good_yc.OrgId,
- Manufacturer: stockInInfo.Manufacturer,
- Dealer: stockInInfo.Dealer,
- LicenseNumber: stockInInfo.LicenseNumber,
- IsEdit: 2,
- Creator: creater,
- SystemTime: record_time,
- ConsumableType: 3,
- WarehousingDetailId: 0,
- IsSys: 1,
- UpdateCreator: creater,
- PatientId: patient_id,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: sum_count,
- ProjectId: good_yc.ProjectId,
- }
- err := service.CreateStockFlowOne(stockFlow)
- fmt.Println("err", err)
- } else if errcod == nil {
- service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
- }
-
- //创建退库单
- operation_time := time.Now().Unix()
-
- //创建退库单
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllCancelStockTotal(orgID)
- total = total + 1
- orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
-
- cancelStock := models.CancelStock{
- OrderNumber: orderNumber,
- OperaTime: operation_time,
- OrgId: orgID,
- Creater: warehouseOut.Creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- ReturnTime: record_time,
- Type: 1,
- StorehouseId: stockInInfo.StorehouseId,
- IsCheck: 1,
- }
- _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
- if msgerrkonde == gorm.ErrRecordNotFound {
- service.AddSigleCancelStock(&cancelStock)
- }
-
- cancel, _ := service.GetLastCancelStockById(orgID)
-
- manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
- deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
- cancelStockInfo := models.CancelStockInfo{
- GoodId: stockInInfo.GoodId,
- CancelStockId: cancel.ID,
- GoodTypeId: stockInInfo.GoodTypeId,
- Count: delete_count,
- Price: stockInInfo.PackingPrice,
- Total: 0,
- ProductDate: stockInInfo.ProductDate,
- ExpiryDate: stockInInfo.ExpiryDate,
- Ctime: time.Now().Unix(),
- Status: 1,
- OrgId: orgID,
- OrderNumber: cancel.OrderNumber,
- Type: 0,
- Dealer: deaerler.DealerName,
- Manufacturer: manufacturer.ManufacturerName,
- Number: stockInInfo.Number,
- RegisterAccount: "",
- Remark: "",
- WarehouseInfoId: stockInInfo.ID,
- PatientId: patient_id,
- RecordDate: record_time,
- StorehouseId: stockInInfo.StorehouseId,
- IsCheck: 1,
- }
-
- service.CreateCancelStockInfoOne(&cancelStockInfo)
-
- cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
-
- flow := models.VmStockFlow{
- WarehousingId: warehouseOutInfo.WarehouseInfotId,
- GoodId: good_yc.GoodId,
- Number: warehouseOutInfos.Number,
- LicenseNumber: stockInInfo.LicenseNumber,
- Count: delete_count,
- UserOrgId: orgID,
- PatientId: patient_id,
- SystemTime: record_time,
- ConsumableType: 7,
- IsSys: 0,
- WarehousingOrder: "",
- WarehouseOutId: warehouseOutInfos.WarehouseOutId,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- IsEdit: 0,
- CancelStockId: cancel.ID,
- CancelOrderNumber: cancel.OrderNumber,
- Manufacturer: manufacturer.ID,
- Dealer: 0,
- Creator: warehouseOut.Creater,
- UpdateCreator: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Price: stockInInfo.Price,
- WarehousingDetailId: stockInInfo.ID,
- WarehouseOutDetailId: warehouseOutInfos.ID,
- CancelOutDetailId: cancelInfo.ID,
- ProductDate: stockInInfo.ProductDate,
- ExpireDate: stockInInfo.ExpiryDate,
- StorehouseId: houseConfig.StorehouseOutInfo,
- OverCount: sum_count,
- }
- service.CreateStockFlowOne(flow)
-
- //更改自动出库的表格
- details := models.BloodAutomaticReduceDetail{
- WarehouseOutId: warehouseOutInfo.ID,
- WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- RecordTime: record_time,
- OrgId: orgID,
- GoodId: good_yc.GoodId,
- GoodTypeId: good_yc.GoodTypeId,
- Count: count,
- StorehouseId: houseConfig.StorehouseOutInfo,
- }
- //查询当天耗材是否已经存在数据
- _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
-
- if errcode == gorm.ErrRecordNotFound {
- errTwo := service.CreateAutoReduceRecord(&details)
- if errTwo != nil {
- return errTwo
- }
- } else if errcode == nil {
- service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
- service.CreateAutoReduceRecord(&details)
-
- }
-
- service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
-
- //增加出库库存数量
- //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
-
- if good_yc.Count == 0 {
- return nil
- } else {
- return errors.New("退库和出库数据不匹配")
- }
- }
-
- func (this *DialysisAPIController) SavePatientSign() {
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient_id, _ := this.GetInt64("patient_id")
- dialysis_date, _ := this.GetInt64("dialysis_date")
- orgid := adminUserInfo.Org.Id
-
- var esdata models.DialysisOrder
- var err error
- if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- esdata.Hash = esdata.Hash
- esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
-
- order := models.DialysisOrder{
- Hash: esdata.Hash,
- Url: esdata.Url,
- }
- err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
-
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- //scheduleDateStartOne := startDate.Format("2006-01-02")
- //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- //redis.Set(keyTwo, "", time.Second)
-
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
- redis.Set(keyThree, "", time.Second)
- keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "electronic_signature": esdata,
- })
- }
-
- func (this *DialysisAPIController) GetPatientSign() {
-
- patient_id, _ := this.GetInt64("patient_id")
-
- dialysis_date, _ := this.GetInt64("dialysis_date")
- adminUserInfo := this.GetMobileAdminUserInfo()
- orgId := adminUserInfo.Org.Id
- dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
- if err != nil {
- fmt.Println(err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "dialysisOrder": dialysisOrder,
- })
- }
-
- func (this *DialysisAPIController) GetScheduleByPatient() {
-
- patient_id, _ := this.GetInt64("patient_id")
- schedule_date, _ := this.GetInt64("schedule_date")
- orgid := this.GetMobileAdminUserInfo().Org.Id
- schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
- this.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- })
-
- }
-
- func (this *DialysisAPIController) GetDialysisRecordOrder() {
-
- org_id := this.GetMobileAdminUserInfo().Org.Id
- patient_id, _ := this.GetInt64("patient_id")
- schedule_date, _ := this.GetInt64("schedule_date")
- order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
- this.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- })
- }
-
- func (this *DialysisAPIController) GetScheduleTypeByIdList() {
-
- org_id := this.GetMobileAdminUserInfo().Org.Id
-
- schedule_date := this.GetString("schedule_date")
- schedule_type, _ := this.GetInt64("schedule_type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startdateunix int64
-
- if len(schedule_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startdateunix = theTime.Unix()
- }
-
- list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
- scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
- devices, _ := service.GetAllDevicetByListSix(org_id)
- for key, item := range scheduals {
- // 床位信息
- for _, device := range devices {
- if item.BedId == device.ID {
- scheduals[key].DeviceNumber = device
- break
- }
- }
-
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "scheduals": scheduals,
- })
- }
-
- func (this *DialysisAPIController) SavePatientPicture() {
-
- patient_id, _ := this.GetInt64("patient_id")
- dialysis_date, _ := this.GetInt64("schedule_date")
- avatar := this.GetString("avatar")
- fmt.Println("patient_id", patient_id)
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- order := models.DialysisOrder{
- Url: avatar,
- }
- err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
- //清空key 值
- redis.Set(keyOne, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
- redis.Set(keyThree, "", time.Second)
- keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
- redis.Set(keyFour, "", time.Second)
-
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
- redis.Set(keyFive, "", time.Second)
-
- keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "order": order,
- })
- }
-
- func (this *DialysisAPIController) ExectionMobileAdvice() {
-
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
- execution_time := this.GetString("exce_time")
- timeLayout2 := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //his客户
- if config.IsOpen == 1 {
-
- list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
- adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
- for _, item := range list {
- for _, it := range adviceList {
- if item.DrugId == it.DrugId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
-
- for _, item := range list {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- var sum_out_count int64
- for _, itemThree := range item.ChildDoctorAdvice {
- var prescribing_number int64
- stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
- parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
- if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber * medical.MinNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- sum_out_count += prescribing_number
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
-
- //库存不足
- if sum_out_count > drugStockOut.FlushCount {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- "ids": ids,
- })
- return
- }
- }
- creater := this.GetMobileAdminUserInfo().AdminUser.Id
- //执行医嘱
- errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
- advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
- for _, item := range advices {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
- if errs == nil {
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- if drugStockConfig.IsOpen == 1 {
- for _, item := range advices {
- advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
- config, _ := service.GetDrugOpenConfigOne(orgId)
- if config.IsOpen != 1 {
- //查询该药品是否有库存
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
- if medical.IsUse == 2 {
- if config.IsOpen != 1 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.HisDrugsDelivery(orgId, creater, &advice)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.HisDrugsDelivery(orgId, creater, &advice)
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
-
- }
-
- }
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- fmt.Println("config233322333223", config.IsOpen)
-
- //血透客户
- if config.IsOpen == 2 || config.IsOpen == 0 {
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
- if drugStockConfig.IsOpen == 1 {
- list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
- adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
- for _, item := range list {
- for _, it := range adviceList {
- if item.DrugId == it.DrugId {
- item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
- }
- }
- }
- for _, item := range list {
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- var sum_out_count int64
- for _, itemThree := range item.ChildDoctorAdvice {
- var prescribing_number int64
- stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
- parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
- if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber * medical.MinNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
- prescribing_number = parseIntPrescribingNumber
- }
- sum_out_count += prescribing_number
- }
- houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
-
- //库存不足
- if sum_out_count > drugStockOut.FlushCount {
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "drug": medical,
- "ids": ids,
- })
- return
- }
- }
-
- creater := this.GetMobileAdminUserInfo().AdminUser.Id
- fmt.Println("creater2332243244224242424", creater)
- //执行医嘱
- errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
- advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
- for _, item := range advices {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
- if errs == nil {
-
- for _, item := range advices {
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //查询是否出库按钮开启
- adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
- if adviceSetting.IsAdviceOpen == 1 {
- //查询是否出库按钮开启
- prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if prescriptionConfig.IsOpen == 1 {
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- }
- } else {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
-
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- }
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
-
- } else {
-
- creater := this.GetMobileAdminUserInfo().AdminUser.Id
- //执行医嘱
- service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
- advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
- for _, item := range advices {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- }
-
- }
-
- func (this *DialysisAPIController) GetSettleMobileAdvice() {
-
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- orgId := this.GetMobileAdminUserInfo().Org.Id
- config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
-
- if config.IsOpen == 1 {
- service.UpdateSettleMobileHisAdvice(orgId, idSplit)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- if config.IsOpen == 0 || config.IsOpen == 2 {
-
- service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
- }
-
- func (this *DialysisAPIController) GetCheckMobileAdvice() {
-
- ids := this.GetString("ids")
- idSplit := strings.Split(ids, ",")
- orgId := this.GetMobileAdminUserInfo().Org.Id
-
- config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
-
- //his
- if config.IsOpen == 1 {
- checker := this.GetMobileAdminUserInfo().AdminUser.Id
- theTime := time.Now()
-
- advices := models.HisDoctorAdviceThirty{
- CheckTime: theTime.Unix(),
- Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
- service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
-
- list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
- for _, item := range list {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- //血透
- if config.IsOpen == 0 || config.IsOpen == 2 {
-
- checker := this.GetMobileAdminUserInfo().AdminUser.Id
- theTime := time.Now()
-
- advices := models.DoctorAdvice{
- CheckTime: theTime.Unix(),
- Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
-
- service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
- list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
- for _, item := range list {
- key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "ids": ids,
- })
- return
- }
-
- }
-
- func (this *DialysisAPIController) CheckSchedule() {
-
- patientID, _ := this.GetInt64("patient_id")
- recordDateStr := this.GetString("record_date")
- nurseID, _ := this.GetInt64("nurse")
- schedual_type, _ := this.GetInt64("schedual_type")
-
- bedID, _ := this.GetInt64("bed")
- start_time := this.GetString("start_time")
-
- if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
- if parseStartDateErr != nil {
- this.ErrorLog("时间解析失败:%v", parseStartDateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
- if parseErr != nil {
- this.ErrorLog("时间解析失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
- if getPatientErr != nil {
- this.ErrorLog("获取患者信息失败:%v", getPatientErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if patient == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
- if getNurseErr != nil {
- this.ErrorLog("获取护士失败:%v", getNurseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if nurse == nil {
- this.ErrorLog("护士不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
- if getDeviceNumberErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if deviceNumber == nil {
- this.ErrorLog("床位号不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
- if getRecordErr != nil {
- this.ErrorLog("获取透析记录失败:%v", getRecordErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if dialysisRecord != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
- return
- }
-
- scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
- scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
- theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
- schedulestartTime := theStartTime.Unix()
- scheduleendTime := theEndTime.Unix()
-
- //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
- //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
-
- schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- //查询该床位是否有人用了
- order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
-
- if err == nil {
- if schedule.ID == 0 {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "请求失败",
- })
-
- } else {
-
- if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
- if order.ID > 0 { //该机位被其他人占用了
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
- return
- } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
- daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
- if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
-
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 1,
- "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
- })
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "",
- })
- }
- }
- } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 2,
- "msg": "当前机位已有患者在使用,请重新选择!",
- })
-
- }
-
- }
-
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "status": 0,
- "msg": "",
- })
-
- }
-
- }
|