dialysis_api_controller.go 423KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. fmt.Print("projectOne------------------------", projectsOne)
  468. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  469. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  470. var team_projects []*models.HisPrescriptionProject
  471. //var index int64 = 0
  472. for _, item := range temp_team_projects {
  473. //组套里面非检验项目的
  474. if item.HisProject.CostClassify != 3 {
  475. projects = append(projects, item)
  476. }
  477. //组套里面检验项目的
  478. if item.HisProject.CostClassify == 3 {
  479. team_projects = append(team_projects, item)
  480. }
  481. }
  482. //针对茂名舒和
  483. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  484. if len(projects) > 0 {
  485. for _, item := range projects {
  486. if item.Type == 2 {
  487. if item.HisProject.IsShow == 1 {
  488. projectsOne = append(projectsOne, item)
  489. }
  490. }
  491. if item.Type == 3 {
  492. if item.GoodInfo.IsShow == 1 {
  493. projectsOne = append(projectsOne, item)
  494. }
  495. }
  496. }
  497. }
  498. } else {
  499. for _, item := range projects {
  500. projectsOne = append(projectsOne, item)
  501. }
  502. }
  503. team_projects = RemoveRepeatedCheckRecod(team_projects)
  504. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  505. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  506. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  507. var his_advices []*models.HisDoctorAdviceInfo
  508. var his_advices_one []*models.HisDoctorAdviceInfo
  509. if is_open_config.IsOpen == 1 {
  510. // 先走redis,没有走数据库
  511. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  512. }
  513. //针对茂名舒和
  514. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  515. if len(his_advices) > 0 {
  516. for _, item := range his_advices {
  517. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  518. if drug.IsShow == 1 {
  519. his_advices_one = append(his_advices_one, item)
  520. }
  521. }
  522. }
  523. } else {
  524. if len(his_advices) > 0 {
  525. for _, item := range his_advices {
  526. his_advices_one = append(his_advices_one, item)
  527. }
  528. }
  529. }
  530. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  531. if is_advice_open.IsAdviceOpen == 1 {
  532. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  533. }
  534. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  535. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  536. var remind_lists []models.XtCheckRemind
  537. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  538. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  539. }
  540. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  541. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  542. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  543. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  544. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  545. returnData := map[string]interface{}{
  546. "patient": patient,
  547. "schedual": schedual,
  548. "prescription": dialysisPrescribe,
  549. "solution": dialysisSolution,
  550. "last_prescription": lastDialysisPrescribe,
  551. "receiver_treatment_access": receiverTreatmentAccess,
  552. "predialysis_evaluation": predialysisEvaluation,
  553. "doctor_advices": doctorAdvices,
  554. "double_check": doubleCheck,
  555. "assessment_after_dislysis": assessmentAfterDislysis,
  556. "treatment_summary": treatmentSummary,
  557. "monitor_records": monitorRecords,
  558. "dialysis_order": dialysisOrder,
  559. "operators": operators,
  560. "last_predialysis_evaluation": lastPredialysisEvaluation,
  561. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  562. "last_monitor_record": lastMonitorRecord,
  563. "config": gobalConfig,
  564. "dry_weight": lastDryWeightDislysis,
  565. "system_prescription": systemDialysisPrescribe,
  566. "his_advices": his_advices_one,
  567. "is_open_config": is_open_config,
  568. "stockType": stockType,
  569. "prepare": prepare,
  570. "lastAssessment": lastAssessment,
  571. "prescribeOne": prescribeOne,
  572. "is_project_open_config": is_project_open_config,
  573. "project": projectsOne,
  574. "team_projects": team_projects,
  575. "is_advice_open": is_advice_open,
  576. "prescription_open": prescriptionConfig.IsOpen,
  577. "lastOrder": lastOrder,
  578. "remind_lists": remind_lists,
  579. "lastDialysisPrescription": lastDialysisPrescription,
  580. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  581. "dryWeightList": dryWeightList,
  582. "firstMonitor": firstMonitor,
  583. "lastMonitor": lastMonitor,
  584. }
  585. this.ServeSuccessJSON(returnData)
  586. }
  587. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  588. adminInfo := c.GetMobileAdminUserInfo()
  589. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  590. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  591. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  592. returnData := map[string]interface{}{
  593. "admin_users": adminUsers,
  594. "devices": devices,
  595. "device_numbers": device_numbers,
  596. }
  597. c.ServeSuccessJSON(returnData)
  598. }
  599. func (c *DialysisAPIController) PostAtreatmentInfo() {
  600. id, _ := c.GetInt64("patient", 0)
  601. recordDateStr := c.GetString("record_date")
  602. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  603. summaryContent := c.GetString("summaryContent")
  604. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  605. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  606. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  607. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  608. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  609. nursingRecord := c.GetString("nursing_record")
  610. fmt.Println("护理记录", nursingRecord)
  611. specialRecord := c.GetString("special_record")
  612. fmt.Println("特殊记录", specialRecord)
  613. adminUserInfo := c.GetMobileAdminUserInfo()
  614. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  615. checkStaffId = adminUserInfo.AdminUser.Id
  616. deboardNurseId = adminUserInfo.AdminUser.Id
  617. treatDoctor = adminUserInfo.AdminUser.Id
  618. if id <= 0 {
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  623. if patient.ID == 0 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  625. return
  626. }
  627. if len(recordDateStr) == 0 {
  628. recordDateStr = time.Now().Format("2006-01-02")
  629. }
  630. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  631. if parseDateErr != nil {
  632. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. summary := models.TreatmentSummary{
  637. UserOrgId: adminUserInfo.Org.Id,
  638. PatientId: id,
  639. AssessmentDate: recordDate.Unix(),
  640. Mission: propagandaAndEducationContent,
  641. DialysisSummary: summaryContent,
  642. SjNurse: changeMedicalNurseId,
  643. ZlNurse: treatNurseId,
  644. HdNurse: checkStaffId,
  645. XjNurse: deboardNurseId,
  646. ZlDoctor: treatDoctor,
  647. CreatedTime: time.Now().Unix(),
  648. Status: 1,
  649. NursingRecord: nursingRecord,
  650. SpecialRecord: specialRecord,
  651. }
  652. // 查询信息规挡的设置天数
  653. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  654. if infor.ID > 0 && infor.WeekDay > 0 {
  655. var cha_time int64
  656. timeNowStr := time.Now().Format("2006-01-02")
  657. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  658. //今日的日期减去设置的日期
  659. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  660. if cha_time >= recordDate.Unix() {
  661. //查询审核是否允许
  662. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  663. //申请状态不允许的情况 拒绝修改
  664. if infor.ApplicationStatus != 1 {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  666. return
  667. }
  668. }
  669. }
  670. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  671. if treatmentSummary.ID == 0 { //新增
  672. summary.Creater = adminUserInfo.AdminUser.Id
  673. service.AddSigleSummaryRecord(&summary)
  674. finish := models.XtDialysisFinish{
  675. IsFinish: 1,
  676. UserOrgId: adminUserInfo.Org.Id,
  677. Status: 1,
  678. Ctime: time.Now().Unix(),
  679. Mtime: 0,
  680. Module: 10,
  681. RecordDate: recordDate.Unix(),
  682. Sourse: 1,
  683. PatientId: id,
  684. }
  685. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  686. if dialysisFinish.ID == 0 {
  687. service.CreateDialysisFinish(finish)
  688. }
  689. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  690. redis := service.RedisClient()
  691. //清空key 值
  692. redis.Set(key, "", time.Second)
  693. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  694. redis.Set(keyOne, "", time.Second)
  695. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  696. redis.Set(keyThree, "", time.Second)
  697. defer redis.Close()
  698. c.ServeSuccessJSON(map[string]interface{}{
  699. "summary": summary,
  700. })
  701. } else { //修改
  702. summary.Creater = treatmentSummary.Creater
  703. summary.CreatedTime = treatmentSummary.CreatedTime
  704. summary.Modifier = adminUserInfo.AdminUser.Id
  705. summary.ID = treatmentSummary.ID
  706. service.UpdateSummeRecord(&summary)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  708. redis := service.RedisClient()
  709. //清空key 值
  710. redis.Set(key, "", time.Second)
  711. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  712. redis.Set(keyOne, "", time.Second)
  713. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  714. redis.Set(keyThree, "", time.Second)
  715. defer redis.Close()
  716. c.ServeSuccessJSON(map[string]interface{}{
  717. "summary": summary,
  718. })
  719. }
  720. }
  721. func (c *DialysisAPIController) PostDoubleCheck() {
  722. id, _ := c.GetInt64("patient", 0)
  723. recordDateStr := c.GetString("record_date")
  724. checkTimeStr := c.GetString("check_time")
  725. firstCheckTimeStr := c.GetString("first_check_time")
  726. creater, _ := c.GetInt64("creater", 0)
  727. modifier, _ := c.GetInt64("modifier", 0)
  728. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  729. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  730. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  731. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  732. dialysis_item_desc := c.GetString("dialysis_item_desc")
  733. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  734. vascular_access_desc := c.GetString("vascular_access_desc")
  735. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  736. collator, _ := c.GetInt64("collator", 0)
  737. employee_number := c.GetString("employee_number")
  738. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  739. needle_batch_number := c.GetString("needle_batch_number")
  740. if id <= 0 {
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. adminUserInfo := c.GetMobileAdminUserInfo()
  745. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  746. if patient.ID == 0 {
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  748. return
  749. }
  750. if len(recordDateStr) == 0 {
  751. recordDateStr = time.Now().Format("2006-01-02")
  752. }
  753. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  754. if parseDateErr != nil {
  755. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  757. return
  758. }
  759. var checkDate int64
  760. if len(checkTimeStr) == 0 {
  761. checkDate = 0
  762. } else {
  763. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  764. checkDate = checkDateUnix.Unix()
  765. }
  766. var firstCheckDate int64
  767. if len(firstCheckTimeStr) == 0 {
  768. firstCheckDate = 0
  769. } else {
  770. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  771. firstCheckDate = firstCheckDateUnix.Unix()
  772. }
  773. if adminUserInfo.Org.Id == 10644 {
  774. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  775. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  776. if check.ID == 0 {
  777. if employee_number != list.JobNumber {
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "doubleCheck": check,
  780. "msg": "2",
  781. })
  782. return
  783. }
  784. }
  785. if check.ID > 0 {
  786. if employee_number != list.JobNumber {
  787. c.ServeSuccessJSON(map[string]interface{}{
  788. "doubleCheck": check,
  789. "msg": "2",
  790. })
  791. return
  792. }
  793. }
  794. }
  795. doubleCheck := models.DoubleCheck{
  796. UserOrgId: adminUserInfo.Org.Id,
  797. PatientId: id,
  798. DialysisItemCheck: dialysis_item_check,
  799. DialysisParameterCheck: dialysis_parameter_check,
  800. VascularAccessVerification: vascular_access_verification,
  801. PipelineConnectionCheck: pipeline_connection_check,
  802. DialysisItemDesc: dialysis_item_desc,
  803. DialysisParameterDesc: dialysis_parameter_desc,
  804. VascularAccessDesc: vascular_access_desc,
  805. PipelineConnectionDesc: pipeline_connection_desc,
  806. Collator: collator,
  807. Status: 1,
  808. CreatedTime: time.Now().Unix(),
  809. CheckDate: recordDate.Unix(),
  810. UpdatedTime: time.Now().Unix(),
  811. EmployeeNumber: employee_number,
  812. DialyzerBatchNumber: dialyzer_batch_number,
  813. NeedleBatchNumber: needle_batch_number,
  814. }
  815. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  816. if check.ID == 0 { //新增
  817. doubleCheck.FirstCheckTime = firstCheckDate
  818. doubleCheck.CheckTime = checkDate
  819. doubleCheck.Creater = creater
  820. doubleCheck.Modifier = modifier
  821. if adminUserInfo.Org.Id == 10340 {
  822. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  823. doubleCheck.Creater = order.StartNurse
  824. }
  825. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  826. //查询未核对的医嘱
  827. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  828. for _, advice := range doctorList {
  829. if advice.ExecutionStaff == modifier {
  830. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  831. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  832. return
  833. }
  834. }
  835. }
  836. // 查询信息规挡的设置天数
  837. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  838. if infor.ID > 0 && infor.WeekDay > 0 {
  839. var cha_time int64
  840. timeNowStr := time.Now().Format("2006-01-02")
  841. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  842. //今日的日期减去设置的日期
  843. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  844. if cha_time >= recordDate.Unix() {
  845. //查询审核是否允许
  846. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  847. //申请状态不允许的情况 拒绝修改
  848. if infor.ApplicationStatus != 1 {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  850. return
  851. }
  852. }
  853. }
  854. err := service.AddSigleDoubleCheck(&doubleCheck)
  855. finish := models.XtDialysisFinish{
  856. IsFinish: 1,
  857. UserOrgId: adminUserInfo.Org.Id,
  858. Status: 1,
  859. Ctime: time.Now().Unix(),
  860. Mtime: 0,
  861. Module: 5,
  862. RecordDate: recordDate.Unix(),
  863. Sourse: 1,
  864. PatientId: id,
  865. }
  866. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  867. if dialysisFinish.ID == 0 {
  868. service.CreateDialysisFinish(finish)
  869. }
  870. //针对长沙南雅
  871. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  872. //查询未核对的医嘱
  873. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  874. if len(doctorList) > 0 && modifier > 0 {
  875. for _, advice := range doctorList {
  876. service.UpdateDoctorAdviceList(advice.ID, modifier)
  877. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  878. redis := service.RedisClient()
  879. //清空key 值
  880. redis.Set(key, "", time.Second)
  881. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  882. redis.Set(keyTwo, "", time.Second)
  883. theTime := time.Now()
  884. recordDate := theTime.Format("2006-01-02")
  885. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  886. redis.Set(keyFour, "", time.Second)
  887. defer redis.Close()
  888. }
  889. }
  890. }
  891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  892. redis := service.RedisClient()
  893. //清空key 值
  894. redis.Set(key, "", time.Second)
  895. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  896. redis.Set(keyOne, "", time.Second)
  897. defer redis.Close()
  898. if err == nil {
  899. c.ServeSuccessJSON(map[string]interface{}{
  900. "doubleCheck": &doubleCheck,
  901. })
  902. }
  903. } else { //修改
  904. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  905. if infor.ID > 0 {
  906. var cha_time int64
  907. timeNowStr := time.Now().Format("2006-01-02")
  908. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  909. //今日的日期减去设置的日期
  910. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  911. if cha_time >= recordDate.Unix() {
  912. //查询审核是否允许
  913. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  914. //申请状态不允许的情况 拒绝修改
  915. if infor.ApplicationStatus != 1 {
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  917. return
  918. }
  919. }
  920. }
  921. doubleCheck.FirstCheckTime = firstCheckDate
  922. doubleCheck.CheckTime = checkDate
  923. doubleCheck.Creater = creater
  924. doubleCheck.Modifier = modifier
  925. doubleCheck.CreatedTime = check.CreatedTime
  926. doubleCheck.ID = check.ID
  927. doubleCheck.EmployeeNumber = employee_number
  928. doubleCheck.NeedleBatchNumber = needle_batch_number
  929. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  930. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  931. //查询未核对的医嘱
  932. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  933. for _, advice := range doctorList {
  934. if advice.ExecutionStaff == modifier {
  935. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  936. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  937. return
  938. }
  939. }
  940. }
  941. err := service.UpdateDoubleCheck(&doubleCheck)
  942. //针对长沙南雅
  943. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  944. //查询未核对的医嘱
  945. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  946. if len(doctorList) > 0 && modifier > 0 {
  947. for _, advice := range doctorList {
  948. service.UpdateDoctorAdviceList(advice.ID, modifier)
  949. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  950. redis := service.RedisClient()
  951. //清空key 值
  952. redis.Set(key, "", time.Second)
  953. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  954. redis.Set(keyTwo, "", time.Second)
  955. theTime := time.Now()
  956. recordDate := theTime.Format("2006-01-02")
  957. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  958. redis.Set(keyFour, "", time.Second)
  959. defer redis.Close()
  960. }
  961. }
  962. }
  963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  964. redis := service.RedisClient()
  965. //清空key 值
  966. redis.Set(key, "", time.Second)
  967. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  968. redis.Set(keyOne, "", time.Second)
  969. defer redis.Close()
  970. if err == nil {
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "doubleCheck": &doubleCheck,
  973. "msg": "1",
  974. })
  975. }
  976. }
  977. }
  978. func (c *DialysisAPIController) PostAcceptsAssessment() {
  979. id, _ := c.GetInt64("patient", 0)
  980. recordDateStr := c.GetString("record_date")
  981. way, _ := c.GetInt64("way", 0)
  982. consciousness, _ := c.GetInt64("consciousness", 0)
  983. appetite, _ := c.GetInt64("appetite", 0)
  984. condition, _ := c.GetInt64("condition", 0)
  985. posture, _ := c.GetInt64("posture")
  986. sick_condition, _ := c.GetInt64("sick_condition", 0)
  987. danger_level, _ := c.GetInt64("danger_level", 0)
  988. intake, _ := c.GetInt64("intake", 0)
  989. nutrition, _ := c.GetInt64("nutrition", 0)
  990. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  991. psychological_assessment_other := c.GetString("psychological_assessment_other")
  992. score := c.GetString("score")
  993. sick_condition_other := c.GetString("sick_condition_other")
  994. //precaution, _ := c.GetInt64("precaution", 0)
  995. precaution := c.GetString("precaution")
  996. precaution_other := c.GetString("precaution_other")
  997. psychological_other := c.GetString("psychological_other")
  998. admission_number := c.GetString("admission_number")
  999. tumble, _ := c.GetInt64("tumble")
  1000. diacrisis := c.GetString("diacrisis")
  1001. his_department := c.GetString("his_department")
  1002. his_bed := c.GetString("his_bed")
  1003. if id <= 0 {
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. adminUserInfo := c.GetMobileAdminUserInfo()
  1008. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1009. if patient.ID == 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1011. return
  1012. }
  1013. //now := time.Now()
  1014. //year, month, day := now.Date()
  1015. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1016. //todayTimeStamp := today_time.Unix()
  1017. if len(recordDateStr) == 0 {
  1018. recordDateStr = time.Now().Format("2006-01-02")
  1019. }
  1020. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1021. if parseDateErr != nil {
  1022. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. // 查询信息规挡的设置天数
  1027. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1028. if infor.ID > 0 && infor.WeekDay > 0 {
  1029. var cha_time int64
  1030. timeNowStr := time.Now().Format("2006-01-02")
  1031. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1032. //今日的日期减去设置的日期
  1033. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1034. if cha_time >= recordDate.Unix() {
  1035. //查询审核是否允许
  1036. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1037. //申请状态不允许的情况 拒绝修改
  1038. if infor.ApplicationStatus != 1 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1040. return
  1041. }
  1042. }
  1043. }
  1044. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1045. if adminUserInfo.Org.Id == 10340 {
  1046. if condition == 1 {
  1047. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1048. if admission_number == "" {
  1049. admission_number = lastAcceptTreatment.AdmissionNumber
  1050. }
  1051. }
  1052. }
  1053. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1054. UserOrgId: adminUserInfo.Org.Id,
  1055. PatientId: id,
  1056. RecordDate: recordDate.Unix(),
  1057. Way: way,
  1058. Consciousness: consciousness,
  1059. Appetite: appetite,
  1060. Condition: condition,
  1061. SickCondition: sick_condition,
  1062. DangerLevel: danger_level,
  1063. Intake: intake,
  1064. Nutrition: nutrition,
  1065. PsychologicalAssessment: psychological_assessment,
  1066. PsychologicalAssessmentOther: psychological_assessment_other,
  1067. SickConditionOther: sick_condition_other,
  1068. Posture: posture,
  1069. CreatedTime: time.Now().Unix(),
  1070. UpdateTime: time.Now().Unix(),
  1071. Status: 1,
  1072. Score: score,
  1073. Precaution: precaution,
  1074. PrecautionOther: precaution_other,
  1075. PsychologicalOther: psychological_other,
  1076. AdmissionNumber: admission_number,
  1077. Tumble: tumble,
  1078. Diacrisis: diacrisis,
  1079. HisBed: his_bed,
  1080. HisDepartment: his_department,
  1081. }
  1082. if receiveTreatment.ID == 0 { //新增
  1083. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1084. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1085. finish := models.XtDialysisFinish{
  1086. IsFinish: 1,
  1087. UserOrgId: adminUserInfo.Org.Id,
  1088. Status: 1,
  1089. Ctime: time.Now().Unix(),
  1090. Mtime: 0,
  1091. Module: 2,
  1092. RecordDate: recordDate.Unix(),
  1093. Sourse: 1,
  1094. PatientId: id,
  1095. }
  1096. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1097. if dialysisFinish.ID == 0 {
  1098. service.CreateDialysisFinish(finish)
  1099. }
  1100. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1101. redis := service.RedisClient()
  1102. defer redis.Close()
  1103. //清空key 值
  1104. redis.Set(key, "", time.Second)
  1105. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1106. redis.Set(keyOne, "", time.Second)
  1107. if err == nil {
  1108. c.ServeSuccessJSON(map[string]interface{}{
  1109. "receiveTreatmentAsses": receiveTreatmentAsses,
  1110. })
  1111. }
  1112. } else { //修改
  1113. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1114. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1115. // if getPermissionErr != nil {
  1116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. // return
  1118. // } else if headNursePermission == nil {
  1119. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1120. // return
  1121. // }
  1122. //}
  1123. // 查询信息规挡的设置天数
  1124. if adminUserInfo.Org.Id == 10340 {
  1125. if condition == 1 {
  1126. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1127. if receiveTreatmentAsses.AdmissionNumber == "" {
  1128. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1129. }
  1130. }
  1131. }
  1132. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1133. if infor.ID > 0 && infor.WeekDay > 0 {
  1134. var cha_time int64
  1135. timeNowStr := time.Now().Format("2006-01-02")
  1136. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1137. //今日的日期减去设置的日期
  1138. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1139. if cha_time >= recordDate.Unix() {
  1140. //查询审核是否允许
  1141. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1142. //申请状态不允许的情况 拒绝修改
  1143. if infor.ApplicationStatus != 1 {
  1144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1145. return
  1146. }
  1147. }
  1148. }
  1149. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1150. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1151. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1152. receiveTreatmentAsses.ID = receiveTreatment.ID
  1153. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1154. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1155. redis := service.RedisClient()
  1156. defer redis.Close()
  1157. //清空key 值
  1158. redis.Set(key, "", time.Second)
  1159. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1160. redis.Set(keyOne, "", time.Second)
  1161. if err == nil {
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "receiveTreatmentAsses": receiveTreatmentAsses,
  1164. })
  1165. }
  1166. }
  1167. }
  1168. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1169. id, _ := c.GetInt64("patient", 0)
  1170. recordDateStr := c.GetString("record_date")
  1171. weightAfter, _ := c.GetFloat("weight_after", 0)
  1172. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1173. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1174. fmt.Println("weight_loss", weightReduce)
  1175. temperature, _ := c.GetFloat("temperature", 0)
  1176. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1177. breathing_rate := c.GetString("breathing_rate")
  1178. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1179. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1180. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1181. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1182. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1183. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1184. cruor := c.GetString("cruor")
  1185. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1186. internalFistula := c.GetString("internal_fistula")
  1187. catheter := c.GetString("catheter")
  1188. complications := c.GetString("complication")
  1189. remark := c.GetString("remark")
  1190. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1191. dialysis_intakes := c.GetString("dialysis_intakes")
  1192. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1193. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1194. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1195. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1196. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1197. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1198. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1199. patientGose, _ := c.GetInt64("patient_gose", 0)
  1200. inpatientDepartment := c.GetString("inpatient_department")
  1201. observationContent := c.GetString("observation_content")
  1202. observationContentOther := c.GetString("observation_content_other")
  1203. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1204. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1205. in_advance_reason := c.GetString("in_advance_reason")
  1206. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1207. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1208. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1209. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1210. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1211. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1212. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1213. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1214. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1215. is_eat, _ := c.GetInt64("is_eat", 0)
  1216. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1217. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1218. channels, _ := c.GetInt64("channel", 0)
  1219. return_blood, _ := c.GetInt64("return_blood", 0)
  1220. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1221. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1222. dialysis_during, _ := c.GetFloat("dialysis_during")
  1223. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1224. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1225. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1226. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1227. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1228. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1229. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1230. setting_pressure := c.GetString("setting_pressure")
  1231. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1232. diastolic_pressure := c.GetString("diastolic_pressure")
  1233. other_complication := c.GetString("other_complication")
  1234. ktv := c.GetString("ktv")
  1235. urr := c.GetString("urr")
  1236. hypertenison, _ := c.GetInt64("hypertenison")
  1237. hypopiesia, _ := c.GetInt64("hypopiesia")
  1238. leave_office_method, _ := c.GetInt64("leave_office_method")
  1239. lapse, _ := c.GetInt64("lapse")
  1240. consciousness, _ := c.GetInt64("consciousness")
  1241. fallrisk, _ := c.GetInt64("fallrisk")
  1242. machine_run := c.GetString("machine_run")
  1243. after_urea := c.GetString("after_urea")
  1244. pip_coagulation := c.GetString("pip_coagulation")
  1245. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1246. transfusion_volume := c.GetString("transfusion_volume")
  1247. last_after_weight := c.GetString("last_after_weight")
  1248. displace_liqui_value := c.GetString("displace_liqui_value")
  1249. if id <= 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. adminUserInfo := c.GetMobileAdminUserInfo()
  1254. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1255. if patient.ID == 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1257. return
  1258. }
  1259. if len(recordDateStr) == 0 {
  1260. recordDateStr = time.Now().Format("2006-01-02")
  1261. }
  1262. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1263. fmt.Println("parseDateErr", parseDateErr)
  1264. if parseDateErr != nil {
  1265. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. //now := time.Now()
  1270. //year, month, day := now.Date()
  1271. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1272. //todayTimeStamp := today_time.Unix()
  1273. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1274. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1275. UserOrgId: adminUserInfo.Org.Id,
  1276. PatientId: id,
  1277. AssessmentDate: recordDate.Unix(),
  1278. Temperature: temperature,
  1279. PulseFrequency: pulse_frequency,
  1280. BreathingRate: breathing_rate,
  1281. SystolicBloodPressure: systolic_blood_pressure,
  1282. DiastolicBloodPressure: diastolic_blood_pressure,
  1283. ActualUltrafiltration: actual_ultrafiltration,
  1284. ActualDisplacement: actual_displacement,
  1285. ActualTreatmentHour: actualtreatHour,
  1286. ActualTreatmentMinute: actualtreatmin,
  1287. WeightAfter: weightAfter,
  1288. AdditionalWeight: additionalWeight,
  1289. WeightLoss: weightReduce,
  1290. Cruor: cruor,
  1291. SymptomAfterDialysis: symptomsAfterDialysi,
  1292. InternalFistula: internalFistula,
  1293. Catheter: catheter,
  1294. Complication: complications,
  1295. DialysisIntakes: dialysateVolume,
  1296. CreatedTime: time.Now().Unix(),
  1297. UpdatedTime: time.Now().Unix(),
  1298. Status: 1,
  1299. Remark: remark,
  1300. BloodAccessPartId: blood_access_part_id,
  1301. BloodAccessPartOperaId: blood_access_part_opera_id,
  1302. DialysisIntakesUnit: dialysis_intakes_unit,
  1303. PuncturePointOozingBlood: puncturePointOozingBlood,
  1304. PuncturePointHaematoma: puncturePointHaematoma,
  1305. InternalFistulaTremorAc: internalFistulaTremorAc,
  1306. PatientGose: patientGose,
  1307. InpatientDepartment: inpatientDepartment,
  1308. ObservationContent: observationContent,
  1309. ObservationContentOther: observationContentOther,
  1310. DialysisProcess: dialysis_process,
  1311. InAdvanceMinute: in_advance_minute,
  1312. InAdvanceReason: in_advance_reason,
  1313. HemostasisMinute: hemostasis_minute,
  1314. HemostasisOpera: hemostasis_opera,
  1315. TremorNoise: tremor_noise,
  1316. DisequilibriumSyndrome: disequilibrium_syndrome,
  1317. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1318. ArterialTube: arterial_tube,
  1319. IntravenousTube: intravenous_tube,
  1320. Dialyzer: dialyzer,
  1321. InAdvanceReasonOther: in_advance_reason_other,
  1322. IsEat: is_eat,
  1323. CvcA: cvc_a,
  1324. CvcV: cvc_v,
  1325. Channel: channels,
  1326. ReturnBlood: return_blood,
  1327. RehydrationVolume: rehydration_volume,
  1328. DialysisDuring: dialysis_during,
  1329. StrokeVolume: stroke_volume,
  1330. BloodFlow: blood_flow,
  1331. SealingFluidDispose: sealing_fluid_dispose,
  1332. SealingFluidSpecial: sealing_fluid_special,
  1333. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1334. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1335. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1336. SettingPressure: setting_pressure,
  1337. DiastolicPressure: diastolic_pressure,
  1338. OtherComplication: other_complication,
  1339. Ktv: ktv,
  1340. Urr: urr,
  1341. Hypopiesia: hypopiesia,
  1342. Hypertenison: hypertenison,
  1343. Lapse: lapse,
  1344. LeaveOfficeMethod: leave_office_method,
  1345. Consciousness: consciousness,
  1346. Fallrisk: fallrisk,
  1347. MachineRun: machine_run,
  1348. AfterUrea: after_urea,
  1349. PipCoagulation: pip_coagulation,
  1350. AccumulatedBloodVolume: accumulated_blood_volume,
  1351. TransfusionVolume: transfusion_volume,
  1352. LastAfterWeight: last_after_weight,
  1353. DisplaceLiquiValue: displace_liqui_value,
  1354. }
  1355. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1356. // 查询信息规挡的设置天数
  1357. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1358. if infor.ID > 0 && infor.WeekDay > 0 {
  1359. var cha_time int64
  1360. timeNowStr := time.Now().Format("2006-01-02")
  1361. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1362. //今日的日期减去设置的日期
  1363. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1364. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1365. if cha_time >= recordDate.Unix() {
  1366. //查询审核是否允许
  1367. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1368. //申请状态不允许的情况 拒绝修改
  1369. if infor.ApplicationStatus != 1 {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1371. return
  1372. }
  1373. }
  1374. }
  1375. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1376. if assessmentAfter.ID == 0 { //新增
  1377. if appRole.UserType == 2 || appRole.UserType == 1 {
  1378. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1379. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1380. } else {
  1381. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1382. }
  1383. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1384. if assessmentAfterDislysis.UserOrgId != 10340 {
  1385. if assessmentAfterDislysis.WeightAfter == 0 {
  1386. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1387. }
  1388. }
  1389. if adminUserInfo.Org.Id == 10693 {
  1390. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1391. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1392. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1393. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1394. }
  1395. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1396. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1397. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1398. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1399. }
  1400. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1401. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1402. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1403. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1404. }
  1405. if assessmentAfterDislysis.PulseFrequency == 0 {
  1406. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1407. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1408. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1409. }
  1410. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1411. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1412. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1413. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1414. }
  1415. }
  1416. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1417. //记录日志
  1418. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1419. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1420. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1421. PatientId: assessmentAfterDislysis.PatientId,
  1422. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1423. Status: 1,
  1424. ErrLog: string(byterequest),
  1425. AdminUserId: adminUserInfo.AdminUser.Id,
  1426. Ctime: 0,
  1427. Mtime: 0,
  1428. Source: "手机端保存透后评估",
  1429. }
  1430. service.CreateAfterDialysisLog(afterDialysisLog)
  1431. finish := models.XtDialysisFinish{
  1432. IsFinish: 1,
  1433. UserOrgId: adminUserInfo.Org.Id,
  1434. Status: 1,
  1435. Ctime: time.Now().Unix(),
  1436. Mtime: 0,
  1437. Module: 9,
  1438. RecordDate: recordDate.Unix(),
  1439. Sourse: 1,
  1440. PatientId: id,
  1441. }
  1442. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1443. if dialysisFinish.ID == 0 {
  1444. service.CreateDialysisFinish(finish)
  1445. }
  1446. redis := service.RedisClient()
  1447. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1448. redis.Set(keyTwo, "", time.Second)
  1449. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1450. //清空key 值
  1451. redis.Set(key, "", time.Second)
  1452. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1453. redis.Set(keyOne, "", time.Second)
  1454. defer redis.Close()
  1455. if err == nil {
  1456. c.ServeSuccessJSON(map[string]interface{}{
  1457. "assessmentAfterDislysis": assessmentAfterDislysis,
  1458. })
  1459. }
  1460. return
  1461. } else { //修改
  1462. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1463. if infor.ID > 0 && infor.WeekDay > 0 {
  1464. var cha_time int64
  1465. timeNowStr := time.Now().Format("2006-01-02")
  1466. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1467. //今日的日期减去设置的日期
  1468. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1469. if cha_time >= recordDate.Unix() {
  1470. //查询审核是否允许
  1471. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1472. //申请状态不允许的情况 拒绝修改
  1473. if infor.ApplicationStatus != 1 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1475. return
  1476. }
  1477. }
  1478. }
  1479. if appRole.UserType == 2 || appRole.UserType == 1 {
  1480. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1481. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1482. } else {
  1483. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1484. if assessmentAfterDislysis.Creater == 0 {
  1485. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1486. }
  1487. }
  1488. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1489. assessmentAfterDislysis.ID = assessmentAfter.ID
  1490. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1491. if assessmentAfterDislysis.UserOrgId != 10340 {
  1492. if assessmentAfterDislysis.WeightAfter == 0 {
  1493. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1494. }
  1495. }
  1496. if adminUserInfo.Org.Id == 10693 {
  1497. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1498. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1499. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1500. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1501. }
  1502. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1503. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1504. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1505. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1506. }
  1507. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1508. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1509. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1510. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1511. }
  1512. if assessmentAfterDislysis.PulseFrequency == 0 {
  1513. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1514. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1515. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1516. }
  1517. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1518. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1519. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1520. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1521. }
  1522. }
  1523. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1524. //记录日志
  1525. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1526. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1527. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1528. PatientId: assessmentAfterDislysis.PatientId,
  1529. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1530. Status: 1,
  1531. ErrLog: string(byterequest),
  1532. AdminUserId: adminUserInfo.AdminUser.Id,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. Source: "手机端修改保存透后评估",
  1536. }
  1537. service.CreateAfterDialysisLog(afterDialysisLog)
  1538. redis := service.RedisClient()
  1539. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1540. redis.Set(keyTwo, "", time.Second)
  1541. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1542. //清空key 值
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. if err == nil {
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "assessmentAfterDislysis": assessmentAfterDislysis,
  1549. })
  1550. return
  1551. }
  1552. }
  1553. return
  1554. }
  1555. func (c *DialysisAPIController) PostDialysisPrescription() {
  1556. id, _ := c.GetInt64("patient", 0)
  1557. recordDateStr := c.GetString("record_date")
  1558. if id <= 0 {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. adminUserInfo := c.GetMobileAdminUserInfo()
  1563. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1564. if patient.ID == 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1566. return
  1567. }
  1568. if len(recordDateStr) == 0 {
  1569. recordDateStr = time.Now().Format("2006-01-02")
  1570. }
  1571. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1572. if parseDateErr != nil {
  1573. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. mode_id, _ := c.GetInt64("mode_id", 0)
  1578. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1579. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1580. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1581. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1582. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1583. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1584. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1585. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1586. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1587. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1588. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1589. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1590. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1591. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1592. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1593. kalium, _ := c.GetFloat("kalium", 0)
  1594. sodium, _ := c.GetFloat("sodium", 0)
  1595. calcium, _ := c.GetFloat("calcium", 0)
  1596. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1597. glucose, _ := c.GetFloat("glucose", 0)
  1598. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1599. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1600. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1601. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1602. conductivity, _ := c.GetFloat("conductivity", 0)
  1603. remark := c.GetString("remark")
  1604. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1605. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1606. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1607. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1608. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1609. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1610. special_medicine_other := c.GetString("special_medicine_other")
  1611. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1612. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1613. blood_access, _ := c.GetInt64("blood_access", 0)
  1614. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1615. body_fluid_other := c.GetString("body_fluid_other")
  1616. niprocart, _ := c.GetInt64("niprocart", 0)
  1617. jms, _ := c.GetInt64("jms", 0)
  1618. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1619. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1620. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1621. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1622. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1623. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1624. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1625. injector, _ := c.GetInt64("injector", 0)
  1626. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1627. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1628. safe_package, _ := c.GetInt64("package", 0)
  1629. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1630. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1631. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1632. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1633. blood := c.GetString("blood")
  1634. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1635. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1636. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1637. displace_speed := c.GetString("displace_speed")
  1638. illness, _ := c.GetInt64("illness")
  1639. amylaceum := c.GetString("amylaceum")
  1640. single_time := c.GetString("single_time")
  1641. single_water := c.GetString("single_water")
  1642. replacement_flow := c.GetString("replacement_flow")
  1643. plasma_separator := c.GetString("plasma_separator")
  1644. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1645. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1646. oxygen_flow := c.GetString("oxygen_flow")
  1647. oxygen_time := c.GetString("oxygen_time")
  1648. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1649. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1650. puncture_needle := c.GetString("puncture_needle")
  1651. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1652. epo := c.GetString("epo")
  1653. epo_count, _ := c.GetFloat("epo_count", 0)
  1654. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1655. admin_user_id, _ := c.GetInt64("admin_user_id")
  1656. is_water := c.GetString("is_water")
  1657. var is_war int64
  1658. if is_water == "是" {
  1659. is_war = 1
  1660. }
  1661. if is_water == "否" {
  1662. is_war = 2
  1663. }
  1664. if is_water == "请选择" {
  1665. is_war = 0
  1666. }
  1667. drhy_water := c.GetString("drhy_water")
  1668. dry_water_hour := c.GetString("dry_water_hour")
  1669. water_machine := c.GetString("water_machine")
  1670. add_amount, _ := c.GetFloat("add_amount")
  1671. reduce_amount, _ := c.GetFloat("reduce_amount")
  1672. dialysis_remark := c.GetString("dialysis_remark")
  1673. prescribing_number, _ := c.GetFloat("prescribing_number")
  1674. prescription_sodium := c.GetString("prescription_sodium")
  1675. start_sodium := c.GetString("start_sodium")
  1676. sodium_curve := c.GetString("sodium_curve")
  1677. treatment_remark := c.GetString("treatment_remark")
  1678. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1679. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1680. prescription_water, _ := c.GetFloat("prescription_water")
  1681. dialysis_strainer := c.GetString("dialysis_strainer")
  1682. chaptalization := c.GetString("chaptalization")
  1683. washing_time := c.GetString("washing_time")
  1684. warsh_count := c.GetString("warsh_count")
  1685. blood_access_part_id := c.GetString("blood_access_part_id")
  1686. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1687. dialyzate := c.GetString("dialyzate")
  1688. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1689. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1690. //
  1691. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1692. // if appRole.UserType == 3 {
  1693. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1694. // if getPermissionErr != nil {
  1695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. // return
  1697. // } else if headNursePermission == nil {
  1698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1699. // return
  1700. // }
  1701. // }
  1702. //}
  1703. // 查询信息规挡的设置天数
  1704. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1705. if infor.ID > 0 && infor.WeekDay > 0 {
  1706. var cha_time int64
  1707. timeNowStr := time.Now().Format("2006-01-02")
  1708. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1709. //今日的日期减去设置的日期
  1710. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1711. if cha_time >= recordDate.Unix() {
  1712. //查询审核是否允许
  1713. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1714. //申请状态不允许的情况 拒绝修改
  1715. if infor.ApplicationStatus != 1 {
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1717. return
  1718. }
  1719. }
  1720. }
  1721. if mode_id > 0 {
  1722. var str string
  1723. //查找该机构用的是什么透析器
  1724. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1725. if filedConfig.ID > 0 {
  1726. str = dialyzerPerfusionApparatus
  1727. } else {
  1728. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1729. }
  1730. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1731. }
  1732. //TODO 需要根据角色去判断
  1733. prescription := models.DialysisPrescription{
  1734. UserOrgId: adminUserInfo.Org.Id,
  1735. PatientId: id,
  1736. RecordDate: recordDate.Unix(),
  1737. ModeId: mode_id,
  1738. DialysisDuration: dialysis_duration,
  1739. Dialyzer: dialyzer,
  1740. PerfusionApparatus: perfusion_apparatus,
  1741. BloodFlowVolume: blood_flow_volume,
  1742. DewaterAmount: dewater_amount,
  1743. DisplaceLiqui: displace_liqui,
  1744. ReplacementWay: replacement_way,
  1745. Anticoagulant: anticoagulant,
  1746. AnticoagulantShouji: anticoagulant_shouji,
  1747. AnticoagulantWeichi: anticoagulant_weichi,
  1748. AnticoagulantZongliang: anticoagulant_zongliang,
  1749. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1750. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1751. Kalium: kalium,
  1752. Sodium: sodium,
  1753. Calcium: calcium,
  1754. Bicarbonate: bicarbonate,
  1755. Glucose: glucose,
  1756. // DryWeight: dry_weight,
  1757. DialysateFlow: dialysate_flow,
  1758. DialysateTemperature: dialysate_temperature,
  1759. // PrescriptionDoctor: prescription_doctor,
  1760. ReplacementTotal: replacement_total,
  1761. Conductivity: conductivity,
  1762. Remark: remark,
  1763. Status: 1,
  1764. CreatedTime: time.Now().Unix(),
  1765. UpdatedTime: time.Now().Unix(),
  1766. DialysisDurationMinute: dialysisDurationMinute,
  1767. DialysisDurationHour: dialysisDurationHour,
  1768. TargetUltrafiltration: targetUltrafiltration,
  1769. DialysateFormulation: dialysateFormulation,
  1770. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1771. BodyFluid: body_fluid,
  1772. SpecialMedicine: special_medicine,
  1773. SpecialMedicineOther: special_medicine_other,
  1774. DisplaceLiquiPart: displace_liqui_part,
  1775. DisplaceLiquiValue: displace_liqui_value,
  1776. BloodAccess: blood_access,
  1777. Ultrafiltration: ultrafiltration,
  1778. BodyFluidOther: body_fluid_other,
  1779. Niprocart: niprocart,
  1780. Jms: jms,
  1781. FistulaNeedleSet: fistula_needle_set,
  1782. FistulaNeedleSet16: fistula_needle_set_16,
  1783. Hemoperfusion: hemoperfusion,
  1784. DialyserSterilised: dialyser_sterilised,
  1785. Filtryzer: filtryzer,
  1786. Dialyzers: dialyzers,
  1787. Injector: injector,
  1788. Bloodlines: bloodlines,
  1789. TubingHemodialysis: tubing_hemodialysis,
  1790. Package: safe_package,
  1791. ALiquid: a_liquid,
  1792. TargetKtv: target_ktv,
  1793. PreImpulse: pre_impulse,
  1794. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1795. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1796. Blood: blood,
  1797. DialysisDialyszers: dialysis_dialyszers,
  1798. DialysisIrrigation: dialysis_irrigation,
  1799. AntioxidantCommodityName: antioxidant_commodity_name,
  1800. DisplaceSpeed: displace_speed,
  1801. Illness: illness,
  1802. Amylaceum: amylaceum,
  1803. SingleTime: single_time,
  1804. SingleWater: single_water,
  1805. ReplacementFlow: replacement_flow,
  1806. PlasmaSeparator: plasma_separator,
  1807. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1808. OxygenUptake: oxygen_uptake,
  1809. OxygenFlow: oxygen_flow,
  1810. OxygenTime: oxygen_time,
  1811. HemodialysisPipelines: hemodialysis_pipelines,
  1812. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1813. PunctureNeedle: puncture_needle,
  1814. PunctureNeedleCount: puncture_needle_count,
  1815. Epo: epo,
  1816. EpoCount: epo_count,
  1817. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1818. AdminUserId: admin_user_id,
  1819. IsWater: is_war,
  1820. DrhyWater: drhy_water,
  1821. DryWaterHour: dry_water_hour,
  1822. WaterMachine: water_machine,
  1823. AddAmount: add_amount,
  1824. ReduceAmount: reduce_amount,
  1825. DialysisRemark: dialysis_remark,
  1826. PrescribingNumber: prescribing_number,
  1827. StartSodium: start_sodium,
  1828. SodiumCurve: sodium_curve,
  1829. TreatmentRemark: treatment_remark,
  1830. PrescriptionSodium: prescription_sodium,
  1831. DialysisFluidFlow: dialysis_fluid_flow,
  1832. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1833. PrescriptionWater: prescription_water,
  1834. DialysisStrainer: dialysis_strainer,
  1835. Chaptalization: chaptalization,
  1836. WashingTime: washing_time,
  1837. WarshCount: warsh_count,
  1838. BloodAccessPartId: blood_access_part_id,
  1839. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1840. Dialyzate: dialyzate,
  1841. }
  1842. //查询最近透析准备表里是否存在 透析器 灌流器
  1843. //
  1844. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1845. //
  1846. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1847. //
  1848. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1849. //if len(mation)>0{
  1850. // for _, item := range splitStr {
  1851. // for _,it := range mation{
  1852. // if(item == it.SpecificationName){
  1853. //
  1854. // //查询最近一次的透析器
  1855. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1856. //
  1857. // if errcode == gorm.ErrRecordNotFound{
  1858. // //插入数据
  1859. // prepare := models.DialysisBeforePrepare{
  1860. // UserOrgId: adminUserInfo.Org.Id,
  1861. // PatientId: id,
  1862. // RecordDate: recordDate.Unix(),
  1863. // GoodTypeId: it.GoodTypeId,
  1864. // GoodId: it.ID,
  1865. // Count: 1,
  1866. // Ctime: time.Now().Unix(),
  1867. // Creater: adminUserInfo.AdminUser.Id,
  1868. // Status:1,
  1869. //
  1870. // }
  1871. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1872. // fmt.Println("",errcode)
  1873. // }
  1874. // }
  1875. // }
  1876. //
  1877. // }
  1878. //
  1879. // for _, item := range splitIrrigation {
  1880. // for _,it := range mation{
  1881. // if(item == it.SpecificationName){
  1882. // //查询最近一次的透析器
  1883. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1884. // if errcode == gorm.ErrRecordNotFound{
  1885. // //插入数据
  1886. // prepare := models.DialysisBeforePrepare{
  1887. // UserOrgId: adminUserInfo.Org.Id,
  1888. // PatientId: id,
  1889. // RecordDate: recordDate.Unix(),
  1890. // GoodTypeId: it.GoodTypeId,
  1891. // GoodId: it.ID,
  1892. // Count: 1,
  1893. // Ctime: time.Now().Unix(),
  1894. // Creater: adminUserInfo.AdminUser.Id,
  1895. // Status:1,
  1896. //
  1897. // }
  1898. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1899. // fmt.Println(errcode)
  1900. // }
  1901. // }
  1902. // }
  1903. // }
  1904. //}
  1905. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1906. if dialysisPrescription.ID == 0 { //新增
  1907. if appRole.UserType == 2 || appRole.UserType == 1 {
  1908. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1909. }
  1910. prescription.Creater = adminUserInfo.AdminUser.Id
  1911. //针对河间咸得
  1912. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1913. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1914. prescription.DisplaceLiquiPart = 0
  1915. prescription.DisplaceLiquiValue = 0
  1916. }
  1917. }
  1918. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1919. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1920. }
  1921. err := service.AddSigleRecord(&prescription)
  1922. //记录日志
  1923. byterequest, _ := json.Marshal(prescription)
  1924. prescriptionLog := models.XtDialysisPrescriptionLog{
  1925. UserOrgId: prescription.UserOrgId,
  1926. Ctime: time.Now().Unix(),
  1927. Mtime: 0,
  1928. ErrLog: string(byterequest),
  1929. AdminUserId: adminUserInfo.AdminUser.Id,
  1930. RecordDate: prescription.RecordDate,
  1931. PatientId: prescription.PatientId,
  1932. Source: "手机端新增保存处方",
  1933. Status: 1,
  1934. }
  1935. service.CreatePrescriptionLog(prescriptionLog)
  1936. finish := models.XtDialysisFinish{
  1937. IsFinish: 1,
  1938. UserOrgId: adminUserInfo.Org.Id,
  1939. Status: 1,
  1940. Ctime: time.Now().Unix(),
  1941. Mtime: 0,
  1942. Module: 1,
  1943. RecordDate: recordDate.Unix(),
  1944. Sourse: 1,
  1945. PatientId: id,
  1946. }
  1947. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1948. if dialysisFinish.ID == 0 {
  1949. service.CreateDialysisFinish(finish)
  1950. }
  1951. //长沙南雅医院,自动生成抗凝剂的临时处方
  1952. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1953. if prescribing_number == 0 {
  1954. prescribing_number = 1
  1955. }
  1956. if prescribing_number == 0 && id == 14682 {
  1957. prescribing_number = 2
  1958. }
  1959. if prescribing_number == 0 && id == 18560 {
  1960. prescribing_number = 2
  1961. }
  1962. advice := models.DoctorAdvice{
  1963. UserOrgId: adminUserInfo.Org.Id,
  1964. PatientId: id,
  1965. GroupNo: 0,
  1966. AdviceType: 2,
  1967. RecordDate: recordDate.Unix(),
  1968. AdviceDate: recordDate.Unix(),
  1969. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1970. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1971. AdviceDesc: "",
  1972. ReminderDate: 0,
  1973. SingleDose: anticoagulant_zongliang,
  1974. SingleDoseUnit: "iu",
  1975. DrugSpec: 0,
  1976. DrugSpecUnit: "",
  1977. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1978. PrescribingNumberUnit: "支",
  1979. DeliveryWay: "静脉注射",
  1980. ExecutionFrequency: "上机前",
  1981. AdviceDoctor: 0,
  1982. Status: 1,
  1983. CreatedTime: time.Now().Unix(),
  1984. UpdatedTime: time.Now().Unix(),
  1985. IsPrescription: 1,
  1986. ExecutionState: 2,
  1987. StopState: 2,
  1988. IsSettle: 2,
  1989. }
  1990. // 查询排班信息
  1991. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1992. if schedulePatient.ID > 0 {
  1993. if schedulePatient.ScheduleType == 1 {
  1994. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1995. }
  1996. if schedulePatient.ScheduleType == 2 {
  1997. advice.StartTime = recordDate.Unix() + 9*60*60
  1998. }
  1999. }
  2000. // 抗凝剂名称
  2001. switch anticoagulant {
  2002. case 1:
  2003. advice.AdviceName = "无肝素"
  2004. break
  2005. case 2:
  2006. advice.AdviceName = "普通肝素"
  2007. break
  2008. case 3:
  2009. advice.AdviceName = "低分子肝素"
  2010. break
  2011. case 4:
  2012. advice.AdviceName = "阿加曲班"
  2013. break
  2014. case 5:
  2015. advice.AdviceName = "枸橼酸钠"
  2016. break
  2017. case 6:
  2018. advice.AdviceName = "低分子肝素钙"
  2019. break
  2020. case 7:
  2021. advice.AdviceName = "低分子肝素钠"
  2022. break
  2023. case 8:
  2024. advice.AdviceName = "依诺肝素"
  2025. break
  2026. case 9:
  2027. advice.AdviceName = "达肝素"
  2028. break
  2029. case 10:
  2030. advice.AdviceName = "体外抗凝"
  2031. break
  2032. case 11:
  2033. advice.AdviceName = "那曲肝素"
  2034. break
  2035. case 12:
  2036. advice.AdviceName = "无抗凝剂"
  2037. break
  2038. }
  2039. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2040. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2041. advice.AdviceDoctor = appRole.AdminUserId
  2042. }
  2043. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2044. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2045. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2046. advice.AdviceName = "低分子肝素钠注射液"
  2047. // 修改患者临时医嘱里的抗凝剂医嘱
  2048. advice.ID = advicePrescription.ID
  2049. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. } else {
  2051. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2052. advice.AdviceName = "低分子肝素钠注射液"
  2053. // 新增患者临时医嘱里的抗凝剂医嘱
  2054. service.CreateDoctorAdvice(&advice)
  2055. }
  2056. }
  2057. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2058. redis := service.RedisClient()
  2059. defer redis.Close()
  2060. //清空key 值
  2061. redis.Set(key, "", time.Second)
  2062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2063. redis.Set(keyOne, "", time.Second)
  2064. }
  2065. //获取key,清空redis
  2066. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2067. redis := service.RedisClient()
  2068. //清空key 值
  2069. redis.Set(key, "", time.Second)
  2070. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2071. //清空key 值
  2072. redis.Set(keyOne, "", time.Second)
  2073. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2074. //清空key 值
  2075. redis.Set(keyTwo, "", time.Second)
  2076. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2077. redis.Set(keySix, "", time.Second)
  2078. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2079. redis.Set(keySeven, "", time.Second)
  2080. if err == nil {
  2081. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2082. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2083. //清空key 值
  2084. redis.Set(keyThree, "", time.Second)
  2085. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2086. //清空key 值
  2087. redis.Set(keyFour, "", time.Second)
  2088. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2089. redis.Set(keyFive, "", time.Second)
  2090. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2091. redis.Set(keySix, "", time.Second)
  2092. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2093. redis.Set(keySeven, "", time.Second)
  2094. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2095. //清空key 值
  2096. redis.Set(keyOne, "", time.Second)
  2097. if updateErr != nil {
  2098. utils.ErrorLog("%v", updateErr)
  2099. }
  2100. defer redis.Close()
  2101. c.ServeSuccessJSON(map[string]interface{}{
  2102. "prescription": prescription,
  2103. })
  2104. }
  2105. } else { //修改
  2106. //if mode_id > 0 {
  2107. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2108. //}
  2109. //if template.TemplateId == 1 {
  2110. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2112. // if getPermissionErr != nil {
  2113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. // return
  2115. // } else if headNursePermission == nil {
  2116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2117. // return
  2118. // }
  2119. // }
  2120. //}
  2121. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2122. prescription.Modifier = adminUserInfo.AdminUser.Id
  2123. if appRole.UserType == 2 || appRole.UserType == 1 {
  2124. prescription_doctor := adminUserInfo.AdminUser.Id
  2125. prescription.PrescriptionDoctor = prescription_doctor
  2126. } else {
  2127. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2128. }
  2129. if dialysisPrescription.Creater == 0 { //体重称
  2130. prescription.Creater = adminUserInfo.AdminUser.Id
  2131. } else {
  2132. prescription.Creater = dialysisPrescription.Creater
  2133. if adminUserInfo.Org.Id == 9882 {
  2134. if appRole.UserType == 2 || appRole.UserType == 1 {
  2135. prescription_doctor := adminUserInfo.AdminUser.Id
  2136. prescription.PrescriptionDoctor = prescription_doctor
  2137. prescription.Creater = prescription_doctor
  2138. }
  2139. }
  2140. }
  2141. prescription.ID = dialysisPrescription.ID
  2142. service.UpDateDialysisPrescription(&prescription)
  2143. //记录日志
  2144. byterequest, _ := json.Marshal(prescription)
  2145. prescriptionLog := models.XtDialysisPrescriptionLog{
  2146. UserOrgId: prescription.UserOrgId,
  2147. Ctime: time.Now().Unix(),
  2148. Mtime: 0,
  2149. ErrLog: string(byterequest),
  2150. AdminUserId: adminUserInfo.AdminUser.Id,
  2151. RecordDate: prescription.RecordDate,
  2152. PatientId: prescription.PatientId,
  2153. Source: "手机端修改处方",
  2154. Status: 1,
  2155. }
  2156. service.CreatePrescriptionLog(prescriptionLog)
  2157. finish := models.XtDialysisFinish{
  2158. IsFinish: 1,
  2159. UserOrgId: adminUserInfo.Org.Id,
  2160. Status: 1,
  2161. Ctime: time.Now().Unix(),
  2162. Mtime: 0,
  2163. Module: 1,
  2164. RecordDate: recordDate.Unix(),
  2165. Sourse: 1,
  2166. PatientId: id,
  2167. }
  2168. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2169. if dialysisFinish.ID == 0 {
  2170. service.CreateDialysisFinish(finish)
  2171. }
  2172. //修改处方
  2173. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2174. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2175. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2176. if advicePrescription.ID > 0 {
  2177. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2178. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2179. redis := service.RedisClient()
  2180. defer redis.Close()
  2181. //清空key 值
  2182. redis.Set(key, "", time.Second)
  2183. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2184. redis.Set(keyOne, "", time.Second)
  2185. }
  2186. }
  2187. //获取key,清空redis
  2188. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2189. redis := service.RedisClient()
  2190. //清空key 值
  2191. redis.Set(key, "", time.Second)
  2192. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2193. //清空key 值
  2194. redis.Set(keyOne, "", time.Second)
  2195. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2196. redis.Set(keySix, "", time.Second)
  2197. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2198. redis.Set(keySeven, "", time.Second)
  2199. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2200. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2201. //清空key 值
  2202. redis.Set(keyTwoOne, "", time.Second)
  2203. defer redis.Close()
  2204. if updateErr != nil {
  2205. utils.ErrorLog("%v", updateErr)
  2206. }
  2207. c.ServeSuccessJSON(map[string]interface{}{
  2208. "prescription": prescription,
  2209. })
  2210. }
  2211. }
  2212. func (c *DialysisAPIController) Finish() {
  2213. id, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. nurseID, _ := c.GetInt64("nurse")
  2216. end_time := c.GetString("end_time")
  2217. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2218. internal_fistula := c.GetString("blood_access_internal_fistula")
  2219. catheter := c.GetString("catheter")
  2220. cruor := c.GetString("cruor")
  2221. mission := c.GetString("mission")
  2222. condenser := c.GetString("condenser")
  2223. if id <= 0 || nurseID <= 0 {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. adminUserInfo := c.GetMobileAdminUserInfo()
  2228. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2229. if patient.ID == 0 {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2231. return
  2232. }
  2233. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2234. if getNurseErr != nil {
  2235. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2237. return
  2238. } else if nurse == nil {
  2239. c.ErrorLog("护士不存在")
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2241. return
  2242. }
  2243. if len(recordDateStr) == 0 {
  2244. recordDateStr = time.Now().Format("2006-01-02")
  2245. }
  2246. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2247. if parseDateErr != nil {
  2248. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2253. if parseEndDateErr != nil {
  2254. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. // 查询信息规挡的设置天数
  2259. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2260. if infor.ID > 0 && infor.WeekDay > 0 {
  2261. var cha_time int64
  2262. timeNowStr := time.Now().Format("2006-01-02")
  2263. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2264. //今日的日期减去设置的日期
  2265. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2266. if cha_time >= recordDate.Unix() {
  2267. //查询审核是否允许
  2268. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2269. //申请状态不允许的情况 拒绝修改
  2270. if infor.ApplicationStatus != 1 {
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2272. return
  2273. }
  2274. }
  2275. }
  2276. //now := time.Now()
  2277. //year, month, day := now.Date()
  2278. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2279. //todayTimeStamp := today_time.Unix()
  2280. // 获取当天的第一条透析纪录
  2281. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2282. if getMonitorRecordsErr != nil {
  2283. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2285. return
  2286. }
  2287. // 获取当前的最后一条透析纪录
  2288. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2289. if getMonitorRecordsErr != nil {
  2290. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2292. return
  2293. }
  2294. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2295. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2296. if getAADErr != nil {
  2297. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. }
  2301. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2302. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2303. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2304. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2305. if assessmentAfterDislysis != nil {
  2306. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2307. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2308. } else {
  2309. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2310. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2311. tempassessmentAfterDislysis.Status = 1
  2312. tempassessmentAfterDislysis.PatientId = id
  2313. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2314. }
  2315. //长沙南雅
  2316. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2317. //获取最后一条透析处方数据
  2318. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2319. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2320. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2321. }
  2322. if dialysisOrder.Stage == 1 {
  2323. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2324. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2325. fmt.Println(value)
  2326. a, b := math.Modf(value)
  2327. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2328. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2329. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2330. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2331. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2332. }
  2333. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2334. //var num1 int64
  2335. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2336. //fmt.Println(num1)
  2337. //sub := float64(num1 / 3600)
  2338. //fmt.Println(sub)
  2339. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2340. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2341. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2342. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2343. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2344. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2345. if adminUserInfo.Org.Id != 10375 {
  2346. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2347. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2348. }
  2349. if adminUserInfo.Org.Id != 10445 {
  2350. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2351. }
  2352. //北方营口医院
  2353. if adminUserInfo.Org.Id == 10445 {
  2354. //获取最后一条透析处方数据
  2355. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2356. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2357. } else {
  2358. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2359. }
  2360. //新化博翔
  2361. if adminUserInfo.Org.Id == 10447 {
  2362. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2363. }
  2364. //阳春
  2365. if adminUserInfo.Org.Id == 10485 {
  2366. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2367. }
  2368. if adminUserInfo.Org.Id == 10551 {
  2369. //获取最后一条透析处方数据
  2370. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2371. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2372. }
  2373. if adminUserInfo.Org.Id == 10580 {
  2374. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2375. }
  2376. if adminUserInfo.Org.Id == 10612 {
  2377. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2378. }
  2379. //孝康
  2380. if adminUserInfo.Org.Id == 10693 {
  2381. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2382. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2383. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2384. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2385. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2386. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2387. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2388. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2389. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2390. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2391. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2392. }
  2393. if adminUserInfo.Org.Id == 10697 {
  2394. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2395. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2396. lastWeightAfter.LastAfterWeight = floatAfeter
  2397. }
  2398. }
  2399. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 {
  2400. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2401. if evaluation.SystolicBloodPressure == 0 {
  2402. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2403. if adminUserInfo.Org.Id == 10693 {
  2404. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2405. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2406. }
  2407. pre := models.PredialysisEvaluation{
  2408. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2409. }
  2410. fmt.Println("prew", pre)
  2411. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2412. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2413. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2414. redis := service.RedisClient()
  2415. redis.Set(key, "", time.Second)
  2416. redis.Set(keyOne, "", time.Second)
  2417. defer redis.Close()
  2418. fmt.Println(getNurseErr)
  2419. }
  2420. if evaluation.DiastolicBloodPressure == 0 {
  2421. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2422. if adminUserInfo.Org.Id == 10693 {
  2423. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2424. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2425. }
  2426. pres := models.PredialysisEvaluation{
  2427. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2428. }
  2429. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2430. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2431. redis := service.RedisClient()
  2432. redis.Set(key, "", time.Second)
  2433. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2434. redis.Set(keyOne, "", time.Second)
  2435. defer redis.Close()
  2436. fmt.Println(getNurseErr)
  2437. }
  2438. if evaluation.PulseFrequency == 0 {
  2439. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2440. if adminUserInfo.Org.Id == 10693 {
  2441. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2442. evaluation.PulseFrequency = pulseFrequency
  2443. }
  2444. press := models.PredialysisEvaluation{
  2445. PulseFrequency: evaluation.PulseFrequency,
  2446. }
  2447. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2449. redis := service.RedisClient()
  2450. redis.Set(key, "", time.Second)
  2451. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2452. redis.Set(keyOne, "", time.Second)
  2453. defer redis.Close()
  2454. fmt.Println(getNurseErr)
  2455. }
  2456. if evaluation.Temperature == 0 {
  2457. evaluation.Temperature = fmonitorRecords.Temperature
  2458. press := models.PredialysisEvaluation{
  2459. Temperature: evaluation.Temperature,
  2460. }
  2461. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2462. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2463. redis := service.RedisClient()
  2464. redis.Set(key, "", time.Second)
  2465. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2466. redis.Set(keyOne, "", time.Second)
  2467. defer redis.Close()
  2468. fmt.Println(getNurseErr)
  2469. }
  2470. }
  2471. if adminUserInfo.Org.Id == 9583 {
  2472. //获取透析处方的最后一条数据
  2473. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2474. if diaerr != nil {
  2475. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2477. return
  2478. }
  2479. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2480. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2481. }
  2482. }
  2483. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2484. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2487. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2488. }
  2489. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2490. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2491. }
  2492. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2493. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2494. }
  2495. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2496. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2497. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2498. }
  2499. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2500. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2501. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2502. }
  2503. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2504. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2505. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2506. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2507. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2508. }
  2509. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2510. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2511. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2512. }
  2513. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2514. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2515. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2516. }
  2517. if lastAssessmentAfterDislysis != nil {
  2518. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2519. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2520. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2521. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2522. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2523. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2524. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2525. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2526. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2527. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2528. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2529. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2530. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2531. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2532. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2533. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2534. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2535. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2536. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2537. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2538. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2539. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2540. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2541. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2542. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2543. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2544. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2545. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2546. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2547. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2548. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2549. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2550. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2551. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2552. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2553. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2554. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2555. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2556. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2557. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2558. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2559. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2560. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2561. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2562. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2563. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2564. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2565. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2566. if tempassessmentAfterDislysis.PatientId == 18695 {
  2567. tempassessmentAfterDislysis.ActualDisplacement = 0
  2568. }
  2569. if adminUserInfo.Org.Id != 10375 {
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2571. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2572. }
  2573. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2574. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2576. }
  2577. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2578. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2579. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2580. }
  2581. }
  2582. finish := models.XtDialysisFinish{
  2583. IsFinish: 1,
  2584. UserOrgId: adminUserInfo.Org.Id,
  2585. Status: 1,
  2586. Ctime: time.Now().Unix(),
  2587. Mtime: 0,
  2588. Module: 9,
  2589. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2590. Sourse: 1,
  2591. PatientId: tempassessmentAfterDislysis.PatientId,
  2592. }
  2593. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2594. if dialysisFinish.ID == 0 {
  2595. service.CreateDialysisFinish(finish)
  2596. }
  2597. //孝康
  2598. if adminUserInfo.Org.Id == 10693 {
  2599. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2600. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2601. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2602. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2603. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2604. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2605. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2606. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2607. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2608. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2609. }
  2610. if adminUserInfo.Org.Id == 10697 {
  2611. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2612. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2613. lastWeightAfter.LastAfterWeight = floatAfeter
  2614. }
  2615. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2616. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2617. redis := service.RedisClient()
  2618. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2619. redis.Set(keyOne, "", time.Second)
  2620. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2621. redis.Set(keyTwo, "", time.Second)
  2622. defer redis.Close()
  2623. //清空key 值
  2624. redis.Set(key, "", time.Second)
  2625. if err != nil {
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2627. return
  2628. }
  2629. if dialysisOrder == nil {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2631. return
  2632. }
  2633. if dialysisOrder.Stage == 2 {
  2634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2635. return
  2636. }
  2637. if dialysisOrder.Stage == 1 {
  2638. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2639. finish := models.XtDialysisFinish{
  2640. IsFinish: 1,
  2641. UserOrgId: adminUserInfo.Org.Id,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Module: 8,
  2646. RecordDate: recordDate.Unix(),
  2647. Sourse: 1,
  2648. PatientId: id,
  2649. }
  2650. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2651. if dialysisFinish.ID == 0 {
  2652. service.CreateDialysisFinish(finish)
  2653. }
  2654. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2655. redis := service.RedisClient()
  2656. defer redis.Close()
  2657. //清空key 值
  2658. redis.Set(key, "", time.Second)
  2659. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2660. redis.Set(keyOne, "", time.Second)
  2661. //结束时候透析次数加1
  2662. service.UpdateSolutionByPatientId(id)
  2663. //下机完自动消毒,针对长沙南雅
  2664. if dialysisOrder.Stage == 1 {
  2665. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2666. //根据床位号获取设备型号
  2667. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2668. //查询使用消毒最后一条消毒记录
  2669. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2670. fmt.Println("err", err)
  2671. if err == gorm.ErrRecordNotFound {
  2672. //查找排班
  2673. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2674. //查询改设备是否有消毒计划
  2675. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2676. //根据床位号获取设备id
  2677. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2678. //查询病人信息
  2679. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2680. var con = ""
  2681. if patients.IsInfectious == 0 {
  2682. con = ""
  2683. }
  2684. if patients.IsInfectious == 1 {
  2685. con = "无"
  2686. }
  2687. if patients.IsInfectious == 2 {
  2688. con = "有"
  2689. }
  2690. if errcode == nil {
  2691. var end_time int64
  2692. end_time = endDate.Unix() + plan.DisinfecTime*60
  2693. //新增消毒
  2694. information := models.DeviceInformation{
  2695. Date: dialysisOrder.DialysisDate,
  2696. Zone: dialysisOrder.ZoneId,
  2697. Class: dialysisOrder.SchedualType,
  2698. BedNumber: dialysisOrder.BedID,
  2699. PatientId: dialysisOrder.PatientId,
  2700. DialysisMode: scheduleByPatient.ModeId,
  2701. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2702. Disinfection: 1,
  2703. DialysisConcentration: 1,
  2704. DisinfectionStatus: 1,
  2705. Move: 1,
  2706. UserOrgId: dialysisOrder.UserOrgId,
  2707. DisinfectType: plan.Way,
  2708. DisinfectantType: plan.MachineDisinfectant,
  2709. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2710. Disinfectant: plan.Disinfectant,
  2711. Ctime: time.Now().Unix(),
  2712. Status: 1,
  2713. SignName: nurseID,
  2714. EquimentId: addmacher.ID,
  2715. DisinfectionResidue: 2,
  2716. Bed: addmacher.BedNumber,
  2717. StartTime: dialysisOrder.StartTime,
  2718. EndTime: dialysisOrder.EndTime,
  2719. Contagion: con,
  2720. WeightLoss: 0,
  2721. Hyperfiltratio: 0,
  2722. DialysisHour: "",
  2723. MachineRun: 1,
  2724. DisinfecStartime: endDate.Unix(),
  2725. DisinfecEndtime: end_time,
  2726. }
  2727. err := service.CreateInformationTwo(&information)
  2728. fmt.Println("报错", err)
  2729. }
  2730. }
  2731. }
  2732. }
  2733. dialysisOrder.Stage = 2
  2734. dialysisOrder.FinishNurse = nurseID
  2735. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2736. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2737. dialysisOrder.EndTime = endDate.Unix()
  2738. // 长沙南雅需求
  2739. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2740. //获取最后1条监测的数据
  2741. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2742. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2743. var accumulatedBloodVolume float64
  2744. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2745. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2746. fmt.Println(err)
  2747. // 查询未执行的医嘱
  2748. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2749. for _, item := range doctorAdvice {
  2750. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2751. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2752. redis := service.RedisClient()
  2753. //清空key 值
  2754. redis.Set(key, "", time.Second)
  2755. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2756. redis.Set(keyTwo, "", time.Second)
  2757. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2758. redis.Set(keyThree, "", time.Second)
  2759. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2760. theTime := toTime.Format("2006-01-02")
  2761. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2762. redis.Set(keyFour, "", time.Second)
  2763. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2764. redis.Set(keyFive, "", time.Second)
  2765. defer redis.Close()
  2766. }
  2767. }
  2768. go func() {
  2769. ssoDomain := beego.AppConfig.String("call_domain")
  2770. api := ssoDomain + "/index/downpatient"
  2771. values := make(url.Values)
  2772. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2773. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2774. values.Set("patient_id", strconv.FormatInt(id, 10))
  2775. http.PostForm(api, values)
  2776. }()
  2777. if err == nil {
  2778. c.ServeSuccessJSON(map[string]interface{}{
  2779. "dialysisOrder": dialysisOrder,
  2780. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2781. })
  2782. } else {
  2783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2784. }
  2785. }
  2786. }
  2787. func (c *DialysisAPIController) GetAllZone() {
  2788. adminUserInfo := c.GetMobileAdminUserInfo()
  2789. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2790. if err == nil {
  2791. c.ServeSuccessJSON(map[string]interface{}{
  2792. "zone": zone,
  2793. })
  2794. }
  2795. }
  2796. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2797. adminUserInfo := c.GetMobileAdminUserInfo()
  2798. page, _ := c.GetInt64("page", 1)
  2799. limit, _ := c.GetInt64("limit", 10)
  2800. schedulType, _ := c.GetInt64("schedul_type", 0)
  2801. startTime, _ := c.GetInt64("schedul_time", 0)
  2802. partitionType, _ := c.GetInt64("partition_type", 0)
  2803. keywords := c.GetString("keywords")
  2804. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2805. if err == nil {
  2806. c.ServeSuccessJSON(map[string]interface{}{
  2807. "schedule": dialysisSchedule,
  2808. })
  2809. }
  2810. return
  2811. }
  2812. // /m/api/dialysis/start [post]
  2813. // @param patient_id:int
  2814. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2815. // @param nurse:int 上机护士
  2816. // @param bed:int 床位号
  2817. func (this *DialysisAPIController) StartDialysis() {
  2818. patientID, _ := this.GetInt64("patient_id")
  2819. recordDateStr := this.GetString("record_date")
  2820. nurseID, _ := this.GetInt64("start_nurse")
  2821. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2822. blood_drawing, _ := this.GetInt64("blood_drawing")
  2823. schedual_type, _ := this.GetInt64("schedual_type")
  2824. bedID, _ := this.GetInt64("bed")
  2825. start_time := this.GetString("start_time")
  2826. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2827. change_nurse, _ := this.GetInt64("change_nurse")
  2828. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2829. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2830. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2831. puncture_needle := this.GetString("puncture_needle")
  2832. puncture_way := this.GetString("puncture_way")
  2833. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2834. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2835. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2836. zone_id, _ := this.GetInt64("zone_id")
  2837. elecsign := this.GetString("url")
  2838. nuclein_date_str := this.GetString("nuclein_date_str")
  2839. schedule_remark := this.GetString("schedule_remark")
  2840. order_remark := this.GetString("order_remark")
  2841. catheter_operation := this.GetString("catheter_operation")
  2842. blood_flow_volume := this.GetString("blood_flow_volume")
  2843. dialysis_strainer := this.GetString("dialysis_strainer")
  2844. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2846. return
  2847. }
  2848. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2849. if parseStartDateErr != nil {
  2850. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2852. return
  2853. }
  2854. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2855. if parseErr != nil {
  2856. this.ErrorLog("时间解析失败:%v", parseErr)
  2857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2858. return
  2859. }
  2860. adminUserInfo := this.GetMobileAdminUserInfo()
  2861. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2862. if getPatientErr != nil {
  2863. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2865. return
  2866. } else if patient == nil {
  2867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2868. return
  2869. }
  2870. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2871. if getNurseErr != nil {
  2872. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2874. return
  2875. } else if nurse == nil {
  2876. this.ErrorLog("护士不存在")
  2877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2881. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2882. if getDeviceNumberErr != nil {
  2883. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. return
  2886. } else if deviceNumber == nil {
  2887. this.ErrorLog("床位号不存在")
  2888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2889. return
  2890. }
  2891. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2892. if getRecordErr != nil {
  2893. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2895. return
  2896. } else if dialysisRecord != nil {
  2897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2898. return
  2899. }
  2900. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2901. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2902. timeLayout := "2006-01-02 15:04:05"
  2903. loc, _ := time.LoadLocation("Local")
  2904. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2905. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2906. schedulestartTime := theStartTime.Unix()
  2907. scheduleendTime := theEndTime.Unix()
  2908. var theNucleinDate int64
  2909. timeLayoutOne := "2006-01-02"
  2910. if len(nuclein_date_str) > 0 {
  2911. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2912. if err != nil {
  2913. utils.ErrorLog(err.Error())
  2914. }
  2915. theNucleinDate = theTime.Unix()
  2916. }
  2917. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2918. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2919. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2920. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2921. //查询该床位是否有人用了
  2922. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2923. if err == gorm.ErrRecordNotFound { //空床位
  2924. // 修改了床位逻辑
  2925. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2926. if daySchedule.ID > 0 {
  2927. daySchedule.PartitionId = deviceNumber.ZoneID
  2928. daySchedule.BedId = bedID
  2929. daySchedule.ScheduleType = schedual_type
  2930. daySchedule.UpdatedTime = time.Now().Unix()
  2931. xtSchedule := models.Schedule{
  2932. PartitionId: deviceNumber.ZoneID,
  2933. BedId: bedID,
  2934. ScheduleType: schedual_type,
  2935. UpdatedTime: time.Now().Unix(),
  2936. }
  2937. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2938. if err != nil {
  2939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2940. return
  2941. }
  2942. }
  2943. } else if err == nil {
  2944. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2945. if order.ID > 0 { //该机位被其他人占用了
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2947. return
  2948. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2949. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2950. if daySchedule.ID > 0 {
  2951. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2952. if err != nil {
  2953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2954. return
  2955. }
  2956. }
  2957. }
  2958. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2960. return
  2961. }
  2962. //else if order.ID == 0 { //该床位没被占用
  2963. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2964. // if daySchedule.ID > 0 {
  2965. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2966. // //daySchedule.BedId = bedID
  2967. // //daySchedule.ScheduleType = schedual_type
  2968. // //daySchedule.UpdatedTime = time.Now().Unix()
  2969. // //err := service.UpdateSchedule(&daySchedule)
  2970. // xtSchedule := models.Schedule{
  2971. // PartitionId: deviceNumber.ZoneID,
  2972. // BedId: bedID,
  2973. // ScheduleType: schedual_type,
  2974. // UpdatedTime: time.Now().Unix(),
  2975. // }
  2976. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2977. // if err != nil {
  2978. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. // return
  2980. // }
  2981. // }
  2982. //}
  2983. //}
  2984. } else if err != nil {
  2985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. return
  2987. }
  2988. // 查询信息规挡的设置天数
  2989. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2990. if infor.ID > 0 && infor.WeekDay > 0 {
  2991. var cha_time int64
  2992. timeNowStr := time.Now().Format("2006-01-02")
  2993. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2994. //今日的日期减去设置的日期
  2995. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2996. if cha_time >= recordDate.Unix() {
  2997. //查询审核是否允许
  2998. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2999. //申请状态不允许的情况 拒绝修改
  3000. if infor.ApplicationStatus != 1 {
  3001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3002. return
  3003. }
  3004. }
  3005. }
  3006. dialysisRecord = &models.DialysisOrder{
  3007. DialysisDate: recordDate.Unix(),
  3008. UserOrgId: adminUserInfo.Org.Id,
  3009. PatientId: patientID,
  3010. Stage: 1,
  3011. BedID: bedID,
  3012. StartNurse: nurseID,
  3013. Status: 1,
  3014. StartTime: startDate.Unix(),
  3015. CreatedTime: time.Now().Unix(),
  3016. UpdatedTime: time.Now().Unix(),
  3017. PunctureNurse: puncture_nurse,
  3018. Creator: adminUserInfo.AdminUser.Id,
  3019. Modifier: adminUserInfo.AdminUser.Id,
  3020. SchedualType: schedual_type,
  3021. WashpipeNurse: washpipe_nurse,
  3022. ChangeNurse: change_nurse,
  3023. DifficultPunctureNurse: difficult_puncture_nurse,
  3024. NewFistulaNurse: new_fistula_nurse,
  3025. ZoneId: zone_id,
  3026. QualityNurseId: quality_nurse_id,
  3027. PunctureNeedle: puncture_needle,
  3028. PunctureWay: puncture_way,
  3029. DialysisIrrigation: dialysis_irrigation,
  3030. DialysisDialyszers: dialysis_dialyszers,
  3031. BloodAccessId: blood_access_id,
  3032. Url: elecsign,
  3033. NucleinDate: theNucleinDate,
  3034. ScheduleRemark: schedule_remark,
  3035. OrderRemark: order_remark,
  3036. CatheterOperation: catheter_operation,
  3037. BloodFlowVolume: blood_flow_volume,
  3038. BloodDrawing: blood_drawing,
  3039. DialysisStrainer: dialysis_strainer,
  3040. }
  3041. //查询该床位是否有人用了
  3042. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3043. if errorscode == gorm.ErrRecordNotFound {
  3044. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminUserInfo.Org.Id,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 6,
  3052. RecordDate: schedulestartTime,
  3053. Sourse: 1,
  3054. PatientId: patientID,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3061. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3062. //统计该患者总次数
  3063. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3064. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3065. }
  3066. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3067. //统计该患者总次数
  3068. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3069. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3070. }
  3071. redis := service.RedisClient()
  3072. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3073. redis.Set(key, "", time.Second)
  3074. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3075. //清空key 值
  3076. redis.Set(keyOne, "", time.Second)
  3077. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3078. //清空key 值
  3079. redis.Set(keyTwo, "", time.Second)
  3080. if createErr != nil {
  3081. this.ErrorLog("上机失败:%v", createErr)
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. return
  3084. }
  3085. }
  3086. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3087. var tempdispose string
  3088. // 只针对中能建
  3089. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3090. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3091. }
  3092. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3093. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3094. }
  3095. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3096. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3097. //}
  3098. var ultrafiltration_rate float64
  3099. var ultrafiltration_rate_one string
  3100. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3101. //后期预增脱水量
  3102. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3103. if prescription.ID > 0 {
  3104. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3105. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3106. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3107. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3108. }
  3109. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3110. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3111. }
  3112. //针对医师汇
  3113. if adminUserInfo.Org.Id == 10121 {
  3114. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3115. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3116. }
  3117. //针对通道
  3118. if adminUserInfo.Org.Id == 10234 {
  3119. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3120. }
  3121. //针对监利大垸医院
  3122. if template.TemplateId == 41 {
  3123. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3124. }
  3125. //针对肇庆三鹤血液透析中心
  3126. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3127. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3128. }
  3129. if adminUserInfo.Org.Id == 10469 {
  3130. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3131. }
  3132. if adminUserInfo.Org.Id == 10667 {
  3133. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3134. }
  3135. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3137. }
  3138. // 只针对方济医院
  3139. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3140. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3141. ultrafiltration_rate = value
  3142. }
  3143. //针对
  3144. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3145. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3146. ultrafiltration_rate = ultrafiltration_rate / 1000
  3147. }
  3148. if adminUserInfo.Org.Id == 10551 {
  3149. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3150. ultrafiltration_rate = ultrafiltration_rate / 1000
  3151. }
  3152. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3154. ultrafiltration_rate = ultrafiltration_rate / 1000
  3155. }
  3156. if adminUserInfo.Org.Id == 10580 {
  3157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3158. ultrafiltration_rate = ultrafiltration_rate / 1000
  3159. }
  3160. if adminUserInfo.Org.Id == 10629 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate / 1000
  3163. }
  3164. if adminUserInfo.Org.Id == 10644 {
  3165. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3166. ultrafiltration_rate = ultrafiltration_rate / 1000
  3167. }
  3168. if adminUserInfo.Org.Id == 10667 {
  3169. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3170. ultrafiltration_rate = ultrafiltration_rate / 1000
  3171. }
  3172. if adminUserInfo.Org.Id == 10693 {
  3173. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3174. ultrafiltration_rate = ultrafiltration_rate
  3175. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3176. }
  3177. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3178. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3179. ultrafiltration_rate = ultrafiltration_rate
  3180. }
  3181. if adminUserInfo.Org.Id == 10702 {
  3182. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3183. ultrafiltration_rate = ultrafiltration_rate / 1000
  3184. }
  3185. }
  3186. }
  3187. record := models.MonitoringRecord{
  3188. UserOrgId: adminUserInfo.Org.Id,
  3189. PatientId: patientID,
  3190. DialysisOrderId: dialysisRecord.ID,
  3191. MonitoringDate: schedulestartTime,
  3192. OperateTime: startDate.Unix(),
  3193. // MonitoringTime: recordTime,
  3194. MonitoringNurse: nurseID,
  3195. Dispose: tempdispose,
  3196. UltrafiltrationRate: ultrafiltration_rate,
  3197. UltrafiltrationVolume: 0,
  3198. Status: 1,
  3199. CreatedTime: time.Now().Unix(),
  3200. UpdatedTime: time.Now().Unix(),
  3201. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3202. }
  3203. //只针对广慈医院
  3204. 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 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 {
  3205. // 查询病人是否有透前评估数据
  3206. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3207. //如果有数据就插入
  3208. if errcode == nil {
  3209. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3210. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3211. record.BreathingRate = befor.BreathingRate
  3212. record.PulseFrequency = befor.PulseFrequency
  3213. record.Temperature = befor.Temperature
  3214. }
  3215. }
  3216. //孝昌
  3217. if adminUserInfo.Org.Id == 10693 {
  3218. // 查询病人是否有透前评估数据
  3219. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3220. //如果有数据就插入
  3221. if errcode == nil {
  3222. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3223. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3224. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3225. record.BreathingRate = befor.BreathingRate
  3226. }
  3227. }
  3228. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3229. if newdialysisRecord.ID > 0 {
  3230. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3231. record.Temperature = 36.5
  3232. record.ArterialPressure = -100
  3233. record.DialysateTemperature = 36.5
  3234. record.Conductivity = 14
  3235. record.BreathingRate = "20"
  3236. record.VenousPressure = 80
  3237. record.TransmembranePressure = 60
  3238. record.Dispose = catheter_operation
  3239. }
  3240. //针对新化博翔
  3241. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3242. record.BloodOxygenSaturation = "99"
  3243. record.Conductivity = 14
  3244. record.DialysateTemperature = 36.5
  3245. record.BreathingRate = "20"
  3246. }
  3247. //针对兰溪人民医院的需求
  3248. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3249. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3250. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3251. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3252. record.Temperature = befor.Temperature
  3253. record.PulseFrequency = befor.PulseFrequency
  3254. record.BreathingRate = befor.BreathingRate
  3255. }
  3256. //针对乐山友谊医院的需求
  3257. if adminUserInfo.Org.Id == 10677 {
  3258. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3259. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3260. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3261. record.Temperature = befor.Temperature
  3262. record.PulseFrequency = befor.PulseFrequency
  3263. record.BreathingRate = befor.BreathingRate
  3264. }
  3265. //新化博翔
  3266. if adminUserInfo.Org.Id == 10447 {
  3267. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3268. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3269. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3270. record.BreathingRate = befor.BreathingRate
  3271. }
  3272. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3273. record.PulseFrequency = 80
  3274. record.Temperature = 36.5
  3275. }
  3276. //诊断灵山圣康
  3277. if adminUserInfo.Org.Id == 10375 {
  3278. record.Conductivity = 13.8
  3279. record.DialysateTemperature = 37
  3280. record.DialysateFlow = 500
  3281. record.BloodFlowVolume = 200
  3282. record.BreathingRate = "18"
  3283. record.SodiumConcentration = 140
  3284. }
  3285. //江成肾病医院
  3286. if adminUserInfo.Org.Id == 10517 {
  3287. record.SodiumConcentration = 138
  3288. record.DialysateTemperature = 36.5
  3289. }
  3290. if adminUserInfo.Org.Id != 10683 {
  3291. err = service.CreateMonitor(&record)
  3292. }
  3293. //记录日志
  3294. byterequest, _ := json.Marshal(record)
  3295. monitorRecordLog := models.XtMonitorRecordLog{
  3296. RecordDate: record.MonitoringDate,
  3297. PatientId: record.PatientId,
  3298. Module: 1,
  3299. AdminUserId: adminUserInfo.AdminUser.Id,
  3300. Ctime: time.Now().Unix(),
  3301. Mtime: 0,
  3302. Status: 1,
  3303. UserOrgId: record.UserOrgId,
  3304. ErrLog: string(byterequest),
  3305. Source: "执行上机时新增监测",
  3306. }
  3307. service.CreateMonitorRecordLog(monitorRecordLog)
  3308. finish := models.XtDialysisFinish{
  3309. IsFinish: 1,
  3310. UserOrgId: adminUserInfo.Org.Id,
  3311. Status: 1,
  3312. Ctime: time.Now().Unix(),
  3313. Mtime: 0,
  3314. Module: 7,
  3315. RecordDate: schedulestartTime,
  3316. Sourse: 1,
  3317. PatientId: patientID,
  3318. }
  3319. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3320. if dialysisFinish.ID == 0 {
  3321. service.CreateDialysisFinish(finish)
  3322. }
  3323. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3324. redis := service.RedisClient()
  3325. //清空key 值
  3326. redis.Set(key, "", time.Second)
  3327. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3328. redis.Set(keyOne, "", time.Second)
  3329. defer redis.Close()
  3330. if err != nil {
  3331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3332. return
  3333. }
  3334. }
  3335. go func() {
  3336. ssoDomain := beego.AppConfig.String("call_domain")
  3337. api := ssoDomain + "/index/uppatient"
  3338. values := make(url.Values)
  3339. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3340. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3341. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3342. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3343. http.PostForm(api, values)
  3344. }()
  3345. this.ServeSuccessJSON(map[string]interface{}{
  3346. "dialysis_order": newdialysisRecord,
  3347. "monitor": record,
  3348. })
  3349. return
  3350. }
  3351. func (c *DialysisAPIController) PostSolution() {
  3352. id, _ := c.GetInt64("patient", 0)
  3353. recordDateStr := c.GetString("record_date")
  3354. if id <= 0 {
  3355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3356. return
  3357. }
  3358. adminUserInfo := c.GetMobileAdminUserInfo()
  3359. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3360. if patient.ID == 0 {
  3361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3362. return
  3363. }
  3364. if len(recordDateStr) == 0 {
  3365. recordDateStr = time.Now().Format("2006-01-02")
  3366. }
  3367. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3368. if parseDateErr != nil {
  3369. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3371. return
  3372. }
  3373. mode_id, _ := c.GetInt64("mode_id", 0)
  3374. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3375. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3376. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3377. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3378. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3379. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3380. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3381. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3382. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3383. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3384. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3385. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3386. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3387. kalium, _ := c.GetFloat("kalium", 0)
  3388. sodium, _ := c.GetFloat("sodium", 0)
  3389. calcium, _ := c.GetFloat("calcium", 0)
  3390. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3391. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3392. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3393. glucose, _ := c.GetFloat("glucose", 0)
  3394. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3395. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3396. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3397. conductivity, _ := c.GetFloat("conductivity", 0)
  3398. remark := c.GetString("remark")
  3399. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3400. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3401. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3402. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3403. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3404. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3405. special_medicine_other := c.GetString("special_medicine_other")
  3406. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3407. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3408. blood_access, _ := c.GetInt64("blood_access", 0)
  3409. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3410. body_fluid_other := c.GetString("body_fluid_other")
  3411. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3412. niprocart, _ := c.GetInt64("niprocart", 0)
  3413. jms, _ := c.GetInt64("jms", 0)
  3414. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3415. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3416. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3417. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3418. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3419. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3420. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3421. injector, _ := c.GetInt64("injector", 0)
  3422. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3423. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3424. safe_package, _ := c.GetInt64("package", 0)
  3425. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3426. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3427. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3428. blood := c.GetString("blood")
  3429. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3430. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3431. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3432. displace_speed := c.GetString("displace_speed")
  3433. illness, _ := c.GetInt64("illness")
  3434. amylaceum := c.GetString("amylaceum")
  3435. single_time := c.GetString("single_time")
  3436. single_water := c.GetString("single_water")
  3437. replacement_flow := c.GetString("replacement_flow")
  3438. plasma_separator := c.GetString("plasma_separator")
  3439. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3440. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3441. oxygen_flow := c.GetString("oxygen_flow")
  3442. oxygen_time := c.GetString("oxygen_time")
  3443. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3444. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3445. puncture_needle := c.GetString("puncture_needle")
  3446. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3447. epo := c.GetString("epo")
  3448. epo_count, _ := c.GetFloat("epo_count", 0)
  3449. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3450. pre_impulse := c.GetString("pre_impulse")
  3451. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3452. admin_user_id, _ := c.GetInt64("admin_user_id")
  3453. is_water := c.GetString("is_water")
  3454. add_amount, _ := c.GetFloat("add_amount")
  3455. reduce_amount, _ := c.GetFloat("reduce_amount")
  3456. prescribing_number, _ := c.GetFloat("prescribing_number")
  3457. treatment_remark := c.GetString("treatment_remark")
  3458. prescription_sodium := c.GetString("prescription_sodium")
  3459. start_sodium := c.GetString("start_sodium")
  3460. sodium_curve := c.GetString("sodium_curve")
  3461. var is_war int64
  3462. if is_water == "是" {
  3463. is_war = 1
  3464. }
  3465. if is_water == "否" {
  3466. is_war = 2
  3467. }
  3468. if is_water == "请选择" {
  3469. is_war = 0
  3470. }
  3471. drhy_water := c.GetString("drhy_water")
  3472. dry_water_hour := c.GetString("dry_water_hour")
  3473. water_machine := c.GetString("water_machine")
  3474. dialysis_remark := c.GetString("dialysis_remark")
  3475. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3476. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3477. prescription_water, _ := c.GetFloat("prescription_water")
  3478. dialysis_strainer := c.GetString("dialysis_strainer")
  3479. chaptalization := c.GetString("chaptalization")
  3480. washing_time := c.GetString("washing_time")
  3481. warsh_count := c.GetString("warsh_count")
  3482. blood_access_part_id := c.GetString("blood_access_part_id")
  3483. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3484. dialyzate := c.GetString("dialyzate")
  3485. if mode_id > 0 {
  3486. var str string
  3487. //查找该机构用的是什么透析器
  3488. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3489. if filedConfig.ID > 0 {
  3490. str = dialyzerPerfusionApparatus
  3491. } else {
  3492. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3493. }
  3494. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3495. }
  3496. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3497. //
  3498. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3499. // if appRole.UserType == 3 {
  3500. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3501. // if getPermissionErr != nil {
  3502. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3503. // return
  3504. // } else if headNursePermission == nil {
  3505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3506. // return
  3507. // }
  3508. // }
  3509. //}
  3510. // 查询信息规挡的设置天数
  3511. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3512. if infor.ID > 0 && infor.WeekDay > 0 {
  3513. var cha_time int64
  3514. timeNowStr := time.Now().Format("2006-01-02")
  3515. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3516. //今日的日期减去设置的日期
  3517. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3518. if cha_time >= recordDate.Unix() {
  3519. //查询审核是否允许
  3520. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3521. //申请状态不允许的情况 拒绝修改
  3522. if infor.ApplicationStatus != 1 {
  3523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3524. return
  3525. }
  3526. }
  3527. }
  3528. prescription := models.DialysisPrescription{
  3529. UserOrgId: adminUserInfo.Org.Id,
  3530. PatientId: id,
  3531. RecordDate: recordDate.Unix(),
  3532. ModeId: mode_id,
  3533. DialysisDuration: dialysis_duration,
  3534. Dialyzer: dialyzer,
  3535. PerfusionApparatus: perfusion_apparatus,
  3536. BloodFlowVolume: blood_flow_volume,
  3537. DewaterAmount: dewater_amount,
  3538. DisplaceLiqui: displace_liqui,
  3539. ReplacementWay: replacement_way,
  3540. Anticoagulant: anticoagulant,
  3541. AnticoagulantShouji: anticoagulant_shouji,
  3542. AnticoagulantWeichi: anticoagulant_weichi,
  3543. AnticoagulantZongliang: anticoagulant_zongliang,
  3544. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3545. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3546. Kalium: kalium,
  3547. Sodium: sodium,
  3548. Calcium: calcium,
  3549. Bicarbonate: bicarbonate,
  3550. Glucose: glucose,
  3551. // DryWeight: dry_weight,
  3552. DialysateFlow: dialysate_flow,
  3553. DialysateTemperature: dialysate_temperature,
  3554. Conductivity: conductivity,
  3555. Remark: remark,
  3556. Status: 1,
  3557. CreatedTime: time.Now().Unix(),
  3558. UpdatedTime: time.Now().Unix(),
  3559. DialysisDurationMinute: dialysisDurationMinute,
  3560. DialysisDurationHour: dialysisDurationHour,
  3561. TargetUltrafiltration: targetUltrafiltration,
  3562. DialysateFormulation: dialysateFormulation,
  3563. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3564. BodyFluid: body_fluid,
  3565. SpecialMedicine: special_medicine,
  3566. SpecialMedicineOther: special_medicine_other,
  3567. DisplaceLiquiPart: displace_liqui_part,
  3568. DisplaceLiquiValue: displace_liqui_value,
  3569. BloodAccess: blood_access,
  3570. Ultrafiltration: ultrafiltration,
  3571. BodyFluidOther: body_fluid_other,
  3572. ReplacementTotal: replacement_total,
  3573. Niprocart: niprocart,
  3574. Jms: jms,
  3575. FistulaNeedleSet: fistula_needle_set,
  3576. FistulaNeedleSet16: fistula_needle_set_16,
  3577. Hemoperfusion: hemoperfusion,
  3578. DialyserSterilised: dialyser_sterilised,
  3579. Filtryzer: filtryzer,
  3580. TargetKtv: target_ktv,
  3581. Dialyzers: dialyzers,
  3582. Injector: injector,
  3583. Bloodlines: bloodlines,
  3584. TubingHemodialysis: tubing_hemodialysis,
  3585. Package: safe_package,
  3586. ALiquid: a_liquid,
  3587. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3588. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3589. Blood: blood,
  3590. DialysisDialyszers: dialysis_dialyszers,
  3591. DialysisIrrigation: dialysis_irrigation,
  3592. AntioxidantCommodityName: antioxidant_commodity_name,
  3593. DisplaceSpeed: displace_speed,
  3594. Illness: illness,
  3595. Amylaceum: amylaceum,
  3596. SingleWater: single_water,
  3597. SingleTime: single_time,
  3598. ReplacementFlow: replacement_flow,
  3599. PlasmaSeparator: plasma_separator,
  3600. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3601. OxygenUptake: oxygen_uptake,
  3602. OxygenTime: oxygen_time,
  3603. OxygenFlow: oxygen_flow,
  3604. HemodialysisPipelines: hemodialysis_pipelines,
  3605. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3606. PunctureNeedle: puncture_needle,
  3607. PunctureNeedleCount: puncture_needle_count,
  3608. Epo: epo,
  3609. EpoCount: epo_count,
  3610. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3611. PreImpulse: impulse,
  3612. AdminUserId: admin_user_id,
  3613. IsWater: is_war,
  3614. DrhyWater: drhy_water,
  3615. DryWaterHour: dry_water_hour,
  3616. WaterMachine: water_machine,
  3617. AddAmount: add_amount,
  3618. ReduceAmount: reduce_amount,
  3619. DialysisRemark: dialysis_remark,
  3620. PrescribingNumber: prescribing_number,
  3621. PrescriptionSodium: prescription_sodium,
  3622. StartSodium: start_sodium,
  3623. SodiumCurve: sodium_curve,
  3624. TreatmentRemark: treatment_remark,
  3625. DialysisFluidFlow: dialysis_fluid_flow,
  3626. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3627. PrescriptionWater: prescription_water,
  3628. DialysisStrainer: dialysis_strainer,
  3629. Chaptalization: chaptalization,
  3630. WashingTime: washing_time,
  3631. WarshCount: warsh_count,
  3632. BloodAccessPartId: blood_access_part_id,
  3633. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3634. Dialyzate: dialyzate,
  3635. }
  3636. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3637. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3638. //
  3639. if appRole.UserType == 2 || appRole.UserType == 1 {
  3640. prescription_doctor = adminUserInfo.AdminUser.Id
  3641. prescription.PrescriptionDoctor = prescription_doctor
  3642. }
  3643. if dialysisPrescription.ID == 0 { //新增
  3644. prescription.Creater = adminUserInfo.AdminUser.Id
  3645. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3646. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3647. }
  3648. } else { //修改
  3649. if dialysisPrescription.Creater == 0 {
  3650. prescription.Creater = adminUserInfo.AdminUser.Id
  3651. } else {
  3652. prescription.Creater = dialysisPrescription.Creater
  3653. if adminUserInfo.Org.Id == 9882 {
  3654. if appRole.UserType == 2 || appRole.UserType == 1 {
  3655. prescription.Creater = adminUserInfo.AdminUser.Id
  3656. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3657. }
  3658. }
  3659. }
  3660. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3661. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3662. }
  3663. //if/**/
  3664. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3665. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3666. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3667. // if getPermissionErr != nil {
  3668. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3669. // return
  3670. // } else if headNursePermission == nil {
  3671. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3672. // return
  3673. // }
  3674. //}
  3675. //prescription.Creater = dialysisPrescription.Creater
  3676. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3677. prescription.Modifier = adminUserInfo.AdminUser.Id
  3678. prescription.ID = dialysisPrescription.ID
  3679. }
  3680. solution := models.DialysisSolution{
  3681. RegistrarsId: adminUserInfo.AdminUser.Id,
  3682. UserOrgId: adminUserInfo.Org.Id,
  3683. Doctor: prescription_doctor,
  3684. PatientId: id,
  3685. ModeId: mode_id,
  3686. DialysisDuration: dialysis_duration,
  3687. PerfusionApparatus: perfusion_apparatus,
  3688. BloodFlowVolume: blood_flow_volume,
  3689. Dewater: dewater_amount,
  3690. DisplaceLiqui: displace_liqui,
  3691. ReplacementWay: replacement_way,
  3692. Anticoagulant: anticoagulant,
  3693. AnticoagulantShouji: anticoagulant_shouji,
  3694. AnticoagulantWeichi: anticoagulant_weichi,
  3695. AnticoagulantZongliang: anticoagulant_zongliang,
  3696. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3697. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3698. Kalium: kalium,
  3699. Sodium: sodium,
  3700. Calcium: calcium,
  3701. Bicarbonate: bicarbonate,
  3702. Glucose: glucose,
  3703. // DryWeight: dry_weight,
  3704. DialysateFlow: dialysate_flow,
  3705. DialysateTemperature: dialysate_temperature,
  3706. Conductivity: conductivity,
  3707. Remark: remark,
  3708. Status: 1,
  3709. CreatedTime: time.Now().Unix(),
  3710. UpdatedTime: time.Now().Unix(),
  3711. DialysisDurationMinute: dialysisDurationMinute,
  3712. DialysisDurationHour: dialysisDurationHour,
  3713. TargetUltrafiltration: targetUltrafiltration,
  3714. DialysateFormulation: dialysateFormulation,
  3715. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3716. BodyFluid: body_fluid,
  3717. SpecialMedicine: special_medicine,
  3718. SpecialMedicineOther: special_medicine_other,
  3719. DisplaceLiquiPart: displace_liqui_part,
  3720. DisplaceLiquiValue: displace_liqui_value,
  3721. BloodAccess: blood_access,
  3722. Ultrafiltration: ultrafiltration,
  3723. BodyFluidOther: body_fluid_other,
  3724. ReplacementTotal: replacement_total,
  3725. TargetKtv: target_ktv,
  3726. DialysisDialyszers: dialysis_dialyszers,
  3727. DialysisIrrigation: dialysis_irrigation,
  3728. HemodialysisPipelines: hemodialysis_pipelines,
  3729. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3730. PunctureNeedle: puncture_needle,
  3731. PunctureNeedleCount: puncture_needle_count,
  3732. Epo: epo,
  3733. EpoCount: epo_count,
  3734. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3735. PreImpulse: impulse,
  3736. SolutionStatus: 1,
  3737. DialysisRemark: dialysis_remark,
  3738. PrescribingNumber: prescribing_number,
  3739. PrescriptionSodium: prescription_sodium,
  3740. StartSodium: start_sodium,
  3741. SodiumCurve: sodium_curve,
  3742. TreatmentRemark: treatment_remark,
  3743. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3744. DialysisFluidFlow: dialysis_fluid_flow,
  3745. PrescriptionWater: prescription_water,
  3746. DialysisStrainer: dialysis_strainer,
  3747. Chaptalization: chaptalization,
  3748. WashingTime: washing_time,
  3749. WarshCount: warsh_count,
  3750. BloodAccessPartId: blood_access_part_id,
  3751. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3752. Dialyzate: dialyzate,
  3753. }
  3754. //针对河间咸的
  3755. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3756. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3757. solution.DisplaceLiquiPart = 0
  3758. solution.DisplaceLiquiValue = 0
  3759. }
  3760. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3761. prescription.DisplaceLiquiPart = 0
  3762. prescription.DisplaceLiquiValue = 0
  3763. }
  3764. }
  3765. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3766. if solution.PrescribingNumber == 0 {
  3767. solution.PrescribingNumber = 1
  3768. }
  3769. if prescription.PrescribingNumber == 0 {
  3770. prescription.PrescribingNumber = 1
  3771. }
  3772. if solution.PrescribingNumber == 0 && id == 14682 {
  3773. solution.PrescribingNumber = 2
  3774. }
  3775. if solution.PrescribingNumber == 0 && id == 18560 {
  3776. solution.PrescribingNumber = 2
  3777. }
  3778. if prescription.PrescribingNumber == 0 && id == 14682 {
  3779. prescription.PrescribingNumber = 2
  3780. }
  3781. if prescription.PrescribingNumber == 0 && id == 18560 {
  3782. prescription.PrescribingNumber = 2
  3783. }
  3784. }
  3785. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3786. //记录日志
  3787. byterequest, _ := json.Marshal(prescription)
  3788. prescriptionLog := models.XtDialysisPrescriptionLog{
  3789. UserOrgId: prescription.UserOrgId,
  3790. Ctime: time.Now().Unix(),
  3791. Mtime: 0,
  3792. ErrLog: string(byterequest),
  3793. AdminUserId: adminUserInfo.AdminUser.Id,
  3794. RecordDate: prescription.RecordDate,
  3795. PatientId: prescription.PatientId,
  3796. Source: "手机端新增长期处方",
  3797. Status: 1,
  3798. }
  3799. service.CreatePrescriptionLog(prescriptionLog)
  3800. finish := models.XtDialysisFinish{
  3801. IsFinish: 1,
  3802. UserOrgId: adminUserInfo.Org.Id,
  3803. Status: 1,
  3804. Ctime: time.Now().Unix(),
  3805. Mtime: 0,
  3806. Module: 1,
  3807. RecordDate: recordDate.Unix(),
  3808. Sourse: 1,
  3809. PatientId: id,
  3810. }
  3811. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3812. if dialysisFinish.ID == 0 {
  3813. service.CreateDialysisFinish(finish)
  3814. }
  3815. //获取最新1条
  3816. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3817. //更新状态
  3818. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3819. //长沙南雅医院,自动生成抗凝剂的临时处方
  3820. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3821. if prescribing_number == 0 {
  3822. prescribing_number = 1
  3823. }
  3824. advice := models.DoctorAdvice{
  3825. UserOrgId: adminUserInfo.Org.Id,
  3826. PatientId: id,
  3827. GroupNo: 0,
  3828. AdviceType: 2,
  3829. RecordDate: recordDate.Unix(),
  3830. AdviceDate: recordDate.Unix(),
  3831. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3832. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3833. AdviceDesc: "",
  3834. ReminderDate: 0,
  3835. SingleDose: prescription.AnticoagulantZongliang,
  3836. SingleDoseUnit: "iu",
  3837. DrugSpec: 0,
  3838. DrugSpecUnit: "",
  3839. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3840. PrescribingNumberUnit: "支",
  3841. DeliveryWay: "静脉注射",
  3842. ExecutionFrequency: "上机前",
  3843. AdviceDoctor: 0,
  3844. Status: 1,
  3845. CreatedTime: time.Now().Unix(),
  3846. UpdatedTime: time.Now().Unix(),
  3847. IsPrescription: 1,
  3848. ExecutionState: 2,
  3849. StopState: 2,
  3850. IsSettle: 2,
  3851. }
  3852. // 查询排班信息
  3853. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3854. if schedulePatient.ID > 0 {
  3855. if schedulePatient.ScheduleType == 1 {
  3856. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3857. }
  3858. if schedulePatient.ScheduleType == 2 {
  3859. advice.StartTime = recordDate.Unix() + 9*60*60
  3860. }
  3861. }
  3862. // 抗凝剂名称
  3863. switch anticoagulant {
  3864. case 1:
  3865. advice.AdviceName = "无肝素"
  3866. break
  3867. case 2:
  3868. advice.AdviceName = "普通肝素"
  3869. break
  3870. case 3:
  3871. advice.AdviceName = "低分子肝素"
  3872. break
  3873. case 4:
  3874. advice.AdviceName = "阿加曲班"
  3875. break
  3876. case 5:
  3877. advice.AdviceName = "枸橼酸钠"
  3878. break
  3879. case 6:
  3880. advice.AdviceName = "低分子肝素钙"
  3881. break
  3882. case 7:
  3883. advice.AdviceName = "低分子肝素钠"
  3884. break
  3885. case 8:
  3886. advice.AdviceName = "依诺肝素"
  3887. break
  3888. case 9:
  3889. advice.AdviceName = "达肝素"
  3890. break
  3891. case 10:
  3892. advice.AdviceName = "体外抗凝"
  3893. break
  3894. case 11:
  3895. advice.AdviceName = "那曲肝素"
  3896. break
  3897. case 12:
  3898. advice.AdviceName = "无抗凝剂"
  3899. break
  3900. }
  3901. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3902. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3903. advice.AdviceDoctor = appRole.AdminUserId
  3904. }
  3905. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3906. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3907. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3908. advice.AdviceName = "低分子肝素钠注射液"
  3909. // 修改患者临时医嘱里的抗凝剂医嘱
  3910. advice.ID = advicePrescription.ID
  3911. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3912. } else {
  3913. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3914. advice.AdviceName = "低分子肝素钠注射液"
  3915. service.CreateDoctorAdvice(&advice)
  3916. }
  3917. }
  3918. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3919. redis := service.RedisClient()
  3920. defer redis.Close()
  3921. //清空key 值
  3922. redis.Set(key, "", time.Second)
  3923. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3924. redis.Set(keyOne, "", time.Second)
  3925. }
  3926. //获取key,清空redis
  3927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3928. redis := service.RedisClient()
  3929. defer redis.Close()
  3930. //清空key 值
  3931. redis.Set(key, "", time.Second)
  3932. //清空长期医嘱的key
  3933. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3934. redis.Set(soulution_key, "", time.Second)
  3935. //查询最近透析准备表里是否存在 透析器 灌流器
  3936. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3937. redis.Set(keyOne, "", time.Second)
  3938. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3939. redis.Set(keyTwo, "", time.Second)
  3940. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3941. redis.Set(keyThree, "", time.Second)
  3942. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3943. redis.Set(keyFour, "", time.Second)
  3944. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3945. //
  3946. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3947. //
  3948. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3949. //if len(mation)>0{
  3950. // for _, item := range splitStr {
  3951. // for _,it := range mation{
  3952. // if(item == it.SpecificationName){
  3953. //
  3954. // //查询最近一次的透析器
  3955. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3956. //
  3957. // if errcode == gorm.ErrRecordNotFound{
  3958. // //插入数据
  3959. // prepare := models.DialysisBeforePrepare{
  3960. // UserOrgId: adminUserInfo.Org.Id,
  3961. // PatientId: id,
  3962. // RecordDate: recordDate.Unix(),
  3963. // GoodTypeId: it.GoodTypeId,
  3964. // GoodId: it.ID,
  3965. // Count: 1,
  3966. // Ctime: time.Now().Unix(),
  3967. // Creater: adminUserInfo.AdminUser.Id,
  3968. // Status:1,
  3969. //
  3970. // }
  3971. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3972. // fmt.Println("",errcode)
  3973. // }
  3974. // }
  3975. // }
  3976. //
  3977. // }
  3978. //
  3979. // for _, item := range splitIrrigation {
  3980. // for _,it := range mation{
  3981. // if(item == it.SpecificationName){
  3982. // //查询最近一次的透析器
  3983. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3984. // if errcode == gorm.ErrRecordNotFound{
  3985. // //插入数据
  3986. // prepare := models.DialysisBeforePrepare{
  3987. // UserOrgId: adminUserInfo.Org.Id,
  3988. // PatientId: id,
  3989. // RecordDate: recordDate.Unix(),
  3990. // GoodTypeId: it.GoodTypeId,
  3991. // GoodId: it.ID,
  3992. // Count: 1,
  3993. // Ctime: time.Now().Unix(),
  3994. // Creater: adminUserInfo.AdminUser.Id,
  3995. // Status:1,
  3996. //
  3997. // }
  3998. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3999. // fmt.Println(errcode)
  4000. // }
  4001. // }
  4002. // }
  4003. // }
  4004. //}
  4005. c.ServeSuccessJSON(map[string]interface{}{
  4006. "solution": &solution,
  4007. "prescription": &prescription,
  4008. })
  4009. }
  4010. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4011. patient, _ := c.GetInt64("patient", 0)
  4012. adminUserInfo := c.GetMobileAdminUserInfo()
  4013. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4014. c.ServeSuccessJSON(map[string]interface{}{
  4015. "receiveTreatmentAsses": receiveTreatmentAsses,
  4016. })
  4017. }
  4018. func (this *DialysisAPIController) PostSignInfo() {
  4019. patientID, _ := this.GetInt64("patient_id")
  4020. recordDateStr := this.GetString("date")
  4021. if patientID <= 0 {
  4022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4023. return
  4024. }
  4025. if len(recordDateStr) == 0 {
  4026. recordDateStr = time.Now().Format("2006-01-02")
  4027. }
  4028. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4029. if parseDateErr != nil {
  4030. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4031. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4032. return
  4033. }
  4034. adminInfo := this.GetMobileAdminUserInfo()
  4035. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4036. if err != nil {
  4037. this.ErrorLog("签名失败:%v", err)
  4038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4039. return
  4040. }
  4041. this.ServeSuccessJSON(map[string]interface{}{
  4042. "doctor_id": adminInfo.AdminUser.Id,
  4043. })
  4044. }
  4045. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4046. patientID, _ := this.GetInt64("patient_id")
  4047. adminInfo := this.GetMobileAdminUserInfo()
  4048. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4049. this.ServeSuccessJSON(map[string]interface{}{
  4050. "monitor": record,
  4051. })
  4052. }
  4053. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4054. thisTime := time.Now()
  4055. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4056. timeLayout := "2006-01-02 15:04:05"
  4057. loc, _ := time.LoadLocation("Local")
  4058. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4059. theAssessmentDateTime := theStartTime.Unix()
  4060. patientID, _ := this.GetInt64("patient_id")
  4061. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4062. adminInfo := this.GetMobileAdminUserInfo()
  4063. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4064. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4065. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4066. var ultrafiltration_rate float64
  4067. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4068. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4069. fmt.Println(evaluation)
  4070. fmt.Println("prescription.ID", prescription.ID)
  4071. if prescription.ID > 0 {
  4072. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4073. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4074. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4075. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4076. record.UltrafiltrationRate = ultrafiltration_rate
  4077. }
  4078. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4079. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4080. record.UltrafiltrationRate = ultrafiltration_rate
  4081. }
  4082. if adminInfo.Org.Id == 10510 {
  4083. record.UltrafiltrationRate = 0
  4084. }
  4085. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4086. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4087. record.UltrafiltrationRate = ultrafiltration_rate
  4088. }
  4089. if template.TemplateId == 20 || template.TemplateId == 22 {
  4090. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4091. record.UltrafiltrationRate = ultrafiltration_rate
  4092. }
  4093. // 只针对方济医院
  4094. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4095. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4096. ultrafiltration_rate = value
  4097. record.UltrafiltrationRate = ultrafiltration_rate
  4098. }
  4099. if template.TemplateId == 41 || template.TemplateId == 47 {
  4100. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4101. record.UltrafiltrationRate = ultrafiltration_rate
  4102. }
  4103. if template.TemplateId == 43 {
  4104. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4105. record.UltrafiltrationRate = ultrafiltration_rate
  4106. }
  4107. if template.TemplateId == 46 || template.TemplateId == 54 {
  4108. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4109. record.UltrafiltrationRate = ultrafiltration_rate
  4110. }
  4111. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4112. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4113. record.UltrafiltrationRate = ultrafiltration_rate
  4114. }
  4115. if adminInfo.Org.Id == 10469 {
  4116. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4117. record.UltrafiltrationRate = ultrafiltration_rate
  4118. }
  4119. if adminInfo.Org.Id == 10667 {
  4120. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4121. record.UltrafiltrationRate = ultrafiltration_rate
  4122. }
  4123. if adminInfo.Org.Id == 10471 {
  4124. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4125. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4126. }
  4127. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4128. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4129. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4130. }
  4131. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4132. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4133. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4134. }
  4135. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4136. record.UltrafiltrationRate = 0
  4137. }
  4138. //if template.TemplateId == 47 {
  4139. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4140. // record.UltrafiltrationRate = ultrafiltration_rate
  4141. //}
  4142. }
  4143. }
  4144. // record.UltrafiltrationRate = ultrafiltration_rate
  4145. record.UltrafiltrationVolume = 0
  4146. 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
  4147. if ultrafiltration_rate > 0 {
  4148. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4149. record.UltrafiltrationVolume = value
  4150. }
  4151. }
  4152. if template.TemplateId == 6 || template.TemplateId == 65 || 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 == 10599 { //adminInfo.Org.Id == 9538
  4153. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4154. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4155. record.UltrafiltrationVolume = ultrafiltration_volume
  4156. }
  4157. }
  4158. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4159. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4160. record.UltrafiltrationVolume = ultrafiltration_volume
  4161. }
  4162. //长沙南雅
  4163. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4164. if ultrafiltration_rate > 0 {
  4165. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4166. record.UltrafiltrationVolume = ultrafiltration_volume
  4167. }
  4168. }
  4169. if adminInfo.Org.Id == 10471 {
  4170. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4171. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4172. }
  4173. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4174. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4175. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4176. }
  4177. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4178. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4179. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4180. }
  4181. //长沙南雅累计血容量自动计算
  4182. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4183. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4184. //}
  4185. if template.TemplateId == 47 || template.TemplateId == 54 {
  4186. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4187. }
  4188. if adminInfo.Org.Id == 10510 {
  4189. record.UltrafiltrationVolume = 0
  4190. }
  4191. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4192. this.ServeSuccessJSON(map[string]interface{}{
  4193. "monitor": record,
  4194. "lastMonitorRecordList": lastMonitorRecordList,
  4195. })
  4196. }
  4197. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4198. record_id, _ := this.GetInt64("id")
  4199. nurseID, _ := this.GetInt64("start_nurse")
  4200. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4201. bedID, _ := this.GetInt64("bed")
  4202. start_time := this.GetString("start_time")
  4203. schedual_type, _ := this.GetInt64("schedual_type")
  4204. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4205. change_nurse, _ := this.GetInt64("change_nurse")
  4206. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4207. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4208. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4209. patient_id, _ := this.GetInt64("patient_id")
  4210. record_date, _ := this.GetInt64("record_date")
  4211. puncture_needle := this.GetString("puncture_needle")
  4212. puncture_way := this.GetString("puncture_way")
  4213. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4214. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4215. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4216. nuclein_date_str := this.GetString("nuclein_date_str")
  4217. order_remark := this.GetString("order_remark")
  4218. schedule_remark := this.GetString("schedule_remark")
  4219. catheter_operation := this.GetString("catheter_operation")
  4220. blood_flow_volume := this.GetString("blood_flow_volume")
  4221. blood_drawing, _ := this.GetInt64("blood_drawing")
  4222. dialysis_strainer := this.GetString("dialysis_strainer")
  4223. if record_id == 0 {
  4224. this.ErrorLog("id:%v", record_id)
  4225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. return
  4227. }
  4228. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4229. if parseStartDateErr != nil {
  4230. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4232. return
  4233. }
  4234. adminUserInfo := this.GetMobileAdminUserInfo()
  4235. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4236. if getNurseErr != nil {
  4237. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4239. return
  4240. } else if nurse == nil {
  4241. this.ErrorLog("护士不存在")
  4242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4243. return
  4244. }
  4245. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4246. //if getNurseErr != nil {
  4247. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4248. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4249. // return
  4250. //} else if nurse == nil {
  4251. // this.ErrorLog("护士不存在")
  4252. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4253. // return
  4254. //}
  4255. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4256. if getDeviceNumberErr != nil {
  4257. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4258. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4259. return
  4260. } else if deviceNumber == nil {
  4261. this.ErrorLog("床位号不存在")
  4262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4263. return
  4264. }
  4265. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4266. //
  4267. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4268. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4269. // if getPermissionErr != nil {
  4270. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4271. // return
  4272. // } else if headNursePermission == nil {
  4273. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4274. // return
  4275. // }
  4276. //}
  4277. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4278. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4279. timeLayout := "2006-01-02 15:04:05"
  4280. loc, _ := time.LoadLocation("Local")
  4281. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4282. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4283. schedulestartTime := theStartTime.Unix()
  4284. scheduleendTime := theEndTime.Unix()
  4285. var theNucleinDate int64
  4286. timeLayoutOne := "2006-01-02"
  4287. if len(nuclein_date_str) > 0 {
  4288. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4289. if err != nil {
  4290. utils.ErrorLog(err.Error())
  4291. }
  4292. theNucleinDate = theTime.Unix()
  4293. }
  4294. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4295. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4296. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4297. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4298. if err == gorm.ErrRecordNotFound { //空床位
  4299. // 修改了床位逻辑
  4300. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4301. if daySchedule.ID > 0 {
  4302. //daySchedule.BedId = bedID
  4303. //daySchedule.PartitionId = deviceNumber.ZoneID
  4304. //daySchedule.ScheduleType = schedual_type
  4305. //daySchedule.UpdatedTime = time.Now().Unix()
  4306. //err := service.UpdateSchedule(&daySchedule)
  4307. xtSchedule := models.Schedule{
  4308. PartitionId: deviceNumber.ZoneID,
  4309. BedId: bedID,
  4310. ScheduleType: schedual_type,
  4311. UpdatedTime: time.Now().Unix(),
  4312. }
  4313. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4314. if err != nil {
  4315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4316. return
  4317. }
  4318. }
  4319. } else if err == nil {
  4320. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4321. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4322. if daySchedule.ID > 0 {
  4323. //daySchedule.BedId = bedID
  4324. //daySchedule.PartitionId = deviceNumber.ZoneID
  4325. //
  4326. //daySchedule.ScheduleType = schedual_type
  4327. //daySchedule.UpdatedTime = time.Now().Unix()
  4328. //err := service.UpdateSchedule(&daySchedule)
  4329. xtSchedule := models.Schedule{
  4330. PartitionId: deviceNumber.ZoneID,
  4331. BedId: bedID,
  4332. ScheduleType: schedual_type,
  4333. UpdatedTime: time.Now().Unix(),
  4334. }
  4335. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4336. if err != nil {
  4337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4338. return
  4339. }
  4340. }
  4341. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4343. return
  4344. }
  4345. } else if err != nil {
  4346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4347. return
  4348. }
  4349. }
  4350. dialysisRecord := &models.DialysisOrder{
  4351. ID: record_id,
  4352. UserOrgId: adminUserInfo.Org.Id,
  4353. BedID: bedID,
  4354. StartNurse: nurseID,
  4355. StartTime: startDate.Unix(),
  4356. PunctureNurse: puncture_nurse,
  4357. Creator: adminUserInfo.AdminUser.Id,
  4358. Modifier: adminUserInfo.AdminUser.Id,
  4359. WashpipeNurse: washpipe_nurse,
  4360. SchedualType: schedual_type,
  4361. ChangeNurse: change_nurse,
  4362. DifficultPunctureNurse: difficult_puncture_nurse,
  4363. NewFistulaNurse: new_fistula_nurse,
  4364. QualityNurseId: quality_nurse_id,
  4365. PunctureNeedle: puncture_needle,
  4366. PunctureWay: puncture_way,
  4367. DialysisDialyszers: dialysis_dialyszers,
  4368. DialysisIrrigation: dialysis_irrigation,
  4369. BloodAccessId: blood_access_id,
  4370. NucleinDate: theNucleinDate,
  4371. OrderRemark: order_remark,
  4372. ScheduleRemark: schedule_remark,
  4373. CatheterOperation: catheter_operation,
  4374. BloodFlowVolume: blood_flow_volume,
  4375. BloodDrawing: blood_drawing,
  4376. DialysisStrainer: dialysis_strainer,
  4377. }
  4378. //修改床位号需要重新消毒
  4379. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4380. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4381. //查询第一条监测
  4382. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4383. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4384. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4385. redis := service.RedisClient()
  4386. //清空key 值
  4387. redis.Set(key, "", time.Second)
  4388. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4389. redis.Set(keyOne, "", time.Second)
  4390. defer redis.Close()
  4391. }
  4392. // 查询信息规挡的设置天数
  4393. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4394. if infor.ID > 0 && infor.WeekDay > 0 {
  4395. var cha_time int64
  4396. timeNowStr := time.Now().Format("2006-01-02")
  4397. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4398. //今日的日期减去设置的日期
  4399. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4400. if cha_time >= record_date {
  4401. //查询审核是否允许
  4402. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4403. //申请状态不允许的情况 拒绝修改
  4404. if infor.ApplicationStatus != 1 {
  4405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4406. return
  4407. }
  4408. }
  4409. }
  4410. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4411. order, _ := service.GetLastPatientOrder(record_id)
  4412. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4413. redis := service.RedisClient()
  4414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4415. redis.Set(key, "", time.Second)
  4416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4417. //清空key 值
  4418. redis.Set(keyOne, "", time.Second)
  4419. scheduleDateStartOne := startDate.Format("2006-01-02")
  4420. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4421. redis.Set(keyTwo, "", time.Second)
  4422. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4423. redis.Set(keyThree, "", time.Second)
  4424. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4425. redis.Set(keyFour, "", time.Second)
  4426. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4427. redis.Set(keyFive, "", time.Second)
  4428. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4429. redis.Set(keySix, "", time.Second)
  4430. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4431. redis.Set(keySeven, "", time.Second)
  4432. if updateErr != nil {
  4433. this.ErrorLog("修改上机失败:%v", updateErr)
  4434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4435. return
  4436. }
  4437. if updateErr == nil {
  4438. if tempDialysisRecord.Stage == 2 {
  4439. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4440. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4441. fmt.Println(value)
  4442. a, b := math.Modf(value)
  4443. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4444. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4445. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4446. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4447. redis := service.RedisClient()
  4448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4449. redis.Set(key, "", time.Second)
  4450. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4451. redis.Set(keyOne, "", time.Second)
  4452. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4453. //清空key 值
  4454. redis.Set(keySix, "", time.Second)
  4455. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4456. redis.Set(keySeven, "", time.Second)
  4457. redis.Close()
  4458. if updateAssessmentErr != nil {
  4459. utils.ErrorLog("%v", updateAssessmentErr)
  4460. }
  4461. }
  4462. }
  4463. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4464. this.ServeSuccessJSON(map[string]interface{}{
  4465. "dialysis_order": dialysisRecords,
  4466. })
  4467. }
  4468. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4469. record_id, _ := c.GetInt64("id")
  4470. nurseID, _ := c.GetInt64("nurse")
  4471. end_time := c.GetString("end_time")
  4472. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4473. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4474. catheter := c.GetString("catheter")
  4475. cruor := c.GetString("cruor")
  4476. mission := c.GetString("mission")
  4477. condenser := c.GetString("condenser")
  4478. if record_id <= 0 || nurseID <= 0 {
  4479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4480. return
  4481. }
  4482. adminUserInfo := c.GetMobileAdminUserInfo()
  4483. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4484. if getNurseErr != nil {
  4485. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4487. return
  4488. } else if nurse == nil {
  4489. c.ErrorLog("护士不存在")
  4490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4491. return
  4492. }
  4493. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4494. if parseEndDateErr != nil {
  4495. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4497. return
  4498. }
  4499. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4500. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4501. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4502. // if getPermissionErr != nil {
  4503. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4504. // return
  4505. // } else if headNursePermission == nil {
  4506. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4507. // return
  4508. // }
  4509. //}
  4510. // 查询信息规挡的设置天数
  4511. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4512. if infor.ID > 0 {
  4513. var cha_time int64
  4514. timeNowStr := time.Now().Format("2006-01-02")
  4515. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4516. //今日的日期减去设置的日期
  4517. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4518. if cha_time >= tempDialysisRecords.DialysisDate {
  4519. //查询审核是否允许
  4520. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4521. //申请状态不允许的情况 拒绝修改
  4522. if infor.ApplicationStatus != 1 {
  4523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4524. return
  4525. }
  4526. }
  4527. }
  4528. dialysisRecord := &models.DialysisOrder{
  4529. ID: record_id,
  4530. UserOrgId: adminUserInfo.Org.Id,
  4531. EndTime: endDate.Unix(),
  4532. FinishNurse: nurseID,
  4533. FinishModifier: adminUserInfo.AdminUser.Id,
  4534. PuncturePointHaematoma: puncture_point_haematoma,
  4535. BloodAccessInternalFistula: blood_access_internal_fistula,
  4536. Catheter: catheter,
  4537. Cruor: cruor,
  4538. Mission: mission,
  4539. Condenser: condenser,
  4540. }
  4541. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4542. redis := service.RedisClient()
  4543. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4544. //清空key 值
  4545. redis.Set(key, "", time.Second)
  4546. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4547. //清空key 值
  4548. redis.Set(keyOne, "", time.Second)
  4549. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4550. redis.Set(keySeven, "", time.Second)
  4551. redis.Close()
  4552. if updateErr != nil {
  4553. c.ErrorLog("修改下机失败:%v", updateErr)
  4554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4555. return
  4556. }
  4557. if updateErr == nil {
  4558. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4559. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4560. a, b := math.Modf(value)
  4561. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4562. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4563. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4564. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4565. redis := service.RedisClient()
  4566. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4567. redis.Set(keyTen, "", time.Second)
  4568. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4569. redis.Set(keyTwo, "", time.Second)
  4570. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4571. redis.Set(key, "", time.Second)
  4572. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4573. redis.Set(keyThree, "", time.Second)
  4574. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4575. redis.Set(keySeven, "", time.Second)
  4576. defer redis.Close()
  4577. if updateAssessmentErr != nil {
  4578. utils.ErrorLog("%v", updateAssessmentErr)
  4579. }
  4580. }
  4581. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4582. c.ServeSuccessJSON(map[string]interface{}{
  4583. "dialysis_order": dialysisRecords,
  4584. })
  4585. }
  4586. func (c *DialysisAPIController) GetLongAdvice() {
  4587. patient_id, _ := c.GetInt64("id")
  4588. adminUserInfo := c.GetMobileAdminUserInfo()
  4589. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4590. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4591. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4592. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4593. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4594. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4595. c.ServeSuccessJSON(map[string]interface{}{
  4596. "status": "1",
  4597. })
  4598. return
  4599. } else { //开启推送提醒
  4600. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4601. var advice_three []*models.DoctorAdvice
  4602. recordDateStr := time.Now().Format("2006-01-02")
  4603. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4604. nowtime := recordDate.Unix()
  4605. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4606. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4607. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4608. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4609. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4610. for _, advice := range advices {
  4611. if advice.FrequencyType == 3 {
  4612. t := time.Now()
  4613. week := int(t.Weekday())
  4614. fmt.Println(t.Weekday())
  4615. fmt.Println(week)
  4616. switch week {
  4617. case 1:
  4618. if strings.Index(advice.WeekDay, "周一") == -1 {
  4619. advice_three = append(advice_three, advice)
  4620. }
  4621. break
  4622. case 2:
  4623. if strings.Index(advice.WeekDay, "周二") == -1 {
  4624. advice_three = append(advice_three, advice)
  4625. }
  4626. break
  4627. case 3:
  4628. if strings.Index(advice.WeekDay, "周三") == -1 {
  4629. advice_three = append(advice_three, advice)
  4630. }
  4631. break
  4632. case 4:
  4633. if strings.Index(advice.WeekDay, "周四") == -1 {
  4634. advice_three = append(advice_three, advice)
  4635. }
  4636. break
  4637. case 5:
  4638. if strings.Index(advice.WeekDay, "周五") == -1 {
  4639. advice_three = append(advice_three, advice)
  4640. }
  4641. break
  4642. case 6:
  4643. if strings.Index(advice.WeekDay, "周六") == -1 {
  4644. advice_three = append(advice_three, advice)
  4645. }
  4646. break
  4647. case 0:
  4648. if strings.Index(advice.WeekDay, "周日") == -1 {
  4649. advice_three = append(advice_three, advice)
  4650. }
  4651. break
  4652. }
  4653. }
  4654. }
  4655. for _, advice := range advices_two {
  4656. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4657. now := p.Unix()
  4658. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4659. dayStr2 := "-" + dayStr
  4660. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4661. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4662. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4663. for _, ad := range advices {
  4664. advice_three = append(advice_three, ad)
  4665. }
  4666. }
  4667. if err == nil {
  4668. c.ServeSuccessJSON(map[string]interface{}{
  4669. "status": "2",
  4670. "advices": advices,
  4671. "advices_two": RemoveRepeatedElement(advice_three),
  4672. "is_open_remind": config.IsOpenRemind,
  4673. "his_config_open": hisConfig.IsOpen,
  4674. "is_advice_open": is_advice_open.IsAdviceOpen,
  4675. "prescription_open": prescription_open.IsOpen,
  4676. })
  4677. }
  4678. }
  4679. }
  4680. func (c *DialysisAPIController) GetLongAdviceOne() {
  4681. patient_id, _ := c.GetInt64("id")
  4682. startTime := c.GetString("schedule_date")
  4683. timeLayout := "2006-01-02"
  4684. loc, _ := time.LoadLocation("Local")
  4685. var theStartTime int64
  4686. if len(startTime) > 0 {
  4687. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4688. if err != nil {
  4689. utils.ErrorLog(err.Error())
  4690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4691. return
  4692. }
  4693. theStartTime = theTime.Unix()
  4694. }
  4695. adminUserInfo := c.GetMobileAdminUserInfo()
  4696. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4697. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4698. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4699. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4700. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4701. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4702. c.ServeSuccessJSON(map[string]interface{}{
  4703. "status": "1",
  4704. })
  4705. return
  4706. } else { //开启推送提醒
  4707. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4708. var advice_three []*models.DoctorAdvice
  4709. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4710. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4711. for _, advice := range advices {
  4712. if advice.FrequencyType == 3 {
  4713. t := time.Now()
  4714. week := int(t.Weekday())
  4715. fmt.Println(t.Weekday())
  4716. fmt.Println(week)
  4717. switch week {
  4718. case 1:
  4719. if strings.Index(advice.WeekDay, "周一") == -1 {
  4720. advice_three = append(advice_three, advice)
  4721. }
  4722. break
  4723. case 2:
  4724. if strings.Index(advice.WeekDay, "周二") == -1 {
  4725. advice_three = append(advice_three, advice)
  4726. }
  4727. break
  4728. case 3:
  4729. if strings.Index(advice.WeekDay, "周三") == -1 {
  4730. advice_three = append(advice_three, advice)
  4731. }
  4732. break
  4733. case 4:
  4734. if strings.Index(advice.WeekDay, "周四") == -1 {
  4735. advice_three = append(advice_three, advice)
  4736. }
  4737. break
  4738. case 5:
  4739. if strings.Index(advice.WeekDay, "周五") == -1 {
  4740. advice_three = append(advice_three, advice)
  4741. }
  4742. break
  4743. case 6:
  4744. if strings.Index(advice.WeekDay, "周六") == -1 {
  4745. advice_three = append(advice_three, advice)
  4746. }
  4747. break
  4748. case 0:
  4749. if strings.Index(advice.WeekDay, "周日") == -1 {
  4750. advice_three = append(advice_three, advice)
  4751. }
  4752. break
  4753. }
  4754. }
  4755. }
  4756. for _, advice := range advices_two {
  4757. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4758. now := p.Unix()
  4759. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4760. dayStr2 := "-" + dayStr
  4761. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4762. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4763. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4764. for _, ad := range advices {
  4765. advice_three = append(advice_three, ad)
  4766. }
  4767. }
  4768. if err == nil {
  4769. c.ServeSuccessJSON(map[string]interface{}{
  4770. "status": "2",
  4771. "advices": advices,
  4772. "advices_two": RemoveRepeatedElement(advice_three),
  4773. "is_open_remind": config.IsOpenRemind,
  4774. "his_config_open": hisConfig.IsOpen,
  4775. "is_advice_open": is_advice_open.IsAdviceOpen,
  4776. "prescription_open": prescription_open.IsOpen,
  4777. })
  4778. }
  4779. }
  4780. }
  4781. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4782. newArr = make([]*models.DoctorAdvice, 0)
  4783. for i := 0; i < len(arr); i++ {
  4784. repeat := false
  4785. for j := i + 1; j < len(arr); j++ {
  4786. if arr[i].ID == arr[j].ID {
  4787. repeat = true
  4788. break
  4789. }
  4790. }
  4791. if !repeat {
  4792. newArr = append(newArr, arr[i])
  4793. }
  4794. }
  4795. return
  4796. }
  4797. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4798. patient, _ := c.GetInt64("id", 0)
  4799. groupNo, _ := c.GetInt64("groupno", 0)
  4800. if patient <= 0 {
  4801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4802. return
  4803. }
  4804. adminUserInfo := c.GetMobileAdminUserInfo()
  4805. dataBody := make(map[string]interface{}, 0)
  4806. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4807. if err != nil {
  4808. utils.ErrorLog(err.Error())
  4809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4810. return
  4811. }
  4812. utils.ErrorLog("%v", dataBody)
  4813. timeLayout := "2006-01-02 15:04"
  4814. loc, _ := time.LoadLocation("Local")
  4815. timeLayout2 := "2006-01-02"
  4816. loc2, _ := time.LoadLocation("Local")
  4817. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4818. utils.ErrorLog("advice_type")
  4819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4820. return
  4821. }
  4822. adviceType := int64(2)
  4823. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4824. utils.ErrorLog("advice_date")
  4825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4826. return
  4827. }
  4828. adviceDate, _ := dataBody["advice_date"].(string)
  4829. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4830. AdviceDate := theTime.Unix()
  4831. RecordDate := theTime.Unix()
  4832. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4833. utils.ErrorLog("start_time")
  4834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4835. return
  4836. }
  4837. startTime, _ := dataBody["start_time"].(string)
  4838. if len(startTime) == 0 {
  4839. utils.ErrorLog("len(start_time) == 0")
  4840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4841. return
  4842. }
  4843. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4844. if err != nil {
  4845. utils.ErrorLog(err.Error())
  4846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4847. return
  4848. }
  4849. StartTime := theTime.Unix()
  4850. Remark := ""
  4851. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4852. remark, _ := dataBody["remark"].(string)
  4853. Remark = remark
  4854. }
  4855. var advices []*models.GroupAdvice
  4856. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4857. utils.ErrorLog("advices")
  4858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4859. return
  4860. }
  4861. adviceNames := dataBody["advices"].([]interface{})
  4862. for _, adviceNameMap := range adviceNames {
  4863. adviceNameM := adviceNameMap.(map[string]interface{})
  4864. var advice models.GroupAdvice
  4865. advice.Remark = Remark
  4866. advice.AdviceType = adviceType
  4867. advice.StartTime = StartTime
  4868. advice.AdviceDate = AdviceDate
  4869. advice.RecordDate = RecordDate
  4870. advice.Status = 1
  4871. advice.CreatedTime = time.Now().Unix()
  4872. advice.UpdatedTime = time.Now().Unix()
  4873. advice.StopState = 2
  4874. advice.ExecutionState = 2
  4875. advice.UserOrgId = adminUserInfo.Org.Id
  4876. advice.PatientId = patient
  4877. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4878. advice.IsSettle = 2
  4879. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4880. utils.ErrorLog("advice_name")
  4881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4882. return
  4883. }
  4884. adviceName, _ := adviceNameM["advice_name"].(string)
  4885. if len(adviceName) == 0 {
  4886. utils.ErrorLog("len(advice_name) == 0")
  4887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4888. return
  4889. }
  4890. advice.AdviceName = adviceName
  4891. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4892. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4893. advice.DrugSpec = drugSpec
  4894. }
  4895. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4896. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4897. advice.AdviceDesc = adviceDesc
  4898. }
  4899. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4900. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4901. advice.DrugSpecUnit = drugSpecUnit
  4902. }
  4903. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4904. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4905. // advice.SingleDose = singleDose
  4906. //}
  4907. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4908. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4909. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4910. }
  4911. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4912. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4913. advice.SingleDoseUnit = singleDoseUnit
  4914. }
  4915. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4916. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4917. // advice.PrescribingNumber = prescribingNumber
  4918. //}
  4919. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4920. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4921. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4922. }
  4923. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4924. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4925. advice.PrescribingNumberUnit = prescribingNumberUnit
  4926. }
  4927. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4928. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4929. advice.DeliveryWay = deliveryWay
  4930. }
  4931. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4932. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4933. advice.ExecutionFrequency = executionFrequency
  4934. }
  4935. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4936. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4937. advice.FrequencyType = frequency_type
  4938. }
  4939. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4940. day_count := int64(adviceNameM["day_count"].(float64))
  4941. advice.DayCount = day_count
  4942. }
  4943. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4944. week_day, _ := adviceNameM["week_day"].(string)
  4945. advice.WeekDay = week_day
  4946. }
  4947. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4948. way := int64(adviceNameM["way"].(float64))
  4949. advice.Way = way
  4950. }
  4951. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4952. drug_id := int64(adviceNameM["drug_id"].(float64))
  4953. advice.DrugId = drug_id
  4954. }
  4955. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4956. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4957. advice.DrugNameId = drug_name_id
  4958. }
  4959. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4960. remark, _ := adviceNameM["remark"].(string)
  4961. advice.Remark = remark
  4962. }
  4963. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4964. groupno := int64(adviceNameM["groupno"].(float64))
  4965. advice.GroupNo = groupno
  4966. }
  4967. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4968. template_id, _ := adviceNameM["template_id"].(string)
  4969. advice.TemplateId = template_id
  4970. }
  4971. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4972. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4973. advice.ExecutionFrequency = executionFrequency
  4974. }
  4975. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4976. children := adviceNameM["child"].([]interface{})
  4977. if len(children) > 0 {
  4978. for _, childrenMap := range children {
  4979. childMap := childrenMap.(map[string]interface{})
  4980. var child models.GroupAdvice
  4981. child.Remark = Remark
  4982. child.AdviceType = adviceType
  4983. child.StartTime = StartTime
  4984. child.AdviceDate = AdviceDate
  4985. child.RecordDate = RecordDate
  4986. child.Status = 1
  4987. child.CreatedTime = time.Now().Unix()
  4988. child.UpdatedTime = time.Now().Unix()
  4989. child.StopState = 2
  4990. child.ExecutionState = 2
  4991. child.UserOrgId = adminUserInfo.Org.Id
  4992. child.PatientId = patient
  4993. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4994. child.IsSettle = 1
  4995. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4996. utils.ErrorLog("child advice_name")
  4997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4998. return
  4999. }
  5000. childAdviceName, _ := childMap["advice_name"].(string)
  5001. if len(childAdviceName) == 0 {
  5002. utils.ErrorLog("len(child advice_name) == 0")
  5003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5004. return
  5005. }
  5006. child.AdviceName = childAdviceName
  5007. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5008. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5009. child.AdviceDesc = childAdviceDesc
  5010. }
  5011. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5012. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5013. child.DrugSpec = childDrugSpec
  5014. }
  5015. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5016. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5017. child.DrugSpecUnit = childDrugSpecUnit
  5018. }
  5019. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5020. child.SingleDose = childMap["single_dose"].(float64)
  5021. }
  5022. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5023. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5024. child.SingleDoseUnit = childSingleDoseUnit
  5025. }
  5026. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5027. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5028. }
  5029. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5030. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5031. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5032. }
  5033. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5034. groupno := int64(childMap["groupno"].(float64))
  5035. advice.GroupNo = groupno
  5036. }
  5037. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5038. remark, _ := childMap["remark"].(string)
  5039. child.Remark = remark
  5040. }
  5041. child.DeliveryWay = advice.DeliveryWay
  5042. child.ExecutionFrequency = advice.ExecutionFrequency
  5043. advice.Children = append(advice.Children, &child)
  5044. }
  5045. }
  5046. }
  5047. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5048. if temp_advice.ID == 0 {
  5049. advices = append(advices, &advice)
  5050. }
  5051. }
  5052. if len(advices) > 0 {
  5053. finish := models.XtDialysisFinish{
  5054. IsFinish: 1,
  5055. UserOrgId: adminUserInfo.Org.Id,
  5056. Status: 1,
  5057. Ctime: time.Now().Unix(),
  5058. Mtime: 0,
  5059. Module: 4,
  5060. RecordDate: AdviceDate,
  5061. Sourse: 1,
  5062. PatientId: patient,
  5063. }
  5064. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5065. if dialysisFinish.ID == 0 {
  5066. service.CreateDialysisFinish(finish)
  5067. }
  5068. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5069. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5070. for _, item := range advices {
  5071. byterequest, _ := json.Marshal(item)
  5072. adviceLog := models.XtDoctorAdviceLog{
  5073. UserOrgId: adminUserInfo.Org.Id,
  5074. PatientId: patient,
  5075. AdminUserId: adminUserInfo.AdminUser.Id,
  5076. Module: 1,
  5077. ErrLog: string(byterequest),
  5078. Status: 1,
  5079. Ctime: time.Now().Unix(),
  5080. Mtime: 0,
  5081. Source: "手机端医嘱推送",
  5082. RecordDate: item.AdviceDate,
  5083. }
  5084. service.CreateDoctorAdviceLog(adviceLog)
  5085. }
  5086. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5087. redis := service.RedisClient()
  5088. //清空key 值
  5089. redis.Set(key, "", time.Second)
  5090. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5091. redis.Set(keyOne, "", time.Second)
  5092. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5093. defer redis.Close()
  5094. redis.Set(keyThree, "", time.Second)
  5095. if err != nil {
  5096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5097. return
  5098. }
  5099. c.ServeSuccessJSON(map[string]interface{}{
  5100. "msg": "ok",
  5101. "advices": list,
  5102. })
  5103. } else {
  5104. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5105. for _, item := range advices {
  5106. byterequest, _ := json.Marshal(item)
  5107. adviceLog := models.XtDoctorAdviceLog{
  5108. UserOrgId: adminUserInfo.Org.Id,
  5109. PatientId: patient,
  5110. AdminUserId: adminUserInfo.AdminUser.Id,
  5111. Module: 1,
  5112. ErrLog: string(byterequest),
  5113. Status: 1,
  5114. Ctime: time.Now().Unix(),
  5115. Mtime: 0,
  5116. Source: "手机端医嘱推送",
  5117. RecordDate: item.AdviceDate,
  5118. }
  5119. service.CreateDoctorAdviceLog(adviceLog)
  5120. }
  5121. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5122. redis := service.RedisClient()
  5123. //清空key 值
  5124. redis.Set(key, "", time.Second)
  5125. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5126. redis.Set(keyOne, "", time.Second)
  5127. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5128. defer redis.Close()
  5129. redis.Set(keyThree, "", time.Second)
  5130. if err != nil {
  5131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5132. return
  5133. }
  5134. c.ServeSuccessJSON(map[string]interface{}{
  5135. "msg": "ok",
  5136. "advices": list,
  5137. })
  5138. }
  5139. } else {
  5140. c.ServeSuccessJSON(map[string]interface{}{
  5141. "msg": "ok",
  5142. })
  5143. }
  5144. return
  5145. }
  5146. func (c *DialysisAPIController) UploadDryWeight() {
  5147. patient_id, _ := c.GetInt64("id")
  5148. dry_weight, _ := c.GetFloat("dry_weight")
  5149. doctor_id, _ := c.GetInt64("doctor_id")
  5150. remark := c.GetString("remark")
  5151. adminUserInfo := c.GetMobileAdminUserInfo()
  5152. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5153. if err == gorm.ErrRecordNotFound {
  5154. dryWeight := &models.SgjPatientDryweight{
  5155. PatientId: patient_id,
  5156. DryWeight: dry_weight,
  5157. Remakes: remark,
  5158. Ctime: time.Now().Unix(),
  5159. Mtime: time.Now().Unix(),
  5160. Creator: doctor_id,
  5161. Status: 1,
  5162. UserOrgId: adminUserInfo.Org.Id,
  5163. AdjustedValue: "/",
  5164. UserId: adminUserInfo.AdminUser.Id,
  5165. }
  5166. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5167. redis := service.RedisClient()
  5168. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5169. redis.Set(keyOne, "", time.Second)
  5170. loc, _ := time.LoadLocation("Local")
  5171. nowTime := time.Now()
  5172. nowDay := nowTime.Format("2006-01-02")
  5173. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5174. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5175. redis.Set(key, "", time.Second)
  5176. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5177. redis.Set(keyTwo, "", time.Second)
  5178. redis.Close()
  5179. if createErr == nil {
  5180. c.ServeSuccessJSON(map[string]interface{}{
  5181. "msg": "提交成功",
  5182. "weight": dryWeight,
  5183. })
  5184. }
  5185. } else {
  5186. dryWeight := &models.SgjPatientDryweight{
  5187. PatientId: patient_id,
  5188. DryWeight: dry_weight,
  5189. Remakes: remark,
  5190. Ctime: time.Now().Unix(),
  5191. Mtime: time.Now().Unix(),
  5192. Creator: doctor_id,
  5193. Status: 1,
  5194. UserOrgId: adminUserInfo.Org.Id,
  5195. AdjustedValue: "/",
  5196. UserId: adminUserInfo.AdminUser.Id,
  5197. }
  5198. var value float64
  5199. value = dry_weight - weightAdjust.DryWeight
  5200. if value < 0 {
  5201. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5202. } else if value == 0 {
  5203. dryWeight.AdjustedValue = "/"
  5204. } else if value > 0 {
  5205. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5206. }
  5207. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5208. redis := service.RedisClient()
  5209. loc, _ := time.LoadLocation("Local")
  5210. nowTime := time.Now()
  5211. nowDay := nowTime.Format("2006-01-02")
  5212. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5213. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5214. redis.Set(keyOne, "", time.Second)
  5215. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5216. redis.Set(key, "", time.Second)
  5217. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5218. redis.Set(keyTwo, "", time.Second)
  5219. redis.Close()
  5220. if createErr == nil {
  5221. c.ServeSuccessJSON(map[string]interface{}{
  5222. "msg": "提交成功",
  5223. "weight": dryWeight,
  5224. })
  5225. }
  5226. }
  5227. }
  5228. func (c *DialysisAPIController) GetSolution() {
  5229. patient_id, _ := c.GetInt64("patient_id")
  5230. mode_id, _ := c.GetInt64("mode_id")
  5231. adminUserInfo := c.GetMobileAdminUserInfo()
  5232. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5233. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5234. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5235. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5236. if err != nil {
  5237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5238. return
  5239. }
  5240. c.ServeSuccessJSON(map[string]interface{}{
  5241. "solution": solution,
  5242. "prescription": prescription,
  5243. "system_prescription": system_prescription,
  5244. "dialysisPrescription": dialysisPrescription,
  5245. })
  5246. }
  5247. func (c *DialysisAPIController) GetSchedule() {
  5248. schedual_type, _ := c.GetInt64("schedual_type")
  5249. adminUserInfo := c.GetMobileAdminUserInfo()
  5250. scheduleTime, _ := c.GetInt64("record_date")
  5251. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5252. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5253. c.ServeSuccessJSON(map[string]interface{}{
  5254. "number": deviceNumber,
  5255. "list": list,
  5256. })
  5257. }
  5258. func (c *DialysisAPIController) GetPatientId() {
  5259. id, _ := c.GetInt64("id")
  5260. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5261. patientId, _ := service.GetPatientId(id)
  5262. //获取该患者的所有传染病
  5263. list, _ := service.GetPatientInfectious(id)
  5264. c.ServeSuccessJSON(map[string]interface{}{
  5265. "patient": patientId,
  5266. "infectioulist": list,
  5267. })
  5268. }
  5269. func (this *DialysisAPIController) GetDialysisSchedule() {
  5270. schedualDate := this.GetString("date")
  5271. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5272. if parseDateErr != nil {
  5273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5274. return
  5275. }
  5276. adminInfo := this.GetMobileAdminUserInfo()
  5277. orgID := adminInfo.Org.Id
  5278. redis := service.RedisClient()
  5279. defer redis.Close()
  5280. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5281. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5282. if len(scheduals) > 0 {
  5283. //缓存数据
  5284. scheduals_json, err := json.Marshal(scheduals)
  5285. if err == nil {
  5286. redis.Set(key, scheduals_json, time.Second*30)
  5287. }
  5288. }
  5289. this.ServeSuccessJSON(map[string]interface{}{
  5290. "scheduals": scheduals,
  5291. })
  5292. }
  5293. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5294. change_type, _ := this.GetInt64("type", 0)
  5295. record_date := this.GetString("record_time")
  5296. patient_id, _ := this.GetInt64("patient_id", 0)
  5297. timeLayout := "2006-01-02"
  5298. loc, _ := time.LoadLocation("Local")
  5299. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5300. record_time := theAdviceRecordTime.Unix()
  5301. adminUserInfo := this.GetMobileAdminUserInfo()
  5302. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5303. if err == nil {
  5304. if len(advices) == 0 {
  5305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5306. return
  5307. } else {
  5308. this.ServeSuccessJSON(map[string]interface{}{
  5309. "advices": advices,
  5310. "schedule": sch,
  5311. })
  5312. return
  5313. }
  5314. } else {
  5315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5316. return
  5317. }
  5318. }
  5319. func (c *DialysisAPIController) CreateConsumables() {
  5320. record_date := c.GetString("record_time")
  5321. patient_id, _ := c.GetInt64("patient_id", 0)
  5322. active, _ := c.GetInt64("active")
  5323. adminUser := c.GetMobileAdminUserInfo()
  5324. timeLayout := "2006-01-02"
  5325. loc, _ := time.LoadLocation("Local")
  5326. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5327. record_time := theRecordTime.Unix()
  5328. // 查询信息规挡的设置天数
  5329. orgid := c.GetMobileAdminUserInfo().Org.Id
  5330. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5331. if infor.ID > 0 {
  5332. var cha_time int64
  5333. timeNowStr := time.Now().Format("2006-01-02")
  5334. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5335. //今日的日期减去设置的日期
  5336. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5337. if cha_time >= record_time {
  5338. //查询审核是否允许
  5339. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5340. //申请状态不允许的情况 拒绝修改
  5341. if infor.ApplicationStatus != 1 {
  5342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5343. return
  5344. }
  5345. }
  5346. }
  5347. dataBody := make(map[string]interface{}, 0)
  5348. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5349. if err != nil {
  5350. utils.ErrorLog(err.Error())
  5351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5352. return
  5353. }
  5354. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5355. var beforePrepares []*models.DialysisBeforePrepareGoods
  5356. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5357. var dialysisBefor []*models.DialysisBeforePrepare
  5358. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5359. goods, _ := dataBody["goods"].([]interface{})
  5360. if len(goods) > 0 {
  5361. for _, item := range goods {
  5362. items := item.(map[string]interface{})
  5363. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5364. utils.ErrorLog("good_id")
  5365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5366. return
  5367. }
  5368. good_id := int64(items["good_id"].(float64))
  5369. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5370. utils.ErrorLog("good_type_id")
  5371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5372. return
  5373. }
  5374. good_type_id := int64(items["good_type_id"].(float64))
  5375. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5376. utils.ErrorLog("count")
  5377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5378. return
  5379. }
  5380. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5381. commdity_code := items["commdity_code"].(string)
  5382. fmt.Println("commdity", commdity_code)
  5383. prepareGoods := &models.DialysisBeforePrepareGoods{
  5384. GoodTypeId: good_type_id,
  5385. GoodId: good_id,
  5386. Count: count,
  5387. StorehouseId: houseConfig.StorehouseOutInfo,
  5388. }
  5389. beforePrepares = append(beforePrepares, prepareGoods)
  5390. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5391. GoodTypeId: good_type_id,
  5392. GoodId: good_id,
  5393. Count: count,
  5394. StorehouseId: houseConfig.StorehouseOutInfo,
  5395. }
  5396. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5397. prepare := &models.DialysisBeforePrepare{
  5398. GoodTypeId: good_type_id,
  5399. GoodId: good_id,
  5400. Count: count,
  5401. PatientId: patient_id,
  5402. RecordDate: record_time,
  5403. UserOrgId: adminUser.Org.Id,
  5404. Status: 1,
  5405. Ctime: time.Now().Unix(),
  5406. Creater: adminUser.AdminUser.Id,
  5407. CommdityCode: commdity_code,
  5408. StorehouseId: houseConfig.StorehouseOutInfo,
  5409. }
  5410. dialysisBefor = append(dialysisBefor, prepare)
  5411. }
  5412. }
  5413. //查询是否有库存
  5414. for _, item := range dialysisBefor {
  5415. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5416. if err == gorm.ErrRecordNotFound {
  5417. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5418. c.ServeSuccessJSON(map[string]interface{}{
  5419. "message": "1",
  5420. "good_name": goodObj.GoodName,
  5421. "specification_name": goodObj.SpecificationName,
  5422. })
  5423. return
  5424. }
  5425. if err != nil {
  5426. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5427. c.ServeSuccessJSON(map[string]interface{}{
  5428. "message": "1",
  5429. "good_name": goodObj.GoodName,
  5430. "specification_name": goodObj.SpecificationName,
  5431. })
  5432. return
  5433. }
  5434. }
  5435. //新增
  5436. if active == 1 && len(goods) > 0 {
  5437. for _, item := range dialysisBefor {
  5438. dialyPrepareOne := models.DialysisBeforePrepare{
  5439. GoodTypeId: item.GoodTypeId,
  5440. GoodId: item.GoodId,
  5441. PatientId: item.PatientId,
  5442. RecordDate: item.RecordDate,
  5443. UserOrgId: item.UserOrgId,
  5444. Count: item.Count,
  5445. Ctime: time.Now().Unix(),
  5446. Creater: item.Creater,
  5447. CommdityCode: item.CommdityCode,
  5448. Status: 1,
  5449. StorehouseId: houseConfig.StorehouseOutInfo,
  5450. }
  5451. //先清除再插入
  5452. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5453. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5454. //查询默认仓库
  5455. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5456. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5457. var total_count int64
  5458. for _, it := range stockList {
  5459. total_count += it.StockCount
  5460. }
  5461. //基础库插入数据
  5462. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5463. //更新库存
  5464. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5465. var flush_count int64
  5466. for _, it := range goodList {
  5467. flush_count += it.StockCount
  5468. }
  5469. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5470. }
  5471. if err == nil {
  5472. c.ServeSuccessJSON(map[string]interface{}{
  5473. "msg": "保存成功",
  5474. "message": "2",
  5475. })
  5476. return
  5477. } else {
  5478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5479. return
  5480. }
  5481. }
  5482. if len(beforePrepares) > 0 && active == 2 {
  5483. for _, item := range beforePrepares {
  5484. //1.查看该患者该耗材型号最后一次出库数量
  5485. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5486. //判断当前出库数量和最后一次出库数量的大小
  5487. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5488. if item.Count <= goodInfo.Count {
  5489. //退库
  5490. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5491. //查询今日出库数据
  5492. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5493. for _, it := range list {
  5494. prepare := models.DialysisBeforePrepare{
  5495. UserOrgId: it.OrgId,
  5496. PatientId: patient_id,
  5497. RecordDate: it.RecordTime,
  5498. GoodId: it.GoodId,
  5499. GoodTypeId: it.GoodTypeId,
  5500. Count: it.Count,
  5501. Ctime: time.Now().Unix(),
  5502. Creater: adminUser.AdminUser.Id,
  5503. Status: 1,
  5504. StorehouseId: houseConfig.StorehouseOutInfo,
  5505. }
  5506. //删除准备表数据
  5507. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5508. service.CreateDialysisBeforePrepareOne(&prepare)
  5509. }
  5510. }
  5511. var last_total int64
  5512. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5513. if item.Count >= goodInfo.Count {
  5514. //查询当前批次当前耗材最后一条出库数据
  5515. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5516. //计算当前出库和最后一次出库数据相差数据
  5517. last_total = item.Count - lastOutInfo.Count
  5518. //查询该批次剩余库存
  5519. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5520. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5521. if lastInfo.StockCount >= last_total {
  5522. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5523. //查询今日出库数据
  5524. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5525. for _, it := range list {
  5526. prepare := models.DialysisBeforePrepare{
  5527. UserOrgId: it.OrgId,
  5528. PatientId: patient_id,
  5529. RecordDate: it.RecordTime,
  5530. GoodId: it.GoodId,
  5531. GoodTypeId: it.GoodTypeId,
  5532. Count: it.Count,
  5533. Ctime: time.Now().Unix(),
  5534. Creater: adminUser.AdminUser.Id,
  5535. Status: 1,
  5536. StorehouseId: houseConfig.StorehouseOutInfo,
  5537. }
  5538. //删除准备表数据
  5539. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5540. service.CreateDialysisBeforePrepareOne(&prepare)
  5541. //查询默认仓库
  5542. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5543. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5544. var total_count int64
  5545. for _, it := range stockList {
  5546. total_count += it.StockCount
  5547. }
  5548. //基础库插入数据
  5549. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5550. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5551. var flush_count int64
  5552. for _, it := range goodList {
  5553. flush_count += it.StockCount
  5554. }
  5555. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5556. }
  5557. }
  5558. //如果库存不够,则出库到下一个批次
  5559. if lastInfo.StockCount < last_total {
  5560. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5561. //查询今日出库数据
  5562. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5563. for _, it := range list {
  5564. prepare := models.DialysisBeforePrepare{
  5565. UserOrgId: it.OrgId,
  5566. PatientId: patient_id,
  5567. RecordDate: it.RecordTime,
  5568. GoodId: it.GoodId,
  5569. GoodTypeId: it.GoodTypeId,
  5570. Count: it.Count,
  5571. Ctime: time.Now().Unix(),
  5572. Creater: adminUser.AdminUser.Id,
  5573. Status: 1,
  5574. StorehouseId: houseConfig.StorehouseOutInfo,
  5575. }
  5576. //删除准备表数据
  5577. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5578. service.CreateDialysisBeforePrepareOne(&prepare)
  5579. //查询默认仓库
  5580. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5581. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5582. var total_count int64
  5583. for _, it := range stockList {
  5584. total_count += it.StockCount
  5585. }
  5586. //基础库插入数据
  5587. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5588. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5589. var flush_count int64
  5590. for _, it := range goodList {
  5591. flush_count += it.StockCount
  5592. }
  5593. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5594. }
  5595. if err != nil {
  5596. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5597. c.ServeSuccessJSON(map[string]interface{}{
  5598. "message": "1",
  5599. "good_name": goodObj.GoodName,
  5600. "specification_name": goodObj.SpecificationName,
  5601. })
  5602. return
  5603. }
  5604. }
  5605. }
  5606. if err != nil {
  5607. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5608. c.ServeSuccessJSON(map[string]interface{}{
  5609. "message": "1",
  5610. "good_name": goodObj.GoodName,
  5611. "specification_name": goodObj.SpecificationName,
  5612. })
  5613. return
  5614. }
  5615. }
  5616. }
  5617. }
  5618. var errs error
  5619. if errs == nil {
  5620. c.ServeSuccessJSON(map[string]interface{}{
  5621. "msg": "提交成功",
  5622. "message": "2",
  5623. "good_name": "",
  5624. "specification_name": "",
  5625. })
  5626. return
  5627. } else {
  5628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5629. return
  5630. }
  5631. }
  5632. func (c *DialysisAPIController) CreateStockOutInfo() {
  5633. patient_id, _ := c.GetInt64("patient_id", 0)
  5634. record_date := c.GetString("record_time")
  5635. if patient_id <= 0 {
  5636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5637. return
  5638. }
  5639. adminInfo := c.GetMobileAdminUserInfo()
  5640. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5641. timeLayout := "2006-01-02"
  5642. loc, _ := time.LoadLocation("Local")
  5643. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5644. record_time := theRecordTime.Unix()
  5645. // 查询信息规挡的设置天数
  5646. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5647. if infor.ID > 0 && infor.WeekDay > 0 {
  5648. var cha_time int64
  5649. timeNowStr := time.Now().Format("2006-01-02")
  5650. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5651. //今日的日期减去设置的日期
  5652. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5653. if cha_time >= record_time {
  5654. //查询审核是否允许
  5655. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5656. //申请状态不允许的情况 拒绝修改
  5657. if infor.ApplicationStatus != 1 {
  5658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5659. return
  5660. }
  5661. }
  5662. }
  5663. //创建步骤表
  5664. finish := models.XtDialysisFinish{
  5665. IsFinish: 1,
  5666. UserOrgId: adminInfo.Org.Id,
  5667. Status: 1,
  5668. Ctime: time.Now().Unix(),
  5669. Mtime: 0,
  5670. Module: 11,
  5671. RecordDate: record_time,
  5672. Sourse: 1,
  5673. PatientId: patient_id,
  5674. }
  5675. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5676. if dialysisFinish.ID == 0 {
  5677. service.CreateDialysisFinish(finish)
  5678. }
  5679. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5680. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5681. //去重
  5682. consumables = RemoveRepeatedGood(consumables)
  5683. if adminInfo.Org.Id == 9919 {
  5684. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5685. //查询是否有库存
  5686. for _, item := range consumables {
  5687. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5688. if item.Count > warehouse.Count {
  5689. goodErrcode := models.XtGoodErrcode{
  5690. UserOrgId: item.UserOrgId,
  5691. Errcode: "自动出库库存不足",
  5692. GoodId: item.GoodId,
  5693. Status: 1,
  5694. Ctime: time.Now().Unix(),
  5695. Mtime: 0,
  5696. Count: 0,
  5697. StockCount: 0,
  5698. Creater: creator,
  5699. BatchNumberId: warehouse.ID,
  5700. WarehouseOutId: 0,
  5701. }
  5702. service.CreateGoodErrcode(goodErrcode)
  5703. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5704. c.ServeSuccessJSON(map[string]interface{}{
  5705. "message": "1",
  5706. "good_name": goodObj.GoodName,
  5707. "specification_name": goodObj.SpecificationName,
  5708. })
  5709. return
  5710. }
  5711. }
  5712. //查询是否有出库单
  5713. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5714. if err == gorm.ErrRecordNotFound {
  5715. //没有记录,则创建出库单
  5716. timeStr := time.Now().Format("2006-01-02")
  5717. timeArr := strings.Split(timeStr, "-")
  5718. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5719. total = total + 1
  5720. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5721. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5722. number = number + total
  5723. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5724. creater := adminInfo.AdminUser.Id
  5725. warehouseOut := models.WarehouseOut{
  5726. WarehouseOutOrderNumber: warehousing_out_order,
  5727. OperationTime: time.Now().Unix(),
  5728. OrgId: adminInfo.Org.Id,
  5729. Creater: creater,
  5730. Ctime: time.Now().Unix(),
  5731. Status: 1,
  5732. WarehouseOutTime: record_time,
  5733. Dealer: 0,
  5734. Manufacturer: 0,
  5735. Type: 1,
  5736. IsSys: 1,
  5737. StorehouseId: houseConfig.StorehouseOutInfo,
  5738. IsCheck: 1,
  5739. }
  5740. err := service.AddSigleWarehouseOut(&warehouseOut)
  5741. if err != nil {
  5742. goodErrcode := models.XtGoodErrcode{
  5743. UserOrgId: adminInfo.Org.Id,
  5744. Errcode: "创建出库单失败",
  5745. GoodId: 0,
  5746. Status: 1,
  5747. Ctime: time.Now().Unix(),
  5748. Mtime: 0,
  5749. Count: 0,
  5750. StockCount: 0,
  5751. Creater: creator,
  5752. BatchNumberId: 0,
  5753. WarehouseOutId: 0,
  5754. }
  5755. service.CreateGoodErrcode(goodErrcode)
  5756. utils.TraceLog("创建出库单失败 err = %v", err)
  5757. } else {
  5758. for _, item := range consumables {
  5759. //出库
  5760. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5761. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5762. if err == nil {
  5763. goodErrcode := models.XtGoodErrcode{
  5764. UserOrgId: adminInfo.Org.Id,
  5765. Errcode: "自动出库接口报错",
  5766. GoodId: 0,
  5767. Status: 1,
  5768. Ctime: time.Now().Unix(),
  5769. Mtime: 0,
  5770. Count: 0,
  5771. StockCount: 0,
  5772. Creater: creator,
  5773. BatchNumberId: 0,
  5774. WarehouseOutId: 0,
  5775. }
  5776. service.CreateGoodErrcode(goodErrcode)
  5777. utils.TraceLog("创建出库单失败 err = %v", err)
  5778. }
  5779. //查询
  5780. //出库数量相加
  5781. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5782. if errs != nil {
  5783. goodErrcode := models.XtGoodErrcode{
  5784. UserOrgId: item.UserOrgId,
  5785. Errcode: "创建剩余库存字段报错",
  5786. GoodId: item.GoodId,
  5787. Status: 1,
  5788. Ctime: time.Now().Unix(),
  5789. Mtime: 0,
  5790. Count: 0,
  5791. StockCount: 0,
  5792. Creater: creater,
  5793. BatchNumberId: 0,
  5794. WarehouseOutId: 0,
  5795. }
  5796. service.CreateGoodErrcode(goodErrcode)
  5797. }
  5798. }
  5799. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5800. if len(list) == 0 {
  5801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5802. return
  5803. }
  5804. for _, item := range list {
  5805. prepare := models.DialysisBeforePrepare{
  5806. UserOrgId: adminInfo.Org.Id,
  5807. PatientId: patient_id,
  5808. RecordDate: record_time,
  5809. GoodId: item.GoodId,
  5810. GoodTypeId: item.GoodTypeId,
  5811. Count: item.Count,
  5812. Creater: adminInfo.AdminUser.Id,
  5813. Status: 1,
  5814. Ctime: time.Now().Unix(),
  5815. StorehouseId: houseConfig.StorehouseOutInfo,
  5816. }
  5817. //清空准备表数据
  5818. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5819. if err != nil {
  5820. goodErrcode := models.XtGoodErrcode{
  5821. UserOrgId: item.OrgId,
  5822. Errcode: "自动出库清空准备表数据报错",
  5823. GoodId: item.GoodId,
  5824. Status: 1,
  5825. Ctime: time.Now().Unix(),
  5826. Mtime: 0,
  5827. Count: 0,
  5828. StockCount: 0,
  5829. Creater: creater,
  5830. BatchNumberId: 0,
  5831. WarehouseOutId: 0,
  5832. }
  5833. service.CreateGoodErrcode(goodErrcode)
  5834. }
  5835. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5836. if errs != nil {
  5837. goodErrcode := models.XtGoodErrcode{
  5838. UserOrgId: item.OrgId,
  5839. Errcode: "自动出库创建准备表数据报错",
  5840. GoodId: item.GoodId,
  5841. Status: 1,
  5842. Ctime: time.Now().Unix(),
  5843. Mtime: 0,
  5844. Count: 0,
  5845. StockCount: 0,
  5846. Creater: creater,
  5847. BatchNumberId: 0,
  5848. WarehouseOutId: 0,
  5849. }
  5850. service.CreateGoodErrcode(goodErrcode)
  5851. }
  5852. //查询默认仓库
  5853. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5854. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5855. var total_count int64
  5856. for _, it := range stockList {
  5857. total_count += it.StockCount
  5858. }
  5859. //基础库插入数据
  5860. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5861. if errcodes != nil {
  5862. goodErrcode := models.XtGoodErrcode{
  5863. UserOrgId: item.OrgId,
  5864. Errcode: "自动出库基础库插入数据",
  5865. GoodId: item.GoodId,
  5866. Status: 1,
  5867. Ctime: time.Now().Unix(),
  5868. Mtime: 0,
  5869. Count: 0,
  5870. StockCount: 0,
  5871. Creater: creater,
  5872. BatchNumberId: 0,
  5873. WarehouseOutId: 0,
  5874. }
  5875. service.CreateGoodErrcode(goodErrcode)
  5876. }
  5877. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5878. var flush_count int64
  5879. for _, it := range goodList {
  5880. flush_count += it.StockCount
  5881. }
  5882. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5883. if errsss != nil {
  5884. goodErrcode := models.XtGoodErrcode{
  5885. UserOrgId: item.OrgId,
  5886. Errcode: "自动出库剩余库存更新数据",
  5887. GoodId: item.GoodId,
  5888. Status: 1,
  5889. Ctime: time.Now().Unix(),
  5890. Mtime: 0,
  5891. Count: 0,
  5892. StockCount: 0,
  5893. Creater: creater,
  5894. BatchNumberId: 0,
  5895. WarehouseOutId: 0,
  5896. }
  5897. service.CreateGoodErrcode(goodErrcode)
  5898. }
  5899. }
  5900. }
  5901. //
  5902. } else if err == nil {
  5903. for _, item := range consumables {
  5904. //出库
  5905. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5906. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5907. if err != nil {
  5908. goodErrcode := models.XtGoodErrcode{
  5909. UserOrgId: adminInfo.Org.Id,
  5910. Errcode: "自动出库接口报错",
  5911. GoodId: 0,
  5912. Status: 1,
  5913. Ctime: time.Now().Unix(),
  5914. Mtime: 0,
  5915. Count: 0,
  5916. StockCount: 0,
  5917. Creater: creator,
  5918. BatchNumberId: 0,
  5919. WarehouseOutId: 0,
  5920. }
  5921. service.CreateGoodErrcode(goodErrcode)
  5922. }
  5923. //出库数量相加
  5924. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5925. if errss != nil {
  5926. goodErrcode := models.XtGoodErrcode{
  5927. UserOrgId: item.UserOrgId,
  5928. Errcode: "创建剩余库存字段报错",
  5929. GoodId: item.GoodId,
  5930. Status: 1,
  5931. Ctime: time.Now().Unix(),
  5932. Mtime: time.Now().Unix(),
  5933. Count: 0,
  5934. StockCount: 0,
  5935. Creater: item.Creater,
  5936. BatchNumberId: 0,
  5937. WarehouseOutId: 0,
  5938. }
  5939. service.CreateGoodErrcode(goodErrcode)
  5940. }
  5941. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5942. if len(list) == 0 {
  5943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5944. return
  5945. }
  5946. for _, item := range list {
  5947. prepare := models.DialysisBeforePrepare{
  5948. UserOrgId: adminInfo.Org.Id,
  5949. PatientId: patient_id,
  5950. RecordDate: record_time,
  5951. GoodId: item.GoodId,
  5952. GoodTypeId: item.GoodTypeId,
  5953. Count: item.Count,
  5954. Creater: adminInfo.AdminUser.Id,
  5955. Status: 1,
  5956. Ctime: time.Now().Unix(),
  5957. StorehouseId: houseConfig.StorehouseOutInfo,
  5958. }
  5959. //清空准备表数据
  5960. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5961. if errs != nil {
  5962. goodErrcode := models.XtGoodErrcode{
  5963. UserOrgId: adminInfo.Org.Id,
  5964. Errcode: "自动出库清空准备表数据报错",
  5965. GoodId: 0,
  5966. Status: 1,
  5967. Ctime: time.Now().Unix(),
  5968. Mtime: 0,
  5969. Count: 0,
  5970. StockCount: 0,
  5971. Creater: creator,
  5972. BatchNumberId: 0,
  5973. WarehouseOutId: 0,
  5974. }
  5975. service.CreateGoodErrcode(goodErrcode)
  5976. }
  5977. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5978. if errcodes != nil {
  5979. goodErrcode := models.XtGoodErrcode{
  5980. UserOrgId: adminInfo.Org.Id,
  5981. Errcode: "自动出库创建准备表数据报错",
  5982. GoodId: 0,
  5983. Status: 1,
  5984. Ctime: time.Now().Unix(),
  5985. Mtime: 0,
  5986. Count: 0,
  5987. StockCount: 0,
  5988. Creater: creator,
  5989. BatchNumberId: 0,
  5990. WarehouseOutId: 0,
  5991. }
  5992. service.CreateGoodErrcode(goodErrcode)
  5993. }
  5994. //查询默认仓库
  5995. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5996. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5997. var total_count int64
  5998. for _, it := range stockList {
  5999. total_count += it.StockCount
  6000. }
  6001. //基础库插入数据
  6002. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6003. if errcodes != nil {
  6004. goodErrcode := models.XtGoodErrcode{
  6005. UserOrgId: adminInfo.Org.Id,
  6006. Errcode: "自动出库基础库插入数据报错",
  6007. GoodId: 0,
  6008. Status: 1,
  6009. Ctime: time.Now().Unix(),
  6010. Mtime: 0,
  6011. Count: 0,
  6012. StockCount: 0,
  6013. Creater: creator,
  6014. BatchNumberId: 0,
  6015. WarehouseOutId: 0,
  6016. }
  6017. service.CreateGoodErrcode(goodErrcode)
  6018. }
  6019. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6020. var flush_count int64
  6021. for _, it := range goodList {
  6022. flush_count += it.StockCount
  6023. }
  6024. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6025. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6026. if errss != nil {
  6027. goodErrcode := models.XtGoodErrcode{
  6028. UserOrgId: item.OrgId,
  6029. Errcode: "自动出库剩余库存更新数据",
  6030. GoodId: item.GoodId,
  6031. Status: 1,
  6032. Ctime: time.Now().Unix(),
  6033. Mtime: 0,
  6034. Count: 0,
  6035. StockCount: 0,
  6036. Creater: creater,
  6037. BatchNumberId: 0,
  6038. WarehouseOutId: 0,
  6039. }
  6040. service.CreateGoodErrcode(goodErrcode)
  6041. }
  6042. }
  6043. }
  6044. }
  6045. c.ServeSuccessJSON(map[string]interface{}{
  6046. "msg": "提交成功",
  6047. "message": "2",
  6048. "good_name": "",
  6049. "specification_name": "",
  6050. })
  6051. return
  6052. }
  6053. if record.IsOpen == 1 {
  6054. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6055. //查询是否有库存
  6056. for _, item := range consumables {
  6057. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6058. if item.Count > warehouse.Count {
  6059. goodErrcode := models.XtGoodErrcode{
  6060. UserOrgId: item.UserOrgId,
  6061. Errcode: "自动出库库存不足",
  6062. GoodId: item.GoodId,
  6063. Status: 1,
  6064. Ctime: time.Now().Unix(),
  6065. Mtime: 0,
  6066. Count: 0,
  6067. StockCount: 0,
  6068. Creater: creator,
  6069. BatchNumberId: warehouse.ID,
  6070. WarehouseOutId: 0,
  6071. }
  6072. service.CreateGoodErrcode(goodErrcode)
  6073. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6074. c.ServeSuccessJSON(map[string]interface{}{
  6075. "message": "1",
  6076. "good_name": goodObj.GoodName,
  6077. "specification_name": goodObj.SpecificationName,
  6078. })
  6079. return
  6080. }
  6081. }
  6082. //查询是否有出库单
  6083. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6084. if err == gorm.ErrRecordNotFound {
  6085. //没有记录,则创建出库单
  6086. timeStr := time.Now().Format("2006-01-02")
  6087. timeArr := strings.Split(timeStr, "-")
  6088. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6089. total = total + 1
  6090. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6091. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6092. number = number + total
  6093. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6094. creater := adminInfo.AdminUser.Id
  6095. warehouseOut := models.WarehouseOut{
  6096. WarehouseOutOrderNumber: warehousing_out_order,
  6097. OperationTime: time.Now().Unix(),
  6098. OrgId: adminInfo.Org.Id,
  6099. Creater: creater,
  6100. Ctime: time.Now().Unix(),
  6101. Status: 1,
  6102. WarehouseOutTime: record_time,
  6103. Dealer: 0,
  6104. Manufacturer: 0,
  6105. Type: 1,
  6106. IsSys: 1,
  6107. StorehouseId: houseConfig.StorehouseOutInfo,
  6108. IsCheck: 1,
  6109. }
  6110. err := service.AddSigleWarehouseOut(&warehouseOut)
  6111. if err != nil {
  6112. goodErrcode := models.XtGoodErrcode{
  6113. UserOrgId: adminInfo.Org.Id,
  6114. Errcode: "创建出库单失败",
  6115. GoodId: 0,
  6116. Status: 1,
  6117. Ctime: time.Now().Unix(),
  6118. Mtime: 0,
  6119. Count: 0,
  6120. StockCount: 0,
  6121. Creater: creator,
  6122. BatchNumberId: 0,
  6123. WarehouseOutId: 0,
  6124. }
  6125. service.CreateGoodErrcode(goodErrcode)
  6126. utils.TraceLog("创建出库单失败 err = %v", err)
  6127. } else {
  6128. for _, item := range consumables {
  6129. //出库
  6130. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6131. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6132. if err == nil {
  6133. goodErrcode := models.XtGoodErrcode{
  6134. UserOrgId: adminInfo.Org.Id,
  6135. Errcode: "自动出库接口报错",
  6136. GoodId: 0,
  6137. Status: 1,
  6138. Ctime: time.Now().Unix(),
  6139. Mtime: 0,
  6140. Count: 0,
  6141. StockCount: 0,
  6142. Creater: creator,
  6143. BatchNumberId: 0,
  6144. WarehouseOutId: 0,
  6145. }
  6146. service.CreateGoodErrcode(goodErrcode)
  6147. utils.TraceLog("创建出库单失败 err = %v", err)
  6148. }
  6149. //查询
  6150. //出库数量相加
  6151. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6152. if errs != nil {
  6153. goodErrcode := models.XtGoodErrcode{
  6154. UserOrgId: item.UserOrgId,
  6155. Errcode: "创建剩余库存字段报错",
  6156. GoodId: item.GoodId,
  6157. Status: 1,
  6158. Ctime: time.Now().Unix(),
  6159. Mtime: 0,
  6160. Count: 0,
  6161. StockCount: 0,
  6162. Creater: creater,
  6163. BatchNumberId: 0,
  6164. WarehouseOutId: 0,
  6165. }
  6166. service.CreateGoodErrcode(goodErrcode)
  6167. }
  6168. }
  6169. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6170. if len(list) == 0 {
  6171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6172. return
  6173. }
  6174. for _, item := range list {
  6175. prepare := models.DialysisBeforePrepare{
  6176. UserOrgId: adminInfo.Org.Id,
  6177. PatientId: patient_id,
  6178. RecordDate: record_time,
  6179. GoodId: item.GoodId,
  6180. GoodTypeId: item.GoodTypeId,
  6181. Count: item.Count,
  6182. Creater: adminInfo.AdminUser.Id,
  6183. Status: 1,
  6184. Ctime: time.Now().Unix(),
  6185. StorehouseId: houseConfig.StorehouseOutInfo,
  6186. }
  6187. //清空准备表数据
  6188. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6189. if err != nil {
  6190. goodErrcode := models.XtGoodErrcode{
  6191. UserOrgId: item.OrgId,
  6192. Errcode: "自动出库清空准备表数据报错",
  6193. GoodId: item.GoodId,
  6194. Status: 1,
  6195. Ctime: time.Now().Unix(),
  6196. Mtime: 0,
  6197. Count: 0,
  6198. StockCount: 0,
  6199. Creater: creater,
  6200. BatchNumberId: 0,
  6201. WarehouseOutId: 0,
  6202. }
  6203. service.CreateGoodErrcode(goodErrcode)
  6204. }
  6205. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6206. if errs != nil {
  6207. goodErrcode := models.XtGoodErrcode{
  6208. UserOrgId: item.OrgId,
  6209. Errcode: "自动出库创建准备表数据报错",
  6210. GoodId: item.GoodId,
  6211. Status: 1,
  6212. Ctime: time.Now().Unix(),
  6213. Mtime: 0,
  6214. Count: 0,
  6215. StockCount: 0,
  6216. Creater: creater,
  6217. BatchNumberId: 0,
  6218. WarehouseOutId: 0,
  6219. }
  6220. service.CreateGoodErrcode(goodErrcode)
  6221. }
  6222. //查询默认仓库
  6223. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6224. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6225. var total_count int64
  6226. for _, it := range stockList {
  6227. total_count += it.StockCount
  6228. }
  6229. //基础库插入数据
  6230. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6231. if errcodes != nil {
  6232. goodErrcode := models.XtGoodErrcode{
  6233. UserOrgId: item.OrgId,
  6234. Errcode: "自动出库基础库插入数据",
  6235. GoodId: item.GoodId,
  6236. Status: 1,
  6237. Ctime: time.Now().Unix(),
  6238. Mtime: 0,
  6239. Count: 0,
  6240. StockCount: 0,
  6241. Creater: creater,
  6242. BatchNumberId: 0,
  6243. WarehouseOutId: 0,
  6244. }
  6245. service.CreateGoodErrcode(goodErrcode)
  6246. }
  6247. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6248. var flush_count int64
  6249. for _, it := range goodList {
  6250. flush_count += it.StockCount
  6251. }
  6252. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6253. if errsss != nil {
  6254. goodErrcode := models.XtGoodErrcode{
  6255. UserOrgId: item.OrgId,
  6256. Errcode: "自动出库剩余库存更新数据",
  6257. GoodId: item.GoodId,
  6258. Status: 1,
  6259. Ctime: time.Now().Unix(),
  6260. Mtime: 0,
  6261. Count: 0,
  6262. StockCount: 0,
  6263. Creater: creater,
  6264. BatchNumberId: 0,
  6265. WarehouseOutId: 0,
  6266. }
  6267. service.CreateGoodErrcode(goodErrcode)
  6268. }
  6269. }
  6270. }
  6271. //
  6272. } else if err == nil {
  6273. for _, item := range consumables {
  6274. //出库
  6275. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6276. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6277. if err != nil {
  6278. goodErrcode := models.XtGoodErrcode{
  6279. UserOrgId: adminInfo.Org.Id,
  6280. Errcode: "自动出库接口报错",
  6281. GoodId: 0,
  6282. Status: 1,
  6283. Ctime: time.Now().Unix(),
  6284. Mtime: 0,
  6285. Count: 0,
  6286. StockCount: 0,
  6287. Creater: creator,
  6288. BatchNumberId: 0,
  6289. WarehouseOutId: 0,
  6290. }
  6291. service.CreateGoodErrcode(goodErrcode)
  6292. }
  6293. //出库数量相加
  6294. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6295. if errss != nil {
  6296. goodErrcode := models.XtGoodErrcode{
  6297. UserOrgId: item.UserOrgId,
  6298. Errcode: "创建剩余库存字段报错",
  6299. GoodId: item.GoodId,
  6300. Status: 1,
  6301. Ctime: time.Now().Unix(),
  6302. Mtime: time.Now().Unix(),
  6303. Count: 0,
  6304. StockCount: 0,
  6305. Creater: item.Creater,
  6306. BatchNumberId: 0,
  6307. WarehouseOutId: 0,
  6308. }
  6309. service.CreateGoodErrcode(goodErrcode)
  6310. }
  6311. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6312. if len(list) == 0 {
  6313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6314. return
  6315. }
  6316. for _, item := range list {
  6317. prepare := models.DialysisBeforePrepare{
  6318. UserOrgId: adminInfo.Org.Id,
  6319. PatientId: patient_id,
  6320. RecordDate: record_time,
  6321. GoodId: item.GoodId,
  6322. GoodTypeId: item.GoodTypeId,
  6323. Count: item.Count,
  6324. Creater: adminInfo.AdminUser.Id,
  6325. Status: 1,
  6326. Ctime: time.Now().Unix(),
  6327. StorehouseId: houseConfig.StorehouseOutInfo,
  6328. }
  6329. //清空准备表数据
  6330. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6331. if errs != nil {
  6332. goodErrcode := models.XtGoodErrcode{
  6333. UserOrgId: adminInfo.Org.Id,
  6334. Errcode: "自动出库清空准备表数据报错",
  6335. GoodId: 0,
  6336. Status: 1,
  6337. Ctime: time.Now().Unix(),
  6338. Mtime: 0,
  6339. Count: 0,
  6340. StockCount: 0,
  6341. Creater: creator,
  6342. BatchNumberId: 0,
  6343. WarehouseOutId: 0,
  6344. }
  6345. service.CreateGoodErrcode(goodErrcode)
  6346. }
  6347. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6348. if errcodes != nil {
  6349. goodErrcode := models.XtGoodErrcode{
  6350. UserOrgId: adminInfo.Org.Id,
  6351. Errcode: "自动出库创建准备表数据报错",
  6352. GoodId: 0,
  6353. Status: 1,
  6354. Ctime: time.Now().Unix(),
  6355. Mtime: 0,
  6356. Count: 0,
  6357. StockCount: 0,
  6358. Creater: creator,
  6359. BatchNumberId: 0,
  6360. WarehouseOutId: 0,
  6361. }
  6362. service.CreateGoodErrcode(goodErrcode)
  6363. }
  6364. //查询默认仓库
  6365. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6366. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6367. var total_count int64
  6368. for _, it := range stockList {
  6369. total_count += it.StockCount
  6370. }
  6371. //基础库插入数据
  6372. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6373. if errcodes != nil {
  6374. goodErrcode := models.XtGoodErrcode{
  6375. UserOrgId: adminInfo.Org.Id,
  6376. Errcode: "自动出库基础库插入数据报错",
  6377. GoodId: 0,
  6378. Status: 1,
  6379. Ctime: time.Now().Unix(),
  6380. Mtime: 0,
  6381. Count: 0,
  6382. StockCount: 0,
  6383. Creater: creator,
  6384. BatchNumberId: 0,
  6385. WarehouseOutId: 0,
  6386. }
  6387. service.CreateGoodErrcode(goodErrcode)
  6388. }
  6389. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6390. var flush_count int64
  6391. for _, it := range goodList {
  6392. flush_count += it.StockCount
  6393. }
  6394. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6395. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6396. if errss != nil {
  6397. goodErrcode := models.XtGoodErrcode{
  6398. UserOrgId: item.OrgId,
  6399. Errcode: "自动出库剩余库存更新数据",
  6400. GoodId: item.GoodId,
  6401. Status: 1,
  6402. Ctime: time.Now().Unix(),
  6403. Mtime: 0,
  6404. Count: 0,
  6405. StockCount: 0,
  6406. Creater: creater,
  6407. BatchNumberId: 0,
  6408. WarehouseOutId: 0,
  6409. }
  6410. service.CreateGoodErrcode(goodErrcode)
  6411. }
  6412. }
  6413. }
  6414. }
  6415. c.ServeSuccessJSON(map[string]interface{}{
  6416. "msg": "提交成功",
  6417. "message": "2",
  6418. "good_name": "",
  6419. "specification_name": "",
  6420. })
  6421. return
  6422. } else {
  6423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6424. return
  6425. }
  6426. }
  6427. func (c *DialysisAPIController) EditConsumables() {
  6428. patient_id, _ := c.GetInt64("patient_id", 0)
  6429. record_date := c.GetString("record_time")
  6430. if patient_id <= 0 {
  6431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6432. return
  6433. }
  6434. adminInfo := c.GetMobileAdminUserInfo()
  6435. timeLayout := "2006-01-02"
  6436. loc, _ := time.LoadLocation("Local")
  6437. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6438. record_time := theRecordTime.Unix()
  6439. // 查询信息规挡的设置天数
  6440. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6441. if infor.ID > 0 && infor.WeekDay > 0 {
  6442. var cha_time int64
  6443. timeNowStr := time.Now().Format("2006-01-02")
  6444. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6445. //今日的日期减去设置的日期
  6446. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6447. if cha_time >= record_time {
  6448. //查询审核是否允许
  6449. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6450. //申请状态不允许的情况 拒绝修改
  6451. if infor.ApplicationStatus != 1 {
  6452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6453. return
  6454. }
  6455. }
  6456. }
  6457. dataBody := make(map[string]interface{}, 0)
  6458. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6459. if err != nil {
  6460. utils.ErrorLog(err.Error())
  6461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6462. return
  6463. }
  6464. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6465. var beforePrepares []*models.DialysisBeforePrepareGoods
  6466. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6467. var cancelbefor []*models.DialysisBeforePrepareGoods
  6468. var outbefor []*models.DialysisBeforePrepareGoods
  6469. //判断是否开启自动出库
  6470. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6471. if record.IsOpen == 1 {
  6472. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6473. goods, _ := dataBody["goods"].([]interface{})
  6474. if len(goods) > 0 {
  6475. for _, item := range goods {
  6476. items := item.(map[string]interface{})
  6477. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6478. utils.ErrorLog("good_id")
  6479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6480. return
  6481. }
  6482. good_id := int64(items["good_id"].(float64))
  6483. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6484. utils.ErrorLog("good_type_id")
  6485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6486. return
  6487. }
  6488. good_type_id := int64(items["good_type_id"].(float64))
  6489. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6490. utils.ErrorLog("count")
  6491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6492. return
  6493. }
  6494. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6495. commdity_code := items["commdity_code"].(string)
  6496. fmt.Println(commdity_code)
  6497. prepareGoods := &models.DialysisBeforePrepareGoods{
  6498. GoodTypeId: good_type_id,
  6499. GoodId: good_id,
  6500. Count: count,
  6501. StorehouseId: houseConfig.StorehouseOutInfo,
  6502. }
  6503. beforePrepares = append(beforePrepares, prepareGoods)
  6504. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6505. GoodTypeId: good_type_id,
  6506. GoodId: good_id,
  6507. Count: count,
  6508. StorehouseId: houseConfig.StorehouseOutInfo,
  6509. }
  6510. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6511. }
  6512. for _, item := range beforePrepares {
  6513. //1.查看该患者该耗材型号最后一次出库数量
  6514. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6515. //判断当前出库数量和最后一次出库数量的大小
  6516. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6517. if item.Count < goodInfo.Count {
  6518. cancelbefor = append(cancelbefor, item)
  6519. }
  6520. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6521. if item.Count > goodInfo.Count {
  6522. outbefor = append(outbefor, item)
  6523. }
  6524. //处理编辑耗材新增不了的问题
  6525. if goodInfo.Count == item.Count {
  6526. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6527. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6528. }
  6529. }
  6530. if len(cancelbefor) > 0 {
  6531. //退库
  6532. for _, item := range cancelbefor {
  6533. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6534. creater := adminInfo.AdminUser.Id
  6535. //查询该患者当天已经出库的耗材信息
  6536. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6537. var delete_count int64 = 0
  6538. delete_count = warehouseOutInfos.Count - item.Count
  6539. //增加库存数量
  6540. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6541. //减少实际出库库存数量
  6542. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6543. // 删除出库完成后,要增加对应批次的库存数量
  6544. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6545. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6546. //更新剩余库存
  6547. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6548. var flush_count int64
  6549. for _, it := range goodListOne {
  6550. flush_count += it.StockCount
  6551. }
  6552. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6553. //查询剩余库存
  6554. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6555. var sum_count int64
  6556. for _, item := range goodList {
  6557. sum_count += item.StockCount
  6558. }
  6559. // 在出库记录表里记录退库详情
  6560. warehouseOutInfo := &models.WarehouseOutInfo{
  6561. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6562. WarehouseOutId: warehouseOut.ID,
  6563. Status: 1,
  6564. Ctime: time.Now().Unix(),
  6565. OrgId: adminInfo.Org.Id,
  6566. Type: 1,
  6567. IsSys: 1,
  6568. SysRecordTime: record_time,
  6569. GoodTypeId: item.GoodTypeId,
  6570. GoodId: item.GoodId,
  6571. PatientId: patient_id,
  6572. ConsumableType: 2,
  6573. StorehouseId: houseConfig.StorehouseOutInfo,
  6574. IsCheck: 1,
  6575. OverCount: sum_count,
  6576. }
  6577. warehouseOutInfo.Count = item.Count
  6578. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6579. warehouseOutInfo.Price = stockInInfo.Price
  6580. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6581. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6582. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6583. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6584. warehouseOutInfo.Number = warehouseOutInfos.Number
  6585. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6586. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6587. //查找当天是否存在出库记录
  6588. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6589. if errcod == gorm.ErrRecordNotFound {
  6590. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6591. //插入详情明细表
  6592. stockFlow := models.VmStockFlow{
  6593. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6594. WarehouseOutId: warehouseOut.ID,
  6595. GoodId: item.GoodId,
  6596. Number: warehouseOutInfos.Number,
  6597. ProductDate: stockInInfo.ProductDate,
  6598. ExpireDate: stockInInfo.ExpiryDate,
  6599. Count: item.Count,
  6600. Price: stockInInfo.Price,
  6601. Status: 1,
  6602. Ctime: record_time,
  6603. UserOrgId: adminInfo.Org.Id,
  6604. Manufacturer: stockInInfo.Manufacturer,
  6605. Dealer: stockInInfo.Dealer,
  6606. LicenseNumber: stockInInfo.LicenseNumber,
  6607. IsEdit: 2,
  6608. Creator: creater,
  6609. SystemTime: record_time,
  6610. ConsumableType: 3,
  6611. WarehousingDetailId: 0,
  6612. IsSys: 1,
  6613. UpdateCreator: creater,
  6614. PatientId: patient_id,
  6615. StorehouseId: houseConfig.StorehouseOutInfo,
  6616. }
  6617. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6618. if errflow == gorm.ErrRecordNotFound {
  6619. //创建流水表
  6620. err := service.CreateStockFlowOne(stockFlow)
  6621. fmt.Println("err", err)
  6622. } else if errflow == nil {
  6623. //插入详情明细表
  6624. stockFlow := models.VmStockFlow{
  6625. ID: exsit.ID,
  6626. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6627. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6628. WarehouseOutId: warehouseOut.ID,
  6629. GoodId: item.GoodId,
  6630. Number: warehouseOutInfos.Number,
  6631. ProductDate: stockInInfo.ProductDate,
  6632. ExpireDate: stockInInfo.ExpiryDate,
  6633. Count: exsit.Count - delete_count,
  6634. Price: stockInInfo.Price,
  6635. Status: 1,
  6636. Ctime: record_time,
  6637. UserOrgId: adminInfo.Org.Id,
  6638. Manufacturer: stockInInfo.Manufacturer,
  6639. Dealer: stockInInfo.Dealer,
  6640. LicenseNumber: stockInInfo.LicenseNumber,
  6641. IsEdit: 2,
  6642. Creator: creater,
  6643. SystemTime: record_time,
  6644. ConsumableType: 3,
  6645. WarehousingDetailId: 0,
  6646. IsSys: 1,
  6647. UpdateCreator: creater,
  6648. PatientId: patient_id,
  6649. StorehouseId: houseConfig.StorehouseOutInfo,
  6650. }
  6651. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6652. }
  6653. } else if errcod == nil {
  6654. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6655. //查询剩余库存
  6656. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6657. var sum_count int64
  6658. for _, item := range goodList {
  6659. sum_count += item.StockCount
  6660. }
  6661. //创建退库单,生成退库数据
  6662. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6663. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6664. operation_time := time.Now().Unix()
  6665. creater := adminInfo.AdminUser.Id
  6666. //创建退库单
  6667. timeStr := time.Now().Format("2006-01-02")
  6668. timeArr := strings.Split(timeStr, "-")
  6669. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6670. total = total + 1
  6671. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6672. cancelStock := models.CancelStock{
  6673. OrderNumber: orderNumber,
  6674. OperaTime: operation_time,
  6675. OrgId: adminInfo.Org.Id,
  6676. Creater: creater,
  6677. Ctime: time.Now().Unix(),
  6678. Status: 1,
  6679. ReturnTime: record_time,
  6680. Type: 1,
  6681. StorehouseId: houseConfig.StorehouseOutInfo,
  6682. IsCheck: 1,
  6683. }
  6684. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6685. if msgerrkonde == gorm.ErrRecordNotFound {
  6686. service.AddSigleCancelStock(&cancelStock)
  6687. }
  6688. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6689. //查询是否有出库
  6690. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6691. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6692. deaerler, _ := service.GetDealerById(info.Dealer)
  6693. if info.ID > 0 {
  6694. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6695. cancelStockInfo := models.CancelStockInfo{
  6696. GoodId: item.GoodId,
  6697. CancelStockId: cancel.ID,
  6698. GoodTypeId: good.GoodTypeId,
  6699. Count: delete_count,
  6700. Price: info.Price,
  6701. Total: 0,
  6702. ProductDate: info.ProductDate,
  6703. ExpiryDate: info.ExpiryDate,
  6704. Ctime: time.Now().Unix(),
  6705. Status: 1,
  6706. OrgId: adminInfo.Org.Id,
  6707. OrderNumber: cancel.OrderNumber,
  6708. Type: 0,
  6709. Dealer: deaerler.DealerName,
  6710. Manufacturer: manufacturer.ManufacturerName,
  6711. Number: info.Number,
  6712. RegisterAccount: "",
  6713. Remark: "",
  6714. WarehouseInfoId: info.WarehouseInfotId,
  6715. PatientId: info.PatientId,
  6716. RecordDate: info.SysRecordTime,
  6717. StorehouseId: houseConfig.StorehouseOutInfo,
  6718. IsCheck: 1,
  6719. }
  6720. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6721. //退库数量增加
  6722. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6723. //查询剩余库存
  6724. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6725. var over_count int64
  6726. for _, it := range goodList {
  6727. over_count += it.StockCount
  6728. }
  6729. flow := models.VmStockFlow{
  6730. WarehousingId: info.WarehouseInfotId,
  6731. GoodId: item.GoodId,
  6732. Number: info.Number,
  6733. LicenseNumber: info.LicenseNumber,
  6734. Count: delete_count,
  6735. UserOrgId: adminInfo.Org.Id,
  6736. PatientId: patient_id,
  6737. SystemTime: info.SysRecordTime,
  6738. ConsumableType: 7,
  6739. IsSys: 0,
  6740. WarehousingOrder: "",
  6741. WarehouseOutId: info.WarehouseOutId,
  6742. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6743. IsEdit: 0,
  6744. CancelStockId: cancel.ID,
  6745. CancelOrderNumber: cancel.OrderNumber,
  6746. Manufacturer: manufacturer.ID,
  6747. Dealer: 0,
  6748. Creator: adminInfo.AdminUser.Id,
  6749. UpdateCreator: 0,
  6750. Status: 1,
  6751. Ctime: record_time,
  6752. Mtime: 0,
  6753. Price: info.Price,
  6754. WarehousingDetailId: info.WarehouseInfotId,
  6755. WarehouseOutDetailId: info.ID,
  6756. CancelOutDetailId: cancelInfo.ID,
  6757. ProductDate: info.ProductDate,
  6758. ExpireDate: info.ExpiryDate,
  6759. StorehouseId: houseConfig.StorehouseOutInfo,
  6760. OverCount: over_count,
  6761. }
  6762. service.CreateStockFlowOne(flow)
  6763. }
  6764. }
  6765. //更改自动出库的表格
  6766. details := models.BloodAutomaticReduceDetail{
  6767. WarehouseOutId: warehouseOutInfo.ID,
  6768. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6769. PatientId: patient_id,
  6770. Ctime: time.Now().Unix(),
  6771. Mtime: time.Now().Unix(),
  6772. Status: 1,
  6773. RecordTime: record_time,
  6774. OrgId: adminInfo.Org.Id,
  6775. GoodId: item.GoodId,
  6776. GoodTypeId: item.GoodTypeId,
  6777. Count: item.Count,
  6778. StorehouseId: houseConfig.StorehouseOutInfo,
  6779. }
  6780. //查询当天耗材是否已经存在数据
  6781. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6782. if errcode == gorm.ErrRecordNotFound {
  6783. service.CreateAutoReduceRecord(&details)
  6784. } else if errcode == nil {
  6785. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6786. service.CreateAutoReduceRecord(&details)
  6787. }
  6788. //查询默认仓库
  6789. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6790. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6791. var total_count int64
  6792. for _, it := range stockList {
  6793. total_count += it.StockCount
  6794. }
  6795. //基础库插入数据
  6796. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6797. }
  6798. }
  6799. if len(outbefor) > 0 {
  6800. //出库
  6801. for _, item := range outbefor {
  6802. var last_total int64
  6803. //1.查看该患者该耗材型号最后一次出库数量
  6804. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6805. //计算当前出库和最后一次出库数据相差数据
  6806. last_total = item.Count - goodInfoOne.Count
  6807. //查询该耗材的总库存
  6808. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6809. // 如果库存差大于剩余库存则提示库存不足
  6810. if last_total > wareinfo.StockCount {
  6811. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6812. c.ServeSuccessJSON(map[string]interface{}{
  6813. "message": "1",
  6814. "good_name": goodObj.GoodName,
  6815. "specification_name": goodObj.SpecificationName,
  6816. })
  6817. return
  6818. } else {
  6819. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6820. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6821. if err == gorm.ErrRecordNotFound {
  6822. //没有记录,则创建出库单
  6823. timeStr := time.Now().Format("2006-01-02")
  6824. timeArr := strings.Split(timeStr, "-")
  6825. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6826. total = total + 1
  6827. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6828. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6829. number = number + total
  6830. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6831. warehouseOut := models.WarehouseOut{
  6832. WarehouseOutOrderNumber: warehousing_out_order,
  6833. OperationTime: time.Now().Unix(),
  6834. OrgId: adminInfo.Org.Id,
  6835. Creater: adminInfo.AdminUser.Id,
  6836. Ctime: time.Now().Unix(),
  6837. Status: 1,
  6838. WarehouseOutTime: record_time,
  6839. Dealer: 0,
  6840. Manufacturer: 0,
  6841. Type: 1,
  6842. IsSys: 1,
  6843. StorehouseId: houseConfig.StorehouseOutInfo,
  6844. IsCheck: 1,
  6845. }
  6846. service.AddSigleWarehouseOut(&warehouseOut)
  6847. }
  6848. //出库
  6849. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6850. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6851. //1.查看该患者该耗材型号最后一次出库数量
  6852. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6853. prepare := models.DialysisBeforePrepare{
  6854. UserOrgId: adminInfo.Org.Id,
  6855. PatientId: patient_id,
  6856. RecordDate: record_time,
  6857. GoodId: item.GoodId,
  6858. GoodTypeId: item.GoodTypeId,
  6859. Count: item.Count - goodInfoTwo.Count,
  6860. Ctime: time.Now().Unix(),
  6861. Mtime: 0,
  6862. Creater: adminInfo.AdminUser.Id,
  6863. Modifier: adminInfo.AdminUser.Id,
  6864. Status: 1,
  6865. CommdityCode: "",
  6866. NewCount: 0,
  6867. ProjectId: 0,
  6868. StorehouseId: houseConfig.StorehouseOutInfo,
  6869. }
  6870. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6871. //增加出库数量
  6872. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6873. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6874. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6875. var total_count int64
  6876. for _, it := range stockList {
  6877. total_count += it.StockCount
  6878. }
  6879. //基础库插入数据
  6880. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6881. //剩余库存
  6882. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6883. var flush_count int64
  6884. for _, it := range goodList {
  6885. flush_count += it.StockCount
  6886. }
  6887. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6888. }
  6889. }
  6890. }
  6891. //查询今日出库数据
  6892. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6893. for _, it := range list {
  6894. prepare := models.DialysisBeforePrepare{
  6895. UserOrgId: it.OrgId,
  6896. PatientId: patient_id,
  6897. RecordDate: it.RecordTime,
  6898. GoodId: it.GoodId,
  6899. GoodTypeId: it.GoodTypeId,
  6900. Count: it.Count,
  6901. Ctime: time.Now().Unix(),
  6902. Creater: adminInfo.AdminUser.Id,
  6903. Status: 1,
  6904. StorehouseId: houseConfig.StorehouseOutInfo,
  6905. ProjectId: it.ProjectId,
  6906. }
  6907. //删除准备表数据
  6908. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6909. service.CreateDialysisBeforePrepareOne(&prepare)
  6910. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6911. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6912. var total_count int64
  6913. for _, it := range stockList {
  6914. total_count += it.StockCount
  6915. }
  6916. //基础库插入数据
  6917. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6918. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6919. var flush_count int64
  6920. for _, it := range goodList {
  6921. flush_count += it.StockCount
  6922. }
  6923. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6924. }
  6925. }
  6926. }
  6927. //更新自动出库的地方
  6928. var errs error
  6929. if errs == nil {
  6930. c.ServeSuccessJSON(map[string]interface{}{
  6931. "msg": "修改成功",
  6932. "message": "2",
  6933. "good_name": "",
  6934. "specification_name": "",
  6935. })
  6936. return
  6937. } else {
  6938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6939. return
  6940. }
  6941. }
  6942. }
  6943. func (c *DialysisAPIController) GetDialysisGoods() {
  6944. schedualDate := c.GetString("schedule_date")
  6945. schedule_type, _ := c.GetInt64("schedule_type")
  6946. partition_id, _ := c.GetInt64("partition_id")
  6947. page, _ := c.GetInt("page")
  6948. patient_id, _ := c.GetInt64("patient_id")
  6949. schedualEndDate := int64(0)
  6950. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6951. if parseDateErr != nil && len(schedualDate) != 0 {
  6952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6953. return
  6954. }
  6955. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6956. if parseDateErr != nil && len(schedualDate) != 0 {
  6957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6958. return
  6959. }
  6960. schedualEndDate = endDate.Unix()
  6961. adminUser := c.GetMobileAdminUserInfo()
  6962. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6963. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6964. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6965. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6966. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6967. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6968. //获取当天该病人的透析处方
  6969. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6970. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6971. if err == gorm.ErrRecordNotFound {
  6972. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6973. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6974. if patient_id != 0 {
  6975. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6976. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6977. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6978. //获取患者总的出库数据
  6979. item.LastAutomaticReduceDetail = goodUser
  6980. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6981. item.Project = project
  6982. for _, it := range item.AutomaticReduceDetail {
  6983. var total int64
  6984. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6985. for _, its := range auto {
  6986. total += its.Count
  6987. }
  6988. it.Count = total
  6989. }
  6990. }
  6991. }
  6992. c.ServeSuccessJSON(map[string]interface{}{
  6993. "dialysis_goods": dialysisGoods,
  6994. "good_type": goodTypes,
  6995. "total": total,
  6996. "prescribe": prescribe,
  6997. "good_info": good_info,
  6998. "warehouseOutList": warehouseOutList,
  6999. "config": config,
  7000. "outConfig": outConfig,
  7001. "settleConfig": settleConfig,
  7002. })
  7003. return
  7004. } else if err == nil {
  7005. //获取当天排班的每个患者的库存使用情况
  7006. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7007. //获取患者总的出库数据
  7008. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7009. if patient_id != 0 {
  7010. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7011. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7012. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7013. item.Project = project
  7014. item.LastAutomaticReduceDetail = goodUser
  7015. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7016. for _, it := range item.AutomaticReduceDetail {
  7017. var total int64
  7018. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7019. for _, its := range auto {
  7020. total += its.Count
  7021. }
  7022. it.Count = total
  7023. }
  7024. }
  7025. }
  7026. if err == nil {
  7027. c.ServeSuccessJSON(map[string]interface{}{
  7028. "dialysis_goods": dialysisGoods,
  7029. "good_type": goodTypes,
  7030. "total": total,
  7031. "prescribe": prescribe,
  7032. "good_info": good_info,
  7033. "project": project,
  7034. "warehouseOutList": warehouseOutList,
  7035. "config": config,
  7036. "outConfig": outConfig,
  7037. "settleConfig": settleConfig,
  7038. })
  7039. return
  7040. } else {
  7041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7042. return
  7043. }
  7044. } else if err != nil {
  7045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7046. return
  7047. }
  7048. }
  7049. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7050. start_time := c.GetString("start_time")
  7051. end_time := c.GetString("end_time")
  7052. timeLayout := "2006-01-02"
  7053. loc, _ := time.LoadLocation("Local")
  7054. var theStartTime int64
  7055. if len(start_time) > 0 {
  7056. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7057. if err != nil {
  7058. utils.ErrorLog(err.Error())
  7059. }
  7060. theStartTime = theTime.Unix()
  7061. }
  7062. var theEndtTime int64
  7063. if len(end_time) > 0 {
  7064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7065. if err != nil {
  7066. utils.ErrorLog(err.Error())
  7067. }
  7068. theEndtTime = theTime.Unix()
  7069. }
  7070. adminUser := c.GetMobileAdminUserInfo()
  7071. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7072. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7073. if err == nil {
  7074. c.ServeSuccessJSON(map[string]interface{}{
  7075. "stock_out": outInfo,
  7076. "stockCount": stockCount,
  7077. })
  7078. return
  7079. } else {
  7080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7081. return
  7082. }
  7083. }
  7084. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7085. patient_id, _ := c.GetInt64("patient_id", 0)
  7086. record_time := c.GetString("record_time")
  7087. adminUser := c.GetMobileAdminUserInfo()
  7088. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7089. if parseDateErr != nil && len(record_time) != 0 {
  7090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7091. return
  7092. }
  7093. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7094. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7095. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7096. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7097. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7098. //获取今日患者的透析处方参数
  7099. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7100. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7101. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7102. c.ServeSuccessJSON(map[string]interface{}{
  7103. "good_type": goodTypes,
  7104. "good_user": goodUser,
  7105. "good_info": good_info,
  7106. "last_good_user": lastGoodUserDetial,
  7107. "project": project,
  7108. "prescription": prescribe,
  7109. "outInfo": outInfo,
  7110. "configs": configs,
  7111. })
  7112. return
  7113. }
  7114. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7115. patient_id, _ := c.GetInt64("patient_id", 0)
  7116. record_date := c.GetString("record_time")
  7117. timeLayout := "2006-01-02"
  7118. loc, _ := time.LoadLocation("Local")
  7119. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7120. record_time := theRecordTime.Unix()
  7121. adminInfo := c.GetMobileAdminUserInfo()
  7122. dataBody := make(map[string]interface{}, 0)
  7123. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7124. if err != nil {
  7125. utils.ErrorLog(err.Error())
  7126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7127. return
  7128. }
  7129. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7130. var beforePrepares []*models.DialysisBeforePrepareGoods
  7131. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7132. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7133. goods, _ := dataBody["goods"].([]interface{})
  7134. if len(goods) > 0 {
  7135. for _, item := range goods {
  7136. items := item.(map[string]interface{})
  7137. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7138. utils.ErrorLog("good_id")
  7139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7140. return
  7141. }
  7142. good_id := int64(items["good_id"].(float64))
  7143. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7144. utils.ErrorLog("good_type_id")
  7145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7146. return
  7147. }
  7148. good_type_id := int64(items["good_type_id"].(float64))
  7149. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7150. utils.ErrorLog("count")
  7151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7152. return
  7153. }
  7154. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7155. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7156. utils.ErrorLog("project_id")
  7157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7158. return
  7159. }
  7160. project_id := int64(items["project_id"].(float64))
  7161. new_count := int64(items["new_count"].(float64))
  7162. old_count := int64(items["old_count"].(float64))
  7163. prepare := &models.DialysisBeforePrepareGoods{
  7164. GoodId: good_id,
  7165. GoodTypeId: good_type_id,
  7166. Count: count,
  7167. ProjectId: project_id,
  7168. StorehouseId: houseConfig.StorehouseOutInfo,
  7169. NewCount: new_count,
  7170. OldCount: old_count,
  7171. }
  7172. beforePrepares = append(beforePrepares, prepare)
  7173. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7174. GoodId: good_id,
  7175. GoodTypeId: good_type_id,
  7176. Count: count,
  7177. ProjectId: project_id,
  7178. StorehouseId: houseConfig.StorehouseOutInfo,
  7179. NewCount: new_count,
  7180. OldCount: old_count,
  7181. }
  7182. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7183. }
  7184. }
  7185. }
  7186. //查询是否有库存
  7187. for _, item := range beforePrepares {
  7188. if item.NewCount > 0 {
  7189. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7190. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7191. if item.Count > warehouse.Count {
  7192. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7193. c.ServeSuccessJSON(map[string]interface{}{
  7194. "message": "1",
  7195. "good_name": goodObj.GoodName,
  7196. "specification_name": goodObj.SpecificationName,
  7197. })
  7198. return
  7199. }
  7200. }
  7201. }
  7202. // 查询信息规挡的设置天数
  7203. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7204. if infor.ID > 0 && infor.WeekDay > 0 {
  7205. var cha_time int64
  7206. timeNowStr := time.Now().Format("2006-01-02")
  7207. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7208. //今日的日期减去设置的日期
  7209. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7210. if cha_time >= record_time {
  7211. //查询审核是否允许
  7212. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7213. //申请状态不允许的情况 拒绝修改
  7214. if infor.ApplicationStatus != 1 {
  7215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7216. return
  7217. }
  7218. }
  7219. }
  7220. //出库逻辑
  7221. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7222. if err != nil {
  7223. utils.ErrorLog(err.Error())
  7224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7225. return
  7226. }
  7227. finish := models.XtDialysisFinish{
  7228. IsFinish: 1,
  7229. UserOrgId: adminInfo.Org.Id,
  7230. Status: 1,
  7231. Ctime: time.Now().Unix(),
  7232. Mtime: 0,
  7233. Module: 11,
  7234. RecordDate: record_time,
  7235. Sourse: 1,
  7236. PatientId: patient_id,
  7237. }
  7238. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7239. if dialysisFinish.ID == 0 {
  7240. service.CreateDialysisFinish(finish)
  7241. }
  7242. //查询当天出库的数据
  7243. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7244. for _, item := range list {
  7245. prepare := models.DialysisBeforePrepare{
  7246. UserOrgId: item.OrgId,
  7247. PatientId: item.PatientId,
  7248. RecordDate: item.RecordTime,
  7249. GoodId: item.GoodId,
  7250. GoodTypeId: item.GoodTypeId,
  7251. Count: item.Count,
  7252. Creater: adminInfo.AdminUser.Id,
  7253. Status: 1,
  7254. Ctime: time.Now().Unix(),
  7255. ProjectId: item.ProjectId,
  7256. StorehouseId: houseConfig.StorehouseOutInfo,
  7257. }
  7258. //清空准备表的数据
  7259. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7260. //插入准备表数据
  7261. service.CreateDialysisBeforePrepareOne(&prepare)
  7262. //查询默认仓库
  7263. //查询默认仓库
  7264. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7265. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7266. var total_count int64
  7267. for _, it := range stockList {
  7268. total_count += it.StockCount
  7269. }
  7270. //基础库插入数据
  7271. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7272. ////更新剩余库存
  7273. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7274. var flush_count int64
  7275. for _, it := range goodList {
  7276. flush_count += it.StockCount
  7277. }
  7278. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7279. if errs != nil {
  7280. goodErrcode := models.XtGoodErrcode{
  7281. UserOrgId: item.OrgId,
  7282. Errcode: "手动出库更新剩余出库失败",
  7283. GoodId: item.GoodId,
  7284. Status: 1,
  7285. Ctime: time.Now().Unix(),
  7286. Mtime: 0,
  7287. Count: 0,
  7288. StockCount: 0,
  7289. Creater: adminInfo.AdminUser.Id,
  7290. BatchNumberId: 0,
  7291. WarehouseOutId: 0,
  7292. }
  7293. service.CreateGoodErrcode(goodErrcode)
  7294. }
  7295. }
  7296. //更新自动出库的地方
  7297. var errs error
  7298. if errs == nil {
  7299. c.ServeSuccessJSON(map[string]interface{}{
  7300. "msg": "修改成功",
  7301. "message": "2",
  7302. "good_name": "",
  7303. "specification_name": "",
  7304. })
  7305. return
  7306. } else {
  7307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7308. return
  7309. }
  7310. }
  7311. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7312. newArr = make([]*models.DialysisBeforePrepare, 0)
  7313. for i := 0; i < len(arr); i++ {
  7314. repeat := false
  7315. for j := i + 1; j < len(arr); j++ {
  7316. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7317. repeat = true
  7318. break
  7319. }
  7320. }
  7321. if !repeat {
  7322. newArr = append(newArr, arr[i])
  7323. }
  7324. }
  7325. return
  7326. }
  7327. func (c *DialysisAPIController) GetAllDrug() {
  7328. patient_id, _ := c.GetInt64("patient_id", 0)
  7329. adminInfo := c.GetMobileAdminUserInfo()
  7330. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7331. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7332. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7333. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7334. c.ServeSuccessJSON(map[string]interface{}{
  7335. "base_drug_config": drugStockConfig,
  7336. "private_drug_config": privateDrugConfig,
  7337. "base_drug_list": drugList,
  7338. "private_drug_list": privateDrugList,
  7339. })
  7340. }
  7341. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7342. newArr = make([]*models.DialysisBeforePrepare, 0)
  7343. for i := 0; i < len(arr); i++ {
  7344. repeat := false
  7345. for j := i + 1; j < len(arr); j++ {
  7346. if arr[i].GoodId == arr[j].GoodId {
  7347. repeat = true
  7348. break
  7349. }
  7350. }
  7351. if !repeat {
  7352. newArr = append(newArr, arr[i])
  7353. }
  7354. }
  7355. return
  7356. }
  7357. func (c *DialysisAPIController) GetDepartment() {
  7358. adminInfo := c.GetMobileAdminUserInfo()
  7359. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7360. if err == nil {
  7361. c.ServeSuccessJSON(map[string]interface{}{
  7362. "departments": departments,
  7363. })
  7364. } else {
  7365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7366. return
  7367. }
  7368. }
  7369. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7370. types, _ := c.GetInt("type", 0)
  7371. start_time := c.GetString("start_time")
  7372. end_time := c.GetString("end_time")
  7373. orgId := c.GetMobileAdminUserInfo().Org.Id
  7374. timeLayout := "2006-01-02"
  7375. loc, _ := time.LoadLocation("Local")
  7376. var startTime int64
  7377. if len(start_time) > 0 {
  7378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7379. if err != nil {
  7380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7381. return
  7382. }
  7383. startTime = theTime.Unix()
  7384. }
  7385. var endTime int64
  7386. if len(end_time) > 0 {
  7387. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7388. if err != nil {
  7389. utils.ErrorLog(err.Error())
  7390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7391. return
  7392. }
  7393. endTime = theTime.Unix()
  7394. }
  7395. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7396. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7397. if err != nil {
  7398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7399. } else {
  7400. c.ServeSuccessJSON(map[string]interface{}{
  7401. "list": list,
  7402. "type": types,
  7403. "stockTotal": stockTotal,
  7404. })
  7405. }
  7406. }
  7407. func (c *DialysisAPIController) GetPrescriptionList() {
  7408. start_time := c.GetString("start_time")
  7409. end_time := c.GetString("end_time")
  7410. schedule_type, _ := c.GetInt64("schedule_type")
  7411. partion_id, _ := c.GetInt64("partion_id")
  7412. orgId := c.GetMobileAdminUserInfo().Org.Id
  7413. timeLayout := "2006-01-02"
  7414. loc, _ := time.LoadLocation("Local")
  7415. var startTime int64
  7416. if len(start_time) > 0 {
  7417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7418. if err != nil {
  7419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7420. return
  7421. }
  7422. startTime = theTime.Unix()
  7423. }
  7424. var endTime int64
  7425. if len(end_time) > 0 {
  7426. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7427. if err != nil {
  7428. utils.ErrorLog(err.Error())
  7429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7430. return
  7431. }
  7432. endTime = theTime.Unix()
  7433. }
  7434. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7435. fmt.Println("schedulelist22222222", schedulelist)
  7436. c.ServeSuccessJSON(map[string]interface{}{
  7437. "list": schedulelist,
  7438. })
  7439. return
  7440. }
  7441. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7442. ids := c.GetString("ids")
  7443. //patient_id, _ := c.GetInt64("patient_id")
  7444. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7445. idArray := strings.Split(ids, ",")
  7446. err := service.BatchDeleteMonitor(idArray)
  7447. fmt.Print("err", err)
  7448. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7449. //redis := service.RedisClient()
  7450. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7451. //redis.Set(key, "", time.Second)
  7452. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7453. //redis.Set(keyOne, "", time.Second)
  7454. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7455. //redis.Close()
  7456. c.ServeSuccessJSON(map[string]interface{}{
  7457. "msg": "批量删除成功",
  7458. })
  7459. return
  7460. }
  7461. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7462. id, _ := c.GetInt64("id")
  7463. timeLayout := "2006-01-02"
  7464. loc, _ := time.LoadLocation("Local")
  7465. //start_time := time.Now().Format("2006-01-02")
  7466. start_time := c.GetString("start_time")
  7467. end_time := c.GetString("end_time")
  7468. var startdateunix int64
  7469. if len(start_time) > 0 {
  7470. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7471. if err != nil {
  7472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7473. return
  7474. }
  7475. startdateunix = theTime.Unix()
  7476. }
  7477. var enddateunix int64
  7478. if len(end_time) > 0 {
  7479. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7480. if err != nil {
  7481. utils.ErrorLog(err.Error())
  7482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7483. return
  7484. }
  7485. enddateunix = theTime.Unix()
  7486. }
  7487. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7488. //nowTime := time.Now()
  7489. //endTime := nowTime.AddDate(-30, 0, 0)
  7490. //endTimes := endTime.Format("2006-01-02")
  7491. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7492. org_id := c.GetMobileAdminUserInfo().Org.Id
  7493. //if org_id == 10579 {
  7494. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7495. // c.ServeSuccessJSON(map[string]interface{}{
  7496. // "list": list,
  7497. // })
  7498. // return
  7499. //} else {
  7500. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7501. // c.ServeSuccessJSON(map[string]interface{}{
  7502. // "list": list,
  7503. // })
  7504. // return
  7505. //}
  7506. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7507. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7508. c.ServeSuccessJSON(map[string]interface{}{
  7509. "list": list,
  7510. })
  7511. return
  7512. } else {
  7513. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7514. c.ServeSuccessJSON(map[string]interface{}{
  7515. "list": list,
  7516. })
  7517. }
  7518. return
  7519. }
  7520. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7521. dataBody := make(map[string]interface{}, 0)
  7522. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7523. ids := c.GetString("ids")
  7524. idArray := strings.Split(ids, ",")
  7525. origin, _ := c.GetInt64("origin")
  7526. if origin == 1 {
  7527. err = service.BatchDeleteAdvice(idArray)
  7528. fmt.Print("err", err)
  7529. c.ServeSuccessJSON(map[string]interface{}{
  7530. "msg": "批量删除成功",
  7531. })
  7532. return
  7533. }
  7534. if origin == 2 {
  7535. service.BatchDeleteHisAdvice(idArray)
  7536. }
  7537. }
  7538. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7539. good_id, _ := c.GetInt64("good_id")
  7540. count, _ := c.GetInt64("count")
  7541. record_time, _ := c.GetInt64("record_time")
  7542. patient_id, _ := c.GetInt64("patient_id")
  7543. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7544. c.ServeSuccessJSON(map[string]interface{}{
  7545. "detail": detail,
  7546. })
  7547. return
  7548. }
  7549. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7550. good_id, _ := c.GetInt64("good_id")
  7551. record_time, _ := c.GetInt64("record_time")
  7552. patient_id, _ := c.GetInt64("patient_id")
  7553. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7554. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7555. fmt.Print("err", err)
  7556. c.ServeSuccessJSON(map[string]interface{}{
  7557. "msg": "批量删除成功",
  7558. })
  7559. return
  7560. }
  7561. func (c *DialysisAPIController) BatchAdviceCheck() {
  7562. ids := c.GetString("ids")
  7563. idArray := strings.Split(ids, ",")
  7564. creator, _ := c.GetInt64("creator")
  7565. origin, _ := c.GetInt64("origin")
  7566. if origin == 1 {
  7567. err := service.BatchAdviceCheck(idArray, creator)
  7568. fmt.Println(err)
  7569. list, _ := service.GetAdviceExecutionById(idArray)
  7570. c.ServeSuccessJSON(map[string]interface{}{
  7571. "list": list,
  7572. })
  7573. return
  7574. }
  7575. if origin == 2 {
  7576. service.BatchHisAdviceCheck(idArray, creator)
  7577. list, _ := service.GetHisAdviceExecutionById(idArray)
  7578. c.ServeSuccessJSON(map[string]interface{}{
  7579. "list": list,
  7580. })
  7581. return
  7582. }
  7583. }
  7584. func (c *DialysisAPIController) BatchAdviceExecution() {
  7585. ids := c.GetString("ids")
  7586. idArray := strings.Split(ids, ",")
  7587. executionTime := c.GetString("execution_time")
  7588. creator, _ := c.GetInt64("creator")
  7589. timeLayout := "2006-01-02 15:04:05"
  7590. loc, _ := time.LoadLocation("Local")
  7591. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7592. orgin, _ := c.GetInt64("origin")
  7593. if orgin == 1 {
  7594. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7595. list, _ := service.GetAdviceExecutionById(idArray)
  7596. fmt.Println(err)
  7597. c.ServeSuccessJSON(map[string]interface{}{
  7598. "list": list,
  7599. })
  7600. return
  7601. }
  7602. if orgin == 2 {
  7603. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7604. list, _ := service.GetHisAdviceExecutionById(idArray)
  7605. fmt.Println(err)
  7606. c.ServeSuccessJSON(map[string]interface{}{
  7607. "list": list,
  7608. })
  7609. return
  7610. }
  7611. }
  7612. func (c *DialysisAPIController) UpdateStockGoods() {
  7613. good_id, _ := c.GetInt64("good_id")
  7614. record_time, _ := c.GetInt64("record_time")
  7615. patient_id, _ := c.GetInt64("patient_id")
  7616. count, _ := c.GetInt64("count")
  7617. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7618. fmt.Print("err", err)
  7619. c.ServeSuccessJSON(map[string]interface{}{
  7620. "msg": "更新成功",
  7621. })
  7622. return
  7623. }
  7624. // 当前数据比上一次出库数据少
  7625. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7626. //查询该患者当天已经出库的耗材信息
  7627. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7628. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7629. for i := len(goods_yc) - 1; i >= 0; i-- {
  7630. goods_yc_temp := goods_yc[i]
  7631. for j := len(goods) - 1; j >= 0; j-- {
  7632. goods_temp := goods[j]
  7633. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7634. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7635. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7636. if goods_yc_temp.Count == goods_temp.Count {
  7637. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7638. goods = append(goods[:j], goods[j+1:]...)
  7639. break
  7640. }
  7641. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7642. if goods_yc_temp.Count > goods_temp.Count {
  7643. temp_count := goods_yc_temp.Count - goods_temp.Count
  7644. goods_yc[i].Count = temp_count
  7645. goods = append(goods[:j], goods[j+1:]...)
  7646. break
  7647. }
  7648. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7649. if goods_yc_temp.Count < goods_temp.Count {
  7650. temp_count := goods_temp.Count - goods_yc_temp.Count
  7651. goods[j].Count = temp_count
  7652. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7653. break
  7654. }
  7655. }
  7656. }
  7657. }
  7658. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7659. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7660. //退库
  7661. if len(goods_yc) > 0 {
  7662. for _, good_yc := range goods_yc {
  7663. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7664. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7665. }
  7666. }
  7667. return nil
  7668. }
  7669. // 耗材出库删除
  7670. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7671. // 先根据相关信息查询当天该耗材的出库信息
  7672. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7673. if err != nil {
  7674. return err
  7675. }
  7676. var delete_count int64 = 0
  7677. delete_count = warehouseOutInfos.Count - count
  7678. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7679. // 在出库记录表里记录退库详情
  7680. warehouseOutInfo := &models.WarehouseOutInfo{
  7681. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7682. WarehouseOutId: warehouseOut.ID,
  7683. Status: 1,
  7684. Ctime: time.Now().Unix(),
  7685. OrgId: orgID,
  7686. Type: 1,
  7687. IsSys: 1,
  7688. SysRecordTime: record_time,
  7689. GoodTypeId: good_yc.GoodTypeId,
  7690. GoodId: good_yc.GoodId,
  7691. PatientId: good_yc.PatientId,
  7692. ConsumableType: 2,
  7693. StorehouseId: houseConfig.StorehouseOutInfo,
  7694. IsCheck: 1,
  7695. }
  7696. warehouseOutInfo.Count = count
  7697. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7698. warehouseOutInfo.Price = stockInInfo.Price
  7699. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7700. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7701. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7702. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7703. warehouseOutInfo.Number = warehouseOutInfos.Number
  7704. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7705. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7706. //查找当天是否存在出库记录
  7707. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7708. if errcod == gorm.ErrRecordNotFound {
  7709. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7710. //插入详情明细表
  7711. stockFlow := models.VmStockFlow{
  7712. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7713. WarehouseOutId: warehouseOut.ID,
  7714. GoodId: good_yc.GoodId,
  7715. Number: warehouseOutInfos.Number,
  7716. ProductDate: stockInInfo.ProductDate,
  7717. ExpireDate: stockInInfo.ExpiryDate,
  7718. Count: count,
  7719. Price: stockInInfo.Price,
  7720. Status: 1,
  7721. Ctime: time.Now().Unix(),
  7722. UserOrgId: good_yc.OrgId,
  7723. Manufacturer: stockInInfo.Manufacturer,
  7724. Dealer: stockInInfo.Dealer,
  7725. LicenseNumber: stockInInfo.LicenseNumber,
  7726. IsEdit: 2,
  7727. Creator: creater,
  7728. SystemTime: record_time,
  7729. ConsumableType: 3,
  7730. WarehousingDetailId: 0,
  7731. IsSys: 1,
  7732. UpdateCreator: creater,
  7733. PatientId: patient_id,
  7734. StorehouseId: houseConfig.StorehouseOutInfo,
  7735. }
  7736. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7737. if errflow == gorm.ErrRecordNotFound {
  7738. //创建流水表
  7739. err := service.CreateStockFlowOne(stockFlow)
  7740. fmt.Println("err", err)
  7741. } else if errflow == nil {
  7742. //插入详情明细表
  7743. stockFlow := models.VmStockFlow{
  7744. ID: exsit.ID,
  7745. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7746. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7747. WarehouseOutId: warehouseOut.ID,
  7748. GoodId: good_yc.GoodId,
  7749. Number: warehouseOutInfos.Number,
  7750. ProductDate: stockInInfo.ProductDate,
  7751. ExpireDate: stockInInfo.ExpiryDate,
  7752. Count: exsit.Count - delete_count,
  7753. Price: stockInInfo.Price,
  7754. Status: 1,
  7755. Ctime: time.Now().Unix(),
  7756. UserOrgId: good_yc.OrgId,
  7757. Manufacturer: stockInInfo.Manufacturer,
  7758. Dealer: stockInInfo.Dealer,
  7759. LicenseNumber: stockInInfo.LicenseNumber,
  7760. IsEdit: 2,
  7761. Creator: creater,
  7762. SystemTime: record_time,
  7763. ConsumableType: 3,
  7764. WarehousingDetailId: 0,
  7765. IsSys: 1,
  7766. UpdateCreator: creater,
  7767. PatientId: patient_id,
  7768. StorehouseId: houseConfig.StorehouseOutInfo,
  7769. }
  7770. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7771. }
  7772. if errOne != nil {
  7773. return errOne
  7774. }
  7775. } else if errcod == nil {
  7776. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7777. //插入详情明细表
  7778. stockFlow := models.VmStockFlow{
  7779. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7780. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7781. WarehouseOutId: warehouseOut.ID,
  7782. GoodId: good_yc.GoodId,
  7783. Number: warehouseOutInfos.Number,
  7784. ProductDate: stockInInfo.ProductDate,
  7785. ExpireDate: stockInInfo.ExpiryDate,
  7786. Count: count,
  7787. Price: stockInInfo.Price,
  7788. Status: 1,
  7789. Ctime: time.Now().Unix(),
  7790. UserOrgId: good_yc.OrgId,
  7791. Manufacturer: stockInInfo.Manufacturer,
  7792. Dealer: stockInInfo.Dealer,
  7793. LicenseNumber: stockInInfo.LicenseNumber,
  7794. IsEdit: 2,
  7795. Creator: creater,
  7796. SystemTime: record_time,
  7797. ConsumableType: 3,
  7798. WarehousingDetailId: 0,
  7799. IsSys: 1,
  7800. UpdateCreator: creater,
  7801. PatientId: patient_id,
  7802. ReturnCount: delete_count,
  7803. StorehouseId: houseConfig.StorehouseOutInfo,
  7804. }
  7805. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7806. if errflows == gorm.ErrRecordNotFound {
  7807. //创建流水表
  7808. service.CreateStockFlowOne(stockFlow)
  7809. } else if errflows == nil {
  7810. stockFlow := models.VmStockFlow{
  7811. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7812. ID: exsit.ID,
  7813. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7814. WarehouseOutId: warehouseOut.ID,
  7815. GoodId: good_yc.GoodId,
  7816. Number: warehouseOutInfos.Number,
  7817. ProductDate: stockInInfo.ProductDate,
  7818. ExpireDate: stockInInfo.ExpiryDate,
  7819. Count: exsit.Count - delete_count,
  7820. Price: stockInInfo.Price,
  7821. Status: 1,
  7822. Ctime: time.Now().Unix(),
  7823. UserOrgId: good_yc.OrgId,
  7824. Manufacturer: stockInInfo.Manufacturer,
  7825. Dealer: stockInInfo.Dealer,
  7826. LicenseNumber: stockInInfo.LicenseNumber,
  7827. IsEdit: 2,
  7828. Creator: creater,
  7829. SystemTime: record_time,
  7830. ConsumableType: 3,
  7831. WarehousingDetailId: 0,
  7832. IsSys: 1,
  7833. UpdateCreator: creater,
  7834. PatientId: patient_id,
  7835. ReturnCount: delete_count,
  7836. StorehouseId: houseConfig.StorehouseOutInfo,
  7837. }
  7838. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7839. }
  7840. }
  7841. //更改自动出库的表格
  7842. details := models.BloodAutomaticReduceDetail{
  7843. WarehouseOutId: warehouseOutInfo.ID,
  7844. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7845. PatientId: patient_id,
  7846. Ctime: time.Now().Unix(),
  7847. Mtime: time.Now().Unix(),
  7848. Status: 1,
  7849. RecordTime: record_time,
  7850. OrgId: orgID,
  7851. GoodId: good_yc.GoodId,
  7852. GoodTypeId: good_yc.GoodTypeId,
  7853. Count: count,
  7854. StorehouseId: houseConfig.StorehouseOutInfo,
  7855. }
  7856. //查询当天耗材是否已经存在数据
  7857. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7858. if errcode == gorm.ErrRecordNotFound {
  7859. errTwo := service.CreateAutoReduceRecord(&details)
  7860. if errTwo != nil {
  7861. return errTwo
  7862. }
  7863. } else if errcode == nil {
  7864. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7865. service.CreateAutoReduceRecord(&details)
  7866. }
  7867. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7868. //增加出库库存数量
  7869. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7870. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7871. fmt.Println("errOne", errOne)
  7872. // 删除出库完成后,要增加对应批次的库存数量
  7873. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7874. if errThree != nil {
  7875. return errThree
  7876. }
  7877. if good_yc.Count == 0 {
  7878. return nil
  7879. } else {
  7880. return errors.New("退库和出库数据不匹配")
  7881. }
  7882. }
  7883. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7884. //查询该患者当天已经出库的耗材信息
  7885. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7886. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7887. for i := len(goods_yc) - 1; i >= 0; i-- {
  7888. goods_yc_temp := goods_yc[i]
  7889. for j := len(goods) - 1; j >= 0; j-- {
  7890. goods_temp := goods[j]
  7891. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7892. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7893. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7894. if goods_yc_temp.Count == goods_temp.Count {
  7895. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7896. goods = append(goods[:j], goods[j+1:]...)
  7897. break
  7898. }
  7899. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7900. if goods_yc_temp.Count > goods_temp.Count {
  7901. temp_count := goods_yc_temp.Count - goods_temp.Count
  7902. goods_yc[i].Count = temp_count
  7903. goods = append(goods[:j], goods[j+1:]...)
  7904. break
  7905. }
  7906. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7907. if goods_yc_temp.Count < goods_temp.Count {
  7908. temp_count := goods_temp.Count - goods_yc_temp.Count
  7909. goods[j].Count = temp_count
  7910. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7911. break
  7912. }
  7913. }
  7914. }
  7915. }
  7916. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7917. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7918. fmt.Println("剩余需要出库的", len(goods))
  7919. if len(goods) > 0 {
  7920. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7921. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7922. if err == gorm.ErrRecordNotFound {
  7923. //没有记录,则创建出库单
  7924. timeStr := time.Now().Format("2006-01-02")
  7925. timeArr := strings.Split(timeStr, "-")
  7926. total, _ := service.FindAllWarehouseOut(orgID)
  7927. total = total + 1
  7928. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7929. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7930. number = number + total
  7931. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7932. warehouseOut := models.WarehouseOut{
  7933. WarehouseOutOrderNumber: warehousing_out_order,
  7934. OperationTime: time.Now().Unix(),
  7935. OrgId: orgID,
  7936. Creater: creater,
  7937. Ctime: time.Now().Unix(),
  7938. Status: 1,
  7939. WarehouseOutTime: record_time,
  7940. Dealer: 0,
  7941. Manufacturer: 0,
  7942. Type: 1,
  7943. IsSys: 1,
  7944. StorehouseId: houseConfig.StorehouseOutInfo,
  7945. IsCheck: 1,
  7946. }
  7947. err := service.AddSigleWarehouseOut(&warehouseOut)
  7948. if err != nil {
  7949. utils.TraceLog("创建出库单失败 err = %v", err)
  7950. return err
  7951. } else {
  7952. out = warehouseOut
  7953. }
  7954. }
  7955. for _, item := range goods {
  7956. var newCount int64 = 0
  7957. for _, it := range goodOne {
  7958. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7959. newCount = it.Count
  7960. }
  7961. }
  7962. prepare := models.DialysisBeforePrepare{
  7963. GoodTypeId: item.GoodTypeId,
  7964. GoodId: item.GoodId,
  7965. Count: item.Count,
  7966. StorehouseId: houseConfig.StorehouseOutInfo,
  7967. }
  7968. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7969. //增加出库数量
  7970. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7971. }
  7972. }
  7973. if len(goods_yc) > 0 {
  7974. for _, good_yc := range goods_yc {
  7975. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7976. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7977. }
  7978. }
  7979. return nil
  7980. }
  7981. // 耗材出库删除
  7982. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7983. // 先根据相关信息查询当天该耗材的出库信息
  7984. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7985. if err != nil {
  7986. return err
  7987. }
  7988. var delete_count int64 = 0
  7989. for _, ware := range warehouseOutInfos {
  7990. // 判断当前出库的数据和删除出库数量
  7991. if good_yc.Count <= ware.Count {
  7992. delete_count = good_yc.Count
  7993. } else {
  7994. delete_count = ware.Count
  7995. }
  7996. warehouseOutInfo := &models.WarehouseOutInfo{
  7997. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7998. WarehouseOutId: warehouseOut.ID,
  7999. Status: 1,
  8000. Ctime: time.Now().Unix(),
  8001. Remark: "",
  8002. OrgId: orgID,
  8003. Type: 1,
  8004. Manufacturer: 0,
  8005. Dealer: 0,
  8006. IsSys: 0,
  8007. SysRecordTime: record_time,
  8008. GoodTypeId: good_yc.GoodTypeId,
  8009. GoodId: good_yc.GoodId,
  8010. StorehouseId: warehouseOut.StorehouseId,
  8011. IsCheck: 1,
  8012. }
  8013. warehouseOutInfo.Count = delete_count
  8014. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8015. warehouseOutInfo.Price = stockInInfo.Price
  8016. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8017. if errOne != nil {
  8018. return errOne
  8019. }
  8020. // 删除出库完成后,要改变流水库存(有疑问)
  8021. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8022. fmt.Println("errOne", errOne)
  8023. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8024. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8025. //扣减出库数量
  8026. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8027. if errThree != nil {
  8028. return errThree
  8029. }
  8030. }
  8031. if good_yc.Count == 0 {
  8032. return nil
  8033. } else {
  8034. return errors.New("退库和出库数据不匹配")
  8035. }
  8036. }
  8037. func (this *DialysisAPIController) GetMobileScheduleList() {
  8038. limit, _ := this.GetInt64("limit")
  8039. page, _ := this.GetInt64("page")
  8040. type_options_visible, _ := this.GetInt64("type_options_visible")
  8041. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8042. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8043. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8044. }
  8045. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8046. newArr = make([]*models.HisPrescriptionProject, 0)
  8047. for i := 0; i < len(arr); i++ {
  8048. repeat := false
  8049. for j := i + 1; j < len(arr); j++ {
  8050. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8051. repeat = true
  8052. break
  8053. }
  8054. }
  8055. if !repeat {
  8056. newArr = append(newArr, arr[i])
  8057. }
  8058. }
  8059. return
  8060. }
  8061. func (this *DialysisAPIController) GetRoleList() {
  8062. admin_user_id, _ := this.GetInt64("admin_user_id")
  8063. orgid := this.GetMobileAdminUserInfo().Org.Id
  8064. list, err := service.GetRoleList(orgid, admin_user_id)
  8065. fmt.Println(err)
  8066. this.ServeSuccessJSON(map[string]interface{}{
  8067. "list": list,
  8068. })
  8069. return
  8070. }
  8071. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8072. // 先根据相关信息查询当天该耗材的出库信息
  8073. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8074. if err != nil {
  8075. return err
  8076. }
  8077. var delete_count int64 = 0
  8078. delete_count = warehouseOutInfos.Count - count
  8079. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8080. // 删除出库完成后,要增加对应批次的库存数量
  8081. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8082. if errThree != nil {
  8083. return errThree
  8084. }
  8085. //增加退库数量
  8086. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8087. //扣减出库数量
  8088. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8089. //查询剩余库存
  8090. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8091. var sum_count int64
  8092. for _, item := range goodList {
  8093. sum_count += item.StockCount
  8094. }
  8095. // 在出库记录表里记录退库详情
  8096. warehouseOutInfo := &models.WarehouseOutInfo{
  8097. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8098. WarehouseOutId: warehouseOut.ID,
  8099. Status: 1,
  8100. Ctime: time.Now().Unix(),
  8101. OrgId: orgID,
  8102. Type: 1,
  8103. IsSys: 1,
  8104. SysRecordTime: record_time,
  8105. GoodTypeId: good_yc.GoodTypeId,
  8106. GoodId: good_yc.GoodId,
  8107. PatientId: good_yc.PatientId,
  8108. ConsumableType: 2,
  8109. StorehouseId: houseConfig.StorehouseOutInfo,
  8110. IsCheck: 1,
  8111. OverCount: sum_count,
  8112. }
  8113. warehouseOutInfo.Count = count
  8114. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8115. warehouseOutInfo.Price = stockInInfo.Price
  8116. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8117. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8118. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8119. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8120. warehouseOutInfo.Number = warehouseOutInfos.Number
  8121. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8122. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8123. //查找当天是否存在出库记录
  8124. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8125. if errcod == gorm.ErrRecordNotFound {
  8126. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8127. //插入详情明细表
  8128. if errOne != nil {
  8129. return errOne
  8130. }
  8131. //插入详情明细表
  8132. stockFlow := models.VmStockFlow{
  8133. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8134. WarehouseOutId: warehouseOut.ID,
  8135. GoodId: good_yc.GoodId,
  8136. Number: warehouseOutInfos.Number,
  8137. ProductDate: stockInInfo.ProductDate,
  8138. ExpireDate: stockInInfo.ExpiryDate,
  8139. Count: count,
  8140. Price: stockInInfo.Price,
  8141. Status: 1,
  8142. Ctime: record_time,
  8143. UserOrgId: good_yc.OrgId,
  8144. Manufacturer: stockInInfo.Manufacturer,
  8145. Dealer: stockInInfo.Dealer,
  8146. LicenseNumber: stockInInfo.LicenseNumber,
  8147. IsEdit: 2,
  8148. Creator: creater,
  8149. SystemTime: record_time,
  8150. ConsumableType: 3,
  8151. WarehousingDetailId: 0,
  8152. IsSys: 1,
  8153. UpdateCreator: creater,
  8154. PatientId: patient_id,
  8155. StorehouseId: houseConfig.StorehouseOutInfo,
  8156. OverCount: sum_count,
  8157. ProjectId: good_yc.ProjectId,
  8158. }
  8159. err := service.CreateStockFlowOne(stockFlow)
  8160. fmt.Println("err", err)
  8161. } else if errcod == nil {
  8162. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8163. }
  8164. //创建退库单
  8165. operation_time := time.Now().Unix()
  8166. //创建退库单
  8167. timeStr := time.Now().Format("2006-01-02")
  8168. timeArr := strings.Split(timeStr, "-")
  8169. total, _ := service.FindAllCancelStockTotal(orgID)
  8170. total = total + 1
  8171. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8172. cancelStock := models.CancelStock{
  8173. OrderNumber: orderNumber,
  8174. OperaTime: operation_time,
  8175. OrgId: orgID,
  8176. Creater: warehouseOut.Creater,
  8177. Ctime: time.Now().Unix(),
  8178. Status: 1,
  8179. ReturnTime: record_time,
  8180. Type: 1,
  8181. StorehouseId: stockInInfo.StorehouseId,
  8182. IsCheck: 1,
  8183. }
  8184. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8185. if msgerrkonde == gorm.ErrRecordNotFound {
  8186. service.AddSigleCancelStock(&cancelStock)
  8187. }
  8188. cancel, _ := service.GetLastCancelStockById(orgID)
  8189. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8190. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8191. cancelStockInfo := models.CancelStockInfo{
  8192. GoodId: stockInInfo.GoodId,
  8193. CancelStockId: cancel.ID,
  8194. GoodTypeId: stockInInfo.GoodTypeId,
  8195. Count: delete_count,
  8196. Price: stockInInfo.PackingPrice,
  8197. Total: 0,
  8198. ProductDate: stockInInfo.ProductDate,
  8199. ExpiryDate: stockInInfo.ExpiryDate,
  8200. Ctime: record_time,
  8201. Status: 1,
  8202. OrgId: orgID,
  8203. OrderNumber: cancel.OrderNumber,
  8204. Type: 0,
  8205. Dealer: deaerler.DealerName,
  8206. Manufacturer: manufacturer.ManufacturerName,
  8207. Number: stockInInfo.Number,
  8208. RegisterAccount: "",
  8209. Remark: "",
  8210. WarehouseInfoId: stockInInfo.ID,
  8211. PatientId: patient_id,
  8212. RecordDate: record_time,
  8213. StorehouseId: stockInInfo.StorehouseId,
  8214. IsCheck: 1,
  8215. }
  8216. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8217. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8218. flow := models.VmStockFlow{
  8219. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8220. GoodId: good_yc.GoodId,
  8221. Number: warehouseOutInfos.Number,
  8222. LicenseNumber: stockInInfo.LicenseNumber,
  8223. Count: delete_count,
  8224. UserOrgId: orgID,
  8225. PatientId: patient_id,
  8226. SystemTime: record_time,
  8227. ConsumableType: 7,
  8228. IsSys: 0,
  8229. WarehousingOrder: "",
  8230. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8231. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8232. IsEdit: 0,
  8233. CancelStockId: cancel.ID,
  8234. CancelOrderNumber: cancel.OrderNumber,
  8235. Manufacturer: manufacturer.ID,
  8236. Dealer: 0,
  8237. Creator: warehouseOut.Creater,
  8238. UpdateCreator: 0,
  8239. Status: 1,
  8240. Ctime: record_time,
  8241. Mtime: 0,
  8242. Price: stockInInfo.Price,
  8243. WarehousingDetailId: stockInInfo.ID,
  8244. WarehouseOutDetailId: warehouseOutInfos.ID,
  8245. CancelOutDetailId: cancelInfo.ID,
  8246. ProductDate: stockInInfo.ProductDate,
  8247. ExpireDate: stockInInfo.ExpiryDate,
  8248. StorehouseId: houseConfig.StorehouseOutInfo,
  8249. OverCount: sum_count,
  8250. }
  8251. service.CreateStockFlowOne(flow)
  8252. //更改自动出库的表格
  8253. details := models.BloodAutomaticReduceDetail{
  8254. WarehouseOutId: warehouseOutInfo.ID,
  8255. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8256. PatientId: patient_id,
  8257. Ctime: time.Now().Unix(),
  8258. Mtime: time.Now().Unix(),
  8259. Status: 1,
  8260. RecordTime: record_time,
  8261. OrgId: orgID,
  8262. GoodId: good_yc.GoodId,
  8263. GoodTypeId: good_yc.GoodTypeId,
  8264. Count: count,
  8265. StorehouseId: houseConfig.StorehouseOutInfo,
  8266. }
  8267. //查询当天耗材是否已经存在数据
  8268. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8269. if errcode == gorm.ErrRecordNotFound {
  8270. errTwo := service.CreateAutoReduceRecord(&details)
  8271. if errTwo != nil {
  8272. return errTwo
  8273. }
  8274. } else if errcode == nil {
  8275. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8276. service.CreateAutoReduceRecord(&details)
  8277. }
  8278. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8279. //增加出库库存数量
  8280. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8281. if good_yc.Count == 0 {
  8282. return nil
  8283. } else {
  8284. return errors.New("退库和出库数据不匹配")
  8285. }
  8286. }
  8287. func (this *DialysisAPIController) SavePatientSign() {
  8288. adminUserInfo := this.GetMobileAdminUserInfo()
  8289. patient_id, _ := this.GetInt64("patient_id")
  8290. dialysis_date, _ := this.GetInt64("dialysis_date")
  8291. orgid := adminUserInfo.Org.Id
  8292. var esdata models.DialysisOrder
  8293. var err error
  8294. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8296. return
  8297. }
  8298. esdata.Hash = esdata.Hash
  8299. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8300. order := models.DialysisOrder{
  8301. Hash: esdata.Hash,
  8302. Url: esdata.Url,
  8303. }
  8304. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8305. redis := service.RedisClient()
  8306. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8307. redis.Set(key, "", time.Second)
  8308. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8309. //清空key 值
  8310. redis.Set(keyOne, "", time.Second)
  8311. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8312. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8313. //redis.Set(keyTwo, "", time.Second)
  8314. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8315. redis.Set(keyThree, "", time.Second)
  8316. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8317. redis.Set(keyFour, "", time.Second)
  8318. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8319. redis.Set(keyFive, "", time.Second)
  8320. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8321. redis.Set(keySix, "", time.Second)
  8322. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8323. redis.Set(keySeven, "", time.Second)
  8324. if err != nil {
  8325. fmt.Println(err)
  8326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8327. return
  8328. }
  8329. this.ServeSuccessJSON(map[string]interface{}{
  8330. "electronic_signature": esdata,
  8331. })
  8332. }
  8333. func (this *DialysisAPIController) GetPatientSign() {
  8334. patient_id, _ := this.GetInt64("patient_id")
  8335. dialysis_date, _ := this.GetInt64("dialysis_date")
  8336. adminUserInfo := this.GetMobileAdminUserInfo()
  8337. orgId := adminUserInfo.Org.Id
  8338. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8339. if err != nil {
  8340. fmt.Println(err)
  8341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8342. return
  8343. }
  8344. this.ServeSuccessJSON(map[string]interface{}{
  8345. "dialysisOrder": dialysisOrder,
  8346. })
  8347. }
  8348. func (this *DialysisAPIController) GetScheduleByPatient() {
  8349. patient_id, _ := this.GetInt64("patient_id")
  8350. schedule_date, _ := this.GetInt64("schedule_date")
  8351. orgid := this.GetMobileAdminUserInfo().Org.Id
  8352. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8353. this.ServeSuccessJSON(map[string]interface{}{
  8354. "schedule": schedule,
  8355. })
  8356. }
  8357. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8358. org_id := this.GetMobileAdminUserInfo().Org.Id
  8359. patient_id, _ := this.GetInt64("patient_id")
  8360. schedule_date, _ := this.GetInt64("schedule_date")
  8361. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8362. this.ServeSuccessJSON(map[string]interface{}{
  8363. "order": order,
  8364. })
  8365. }
  8366. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8367. org_id := this.GetMobileAdminUserInfo().Org.Id
  8368. schedule_date := this.GetString("schedule_date")
  8369. schedule_type, _ := this.GetInt64("schedule_type")
  8370. timeLayout := "2006-01-02"
  8371. loc, _ := time.LoadLocation("Local")
  8372. var startdateunix int64
  8373. if len(schedule_date) > 0 {
  8374. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8375. if err != nil {
  8376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8377. return
  8378. }
  8379. startdateunix = theTime.Unix()
  8380. }
  8381. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8382. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8383. devices, _ := service.GetAllDevicetByListSix(org_id)
  8384. for key, item := range scheduals {
  8385. // 床位信息
  8386. for _, device := range devices {
  8387. if item.BedId == device.ID {
  8388. scheduals[key].DeviceNumber = device
  8389. break
  8390. }
  8391. }
  8392. }
  8393. this.ServeSuccessJSON(map[string]interface{}{
  8394. "list": list,
  8395. "scheduals": scheduals,
  8396. })
  8397. }
  8398. func (this *DialysisAPIController) SavePatientPicture() {
  8399. patient_id, _ := this.GetInt64("patient_id")
  8400. dialysis_date, _ := this.GetInt64("schedule_date")
  8401. avatar := this.GetString("avatar")
  8402. fmt.Println("patient_id", patient_id)
  8403. orgId := this.GetMobileAdminUserInfo().Org.Id
  8404. order := models.DialysisOrder{
  8405. Url: avatar,
  8406. }
  8407. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8408. redis := service.RedisClient()
  8409. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8410. redis.Set(key, "", time.Second)
  8411. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8412. //清空key 值
  8413. redis.Set(keyOne, "", time.Second)
  8414. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8415. redis.Set(keyThree, "", time.Second)
  8416. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8417. redis.Set(keyFour, "", time.Second)
  8418. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8419. redis.Set(keyFive, "", time.Second)
  8420. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8421. redis.Set(keySix, "", time.Second)
  8422. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8423. redis.Set(keySeven, "", time.Second)
  8424. if err != nil {
  8425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8426. return
  8427. }
  8428. this.ServeSuccessJSON(map[string]interface{}{
  8429. "order": order,
  8430. })
  8431. }
  8432. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8433. ids := this.GetString("ids")
  8434. idSplit := strings.Split(ids, ",")
  8435. orgId := this.GetMobileAdminUserInfo().Org.Id
  8436. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8437. execution_time := this.GetString("exce_time")
  8438. timeLayout2 := "2006-01-02 15:04:05"
  8439. loc, _ := time.LoadLocation("Local")
  8440. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8441. if errs != nil {
  8442. utils.ErrorLog(errs.Error())
  8443. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8444. return
  8445. }
  8446. //his客户
  8447. if config.IsOpen == 1 {
  8448. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8449. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8450. for _, item := range list {
  8451. for _, it := range adviceList {
  8452. if item.DrugId == it.DrugId {
  8453. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8454. }
  8455. }
  8456. }
  8457. for _, item := range list {
  8458. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8459. var sum_out_count int64
  8460. for _, itemThree := range item.ChildDoctorAdvice {
  8461. var prescribing_number int64
  8462. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8463. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8464. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8465. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8466. }
  8467. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8468. prescribing_number = parseIntPrescribingNumber
  8469. }
  8470. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8471. prescribing_number = parseIntPrescribingNumber
  8472. }
  8473. sum_out_count += prescribing_number
  8474. }
  8475. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8476. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8477. //库存不足
  8478. if sum_out_count > drugStockOut.FlushCount {
  8479. this.ServeSuccessJSON(map[string]interface{}{
  8480. "msg": "2",
  8481. "drug": medical,
  8482. "ids": ids,
  8483. })
  8484. return
  8485. }
  8486. }
  8487. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8488. //执行医嘱
  8489. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8490. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8491. for _, item := range advices {
  8492. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8493. redis := service.RedisClient()
  8494. //清空key 值
  8495. redis.Set(key, "", time.Second)
  8496. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8497. redis.Set(keyTwo, "", time.Second)
  8498. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8499. redis.Set(keyThree, "", time.Second)
  8500. recordDate := theTime.Format("2006-01-02")
  8501. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8502. redis.Set(keyFour, "", time.Second)
  8503. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8504. redis.Set(keyFive, "", time.Second)
  8505. defer redis.Close()
  8506. }
  8507. if errs == nil {
  8508. //药品管理信息
  8509. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8510. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8511. if drugStockConfig.IsOpen == 1 {
  8512. for _, item := range advices {
  8513. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8514. config, _ := service.GetDrugOpenConfigOne(orgId)
  8515. if config.IsOpen != 1 {
  8516. //查询该药品是否有库存
  8517. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8518. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8519. if medical.IsUse == 2 {
  8520. if config.IsOpen != 1 {
  8521. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8522. service.HisDrugsDelivery(orgId, creater, &advice)
  8523. if orgId == 3877 || orgId == 10265 {
  8524. //查询该药品是否有出库记录
  8525. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8526. if len(flowMap) == 0 {
  8527. errs := service.UpdateHisAdviceById(advice.ID)
  8528. if errs != nil {
  8529. drugError := models.XtDrugError{
  8530. UserOrgId: orgId,
  8531. DrugId: item.DrugId,
  8532. RecordDate: item.AdviceDate,
  8533. PatientId: item.PatientId,
  8534. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8535. Status: 1,
  8536. Ctime: time.Now().Unix(),
  8537. Mtime: 0,
  8538. SumCount: 0,
  8539. Prescribingnumber: advice.PrescribingNumber,
  8540. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8541. }
  8542. service.CreateDrugError(drugError)
  8543. }
  8544. this.ServeSuccessJSON(map[string]interface{}{
  8545. "msg": "2",
  8546. "drug": medical,
  8547. "ids": ids,
  8548. })
  8549. return
  8550. }
  8551. }
  8552. }
  8553. if pharmacyConfig.IsOpen != 1 {
  8554. service.HisDrugsDelivery(orgId, creater, &advice)
  8555. if orgId == 3877 || orgId == 10265 {
  8556. //查询该药品是否有出库记录
  8557. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8558. if len(flowMap) == 0 {
  8559. errs := service.UpdateHisAdviceById(advice.ID)
  8560. if errs != nil {
  8561. drugError := models.XtDrugError{
  8562. UserOrgId: orgId,
  8563. DrugId: item.DrugId,
  8564. RecordDate: item.AdviceDate,
  8565. PatientId: item.PatientId,
  8566. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8567. Status: 1,
  8568. Ctime: time.Now().Unix(),
  8569. Mtime: 0,
  8570. SumCount: 0,
  8571. Prescribingnumber: advice.PrescribingNumber,
  8572. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8573. }
  8574. service.CreateDrugError(drugError)
  8575. }
  8576. this.ServeSuccessJSON(map[string]interface{}{
  8577. "msg": "2",
  8578. "drug": medical,
  8579. "ids": ids,
  8580. })
  8581. return
  8582. }
  8583. }
  8584. }
  8585. //更新字典里面的库存
  8586. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8587. var sum_count int64
  8588. for _, its := range stockInfo {
  8589. if its.MaxUnit == medical.MaxUnit {
  8590. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8591. }
  8592. sum_count += its.StockMaxNumber + its.StockMinNumber
  8593. }
  8594. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8595. //剩余库存
  8596. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8597. }
  8598. }
  8599. }
  8600. }
  8601. }
  8602. this.ServeSuccessJSON(map[string]interface{}{
  8603. "msg": "1",
  8604. "ids": ids,
  8605. })
  8606. return
  8607. } else {
  8608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8609. }
  8610. }
  8611. //血透客户
  8612. if config.IsOpen == 2 || config.IsOpen == 0 {
  8613. //药品管理信息
  8614. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8615. if drugStockConfig.IsOpen == 1 {
  8616. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8617. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8618. for _, item := range list {
  8619. for _, it := range adviceList {
  8620. if item.DrugId == it.DrugId {
  8621. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8622. }
  8623. }
  8624. }
  8625. for _, item := range list {
  8626. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8627. var sum_out_count int64
  8628. for _, itemThree := range item.ChildDoctorAdvice {
  8629. var prescribing_number int64
  8630. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8631. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8632. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8633. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8634. }
  8635. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8636. prescribing_number = parseIntPrescribingNumber
  8637. }
  8638. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8639. prescribing_number = parseIntPrescribingNumber
  8640. }
  8641. sum_out_count += prescribing_number
  8642. }
  8643. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8644. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8645. //库存不足
  8646. if sum_out_count > drugStockOut.FlushCount {
  8647. this.ServeSuccessJSON(map[string]interface{}{
  8648. "msg": "2",
  8649. "drug": medical,
  8650. "ids": ids,
  8651. })
  8652. return
  8653. }
  8654. }
  8655. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8656. //执行医嘱
  8657. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8658. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8659. for _, item := range advices {
  8660. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8661. redis := service.RedisClient()
  8662. //清空key 值
  8663. redis.Set(key, "", time.Second)
  8664. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8665. redis.Set(keyTwo, "", time.Second)
  8666. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8667. redis.Set(keyThree, "", time.Second)
  8668. recordDate := theTime.Format("2006-01-02")
  8669. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8670. redis.Set(keyFour, "", time.Second)
  8671. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8672. redis.Set(keyFive, "", time.Second)
  8673. defer redis.Close()
  8674. }
  8675. if errs == nil {
  8676. for _, item := range advices {
  8677. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8678. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8679. //查询是否出库按钮开启
  8680. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8681. if adviceSetting.IsAdviceOpen == 1 {
  8682. //查询是否出库按钮开启
  8683. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8684. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8685. if prescriptionConfig.IsOpen == 1 {
  8686. if medical.IsUse == 2 {
  8687. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8688. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8689. }
  8690. if pharmacyConfig.IsOpen != 1 {
  8691. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8692. }
  8693. //更新字典里面的库存
  8694. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8695. var sum_count int64
  8696. for _, its := range stockInfo {
  8697. if its.MaxUnit == medical.MaxUnit {
  8698. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8699. }
  8700. sum_count += its.StockMaxNumber + its.StockMinNumber
  8701. }
  8702. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8703. //剩余库存
  8704. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8705. }
  8706. }
  8707. } else {
  8708. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8709. if medical.IsUse == 2 {
  8710. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8711. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8712. }
  8713. if pharmacyConfig.IsOpen != 1 {
  8714. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8715. }
  8716. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8717. var sum_count int64
  8718. for _, its := range stockInfo {
  8719. if its.MaxUnit == medical.MaxUnit {
  8720. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8721. }
  8722. sum_count += its.StockMaxNumber + its.StockMinNumber
  8723. }
  8724. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8725. //剩余库存
  8726. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8727. }
  8728. }
  8729. }
  8730. }
  8731. this.ServeSuccessJSON(map[string]interface{}{
  8732. "msg": "1",
  8733. "ids": ids,
  8734. })
  8735. return
  8736. } else {
  8737. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8738. //执行医嘱
  8739. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8740. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8741. for _, item := range advices {
  8742. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8743. redis := service.RedisClient()
  8744. //清空key 值
  8745. redis.Set(key, "", time.Second)
  8746. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8747. redis.Set(keyTwo, "", time.Second)
  8748. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8749. redis.Set(keyThree, "", time.Second)
  8750. recordDate := theTime.Format("2006-01-02")
  8751. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8752. redis.Set(keyFour, "", time.Second)
  8753. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8754. redis.Set(keyFive, "", time.Second)
  8755. defer redis.Close()
  8756. }
  8757. this.ServeSuccessJSON(map[string]interface{}{
  8758. "msg": "1",
  8759. "ids": ids,
  8760. })
  8761. return
  8762. }
  8763. }
  8764. }
  8765. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8766. ids := this.GetString("ids")
  8767. idSplit := strings.Split(ids, ",")
  8768. orgId := this.GetMobileAdminUserInfo().Org.Id
  8769. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8770. if config.IsOpen == 1 {
  8771. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8772. this.ServeSuccessJSON(map[string]interface{}{
  8773. "msg": "1",
  8774. "ids": ids,
  8775. })
  8776. return
  8777. }
  8778. if config.IsOpen == 0 || config.IsOpen == 2 {
  8779. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8780. this.ServeSuccessJSON(map[string]interface{}{
  8781. "msg": "1",
  8782. "ids": ids,
  8783. })
  8784. return
  8785. }
  8786. }
  8787. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8788. ids := this.GetString("ids")
  8789. idSplit := strings.Split(ids, ",")
  8790. orgId := this.GetMobileAdminUserInfo().Org.Id
  8791. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8792. //his
  8793. if config.IsOpen == 1 {
  8794. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8795. theTime := time.Now()
  8796. advices := models.HisDoctorAdviceThirty{
  8797. CheckTime: theTime.Unix(),
  8798. Checker: checker,
  8799. UpdatedTime: time.Now().Unix(),
  8800. }
  8801. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8802. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8803. for _, item := range list {
  8804. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8805. redis := service.RedisClient()
  8806. //清空key 值
  8807. redis.Set(key, "", time.Second)
  8808. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8809. redis.Set(keyTwo, "", time.Second)
  8810. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8811. redis.Set(keyThree, "", time.Second)
  8812. recordDate := theTime.Format("2006-01-02")
  8813. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8814. redis.Set(keyFour, "", time.Second)
  8815. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8816. redis.Set(keyFive, "", time.Second)
  8817. defer redis.Close()
  8818. }
  8819. this.ServeSuccessJSON(map[string]interface{}{
  8820. "msg": "1",
  8821. "ids": ids,
  8822. })
  8823. return
  8824. }
  8825. //血透
  8826. if config.IsOpen == 0 || config.IsOpen == 2 {
  8827. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8828. theTime := time.Now()
  8829. advices := models.DoctorAdvice{
  8830. CheckTime: theTime.Unix(),
  8831. Checker: checker,
  8832. UpdatedTime: time.Now().Unix(),
  8833. }
  8834. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8835. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8836. for _, item := range list {
  8837. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8838. redis := service.RedisClient()
  8839. //清空key 值
  8840. redis.Set(key, "", time.Second)
  8841. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8842. redis.Set(keyTwo, "", time.Second)
  8843. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8844. redis.Set(keyThree, "", time.Second)
  8845. recordDate := theTime.Format("2006-01-02")
  8846. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8847. redis.Set(keyFour, "", time.Second)
  8848. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8849. redis.Set(keyFive, "", time.Second)
  8850. defer redis.Close()
  8851. }
  8852. this.ServeSuccessJSON(map[string]interface{}{
  8853. "msg": "1",
  8854. "ids": ids,
  8855. })
  8856. return
  8857. }
  8858. }
  8859. func (this *DialysisAPIController) CheckSchedule() {
  8860. patientID, _ := this.GetInt64("patient_id")
  8861. recordDateStr := this.GetString("record_date")
  8862. nurseID, _ := this.GetInt64("start_nurse")
  8863. schedual_type, _ := this.GetInt64("schedual_type")
  8864. bedID, _ := this.GetInt64("bed")
  8865. start_time := this.GetString("start_time")
  8866. fmt.Println("patientID", patientID)
  8867. fmt.Println("recordDateStr", recordDateStr)
  8868. fmt.Println("nurseID", nurseID)
  8869. fmt.Println("schedual_type------", schedual_type)
  8870. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8872. return
  8873. }
  8874. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8875. if parseStartDateErr != nil {
  8876. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8878. return
  8879. }
  8880. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8881. if parseErr != nil {
  8882. this.ErrorLog("时间解析失败:%v", parseErr)
  8883. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8884. return
  8885. }
  8886. adminUserInfo := this.GetMobileAdminUserInfo()
  8887. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8888. if getPatientErr != nil {
  8889. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8891. return
  8892. } else if patient == nil {
  8893. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8894. return
  8895. }
  8896. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8897. if getNurseErr != nil {
  8898. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8900. return
  8901. } else if nurse == nil {
  8902. this.ErrorLog("护士不存在")
  8903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8904. return
  8905. }
  8906. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8907. if getDeviceNumberErr != nil {
  8908. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8910. return
  8911. } else if deviceNumber == nil {
  8912. this.ErrorLog("床位号不存在")
  8913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8914. return
  8915. }
  8916. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8917. if getRecordErr != nil {
  8918. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8920. return
  8921. } else if dialysisRecord != nil {
  8922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8923. return
  8924. }
  8925. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8926. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8927. timeLayout := "2006-01-02 15:04:05"
  8928. loc, _ := time.LoadLocation("Local")
  8929. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8930. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8931. schedulestartTime := theStartTime.Unix()
  8932. scheduleendTime := theEndTime.Unix()
  8933. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8934. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8935. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8936. //查询该床位是否有人用了
  8937. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8938. if err == nil {
  8939. if schedule.ID == 0 {
  8940. this.ServeSuccessJSON(map[string]interface{}{
  8941. "status": 0,
  8942. "msg": "请求失败",
  8943. })
  8944. } else {
  8945. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8946. if order.ID > 0 { //该机位被其他人占用了
  8947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8948. return
  8949. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8950. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8951. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8952. this.ServeSuccessJSON(map[string]interface{}{
  8953. "status": 1,
  8954. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8955. })
  8956. return
  8957. } else {
  8958. this.ServeSuccessJSON(map[string]interface{}{
  8959. "status": 0,
  8960. "msg": "",
  8961. })
  8962. }
  8963. }
  8964. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8965. this.ServeSuccessJSON(map[string]interface{}{
  8966. "status": 2,
  8967. "msg": "当前机位已有患者在使用,请重新选择!",
  8968. })
  8969. }
  8970. }
  8971. } else {
  8972. this.ServeSuccessJSON(map[string]interface{}{
  8973. "status": 0,
  8974. "msg": "",
  8975. })
  8976. }
  8977. }
  8978. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8979. orgId := this.GetMobileAdminUserInfo().Org.Id
  8980. schedule_type, _ := this.GetInt64("schedule_type")
  8981. partion_type, _ := this.GetInt64("partion_type")
  8982. start_time := this.GetString("start_time")
  8983. timeLayout := "2006-01-02"
  8984. loc, _ := time.LoadLocation("Local")
  8985. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8986. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8987. _, config := service.FindXTHisRecordByOrgId(orgId)
  8988. appId := this.GetMobileAdminUserInfo().App.Id
  8989. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8990. if err == nil {
  8991. this.ServeSuccessJSON(map[string]interface{}{
  8992. "list": list,
  8993. "config": config,
  8994. "doctorList": doctorList,
  8995. })
  8996. return
  8997. } else {
  8998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8999. return
  9000. }
  9001. }
  9002. func (this *DialysisAPIController) SaveMobileInformation() {
  9003. patient_id, _ := this.GetInt64("patient_id")
  9004. record_date, _ := this.GetInt64("record_date")
  9005. startTime := this.GetString("start_time")
  9006. module, _ := this.GetInt64("module")
  9007. remark := this.GetString("remark")
  9008. timeLayout := "2006-01-02 15:04"
  9009. loc, _ := time.LoadLocation("Local")
  9010. if len(startTime) == 0 {
  9011. utils.ErrorLog("len(start_time) == 0")
  9012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9013. return
  9014. }
  9015. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9016. if err != nil {
  9017. utils.ErrorLog(err.Error())
  9018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9019. return
  9020. }
  9021. StartTime := theTime.Unix()
  9022. fmt.Println("startime-------------", StartTime)
  9023. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9024. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9025. information := models.XtDialysisInformation{
  9026. Module: module,
  9027. PatientId: patient_id,
  9028. RecordDate: record_date,
  9029. ApplicationDate: StartTime,
  9030. Creater: creater,
  9031. ApplicationStatus: 2,
  9032. Checker: 0,
  9033. CheckTime: 0,
  9034. Remark: remark,
  9035. UserOrgId: user_org_id,
  9036. Ctime: time.Now().Unix(),
  9037. Status: 1,
  9038. Mtime: 0,
  9039. }
  9040. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9041. if infor.ID == 0 {
  9042. service.SaveDialysisInformation(information)
  9043. }
  9044. if infor.ID > 0 {
  9045. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9046. }
  9047. this.ServeSuccessJSON(map[string]interface{}{
  9048. "information": information,
  9049. })
  9050. return
  9051. }
  9052. func (this *DialysisAPIController) GetMobileInformation() {
  9053. limit, _ := this.GetInt64("limit")
  9054. page, _ := this.GetInt64("page")
  9055. orgid := this.GetMobileAdminUserInfo().Org.Id
  9056. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9057. appid := this.GetMobileAdminUserInfo().App.Id
  9058. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9059. patients, _ := service.GetAllpatientThirty(orgid)
  9060. this.ServeSuccessJSON(map[string]interface{}{
  9061. "information": information,
  9062. "total": total,
  9063. "doclist": doclist,
  9064. "patients": patients,
  9065. })
  9066. return
  9067. }
  9068. func (this *DialysisAPIController) GetMobileInformationOne() {
  9069. limit, _ := this.GetInt64("limit")
  9070. page, _ := this.GetInt64("page")
  9071. orgid := this.GetMobileAdminUserInfo().Org.Id
  9072. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9073. appid := this.GetMobileAdminUserInfo().App.Id
  9074. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9075. patients, _ := service.GetAllpatientThirty(orgid)
  9076. this.ServeSuccessJSON(map[string]interface{}{
  9077. "information": information,
  9078. "total": total,
  9079. "doclist": doclist,
  9080. "patients": patients,
  9081. })
  9082. return
  9083. }
  9084. func (this *DialysisAPIController) CheckMobileInformation() {
  9085. id, _ := this.GetInt64("id")
  9086. application_status, _ := this.GetInt64("application_status")
  9087. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9088. checktime := time.Now().Unix()
  9089. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9090. if err == nil {
  9091. this.ServeSuccessJSON(map[string]interface{}{
  9092. "msg": "ok",
  9093. })
  9094. return
  9095. }
  9096. }
  9097. func (c *DialysisAPIController) GetControlMonitorList() {
  9098. partition, _ := c.GetInt64("partition")
  9099. monitorDate := c.GetString("date")
  9100. patient_id, _ := c.GetInt64("patient_id")
  9101. pat_type, _ := c.GetInt64("pat_type")
  9102. timeLayout := "2006-01-02"
  9103. loc, _ := time.LoadLocation("Local")
  9104. var theStartTime int64
  9105. if len(monitorDate) > 0 {
  9106. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9107. if err != nil {
  9108. theStartTime = 0
  9109. }
  9110. theStartTime = theTime.Unix()
  9111. }
  9112. adminInfo := c.GetMobileAdminUserInfo()
  9113. orgID := adminInfo.Org.Id
  9114. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9115. if err != nil {
  9116. c.ErrorLog("获取排班信息失败:%v", err)
  9117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9118. } else {
  9119. if len(monitor) > 0 {
  9120. //获取所有床位
  9121. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9122. //获取所有分区
  9123. zoneList, _ := service.GetAllZoneByList(orgID)
  9124. //获取透析处方
  9125. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9126. //获取透前评估
  9127. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9128. //获取上机
  9129. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9130. //获取透后
  9131. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9132. //获取透后监测
  9133. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9134. //获取所有的患者
  9135. patients, _ := service.GetAllPatientListByListOne(orgID)
  9136. //获取所有透析模式
  9137. treatments, _ := service.GetAllTreatModeByList(orgID)
  9138. //获取所有医嘱
  9139. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9140. //获取双人核对
  9141. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9142. //治疗小结
  9143. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9144. //待消毒
  9145. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9146. for key, item := range monitor {
  9147. // 获取床位信息
  9148. for _, it := range numberList {
  9149. if item.BedId == it.ID {
  9150. monitor[key].DeviceNumber = it
  9151. break
  9152. }
  9153. }
  9154. //获取分区信息
  9155. for _, it := range zoneList {
  9156. if item.PartitionId == it.ID {
  9157. monitor[key].DeviceZone = it
  9158. }
  9159. }
  9160. for _, prescription := range prescriptions {
  9161. if item.PatientId == prescription.PatientId {
  9162. monitor[key].Prescription = prescription
  9163. break
  9164. }
  9165. }
  9166. for _, it := range checkList {
  9167. if item.PatientId == it.PatientId {
  9168. monitor[key].DoubleCheck = it
  9169. break
  9170. }
  9171. }
  9172. for _, it := range summaryList {
  9173. if item.PatientId == it.PatientId {
  9174. monitor[key].TreatmentSummaryForList = it
  9175. break
  9176. }
  9177. }
  9178. // 透前评估
  9179. for _, assessmentBefore := range assessmentBefores {
  9180. if item.PatientId == assessmentBefore.PatientId {
  9181. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9182. break
  9183. }
  9184. }
  9185. // 透析上下机
  9186. for _, dialysisOrder := range dialysisOrders {
  9187. if item.PatientId == dialysisOrder.PatientId {
  9188. monitor[key].DialysisOrder = dialysisOrder
  9189. break
  9190. }
  9191. }
  9192. // 治疗小节
  9193. for _, afterDislysis := range AssessmentAfterDislysis {
  9194. if item.PatientId == afterDislysis.PatientId {
  9195. monitor[key].AssessmentAfterDislysis = afterDislysis
  9196. break
  9197. }
  9198. }
  9199. for _, it := range monitorlist {
  9200. if item.PatientId == it.PatientId {
  9201. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9202. }
  9203. }
  9204. for _, it := range adviceList {
  9205. if item.PatientId == it.PatientId {
  9206. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9207. }
  9208. }
  9209. for _, patient := range patients {
  9210. if item.PatientId == patient.ID {
  9211. monitor[key].MonitorPatients = patient
  9212. break
  9213. }
  9214. }
  9215. for _, treatment := range treatments {
  9216. if item.ModeId == treatment.ID {
  9217. monitor[key].TreatmentMode = treatment
  9218. break
  9219. }
  9220. }
  9221. for _, infor := range informationList {
  9222. if item.PatientId == infor.PatientId {
  9223. monitor[key].NewDeviceInformation = infor
  9224. break
  9225. }
  9226. }
  9227. }
  9228. }
  9229. }
  9230. patients, err := service.GetAllpatientFourty(orgID)
  9231. var mds []*models.NewMonitorDialysisScheduleList
  9232. if pat_type == 0 {
  9233. for _, item := range monitor {
  9234. mds = append(mds, item)
  9235. }
  9236. }
  9237. //待医嘱核对
  9238. if pat_type == 1 {
  9239. for _, item := range monitor {
  9240. if len(item.AdviceList) > 0 {
  9241. mds = append(mds, item)
  9242. }
  9243. }
  9244. }
  9245. //待开小结
  9246. if pat_type == 2 {
  9247. for _, item := range monitor {
  9248. if item.TreatmentSummaryForList == nil {
  9249. mds = append(mds, item)
  9250. }
  9251. }
  9252. }
  9253. //待下机
  9254. if pat_type == 3 {
  9255. for _, item := range monitor {
  9256. if item.DialysisOrder != nil {
  9257. if item.DialysisOrder.ID > 0 {
  9258. mds = append(mds, item)
  9259. }
  9260. }
  9261. }
  9262. }
  9263. //待消毒
  9264. if pat_type == 4 {
  9265. for _, item := range monitor {
  9266. if item.NewDeviceInformation == nil {
  9267. mds = append(mds, item)
  9268. }
  9269. }
  9270. }
  9271. //待双人核对
  9272. if pat_type == 5 {
  9273. for _, item := range monitor {
  9274. if item.DoubleCheck == nil {
  9275. mds = append(mds, item)
  9276. }
  9277. }
  9278. }
  9279. //医嘱未执行
  9280. if pat_type == 6 {
  9281. for _, item := range monitor {
  9282. if len(item.AdviceList) > 0 {
  9283. mds = append(mds, item)
  9284. }
  9285. }
  9286. }
  9287. //患者未签名
  9288. if pat_type == 7 {
  9289. for _, item := range monitor {
  9290. if item.DialysisOrder != nil {
  9291. if item.DialysisOrder.ID > 0 {
  9292. mds = append(mds, item)
  9293. }
  9294. }
  9295. }
  9296. }
  9297. //目标超滤于实际超滤不同
  9298. if pat_type == 8 {
  9299. for _, item := range monitor {
  9300. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9301. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9302. mds = append(mds, item)
  9303. }
  9304. }
  9305. }
  9306. }
  9307. //血压少于5次
  9308. if pat_type == 9 {
  9309. for _, item := range monitor {
  9310. if len(item.MonitoringRecord) < 5 {
  9311. mds = append(mds, item)
  9312. }
  9313. }
  9314. }
  9315. if pat_type == 10 {
  9316. for _, item := range monitor {
  9317. if len(item.MonitoringRecord) == 0 {
  9318. mds = append(mds, item)
  9319. }
  9320. }
  9321. }
  9322. if pat_type == 11 {
  9323. for _, item := range monitor {
  9324. if len(item.MonitoringRecord) > 0 {
  9325. mds = append(mds, item)
  9326. }
  9327. }
  9328. }
  9329. if pat_type == 12 {
  9330. for _, item := range monitor {
  9331. if len(item.MonitoringRecord) > 0 {
  9332. mds = append(mds, item)
  9333. }
  9334. }
  9335. }
  9336. if err == nil {
  9337. c.ServeSuccessJSON(map[string]interface{}{
  9338. "monitor": mds,
  9339. "patients": patients,
  9340. })
  9341. } else {
  9342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9343. }
  9344. }
  9345. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9346. admin_user_id, _ := c.GetInt64("admin_user_id")
  9347. timeStr := time.Now().Format("2006-01-02")
  9348. timeLayout := "2006-01-02 15:04:05"
  9349. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9350. timenow := timeStringToTime.Unix()
  9351. orgId := c.GetMobileAdminUserInfo().Org.Id
  9352. //查询当前护士的患者
  9353. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9354. var patientIds []int64
  9355. for _, item := range orderList {
  9356. patientIds = append(patientIds, item.PatientId)
  9357. }
  9358. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9359. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9360. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9361. //药品管理信息
  9362. _, drugStockConfig := service.FindHisConfig(orgId)
  9363. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9364. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9365. c.ServeSuccessJSON(map[string]interface{}{
  9366. "adviceList": adviceList,
  9367. "hisAdviceList": hisAdviceList,
  9368. "projectList": projectList,
  9369. "drugStockConfig": drugStockConfig,
  9370. "patientList": patientList,
  9371. "projectConfig": projectConfig,
  9372. })
  9373. }
  9374. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9375. patient_id, _ := c.GetInt64("patient_id")
  9376. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9377. c.ServeSuccessJSON(map[string]interface{}{
  9378. "recrods": recrods,
  9379. })
  9380. }
  9381. func (c *DialysisAPIController) ExMobileChangeSch() {
  9382. id_one, _ := c.GetInt64("id_one")
  9383. id_two, _ := c.GetInt64("id_two")
  9384. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9385. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9386. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9387. //if order2.ID > 0 {
  9388. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9389. // return
  9390. //}
  9391. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9392. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9393. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9394. if count > 0 {
  9395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9396. return
  9397. }
  9398. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9399. if count1 > 0 {
  9400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9401. return
  9402. }
  9403. }
  9404. err := service.UpdateScheduleThree(sch, sch_two)
  9405. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9406. if order.ID > 0 {
  9407. //查询该患者的排班机位
  9408. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9409. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9410. redis := service.RedisClient()
  9411. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9412. redis.Set(key, "", time.Second)
  9413. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9414. //清空key 值
  9415. redis.Set(keyOne, "", time.Second)
  9416. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9417. //return
  9418. }
  9419. if err == nil {
  9420. //去除当天患者排班中重复数据,保留最后一条数据
  9421. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9422. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9423. c.ServeSuccessJSON(map[string]interface{}{
  9424. "msg": "交换成功",
  9425. })
  9426. } else {
  9427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9428. return
  9429. }
  9430. }
  9431. func (c *DialysisAPIController) MobileCoverSch() {
  9432. id_one, _ := c.GetInt64("id_one")
  9433. id_two, _ := c.GetInt64("id_two")
  9434. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9435. //针对凤凰医院
  9436. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9437. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9438. if len(advice) > 0 {
  9439. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9440. }
  9441. }
  9442. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9443. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9444. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9445. if len(hisAdvice) > 0 {
  9446. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9447. }
  9448. if len(project) > 0 {
  9449. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9450. }
  9451. }
  9452. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9453. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9454. if order.ID > 0 {
  9455. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9456. redis := service.RedisClient()
  9457. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9458. redis.Set(key, "", time.Second)
  9459. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9460. //清空key 值
  9461. redis.Set(keyOne, "", time.Second)
  9462. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9463. //return
  9464. }
  9465. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9466. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9467. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9468. if count > 0 {
  9469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9470. return
  9471. }
  9472. }
  9473. var new_sch models.Schedule
  9474. new_sch = sch
  9475. new_sch.BedId = sch_two.BedId
  9476. new_sch.ScheduleDate = sch_two.ScheduleDate
  9477. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9478. new_sch.PartitionId = sch_two.PartitionId
  9479. new_sch.ScheduleType = sch_two.ScheduleType
  9480. new_sch.ID = 0
  9481. //删除原来的排班
  9482. err := service.SaveSchTwo(sch, sch_two)
  9483. //生成新的排班
  9484. if err == nil {
  9485. err2 := service.SaveSch(&new_sch)
  9486. if err2 == nil {
  9487. //去除当天患者排班中重复数据,保留最后一条数据
  9488. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9489. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9490. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9491. c.ServeSuccessJSON(map[string]interface{}{
  9492. "msg": "覆盖成功",
  9493. "new_sch": new_sch,
  9494. })
  9495. } else {
  9496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9497. return
  9498. }
  9499. } else {
  9500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9501. return
  9502. }
  9503. }
  9504. func (c *DialysisAPIController) BatchCheckAdvice() {
  9505. patient_id, _ := c.GetInt64("patient_id")
  9506. advice_date, _ := c.GetInt64("advice_date")
  9507. org_id := c.GetMobileAdminUserInfo().Org.Id
  9508. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9509. //查询是his系统还是血透系统
  9510. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9511. //his客户
  9512. if configs.IsOpen == 1 {
  9513. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9514. for _, item := range adviceList {
  9515. service.BatchCheckHisAdvice(item.ID, creater)
  9516. }
  9517. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9518. for _, item := range projectList {
  9519. service.BatchCheckProject(item.ID, creater)
  9520. }
  9521. c.ServeSuccessJSON(map[string]interface{}{
  9522. "adviceList": adviceList,
  9523. "projectList": projectList,
  9524. })
  9525. }
  9526. if configs.IsOpen != 1 {
  9527. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9528. for _, item := range adviceList {
  9529. service.BatchAdviceList(item.ID, creater)
  9530. }
  9531. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9532. for _, item := range projectList {
  9533. service.BatchCheckProject(item.ID, creater)
  9534. }
  9535. c.ServeSuccessJSON(map[string]interface{}{
  9536. "adviceList": adviceList,
  9537. "projectList": projectList,
  9538. })
  9539. }
  9540. return
  9541. }
  9542. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9543. org_id := c.GetMobileAdminUserInfo().Org.Id
  9544. drugList, _ := service.GetAllDrugList(org_id)
  9545. c.ServeSuccessJSON(map[string]interface{}{
  9546. "drugList": drugList,
  9547. })
  9548. }
  9549. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9550. org_id := c.GetMobileAdminUserInfo().Org.Id
  9551. dataBody := make(map[string]interface{}, 0)
  9552. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9553. if err != nil {
  9554. utils.ErrorLog(err.Error())
  9555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9556. return
  9557. }
  9558. timeLayout := "2006-01-02"
  9559. loc, _ := time.LoadLocation("Local")
  9560. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9561. utils.ErrorLog("advice_type")
  9562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9563. return
  9564. }
  9565. adviceType := int64(dataBody["advice_type"].(float64))
  9566. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9567. utils.ErrorLog("start_time")
  9568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9569. return
  9570. }
  9571. startTime2, _ := dataBody["start_time"].(string)
  9572. time_arr := strings.Split(startTime2, " ")
  9573. if len(time_arr) > 0 {
  9574. startTime2 = time_arr[0]
  9575. }
  9576. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9577. utils.ErrorLog("advice_date")
  9578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9579. return
  9580. }
  9581. advice_date, _ := dataBody["advice_date"].(string)
  9582. var advicedateunix int64
  9583. if len(advice_date) > 0 {
  9584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9585. if err != nil {
  9586. fmt.Println(err)
  9587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9588. return
  9589. }
  9590. advicedateunix = theTime.Unix()
  9591. }
  9592. adviceDate := startTime2
  9593. if len(adviceDate) == 0 {
  9594. utils.ErrorLog("len(adviceDate) == 0")
  9595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9596. return
  9597. }
  9598. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9599. if err != nil {
  9600. utils.ErrorLog(err.Error())
  9601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9602. return
  9603. }
  9604. AdviceDate := advicedateunix
  9605. RecordDate := advicedateunix
  9606. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9607. utils.ErrorLog("start_time")
  9608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9609. return
  9610. }
  9611. startTime, _ := dataBody["start_time"].(string)
  9612. if len(startTime) == 0 {
  9613. utils.ErrorLog("len(start_time) == 0")
  9614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9615. return
  9616. }
  9617. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9618. if err != nil {
  9619. utils.ErrorLog(err.Error())
  9620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9621. return
  9622. }
  9623. StartTime := theTime.Unix()
  9624. advice_name, _ := dataBody["advice_name"].(string)
  9625. advice_desc, _ := dataBody["advice_desc"].(string)
  9626. delivery_way, _ := dataBody["delivery_way"].(string)
  9627. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9628. frequency_type := int64(dataBody["frequency_type"].(float64))
  9629. frequency_week, _ := dataBody["frequency_week"].(string)
  9630. prescribing_number := dataBody["prescribing_number"].(float64)
  9631. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9632. remark := dataBody["remark"].(string)
  9633. single_dose := dataBody["single_dose"].(float64)
  9634. single_dose_unit := dataBody["single_dose_unit"].(string)
  9635. patient_id := int64(dataBody["patient_id"].(float64))
  9636. day_count := int64(dataBody["day_count"].(float64))
  9637. groupNo := int64(dataBody["group_no"].(float64))
  9638. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9639. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9640. if groupNo <= 0 {
  9641. group := service.GetMaxAdviceGroupID(org_id)
  9642. groupNo = group + 1
  9643. }
  9644. var template_id = ""
  9645. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9646. template_id = "M" + adviceLastId
  9647. advice := models.DoctorAdvice{
  9648. UserOrgId: org_id,
  9649. PatientId: patient_id,
  9650. AdviceType: adviceType,
  9651. AdviceDate: AdviceDate,
  9652. StartTime: StartTime,
  9653. AdviceName: advice_name,
  9654. AdviceDesc: advice_desc,
  9655. ReminderDate: 0,
  9656. SingleDose: single_dose,
  9657. SingleDoseUnit: single_dose_unit,
  9658. DrugSpec: 0,
  9659. DrugSpecUnit: "",
  9660. PrescribingNumber: prescribing_number,
  9661. PrescribingNumberUnit: prescribing_number_unit,
  9662. DeliveryWay: delivery_way,
  9663. ExecutionFrequency: execution_frequency,
  9664. AdviceDoctor: advice_doctor,
  9665. Status: 1,
  9666. CreatedTime: time.Now().Unix(),
  9667. UpdatedTime: 0,
  9668. AdviceAffirm: "",
  9669. Remark: remark,
  9670. StopTime: 0,
  9671. StopReason: "",
  9672. StopDoctor: 0,
  9673. StopState: 0,
  9674. ParentId: 0,
  9675. ExecutionTime: 0,
  9676. ExecutionStaff: 0,
  9677. ExecutionState: 0,
  9678. Checker: 0,
  9679. RecordDate: RecordDate,
  9680. DialysisOrderId: 0,
  9681. CheckTime: 0,
  9682. CheckState: 0,
  9683. AdviceId: 0,
  9684. RemindType: 0,
  9685. FrequencyType: frequency_type,
  9686. DayCount: day_count,
  9687. WeekDay: frequency_week,
  9688. ChildDoctorAdvice: nil,
  9689. TemplateId: template_id,
  9690. Modifier: 0,
  9691. IsCheck: 0,
  9692. Way: 0,
  9693. DrugId: 0,
  9694. DrugNameId: 0,
  9695. IsMedicine: 0,
  9696. PushStartTime: 0,
  9697. IsSettle: 0,
  9698. IsPrescription: 0,
  9699. GroupNo: groupNo,
  9700. }
  9701. service.CreateMobileAdivce(advice)
  9702. c.ServeSuccessJSON(map[string]interface{}{
  9703. "msg": "保存成功!",
  9704. })
  9705. }
  9706. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9707. patient_id, _ := c.GetInt64("patient_id")
  9708. org_id := c.GetMobileAdminUserInfo().Org.Id
  9709. app_id := c.GetMobileAdminUserInfo().App.Id
  9710. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9711. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9712. c.ServeSuccessJSON(map[string]interface{}{
  9713. "adviceList": adviceList,
  9714. "adminRoles": adminRoles,
  9715. })
  9716. }
  9717. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9718. org_id := c.GetMobileAdminUserInfo().Org.Id
  9719. dataBody := make(map[string]interface{}, 0)
  9720. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9721. if err != nil {
  9722. utils.ErrorLog(err.Error())
  9723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9724. return
  9725. }
  9726. timeLayout := "2006-01-02"
  9727. loc, _ := time.LoadLocation("Local")
  9728. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9729. utils.ErrorLog("start_time")
  9730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9731. return
  9732. }
  9733. startTime2, _ := dataBody["start_time"].(string)
  9734. time_arr := strings.Split(startTime2, " ")
  9735. if len(time_arr) > 0 {
  9736. startTime2 = time_arr[0]
  9737. }
  9738. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9739. utils.ErrorLog("advice_date")
  9740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9741. return
  9742. }
  9743. advice_date, _ := dataBody["advice_date"].(string)
  9744. var advicedateunix int64
  9745. if len(advice_date) > 0 {
  9746. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9747. if err != nil {
  9748. fmt.Println(err)
  9749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9750. return
  9751. }
  9752. advicedateunix = theTime.Unix()
  9753. }
  9754. adviceDate := startTime2
  9755. if len(adviceDate) == 0 {
  9756. utils.ErrorLog("len(adviceDate) == 0")
  9757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9758. return
  9759. }
  9760. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9761. if err != nil {
  9762. utils.ErrorLog(err.Error())
  9763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9764. return
  9765. }
  9766. AdviceDate := advicedateunix
  9767. RecordDate := advicedateunix
  9768. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9769. utils.ErrorLog("start_time")
  9770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9771. return
  9772. }
  9773. startTime, _ := dataBody["start_time"].(string)
  9774. if len(startTime) == 0 {
  9775. utils.ErrorLog("len(start_time) == 0")
  9776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9777. return
  9778. }
  9779. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9780. if err != nil {
  9781. utils.ErrorLog(err.Error())
  9782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9783. return
  9784. }
  9785. StartTime := theTime.Unix()
  9786. advice_name, _ := dataBody["advice_name"].(string)
  9787. advice_desc, _ := dataBody["advice_desc"].(string)
  9788. delivery_way, _ := dataBody["delivery_way"].(string)
  9789. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9790. prescribing_number := dataBody["prescribing_number"].(float64)
  9791. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9792. remark := dataBody["remark"].(string)
  9793. single_dose := dataBody["single_dose"].(float64)
  9794. single_dose_unit := dataBody["single_dose_unit"].(string)
  9795. patient_id := int64(dataBody["patient_id"].(float64))
  9796. groupNo := int64(dataBody["group_no"].(float64))
  9797. parent_id := int64(dataBody["parent_id"].(float64))
  9798. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9799. advice := models.XtDoctorAdviceOne{
  9800. UserOrgId: org_id,
  9801. PatientId: patient_id,
  9802. AdviceType: 1,
  9803. AdviceDate: AdviceDate,
  9804. StartTime: StartTime,
  9805. AdviceName: advice_name,
  9806. AdviceDesc: advice_desc,
  9807. ReminderDate: 0,
  9808. SingleDose: single_dose,
  9809. SingleDoseUnit: single_dose_unit,
  9810. PrescribingNumber: prescribing_number,
  9811. PrescribingNumberUnit: prescribing_number_unit,
  9812. DeliveryWay: delivery_way,
  9813. ExecutionFrequency: execution_frequency,
  9814. AdviceDoctor: advice_doctor,
  9815. Status: 1,
  9816. CreatedTime: time.Now().Unix(),
  9817. UpdatedTime: time.Now().Unix(),
  9818. AdviceAffirm: "",
  9819. Remark: remark,
  9820. StopTime: 0,
  9821. StopReason: "",
  9822. StopDoctor: 0,
  9823. StopState: 0,
  9824. ParentId: parent_id,
  9825. ExecutionTime: 0,
  9826. ExecutionStaff: 0,
  9827. ExecutionState: 0,
  9828. Checker: 0,
  9829. RecordDate: RecordDate,
  9830. DialysisOrderId: 0,
  9831. CheckTime: 0,
  9832. CheckState: 0,
  9833. DrugSpec: 0,
  9834. DrugSpecUnit: "",
  9835. Groupno: groupNo,
  9836. RemindType: 0,
  9837. FrequencyType: 0,
  9838. DayCount: 0,
  9839. WeekDay: "",
  9840. TemplateId: "",
  9841. Modifier: 0,
  9842. }
  9843. service.CreateMobileAdivceOne(advice)
  9844. c.ServeSuccessJSON(map[string]interface{}{
  9845. "msg": "保存成功!",
  9846. })
  9847. }
  9848. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9849. id, _ := c.GetInt64("id")
  9850. service.DeleteSelfAdviceSubAdvice(id)
  9851. c.ServeSuccessJSON(map[string]interface{}{
  9852. "msg": "保存成功!",
  9853. })
  9854. }
  9855. func (c *DialysisAPIController) GetEditAdviceAction() {
  9856. id, _ := c.GetInt64("id")
  9857. org_id := c.GetMobileAdminUserInfo().Org.Id
  9858. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9859. drugList, _ := service.GetAllDrugList(org_id)
  9860. c.ServeSuccessJSON(map[string]interface{}{
  9861. "advice": advice,
  9862. "drugList": drugList,
  9863. })
  9864. }
  9865. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  9866. dataBody := make(map[string]interface{}, 0)
  9867. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9868. if err != nil {
  9869. utils.ErrorLog(err.Error())
  9870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9871. return
  9872. }
  9873. timeLayout := "2006-01-02"
  9874. loc, _ := time.LoadLocation("Local")
  9875. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9876. utils.ErrorLog("start_time")
  9877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9878. return
  9879. }
  9880. startTime2, _ := dataBody["start_time"].(string)
  9881. time_arr := strings.Split(startTime2, " ")
  9882. if len(time_arr) > 0 {
  9883. startTime2 = time_arr[0]
  9884. }
  9885. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9886. utils.ErrorLog("advice_date")
  9887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9888. return
  9889. }
  9890. advice_date, _ := dataBody["advice_date"].(string)
  9891. var advicedateunix int64
  9892. if len(advice_date) > 0 {
  9893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9894. if err != nil {
  9895. fmt.Println(err)
  9896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9897. return
  9898. }
  9899. advicedateunix = theTime.Unix()
  9900. }
  9901. adviceDate := startTime2
  9902. if len(adviceDate) == 0 {
  9903. utils.ErrorLog("len(adviceDate) == 0")
  9904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9905. return
  9906. }
  9907. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9908. if err != nil {
  9909. utils.ErrorLog(err.Error())
  9910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9911. return
  9912. }
  9913. AdviceDate := advicedateunix
  9914. RecordDate := advicedateunix
  9915. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9916. utils.ErrorLog("start_time")
  9917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9918. return
  9919. }
  9920. startTime, _ := dataBody["start_time"].(string)
  9921. if len(startTime) == 0 {
  9922. utils.ErrorLog("len(start_time) == 0")
  9923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9924. return
  9925. }
  9926. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9927. if err != nil {
  9928. utils.ErrorLog(err.Error())
  9929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9930. return
  9931. }
  9932. StartTime := theTime.Unix()
  9933. advice_name, _ := dataBody["advice_name"].(string)
  9934. advice_desc, _ := dataBody["advice_desc"].(string)
  9935. delivery_way, _ := dataBody["delivery_way"].(string)
  9936. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9937. prescribing_number := dataBody["prescribing_number"].(float64)
  9938. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9939. remark := dataBody["remark"].(string)
  9940. single_dose := dataBody["single_dose"].(float64)
  9941. single_dose_unit := dataBody["single_dose_unit"].(string)
  9942. id := int64(dataBody["id"].(float64))
  9943. frequency_type := int64(dataBody["frequency_type"].(float64))
  9944. frequency_week, _ := dataBody["frequency_week"].(string)
  9945. day_count := int64(dataBody["day_count"].(float64))
  9946. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9947. advice := models.XtDoctorAdviceOne{
  9948. AdviceDate: AdviceDate,
  9949. StartTime: StartTime,
  9950. AdviceName: advice_name,
  9951. AdviceDesc: advice_desc,
  9952. SingleDose: single_dose,
  9953. SingleDoseUnit: single_dose_unit,
  9954. PrescribingNumber: prescribing_number,
  9955. PrescribingNumberUnit: prescribing_number_unit,
  9956. DeliveryWay: delivery_way,
  9957. ExecutionFrequency: execution_frequency,
  9958. AdviceDoctor: advice_doctor,
  9959. Remark: remark,
  9960. RecordDate: RecordDate,
  9961. FrequencyType: frequency_type,
  9962. DayCount: day_count,
  9963. WeekDay: frequency_week,
  9964. }
  9965. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  9966. c.ServeSuccessJSON(map[string]interface{}{
  9967. "advice": advice,
  9968. })
  9969. }
  9970. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  9971. dataBody := make(map[string]interface{}, 0)
  9972. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9973. if err != nil {
  9974. utils.ErrorLog(err.Error())
  9975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9976. return
  9977. }
  9978. timeLayout := "2006-01-02"
  9979. loc, _ := time.LoadLocation("Local")
  9980. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9981. utils.ErrorLog("start_time")
  9982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9983. return
  9984. }
  9985. startTime2, _ := dataBody["start_time"].(string)
  9986. time_arr := strings.Split(startTime2, " ")
  9987. if len(time_arr) > 0 {
  9988. startTime2 = time_arr[0]
  9989. }
  9990. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9991. utils.ErrorLog("advice_date")
  9992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9993. return
  9994. }
  9995. advice_date, _ := dataBody["advice_date"].(string)
  9996. var advicedateunix int64
  9997. if len(advice_date) > 0 {
  9998. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9999. if err != nil {
  10000. fmt.Println(err)
  10001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10002. return
  10003. }
  10004. advicedateunix = theTime.Unix()
  10005. }
  10006. adviceDate := startTime2
  10007. if len(adviceDate) == 0 {
  10008. utils.ErrorLog("len(adviceDate) == 0")
  10009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10010. return
  10011. }
  10012. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10013. if err != nil {
  10014. utils.ErrorLog(err.Error())
  10015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10016. return
  10017. }
  10018. AdviceDate := advicedateunix
  10019. RecordDate := advicedateunix
  10020. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10021. utils.ErrorLog("start_time")
  10022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10023. return
  10024. }
  10025. startTime, _ := dataBody["start_time"].(string)
  10026. if len(startTime) == 0 {
  10027. utils.ErrorLog("len(start_time) == 0")
  10028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10029. return
  10030. }
  10031. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10032. if err != nil {
  10033. utils.ErrorLog(err.Error())
  10034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10035. return
  10036. }
  10037. StartTime := theTime.Unix()
  10038. advice_name, _ := dataBody["advice_name"].(string)
  10039. advice_desc, _ := dataBody["advice_desc"].(string)
  10040. delivery_way, _ := dataBody["delivery_way"].(string)
  10041. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10042. prescribing_number := dataBody["prescribing_number"].(float64)
  10043. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10044. remark := dataBody["remark"].(string)
  10045. single_dose := dataBody["single_dose"].(float64)
  10046. single_dose_unit := dataBody["single_dose_unit"].(string)
  10047. id := int64(dataBody["id"].(float64))
  10048. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10049. advice := models.XtDoctorAdviceOne{
  10050. AdviceDate: AdviceDate,
  10051. StartTime: StartTime,
  10052. AdviceName: advice_name,
  10053. AdviceDesc: advice_desc,
  10054. SingleDose: single_dose,
  10055. SingleDoseUnit: single_dose_unit,
  10056. PrescribingNumber: prescribing_number,
  10057. PrescribingNumberUnit: prescribing_number_unit,
  10058. DeliveryWay: delivery_way,
  10059. ExecutionFrequency: execution_frequency,
  10060. AdviceDoctor: advice_doctor,
  10061. Remark: remark,
  10062. RecordDate: RecordDate,
  10063. }
  10064. service.UpdateMobileDoctorAdviceById(id, advice)
  10065. c.ServeSuccessJSON(map[string]interface{}{
  10066. "advice": advice,
  10067. })
  10068. }
  10069. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10070. dataBody := make(map[string]interface{}, 0)
  10071. timeLayout := "2006-01-02"
  10072. loc, _ := time.LoadLocation("Local")
  10073. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10074. if err != nil {
  10075. utils.ErrorLog(err.Error())
  10076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10077. return
  10078. }
  10079. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10080. utils.ErrorLog("start_time")
  10081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10082. return
  10083. }
  10084. startTime2, _ := dataBody["start_time"].(string)
  10085. time_arr := strings.Split(startTime2, " ")
  10086. if len(time_arr) > 0 {
  10087. startTime2 = time_arr[0]
  10088. }
  10089. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10090. utils.ErrorLog("advice_date")
  10091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10092. return
  10093. }
  10094. advice_date, _ := dataBody["advice_date"].(string)
  10095. var advicedateunix int64
  10096. if len(advice_date) > 0 {
  10097. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10098. if err != nil {
  10099. fmt.Println(err)
  10100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10101. return
  10102. }
  10103. advicedateunix = theTime.Unix()
  10104. }
  10105. adviceDate := startTime2
  10106. if len(adviceDate) == 0 {
  10107. utils.ErrorLog("len(adviceDate) == 0")
  10108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10109. return
  10110. }
  10111. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10112. if err != nil {
  10113. utils.ErrorLog(err.Error())
  10114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10115. return
  10116. }
  10117. RecordDate := advicedateunix
  10118. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10119. utils.ErrorLog("start_time")
  10120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10121. return
  10122. }
  10123. startTime, _ := dataBody["start_time"].(string)
  10124. if len(startTime) == 0 {
  10125. utils.ErrorLog("len(start_time) == 0")
  10126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10127. return
  10128. }
  10129. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10130. if err != nil {
  10131. utils.ErrorLog(err.Error())
  10132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10133. return
  10134. }
  10135. StartTime := theTime.Unix()
  10136. patient_id := int64(dataBody["patient_id"].(float64))
  10137. group_no := int64(dataBody["group_no"].(float64))
  10138. org_id := c.GetMobileAdminUserInfo().Org.Id
  10139. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10140. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10141. utils.ErrorLog("advices")
  10142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10143. return
  10144. }
  10145. adviceNames := dataBody["advices"].([]interface{})
  10146. var advices []*models.GroupAdvice
  10147. for _, adviceNameMap := range adviceNames {
  10148. var advice models.GroupAdvice
  10149. adviceNameM := adviceNameMap.(map[string]interface{})
  10150. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10151. utils.ErrorLog("advice_name")
  10152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10153. return
  10154. }
  10155. adviceName, _ := adviceNameM["advice_name"].(string)
  10156. if len(adviceName) == 0 {
  10157. utils.ErrorLog("len(advice_name) == 0")
  10158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10159. return
  10160. }
  10161. advice.AdviceName = adviceName
  10162. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10163. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10164. advice.DrugSpec = drugSpec
  10165. }
  10166. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10167. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10168. advice.AdviceDesc = adviceDesc
  10169. }
  10170. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10171. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10172. advice.DrugSpecUnit = drugSpecUnit
  10173. }
  10174. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10175. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10176. advice.SingleDose = singleDose
  10177. }
  10178. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10179. singleDose := adviceNameM["single_dose"].(float64)
  10180. advice.SingleDose = singleDose
  10181. }
  10182. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10183. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10184. advice.SingleDoseUnit = singleDoseUnit
  10185. }
  10186. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10187. tmp := adviceNameM["single_dose_unit"].(float64)
  10188. singleDoseUnit := service.TypeConversion(tmp)
  10189. advice.SingleDoseUnit = singleDoseUnit
  10190. }
  10191. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10192. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10193. advice.PrescribingNumber = prescribingNumber
  10194. }
  10195. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10196. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10197. advice.PrescribingNumber = prescribingNumber
  10198. }
  10199. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10200. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10201. advice.PrescribingNumberUnit = prescribingNumberUnit
  10202. }
  10203. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10204. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10205. advice.DeliveryWay = deliveryWay
  10206. }
  10207. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10208. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10209. advice.ExecutionFrequency = executionFrequency
  10210. }
  10211. remark, _ := adviceNameM["remark"].(string)
  10212. advice.Remark = remark
  10213. advice.AdviceType = 1
  10214. advice.StartTime = StartTime
  10215. advice.RecordDate = RecordDate
  10216. advice.PatientId = patient_id
  10217. advice.UserOrgId = org_id
  10218. advice.AdviceDoctor = advice_doctor
  10219. advices = append(advices, &advice)
  10220. }
  10221. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10222. c.ServeSuccessJSON(map[string]interface{}{
  10223. "advice": newAdvices,
  10224. })
  10225. }