dialysis_api_controller.go 285KB

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