dialysis_api_controller.go 426KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976
  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. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1125. if infor.ID > 0 && infor.WeekDay > 0 {
  1126. var cha_time int64
  1127. timeNowStr := time.Now().Format("2006-01-02")
  1128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1129. //今日的日期减去设置的日期
  1130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1131. if cha_time >= recordDate.Unix() {
  1132. //查询审核是否允许
  1133. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1134. //申请状态不允许的情况 拒绝修改
  1135. if infor.ApplicationStatus != 1 {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1137. return
  1138. }
  1139. }
  1140. }
  1141. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1142. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1143. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1144. receiveTreatmentAsses.ID = receiveTreatment.ID
  1145. if adminUserInfo.Org.Id == 10340 {
  1146. if condition == 1 {
  1147. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1148. if receiveTreatmentAsses.AdmissionNumber == "" {
  1149. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1150. }
  1151. }
  1152. }
  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. if adminUserInfo.Org.Id == 10723 {
  3186. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3187. ultrafiltration_rate = ultrafiltration_rate / 1000
  3188. }
  3189. }
  3190. }
  3191. record := models.MonitoringRecord{
  3192. UserOrgId: adminUserInfo.Org.Id,
  3193. PatientId: patientID,
  3194. DialysisOrderId: dialysisRecord.ID,
  3195. MonitoringDate: schedulestartTime,
  3196. OperateTime: startDate.Unix(),
  3197. // MonitoringTime: recordTime,
  3198. MonitoringNurse: nurseID,
  3199. Dispose: tempdispose,
  3200. UltrafiltrationRate: ultrafiltration_rate,
  3201. UltrafiltrationVolume: 0,
  3202. Status: 1,
  3203. CreatedTime: time.Now().Unix(),
  3204. UpdatedTime: time.Now().Unix(),
  3205. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3206. }
  3207. //只针对广慈医院
  3208. 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 {
  3209. // 查询病人是否有透前评估数据
  3210. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3211. //如果有数据就插入
  3212. if errcode == nil {
  3213. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3214. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3215. record.BreathingRate = befor.BreathingRate
  3216. record.PulseFrequency = befor.PulseFrequency
  3217. record.Temperature = befor.Temperature
  3218. }
  3219. }
  3220. //孝昌
  3221. if adminUserInfo.Org.Id == 10693 {
  3222. // 查询病人是否有透前评估数据
  3223. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3224. //如果有数据就插入
  3225. if errcode == nil {
  3226. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3227. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3228. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3229. record.BreathingRate = befor.BreathingRate
  3230. }
  3231. }
  3232. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3233. if newdialysisRecord.ID > 0 {
  3234. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3235. record.Temperature = 36.5
  3236. record.ArterialPressure = -100
  3237. record.DialysateTemperature = 36.5
  3238. record.Conductivity = 14
  3239. record.BreathingRate = "20"
  3240. record.VenousPressure = 80
  3241. record.TransmembranePressure = 60
  3242. record.Dispose = catheter_operation
  3243. }
  3244. //针对新化博翔
  3245. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3246. record.BloodOxygenSaturation = "99"
  3247. record.Conductivity = 14
  3248. record.DialysateTemperature = 36.5
  3249. record.BreathingRate = "20"
  3250. }
  3251. //针对兰溪人民医院的需求
  3252. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3253. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3254. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3255. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3256. record.Temperature = befor.Temperature
  3257. record.PulseFrequency = befor.PulseFrequency
  3258. record.BreathingRate = befor.BreathingRate
  3259. }
  3260. //针对乐山友谊医院的需求
  3261. if adminUserInfo.Org.Id == 10677 {
  3262. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3263. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3264. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3265. record.Temperature = befor.Temperature
  3266. record.PulseFrequency = befor.PulseFrequency
  3267. record.BreathingRate = befor.BreathingRate
  3268. }
  3269. //新化博翔
  3270. if adminUserInfo.Org.Id == 10447 {
  3271. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3272. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3273. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3274. record.BreathingRate = befor.BreathingRate
  3275. }
  3276. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3277. record.PulseFrequency = 80
  3278. record.Temperature = 36.5
  3279. }
  3280. //诊断灵山圣康
  3281. if adminUserInfo.Org.Id == 10375 {
  3282. record.Conductivity = 13.8
  3283. record.DialysateTemperature = 37
  3284. record.DialysateFlow = 500
  3285. record.BloodFlowVolume = 200
  3286. record.BreathingRate = "18"
  3287. record.SodiumConcentration = 140
  3288. }
  3289. //江成肾病医院
  3290. if adminUserInfo.Org.Id == 10517 {
  3291. record.SodiumConcentration = 138
  3292. record.DialysateTemperature = 36.5
  3293. }
  3294. if adminUserInfo.Org.Id != 10683 {
  3295. err = service.CreateMonitor(&record)
  3296. }
  3297. //记录日志
  3298. byterequest, _ := json.Marshal(record)
  3299. monitorRecordLog := models.XtMonitorRecordLog{
  3300. RecordDate: record.MonitoringDate,
  3301. PatientId: record.PatientId,
  3302. Module: 1,
  3303. AdminUserId: adminUserInfo.AdminUser.Id,
  3304. Ctime: time.Now().Unix(),
  3305. Mtime: 0,
  3306. Status: 1,
  3307. UserOrgId: record.UserOrgId,
  3308. ErrLog: string(byterequest),
  3309. Source: "执行上机时新增监测",
  3310. }
  3311. service.CreateMonitorRecordLog(monitorRecordLog)
  3312. finish := models.XtDialysisFinish{
  3313. IsFinish: 1,
  3314. UserOrgId: adminUserInfo.Org.Id,
  3315. Status: 1,
  3316. Ctime: time.Now().Unix(),
  3317. Mtime: 0,
  3318. Module: 7,
  3319. RecordDate: schedulestartTime,
  3320. Sourse: 1,
  3321. PatientId: patientID,
  3322. }
  3323. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3324. if dialysisFinish.ID == 0 {
  3325. service.CreateDialysisFinish(finish)
  3326. }
  3327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3328. redis := service.RedisClient()
  3329. //清空key 值
  3330. redis.Set(key, "", time.Second)
  3331. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3332. redis.Set(keyOne, "", time.Second)
  3333. defer redis.Close()
  3334. if err != nil {
  3335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3336. return
  3337. }
  3338. }
  3339. go func() {
  3340. ssoDomain := beego.AppConfig.String("call_domain")
  3341. api := ssoDomain + "/index/uppatient"
  3342. values := make(url.Values)
  3343. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3344. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3345. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3346. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3347. http.PostForm(api, values)
  3348. }()
  3349. this.ServeSuccessJSON(map[string]interface{}{
  3350. "dialysis_order": newdialysisRecord,
  3351. "monitor": record,
  3352. })
  3353. return
  3354. }
  3355. func (c *DialysisAPIController) PostSolution() {
  3356. id, _ := c.GetInt64("patient", 0)
  3357. recordDateStr := c.GetString("record_date")
  3358. if id <= 0 {
  3359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3360. return
  3361. }
  3362. adminUserInfo := c.GetMobileAdminUserInfo()
  3363. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3364. if patient.ID == 0 {
  3365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3366. return
  3367. }
  3368. if len(recordDateStr) == 0 {
  3369. recordDateStr = time.Now().Format("2006-01-02")
  3370. }
  3371. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3372. if parseDateErr != nil {
  3373. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3375. return
  3376. }
  3377. mode_id, _ := c.GetInt64("mode_id", 0)
  3378. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3379. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3380. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3381. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3382. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3383. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3384. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3385. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3386. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3387. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3388. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3389. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3390. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3391. kalium, _ := c.GetFloat("kalium", 0)
  3392. sodium, _ := c.GetFloat("sodium", 0)
  3393. calcium, _ := c.GetFloat("calcium", 0)
  3394. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3395. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3396. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3397. glucose, _ := c.GetFloat("glucose", 0)
  3398. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3399. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3400. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3401. conductivity, _ := c.GetFloat("conductivity", 0)
  3402. remark := c.GetString("remark")
  3403. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3404. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3405. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3406. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3407. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3408. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3409. special_medicine_other := c.GetString("special_medicine_other")
  3410. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3411. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3412. blood_access, _ := c.GetInt64("blood_access", 0)
  3413. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3414. body_fluid_other := c.GetString("body_fluid_other")
  3415. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3416. niprocart, _ := c.GetInt64("niprocart", 0)
  3417. jms, _ := c.GetInt64("jms", 0)
  3418. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3419. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3420. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3421. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3422. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3423. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3424. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3425. injector, _ := c.GetInt64("injector", 0)
  3426. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3427. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3428. safe_package, _ := c.GetInt64("package", 0)
  3429. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3430. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3431. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3432. blood := c.GetString("blood")
  3433. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3434. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3435. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3436. displace_speed := c.GetString("displace_speed")
  3437. illness, _ := c.GetInt64("illness")
  3438. amylaceum := c.GetString("amylaceum")
  3439. single_time := c.GetString("single_time")
  3440. single_water := c.GetString("single_water")
  3441. replacement_flow := c.GetString("replacement_flow")
  3442. plasma_separator := c.GetString("plasma_separator")
  3443. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3444. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3445. oxygen_flow := c.GetString("oxygen_flow")
  3446. oxygen_time := c.GetString("oxygen_time")
  3447. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3448. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3449. puncture_needle := c.GetString("puncture_needle")
  3450. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3451. epo := c.GetString("epo")
  3452. epo_count, _ := c.GetFloat("epo_count", 0)
  3453. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3454. pre_impulse := c.GetString("pre_impulse")
  3455. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3456. admin_user_id, _ := c.GetInt64("admin_user_id")
  3457. is_water := c.GetString("is_water")
  3458. add_amount, _ := c.GetFloat("add_amount")
  3459. reduce_amount, _ := c.GetFloat("reduce_amount")
  3460. prescribing_number, _ := c.GetFloat("prescribing_number")
  3461. treatment_remark := c.GetString("treatment_remark")
  3462. prescription_sodium := c.GetString("prescription_sodium")
  3463. start_sodium := c.GetString("start_sodium")
  3464. sodium_curve := c.GetString("sodium_curve")
  3465. var is_war int64
  3466. if is_water == "是" {
  3467. is_war = 1
  3468. }
  3469. if is_water == "否" {
  3470. is_war = 2
  3471. }
  3472. if is_water == "请选择" {
  3473. is_war = 0
  3474. }
  3475. drhy_water := c.GetString("drhy_water")
  3476. dry_water_hour := c.GetString("dry_water_hour")
  3477. water_machine := c.GetString("water_machine")
  3478. dialysis_remark := c.GetString("dialysis_remark")
  3479. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3480. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3481. prescription_water, _ := c.GetFloat("prescription_water")
  3482. dialysis_strainer := c.GetString("dialysis_strainer")
  3483. chaptalization := c.GetString("chaptalization")
  3484. washing_time := c.GetString("washing_time")
  3485. warsh_count := c.GetString("warsh_count")
  3486. blood_access_part_id := c.GetString("blood_access_part_id")
  3487. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3488. dialyzate := c.GetString("dialyzate")
  3489. if mode_id > 0 {
  3490. var str string
  3491. //查找该机构用的是什么透析器
  3492. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3493. if filedConfig.ID > 0 {
  3494. str = dialyzerPerfusionApparatus
  3495. } else {
  3496. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3497. }
  3498. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3499. }
  3500. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3501. //
  3502. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3503. // if appRole.UserType == 3 {
  3504. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3505. // if getPermissionErr != nil {
  3506. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3507. // return
  3508. // } else if headNursePermission == nil {
  3509. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3510. // return
  3511. // }
  3512. // }
  3513. //}
  3514. // 查询信息规挡的设置天数
  3515. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3516. if infor.ID > 0 && infor.WeekDay > 0 {
  3517. var cha_time int64
  3518. timeNowStr := time.Now().Format("2006-01-02")
  3519. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3520. //今日的日期减去设置的日期
  3521. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3522. if cha_time >= recordDate.Unix() {
  3523. //查询审核是否允许
  3524. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3525. //申请状态不允许的情况 拒绝修改
  3526. if infor.ApplicationStatus != 1 {
  3527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3528. return
  3529. }
  3530. }
  3531. }
  3532. prescription := models.DialysisPrescription{
  3533. UserOrgId: adminUserInfo.Org.Id,
  3534. PatientId: id,
  3535. RecordDate: recordDate.Unix(),
  3536. ModeId: mode_id,
  3537. DialysisDuration: dialysis_duration,
  3538. Dialyzer: dialyzer,
  3539. PerfusionApparatus: perfusion_apparatus,
  3540. BloodFlowVolume: blood_flow_volume,
  3541. DewaterAmount: dewater_amount,
  3542. DisplaceLiqui: displace_liqui,
  3543. ReplacementWay: replacement_way,
  3544. Anticoagulant: anticoagulant,
  3545. AnticoagulantShouji: anticoagulant_shouji,
  3546. AnticoagulantWeichi: anticoagulant_weichi,
  3547. AnticoagulantZongliang: anticoagulant_zongliang,
  3548. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3549. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3550. Kalium: kalium,
  3551. Sodium: sodium,
  3552. Calcium: calcium,
  3553. Bicarbonate: bicarbonate,
  3554. Glucose: glucose,
  3555. // DryWeight: dry_weight,
  3556. DialysateFlow: dialysate_flow,
  3557. DialysateTemperature: dialysate_temperature,
  3558. Conductivity: conductivity,
  3559. Remark: remark,
  3560. Status: 1,
  3561. CreatedTime: time.Now().Unix(),
  3562. UpdatedTime: time.Now().Unix(),
  3563. DialysisDurationMinute: dialysisDurationMinute,
  3564. DialysisDurationHour: dialysisDurationHour,
  3565. TargetUltrafiltration: targetUltrafiltration,
  3566. DialysateFormulation: dialysateFormulation,
  3567. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3568. BodyFluid: body_fluid,
  3569. SpecialMedicine: special_medicine,
  3570. SpecialMedicineOther: special_medicine_other,
  3571. DisplaceLiquiPart: displace_liqui_part,
  3572. DisplaceLiquiValue: displace_liqui_value,
  3573. BloodAccess: blood_access,
  3574. Ultrafiltration: ultrafiltration,
  3575. BodyFluidOther: body_fluid_other,
  3576. ReplacementTotal: replacement_total,
  3577. Niprocart: niprocart,
  3578. Jms: jms,
  3579. FistulaNeedleSet: fistula_needle_set,
  3580. FistulaNeedleSet16: fistula_needle_set_16,
  3581. Hemoperfusion: hemoperfusion,
  3582. DialyserSterilised: dialyser_sterilised,
  3583. Filtryzer: filtryzer,
  3584. TargetKtv: target_ktv,
  3585. Dialyzers: dialyzers,
  3586. Injector: injector,
  3587. Bloodlines: bloodlines,
  3588. TubingHemodialysis: tubing_hemodialysis,
  3589. Package: safe_package,
  3590. ALiquid: a_liquid,
  3591. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3592. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3593. Blood: blood,
  3594. DialysisDialyszers: dialysis_dialyszers,
  3595. DialysisIrrigation: dialysis_irrigation,
  3596. AntioxidantCommodityName: antioxidant_commodity_name,
  3597. DisplaceSpeed: displace_speed,
  3598. Illness: illness,
  3599. Amylaceum: amylaceum,
  3600. SingleWater: single_water,
  3601. SingleTime: single_time,
  3602. ReplacementFlow: replacement_flow,
  3603. PlasmaSeparator: plasma_separator,
  3604. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3605. OxygenUptake: oxygen_uptake,
  3606. OxygenTime: oxygen_time,
  3607. OxygenFlow: oxygen_flow,
  3608. HemodialysisPipelines: hemodialysis_pipelines,
  3609. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3610. PunctureNeedle: puncture_needle,
  3611. PunctureNeedleCount: puncture_needle_count,
  3612. Epo: epo,
  3613. EpoCount: epo_count,
  3614. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3615. PreImpulse: impulse,
  3616. AdminUserId: admin_user_id,
  3617. IsWater: is_war,
  3618. DrhyWater: drhy_water,
  3619. DryWaterHour: dry_water_hour,
  3620. WaterMachine: water_machine,
  3621. AddAmount: add_amount,
  3622. ReduceAmount: reduce_amount,
  3623. DialysisRemark: dialysis_remark,
  3624. PrescribingNumber: prescribing_number,
  3625. PrescriptionSodium: prescription_sodium,
  3626. StartSodium: start_sodium,
  3627. SodiumCurve: sodium_curve,
  3628. TreatmentRemark: treatment_remark,
  3629. DialysisFluidFlow: dialysis_fluid_flow,
  3630. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3631. PrescriptionWater: prescription_water,
  3632. DialysisStrainer: dialysis_strainer,
  3633. Chaptalization: chaptalization,
  3634. WashingTime: washing_time,
  3635. WarshCount: warsh_count,
  3636. BloodAccessPartId: blood_access_part_id,
  3637. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3638. Dialyzate: dialyzate,
  3639. }
  3640. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3641. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3642. //
  3643. if appRole.UserType == 2 || appRole.UserType == 1 {
  3644. prescription_doctor = adminUserInfo.AdminUser.Id
  3645. prescription.PrescriptionDoctor = prescription_doctor
  3646. }
  3647. if dialysisPrescription.ID == 0 { //新增
  3648. prescription.Creater = adminUserInfo.AdminUser.Id
  3649. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3650. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3651. }
  3652. } else { //修改
  3653. if dialysisPrescription.Creater == 0 {
  3654. prescription.Creater = adminUserInfo.AdminUser.Id
  3655. } else {
  3656. prescription.Creater = dialysisPrescription.Creater
  3657. if adminUserInfo.Org.Id == 9882 {
  3658. if appRole.UserType == 2 || appRole.UserType == 1 {
  3659. prescription.Creater = adminUserInfo.AdminUser.Id
  3660. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3661. }
  3662. }
  3663. }
  3664. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3665. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3666. }
  3667. //if/**/
  3668. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3669. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3670. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3671. // if getPermissionErr != nil {
  3672. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3673. // return
  3674. // } else if headNursePermission == nil {
  3675. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3676. // return
  3677. // }
  3678. //}
  3679. //prescription.Creater = dialysisPrescription.Creater
  3680. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3681. prescription.Modifier = adminUserInfo.AdminUser.Id
  3682. prescription.ID = dialysisPrescription.ID
  3683. }
  3684. solution := models.DialysisSolution{
  3685. RegistrarsId: adminUserInfo.AdminUser.Id,
  3686. UserOrgId: adminUserInfo.Org.Id,
  3687. Doctor: prescription_doctor,
  3688. PatientId: id,
  3689. ModeId: mode_id,
  3690. DialysisDuration: dialysis_duration,
  3691. PerfusionApparatus: perfusion_apparatus,
  3692. BloodFlowVolume: blood_flow_volume,
  3693. Dewater: dewater_amount,
  3694. DisplaceLiqui: displace_liqui,
  3695. ReplacementWay: replacement_way,
  3696. Anticoagulant: anticoagulant,
  3697. AnticoagulantShouji: anticoagulant_shouji,
  3698. AnticoagulantWeichi: anticoagulant_weichi,
  3699. AnticoagulantZongliang: anticoagulant_zongliang,
  3700. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3701. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3702. Kalium: kalium,
  3703. Sodium: sodium,
  3704. Calcium: calcium,
  3705. Bicarbonate: bicarbonate,
  3706. Glucose: glucose,
  3707. // DryWeight: dry_weight,
  3708. DialysateFlow: dialysate_flow,
  3709. DialysateTemperature: dialysate_temperature,
  3710. Conductivity: conductivity,
  3711. Remark: remark,
  3712. Status: 1,
  3713. CreatedTime: time.Now().Unix(),
  3714. UpdatedTime: time.Now().Unix(),
  3715. DialysisDurationMinute: dialysisDurationMinute,
  3716. DialysisDurationHour: dialysisDurationHour,
  3717. TargetUltrafiltration: targetUltrafiltration,
  3718. DialysateFormulation: dialysateFormulation,
  3719. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3720. BodyFluid: body_fluid,
  3721. SpecialMedicine: special_medicine,
  3722. SpecialMedicineOther: special_medicine_other,
  3723. DisplaceLiquiPart: displace_liqui_part,
  3724. DisplaceLiquiValue: displace_liqui_value,
  3725. BloodAccess: blood_access,
  3726. Ultrafiltration: ultrafiltration,
  3727. BodyFluidOther: body_fluid_other,
  3728. ReplacementTotal: replacement_total,
  3729. TargetKtv: target_ktv,
  3730. DialysisDialyszers: dialysis_dialyszers,
  3731. DialysisIrrigation: dialysis_irrigation,
  3732. HemodialysisPipelines: hemodialysis_pipelines,
  3733. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3734. PunctureNeedle: puncture_needle,
  3735. PunctureNeedleCount: puncture_needle_count,
  3736. Epo: epo,
  3737. EpoCount: epo_count,
  3738. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3739. PreImpulse: impulse,
  3740. SolutionStatus: 1,
  3741. DialysisRemark: dialysis_remark,
  3742. PrescribingNumber: prescribing_number,
  3743. PrescriptionSodium: prescription_sodium,
  3744. StartSodium: start_sodium,
  3745. SodiumCurve: sodium_curve,
  3746. TreatmentRemark: treatment_remark,
  3747. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3748. DialysisFluidFlow: dialysis_fluid_flow,
  3749. PrescriptionWater: prescription_water,
  3750. DialysisStrainer: dialysis_strainer,
  3751. Chaptalization: chaptalization,
  3752. WashingTime: washing_time,
  3753. WarshCount: warsh_count,
  3754. BloodAccessPartId: blood_access_part_id,
  3755. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3756. Dialyzate: dialyzate,
  3757. }
  3758. //针对河间咸的
  3759. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3760. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3761. solution.DisplaceLiquiPart = 0
  3762. solution.DisplaceLiquiValue = 0
  3763. }
  3764. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3765. prescription.DisplaceLiquiPart = 0
  3766. prescription.DisplaceLiquiValue = 0
  3767. }
  3768. }
  3769. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3770. if solution.PrescribingNumber == 0 {
  3771. solution.PrescribingNumber = 1
  3772. }
  3773. if prescription.PrescribingNumber == 0 {
  3774. prescription.PrescribingNumber = 1
  3775. }
  3776. if solution.PrescribingNumber == 0 && id == 14682 {
  3777. solution.PrescribingNumber = 2
  3778. }
  3779. if solution.PrescribingNumber == 0 && id == 18560 {
  3780. solution.PrescribingNumber = 2
  3781. }
  3782. if prescription.PrescribingNumber == 0 && id == 14682 {
  3783. prescription.PrescribingNumber = 2
  3784. }
  3785. if prescription.PrescribingNumber == 0 && id == 18560 {
  3786. prescription.PrescribingNumber = 2
  3787. }
  3788. }
  3789. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3790. //记录日志
  3791. byterequest, _ := json.Marshal(prescription)
  3792. prescriptionLog := models.XtDialysisPrescriptionLog{
  3793. UserOrgId: prescription.UserOrgId,
  3794. Ctime: time.Now().Unix(),
  3795. Mtime: 0,
  3796. ErrLog: string(byterequest),
  3797. AdminUserId: adminUserInfo.AdminUser.Id,
  3798. RecordDate: prescription.RecordDate,
  3799. PatientId: prescription.PatientId,
  3800. Source: "手机端新增长期处方",
  3801. Status: 1,
  3802. }
  3803. service.CreatePrescriptionLog(prescriptionLog)
  3804. finish := models.XtDialysisFinish{
  3805. IsFinish: 1,
  3806. UserOrgId: adminUserInfo.Org.Id,
  3807. Status: 1,
  3808. Ctime: time.Now().Unix(),
  3809. Mtime: 0,
  3810. Module: 1,
  3811. RecordDate: recordDate.Unix(),
  3812. Sourse: 1,
  3813. PatientId: id,
  3814. }
  3815. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3816. if dialysisFinish.ID == 0 {
  3817. service.CreateDialysisFinish(finish)
  3818. }
  3819. //获取最新1条
  3820. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3821. //更新状态
  3822. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3823. //长沙南雅医院,自动生成抗凝剂的临时处方
  3824. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3825. if prescribing_number == 0 {
  3826. prescribing_number = 1
  3827. }
  3828. advice := models.DoctorAdvice{
  3829. UserOrgId: adminUserInfo.Org.Id,
  3830. PatientId: id,
  3831. GroupNo: 0,
  3832. AdviceType: 2,
  3833. RecordDate: recordDate.Unix(),
  3834. AdviceDate: recordDate.Unix(),
  3835. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3836. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3837. AdviceDesc: "",
  3838. ReminderDate: 0,
  3839. SingleDose: prescription.AnticoagulantZongliang,
  3840. SingleDoseUnit: "iu",
  3841. DrugSpec: 0,
  3842. DrugSpecUnit: "",
  3843. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3844. PrescribingNumberUnit: "支",
  3845. DeliveryWay: "静脉注射",
  3846. ExecutionFrequency: "上机前",
  3847. AdviceDoctor: 0,
  3848. Status: 1,
  3849. CreatedTime: time.Now().Unix(),
  3850. UpdatedTime: time.Now().Unix(),
  3851. IsPrescription: 1,
  3852. ExecutionState: 2,
  3853. StopState: 2,
  3854. IsSettle: 2,
  3855. }
  3856. // 查询排班信息
  3857. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3858. if schedulePatient.ID > 0 {
  3859. if schedulePatient.ScheduleType == 1 {
  3860. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3861. }
  3862. if schedulePatient.ScheduleType == 2 {
  3863. advice.StartTime = recordDate.Unix() + 9*60*60
  3864. }
  3865. }
  3866. // 抗凝剂名称
  3867. switch anticoagulant {
  3868. case 1:
  3869. advice.AdviceName = "无肝素"
  3870. break
  3871. case 2:
  3872. advice.AdviceName = "普通肝素"
  3873. break
  3874. case 3:
  3875. advice.AdviceName = "低分子肝素"
  3876. break
  3877. case 4:
  3878. advice.AdviceName = "阿加曲班"
  3879. break
  3880. case 5:
  3881. advice.AdviceName = "枸橼酸钠"
  3882. break
  3883. case 6:
  3884. advice.AdviceName = "低分子肝素钙"
  3885. break
  3886. case 7:
  3887. advice.AdviceName = "低分子肝素钠"
  3888. break
  3889. case 8:
  3890. advice.AdviceName = "依诺肝素"
  3891. break
  3892. case 9:
  3893. advice.AdviceName = "达肝素"
  3894. break
  3895. case 10:
  3896. advice.AdviceName = "体外抗凝"
  3897. break
  3898. case 11:
  3899. advice.AdviceName = "那曲肝素"
  3900. break
  3901. case 12:
  3902. advice.AdviceName = "无抗凝剂"
  3903. break
  3904. }
  3905. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3906. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3907. advice.AdviceDoctor = appRole.AdminUserId
  3908. }
  3909. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3910. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3911. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3912. advice.AdviceName = "低分子肝素钠注射液"
  3913. // 修改患者临时医嘱里的抗凝剂医嘱
  3914. advice.ID = advicePrescription.ID
  3915. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3916. } else {
  3917. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3918. advice.AdviceName = "低分子肝素钠注射液"
  3919. service.CreateDoctorAdvice(&advice)
  3920. }
  3921. }
  3922. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3923. redis := service.RedisClient()
  3924. defer redis.Close()
  3925. //清空key 值
  3926. redis.Set(key, "", time.Second)
  3927. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3928. redis.Set(keyOne, "", time.Second)
  3929. }
  3930. //获取key,清空redis
  3931. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3932. redis := service.RedisClient()
  3933. defer redis.Close()
  3934. //清空key 值
  3935. redis.Set(key, "", time.Second)
  3936. //清空长期医嘱的key
  3937. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3938. redis.Set(soulution_key, "", time.Second)
  3939. //查询最近透析准备表里是否存在 透析器 灌流器
  3940. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3941. redis.Set(keyOne, "", time.Second)
  3942. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3943. redis.Set(keyTwo, "", time.Second)
  3944. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3945. redis.Set(keyThree, "", time.Second)
  3946. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3947. redis.Set(keyFour, "", time.Second)
  3948. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3949. //
  3950. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3951. //
  3952. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3953. //if len(mation)>0{
  3954. // for _, item := range splitStr {
  3955. // for _,it := range mation{
  3956. // if(item == it.SpecificationName){
  3957. //
  3958. // //查询最近一次的透析器
  3959. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3960. //
  3961. // if errcode == gorm.ErrRecordNotFound{
  3962. // //插入数据
  3963. // prepare := models.DialysisBeforePrepare{
  3964. // UserOrgId: adminUserInfo.Org.Id,
  3965. // PatientId: id,
  3966. // RecordDate: recordDate.Unix(),
  3967. // GoodTypeId: it.GoodTypeId,
  3968. // GoodId: it.ID,
  3969. // Count: 1,
  3970. // Ctime: time.Now().Unix(),
  3971. // Creater: adminUserInfo.AdminUser.Id,
  3972. // Status:1,
  3973. //
  3974. // }
  3975. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3976. // fmt.Println("",errcode)
  3977. // }
  3978. // }
  3979. // }
  3980. //
  3981. // }
  3982. //
  3983. // for _, item := range splitIrrigation {
  3984. // for _,it := range mation{
  3985. // if(item == it.SpecificationName){
  3986. // //查询最近一次的透析器
  3987. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3988. // if errcode == gorm.ErrRecordNotFound{
  3989. // //插入数据
  3990. // prepare := models.DialysisBeforePrepare{
  3991. // UserOrgId: adminUserInfo.Org.Id,
  3992. // PatientId: id,
  3993. // RecordDate: recordDate.Unix(),
  3994. // GoodTypeId: it.GoodTypeId,
  3995. // GoodId: it.ID,
  3996. // Count: 1,
  3997. // Ctime: time.Now().Unix(),
  3998. // Creater: adminUserInfo.AdminUser.Id,
  3999. // Status:1,
  4000. //
  4001. // }
  4002. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4003. // fmt.Println(errcode)
  4004. // }
  4005. // }
  4006. // }
  4007. // }
  4008. //}
  4009. c.ServeSuccessJSON(map[string]interface{}{
  4010. "solution": &solution,
  4011. "prescription": &prescription,
  4012. })
  4013. }
  4014. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4015. patient, _ := c.GetInt64("patient", 0)
  4016. adminUserInfo := c.GetMobileAdminUserInfo()
  4017. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4018. c.ServeSuccessJSON(map[string]interface{}{
  4019. "receiveTreatmentAsses": receiveTreatmentAsses,
  4020. })
  4021. }
  4022. func (this *DialysisAPIController) PostSignInfo() {
  4023. patientID, _ := this.GetInt64("patient_id")
  4024. recordDateStr := this.GetString("date")
  4025. if patientID <= 0 {
  4026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4027. return
  4028. }
  4029. if len(recordDateStr) == 0 {
  4030. recordDateStr = time.Now().Format("2006-01-02")
  4031. }
  4032. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4033. if parseDateErr != nil {
  4034. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4036. return
  4037. }
  4038. adminInfo := this.GetMobileAdminUserInfo()
  4039. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4040. if err != nil {
  4041. this.ErrorLog("签名失败:%v", err)
  4042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4043. return
  4044. }
  4045. this.ServeSuccessJSON(map[string]interface{}{
  4046. "doctor_id": adminInfo.AdminUser.Id,
  4047. })
  4048. }
  4049. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4050. patientID, _ := this.GetInt64("patient_id")
  4051. adminInfo := this.GetMobileAdminUserInfo()
  4052. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4053. this.ServeSuccessJSON(map[string]interface{}{
  4054. "monitor": record,
  4055. })
  4056. }
  4057. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4058. thisTime := time.Now()
  4059. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4060. timeLayout := "2006-01-02 15:04:05"
  4061. loc, _ := time.LoadLocation("Local")
  4062. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4063. theAssessmentDateTime := theStartTime.Unix()
  4064. patientID, _ := this.GetInt64("patient_id")
  4065. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4066. adminInfo := this.GetMobileAdminUserInfo()
  4067. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4068. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4069. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4070. var ultrafiltration_rate float64
  4071. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4072. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4073. fmt.Println(evaluation)
  4074. fmt.Println("prescription.ID", prescription.ID)
  4075. if prescription.ID > 0 {
  4076. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4077. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4078. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4079. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4080. record.UltrafiltrationRate = ultrafiltration_rate
  4081. }
  4082. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4083. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4084. record.UltrafiltrationRate = ultrafiltration_rate
  4085. }
  4086. if adminInfo.Org.Id == 10510 {
  4087. record.UltrafiltrationRate = 0
  4088. }
  4089. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4090. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4091. record.UltrafiltrationRate = ultrafiltration_rate
  4092. }
  4093. if template.TemplateId == 20 || template.TemplateId == 22 {
  4094. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4095. record.UltrafiltrationRate = ultrafiltration_rate
  4096. }
  4097. // 只针对方济医院
  4098. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4099. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4100. ultrafiltration_rate = value
  4101. record.UltrafiltrationRate = ultrafiltration_rate
  4102. }
  4103. if template.TemplateId == 41 || template.TemplateId == 47 {
  4104. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4105. record.UltrafiltrationRate = ultrafiltration_rate
  4106. }
  4107. if template.TemplateId == 43 {
  4108. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4109. record.UltrafiltrationRate = ultrafiltration_rate
  4110. }
  4111. if template.TemplateId == 46 || template.TemplateId == 54 {
  4112. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4113. record.UltrafiltrationRate = ultrafiltration_rate
  4114. }
  4115. 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 {
  4116. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4117. record.UltrafiltrationRate = ultrafiltration_rate
  4118. }
  4119. if adminInfo.Org.Id == 10469 {
  4120. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4121. record.UltrafiltrationRate = ultrafiltration_rate
  4122. }
  4123. if adminInfo.Org.Id == 10667 {
  4124. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4125. record.UltrafiltrationRate = ultrafiltration_rate
  4126. }
  4127. if adminInfo.Org.Id == 10471 {
  4128. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4129. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4130. }
  4131. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4132. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4133. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4134. }
  4135. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4137. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4138. }
  4139. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4140. record.UltrafiltrationRate = 0
  4141. }
  4142. //if template.TemplateId == 47 {
  4143. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4144. // record.UltrafiltrationRate = ultrafiltration_rate
  4145. //}
  4146. }
  4147. }
  4148. // record.UltrafiltrationRate = ultrafiltration_rate
  4149. record.UltrafiltrationVolume = 0
  4150. 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
  4151. if ultrafiltration_rate > 0 {
  4152. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4153. record.UltrafiltrationVolume = value
  4154. }
  4155. }
  4156. 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
  4157. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4158. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4159. record.UltrafiltrationVolume = ultrafiltration_volume
  4160. }
  4161. }
  4162. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4163. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4164. record.UltrafiltrationVolume = ultrafiltration_volume
  4165. }
  4166. //长沙南雅
  4167. 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 {
  4168. if ultrafiltration_rate > 0 {
  4169. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4170. record.UltrafiltrationVolume = ultrafiltration_volume
  4171. }
  4172. }
  4173. if adminInfo.Org.Id == 10471 {
  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 == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4178. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4179. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4180. }
  4181. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4182. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4183. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4184. }
  4185. //长沙南雅累计血容量自动计算
  4186. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4187. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4188. //}
  4189. if template.TemplateId == 47 || template.TemplateId == 54 {
  4190. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4191. }
  4192. if adminInfo.Org.Id == 10510 {
  4193. record.UltrafiltrationVolume = 0
  4194. }
  4195. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4196. this.ServeSuccessJSON(map[string]interface{}{
  4197. "monitor": record,
  4198. "lastMonitorRecordList": lastMonitorRecordList,
  4199. })
  4200. }
  4201. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4202. record_id, _ := this.GetInt64("id")
  4203. nurseID, _ := this.GetInt64("start_nurse")
  4204. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4205. bedID, _ := this.GetInt64("bed")
  4206. start_time := this.GetString("start_time")
  4207. schedual_type, _ := this.GetInt64("schedual_type")
  4208. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4209. change_nurse, _ := this.GetInt64("change_nurse")
  4210. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4211. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4212. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4213. patient_id, _ := this.GetInt64("patient_id")
  4214. record_date, _ := this.GetInt64("record_date")
  4215. puncture_needle := this.GetString("puncture_needle")
  4216. puncture_way := this.GetString("puncture_way")
  4217. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4218. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4219. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4220. nuclein_date_str := this.GetString("nuclein_date_str")
  4221. order_remark := this.GetString("order_remark")
  4222. schedule_remark := this.GetString("schedule_remark")
  4223. catheter_operation := this.GetString("catheter_operation")
  4224. blood_flow_volume := this.GetString("blood_flow_volume")
  4225. blood_drawing, _ := this.GetInt64("blood_drawing")
  4226. dialysis_strainer := this.GetString("dialysis_strainer")
  4227. if record_id == 0 {
  4228. this.ErrorLog("id:%v", record_id)
  4229. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4230. return
  4231. }
  4232. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4233. if parseStartDateErr != nil {
  4234. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4236. return
  4237. }
  4238. adminUserInfo := this.GetMobileAdminUserInfo()
  4239. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4240. if getNurseErr != nil {
  4241. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4243. return
  4244. } else if nurse == nil {
  4245. this.ErrorLog("护士不存在")
  4246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4247. return
  4248. }
  4249. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4250. //if getNurseErr != nil {
  4251. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4252. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4253. // return
  4254. //} else if nurse == nil {
  4255. // this.ErrorLog("护士不存在")
  4256. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4257. // return
  4258. //}
  4259. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4260. if getDeviceNumberErr != nil {
  4261. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4263. return
  4264. } else if deviceNumber == nil {
  4265. this.ErrorLog("床位号不存在")
  4266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4267. return
  4268. }
  4269. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4270. //
  4271. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4272. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4273. // if getPermissionErr != nil {
  4274. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4275. // return
  4276. // } else if headNursePermission == nil {
  4277. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4278. // return
  4279. // }
  4280. //}
  4281. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4282. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4283. timeLayout := "2006-01-02 15:04:05"
  4284. loc, _ := time.LoadLocation("Local")
  4285. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4286. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4287. schedulestartTime := theStartTime.Unix()
  4288. scheduleendTime := theEndTime.Unix()
  4289. var theNucleinDate int64
  4290. timeLayoutOne := "2006-01-02"
  4291. if len(nuclein_date_str) > 0 {
  4292. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4293. if err != nil {
  4294. utils.ErrorLog(err.Error())
  4295. }
  4296. theNucleinDate = theTime.Unix()
  4297. }
  4298. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4299. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4300. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4301. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4302. if err == gorm.ErrRecordNotFound { //空床位
  4303. // 修改了床位逻辑
  4304. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4305. if daySchedule.ID > 0 {
  4306. //daySchedule.BedId = bedID
  4307. //daySchedule.PartitionId = deviceNumber.ZoneID
  4308. //daySchedule.ScheduleType = schedual_type
  4309. //daySchedule.UpdatedTime = time.Now().Unix()
  4310. //err := service.UpdateSchedule(&daySchedule)
  4311. xtSchedule := models.Schedule{
  4312. PartitionId: deviceNumber.ZoneID,
  4313. BedId: bedID,
  4314. ScheduleType: schedual_type,
  4315. UpdatedTime: time.Now().Unix(),
  4316. }
  4317. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4318. if err != nil {
  4319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4320. return
  4321. }
  4322. }
  4323. } else if err == nil {
  4324. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4325. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4326. if daySchedule.ID > 0 {
  4327. //daySchedule.BedId = bedID
  4328. //daySchedule.PartitionId = deviceNumber.ZoneID
  4329. //
  4330. //daySchedule.ScheduleType = schedual_type
  4331. //daySchedule.UpdatedTime = time.Now().Unix()
  4332. //err := service.UpdateSchedule(&daySchedule)
  4333. xtSchedule := models.Schedule{
  4334. PartitionId: deviceNumber.ZoneID,
  4335. BedId: bedID,
  4336. ScheduleType: schedual_type,
  4337. UpdatedTime: time.Now().Unix(),
  4338. }
  4339. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4340. if err != nil {
  4341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4342. return
  4343. }
  4344. }
  4345. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4347. return
  4348. }
  4349. } else if err != nil {
  4350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4351. return
  4352. }
  4353. }
  4354. dialysisRecord := &models.DialysisOrder{
  4355. ID: record_id,
  4356. UserOrgId: adminUserInfo.Org.Id,
  4357. BedID: bedID,
  4358. StartNurse: nurseID,
  4359. StartTime: startDate.Unix(),
  4360. PunctureNurse: puncture_nurse,
  4361. Creator: adminUserInfo.AdminUser.Id,
  4362. Modifier: adminUserInfo.AdminUser.Id,
  4363. WashpipeNurse: washpipe_nurse,
  4364. SchedualType: schedual_type,
  4365. ChangeNurse: change_nurse,
  4366. DifficultPunctureNurse: difficult_puncture_nurse,
  4367. NewFistulaNurse: new_fistula_nurse,
  4368. QualityNurseId: quality_nurse_id,
  4369. PunctureNeedle: puncture_needle,
  4370. PunctureWay: puncture_way,
  4371. DialysisDialyszers: dialysis_dialyszers,
  4372. DialysisIrrigation: dialysis_irrigation,
  4373. BloodAccessId: blood_access_id,
  4374. NucleinDate: theNucleinDate,
  4375. OrderRemark: order_remark,
  4376. ScheduleRemark: schedule_remark,
  4377. CatheterOperation: catheter_operation,
  4378. BloodFlowVolume: blood_flow_volume,
  4379. BloodDrawing: blood_drawing,
  4380. DialysisStrainer: dialysis_strainer,
  4381. }
  4382. //修改床位号需要重新消毒
  4383. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4384. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4385. //查询第一条监测
  4386. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4387. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4388. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4389. redis := service.RedisClient()
  4390. //清空key 值
  4391. redis.Set(key, "", time.Second)
  4392. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4393. redis.Set(keyOne, "", time.Second)
  4394. defer redis.Close()
  4395. }
  4396. // 查询信息规挡的设置天数
  4397. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4398. if infor.ID > 0 && infor.WeekDay > 0 {
  4399. var cha_time int64
  4400. timeNowStr := time.Now().Format("2006-01-02")
  4401. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4402. //今日的日期减去设置的日期
  4403. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4404. if cha_time >= record_date {
  4405. //查询审核是否允许
  4406. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4407. //申请状态不允许的情况 拒绝修改
  4408. if infor.ApplicationStatus != 1 {
  4409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4410. return
  4411. }
  4412. }
  4413. }
  4414. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4415. //修改床位后重新生成消毒计划
  4416. if adminUserInfo.Org.Id == 10340 {
  4417. //根据床位号获取设备型号
  4418. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4419. //查询使用消毒最后一条消毒记录
  4420. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4421. fmt.Println("err", err)
  4422. if err == gorm.ErrRecordNotFound {
  4423. //查找排班
  4424. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4425. //查询改设备是否有消毒计划
  4426. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4427. //根据床位号获取设备id
  4428. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4429. //查询病人信息
  4430. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4431. var con = ""
  4432. if patients.IsInfectious == 0 {
  4433. con = ""
  4434. }
  4435. if patients.IsInfectious == 1 {
  4436. con = "无"
  4437. }
  4438. if patients.IsInfectious == 2 {
  4439. con = "有"
  4440. }
  4441. if errcode == nil {
  4442. var end_time int64
  4443. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4444. //新增消毒
  4445. information := models.DeviceInformation{
  4446. Date: dialysisRecord.DialysisDate,
  4447. Zone: dialysisRecord.ZoneId,
  4448. Class: dialysisRecord.SchedualType,
  4449. BedNumber: dialysisRecord.BedID,
  4450. PatientId: dialysisRecord.PatientId,
  4451. DialysisMode: scheduleByPatient.ModeId,
  4452. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4453. Disinfection: 1,
  4454. DialysisConcentration: 1,
  4455. DisinfectionStatus: 1,
  4456. Move: 1,
  4457. UserOrgId: dialysisRecord.UserOrgId,
  4458. DisinfectType: plan.Way,
  4459. DisinfectantType: plan.MachineDisinfectant,
  4460. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4461. Disinfectant: plan.Disinfectant,
  4462. Ctime: time.Now().Unix(),
  4463. Status: 1,
  4464. SignName: nurseID,
  4465. EquimentId: addmacher.ID,
  4466. DisinfectionResidue: 2,
  4467. Bed: addmacher.BedNumber,
  4468. StartTime: dialysisRecord.StartTime,
  4469. EndTime: dialysisRecord.EndTime,
  4470. Contagion: con,
  4471. WeightLoss: 0,
  4472. Hyperfiltratio: 0,
  4473. DialysisHour: "",
  4474. MachineRun: 1,
  4475. DisinfecStartime: dialysisRecord.EndTime,
  4476. DisinfecEndtime: end_time,
  4477. }
  4478. err := service.CreateInformationTwo(&information)
  4479. fmt.Println("报错", err)
  4480. }
  4481. }
  4482. }
  4483. order, _ := service.GetLastPatientOrder(record_id)
  4484. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4485. redis := service.RedisClient()
  4486. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4487. redis.Set(key, "", time.Second)
  4488. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4489. //清空key 值
  4490. redis.Set(keyOne, "", time.Second)
  4491. scheduleDateStartOne := startDate.Format("2006-01-02")
  4492. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4493. redis.Set(keyTwo, "", time.Second)
  4494. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4495. redis.Set(keyThree, "", time.Second)
  4496. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4497. redis.Set(keyFour, "", time.Second)
  4498. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4499. redis.Set(keyFive, "", time.Second)
  4500. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4501. redis.Set(keySix, "", time.Second)
  4502. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4503. redis.Set(keySeven, "", time.Second)
  4504. if updateErr != nil {
  4505. this.ErrorLog("修改上机失败:%v", updateErr)
  4506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4507. return
  4508. }
  4509. if updateErr == nil {
  4510. if tempDialysisRecord.Stage == 2 {
  4511. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4513. fmt.Println(value)
  4514. a, b := math.Modf(value)
  4515. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4516. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4517. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4518. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4519. redis := service.RedisClient()
  4520. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4521. redis.Set(key, "", time.Second)
  4522. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4523. redis.Set(keyOne, "", time.Second)
  4524. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4525. //清空key 值
  4526. redis.Set(keySix, "", time.Second)
  4527. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4528. redis.Set(keySeven, "", time.Second)
  4529. redis.Close()
  4530. if updateAssessmentErr != nil {
  4531. utils.ErrorLog("%v", updateAssessmentErr)
  4532. }
  4533. }
  4534. }
  4535. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4536. this.ServeSuccessJSON(map[string]interface{}{
  4537. "dialysis_order": dialysisRecords,
  4538. })
  4539. }
  4540. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4541. record_id, _ := c.GetInt64("id")
  4542. nurseID, _ := c.GetInt64("nurse")
  4543. end_time := c.GetString("end_time")
  4544. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4545. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4546. catheter := c.GetString("catheter")
  4547. cruor := c.GetString("cruor")
  4548. mission := c.GetString("mission")
  4549. condenser := c.GetString("condenser")
  4550. if record_id <= 0 || nurseID <= 0 {
  4551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4552. return
  4553. }
  4554. adminUserInfo := c.GetMobileAdminUserInfo()
  4555. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4556. if getNurseErr != nil {
  4557. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4559. return
  4560. } else if nurse == nil {
  4561. c.ErrorLog("护士不存在")
  4562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4566. if parseEndDateErr != nil {
  4567. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4569. return
  4570. }
  4571. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4572. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4573. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4574. // if getPermissionErr != nil {
  4575. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4576. // return
  4577. // } else if headNursePermission == nil {
  4578. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4579. // return
  4580. // }
  4581. //}
  4582. // 查询信息规挡的设置天数
  4583. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4584. if infor.ID > 0 {
  4585. var cha_time int64
  4586. timeNowStr := time.Now().Format("2006-01-02")
  4587. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4588. //今日的日期减去设置的日期
  4589. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4590. if cha_time >= tempDialysisRecords.DialysisDate {
  4591. //查询审核是否允许
  4592. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4593. //申请状态不允许的情况 拒绝修改
  4594. if infor.ApplicationStatus != 1 {
  4595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4596. return
  4597. }
  4598. }
  4599. }
  4600. dialysisRecord := &models.DialysisOrder{
  4601. ID: record_id,
  4602. UserOrgId: adminUserInfo.Org.Id,
  4603. EndTime: endDate.Unix(),
  4604. FinishNurse: nurseID,
  4605. FinishModifier: adminUserInfo.AdminUser.Id,
  4606. PuncturePointHaematoma: puncture_point_haematoma,
  4607. BloodAccessInternalFistula: blood_access_internal_fistula,
  4608. Catheter: catheter,
  4609. Cruor: cruor,
  4610. Mission: mission,
  4611. Condenser: condenser,
  4612. }
  4613. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4614. redis := service.RedisClient()
  4615. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4616. //清空key 值
  4617. redis.Set(key, "", time.Second)
  4618. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4619. //清空key 值
  4620. redis.Set(keyOne, "", time.Second)
  4621. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4622. redis.Set(keySeven, "", time.Second)
  4623. redis.Close()
  4624. if updateErr != nil {
  4625. c.ErrorLog("修改下机失败:%v", updateErr)
  4626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4627. return
  4628. }
  4629. if updateErr == nil {
  4630. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4631. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4632. a, b := math.Modf(value)
  4633. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4634. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4635. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4636. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4637. redis := service.RedisClient()
  4638. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4639. redis.Set(keyTen, "", time.Second)
  4640. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4641. redis.Set(keyTwo, "", time.Second)
  4642. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4643. redis.Set(key, "", time.Second)
  4644. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4645. redis.Set(keyThree, "", time.Second)
  4646. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4647. redis.Set(keySeven, "", time.Second)
  4648. defer redis.Close()
  4649. if updateAssessmentErr != nil {
  4650. utils.ErrorLog("%v", updateAssessmentErr)
  4651. }
  4652. }
  4653. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4654. c.ServeSuccessJSON(map[string]interface{}{
  4655. "dialysis_order": dialysisRecords,
  4656. })
  4657. }
  4658. func (c *DialysisAPIController) GetLongAdvice() {
  4659. patient_id, _ := c.GetInt64("id")
  4660. adminUserInfo := c.GetMobileAdminUserInfo()
  4661. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4662. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4663. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4664. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4665. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4666. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4667. c.ServeSuccessJSON(map[string]interface{}{
  4668. "status": "1",
  4669. })
  4670. return
  4671. } else { //开启推送提醒
  4672. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4673. var advice_three []*models.DoctorAdvice
  4674. recordDateStr := time.Now().Format("2006-01-02")
  4675. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4676. nowtime := recordDate.Unix()
  4677. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4678. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4679. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4680. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4681. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4682. for _, advice := range advices {
  4683. if advice.FrequencyType == 3 {
  4684. t := time.Now()
  4685. week := int(t.Weekday())
  4686. fmt.Println(t.Weekday())
  4687. fmt.Println(week)
  4688. switch week {
  4689. case 1:
  4690. if strings.Index(advice.WeekDay, "周一") == -1 {
  4691. advice_three = append(advice_three, advice)
  4692. }
  4693. break
  4694. case 2:
  4695. if strings.Index(advice.WeekDay, "周二") == -1 {
  4696. advice_three = append(advice_three, advice)
  4697. }
  4698. break
  4699. case 3:
  4700. if strings.Index(advice.WeekDay, "周三") == -1 {
  4701. advice_three = append(advice_three, advice)
  4702. }
  4703. break
  4704. case 4:
  4705. if strings.Index(advice.WeekDay, "周四") == -1 {
  4706. advice_three = append(advice_three, advice)
  4707. }
  4708. break
  4709. case 5:
  4710. if strings.Index(advice.WeekDay, "周五") == -1 {
  4711. advice_three = append(advice_three, advice)
  4712. }
  4713. break
  4714. case 6:
  4715. if strings.Index(advice.WeekDay, "周六") == -1 {
  4716. advice_three = append(advice_three, advice)
  4717. }
  4718. break
  4719. case 0:
  4720. if strings.Index(advice.WeekDay, "周日") == -1 {
  4721. advice_three = append(advice_three, advice)
  4722. }
  4723. break
  4724. }
  4725. }
  4726. }
  4727. for _, advice := range advices_two {
  4728. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4729. now := p.Unix()
  4730. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4731. dayStr2 := "-" + dayStr
  4732. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4733. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4734. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4735. for _, ad := range advices {
  4736. advice_three = append(advice_three, ad)
  4737. }
  4738. }
  4739. if err == nil {
  4740. c.ServeSuccessJSON(map[string]interface{}{
  4741. "status": "2",
  4742. "advices": advices,
  4743. "advices_two": RemoveRepeatedElement(advice_three),
  4744. "is_open_remind": config.IsOpenRemind,
  4745. "his_config_open": hisConfig.IsOpen,
  4746. "is_advice_open": is_advice_open.IsAdviceOpen,
  4747. "prescription_open": prescription_open.IsOpen,
  4748. })
  4749. }
  4750. }
  4751. }
  4752. func (c *DialysisAPIController) GetLongAdviceOne() {
  4753. patient_id, _ := c.GetInt64("id")
  4754. startTime := c.GetString("schedule_date")
  4755. timeLayout := "2006-01-02"
  4756. loc, _ := time.LoadLocation("Local")
  4757. var theStartTime int64
  4758. if len(startTime) > 0 {
  4759. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4760. if err != nil {
  4761. utils.ErrorLog(err.Error())
  4762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4763. return
  4764. }
  4765. theStartTime = theTime.Unix()
  4766. }
  4767. adminUserInfo := c.GetMobileAdminUserInfo()
  4768. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4769. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4770. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4771. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4772. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4773. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4774. c.ServeSuccessJSON(map[string]interface{}{
  4775. "status": "1",
  4776. })
  4777. return
  4778. } else { //开启推送提醒
  4779. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4780. var advice_three []*models.DoctorAdvice
  4781. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4782. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4783. for _, advice := range advices {
  4784. if advice.FrequencyType == 3 {
  4785. t := time.Now()
  4786. week := int(t.Weekday())
  4787. fmt.Println(t.Weekday())
  4788. fmt.Println(week)
  4789. switch week {
  4790. case 1:
  4791. if strings.Index(advice.WeekDay, "周一") == -1 {
  4792. advice_three = append(advice_three, advice)
  4793. }
  4794. break
  4795. case 2:
  4796. if strings.Index(advice.WeekDay, "周二") == -1 {
  4797. advice_three = append(advice_three, advice)
  4798. }
  4799. break
  4800. case 3:
  4801. if strings.Index(advice.WeekDay, "周三") == -1 {
  4802. advice_three = append(advice_three, advice)
  4803. }
  4804. break
  4805. case 4:
  4806. if strings.Index(advice.WeekDay, "周四") == -1 {
  4807. advice_three = append(advice_three, advice)
  4808. }
  4809. break
  4810. case 5:
  4811. if strings.Index(advice.WeekDay, "周五") == -1 {
  4812. advice_three = append(advice_three, advice)
  4813. }
  4814. break
  4815. case 6:
  4816. if strings.Index(advice.WeekDay, "周六") == -1 {
  4817. advice_three = append(advice_three, advice)
  4818. }
  4819. break
  4820. case 0:
  4821. if strings.Index(advice.WeekDay, "周日") == -1 {
  4822. advice_three = append(advice_three, advice)
  4823. }
  4824. break
  4825. }
  4826. }
  4827. }
  4828. for _, advice := range advices_two {
  4829. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4830. now := p.Unix()
  4831. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4832. dayStr2 := "-" + dayStr
  4833. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4834. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4835. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4836. for _, ad := range advices {
  4837. advice_three = append(advice_three, ad)
  4838. }
  4839. }
  4840. if err == nil {
  4841. c.ServeSuccessJSON(map[string]interface{}{
  4842. "status": "2",
  4843. "advices": advices,
  4844. "advices_two": RemoveRepeatedElement(advice_three),
  4845. "is_open_remind": config.IsOpenRemind,
  4846. "his_config_open": hisConfig.IsOpen,
  4847. "is_advice_open": is_advice_open.IsAdviceOpen,
  4848. "prescription_open": prescription_open.IsOpen,
  4849. })
  4850. }
  4851. }
  4852. }
  4853. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4854. newArr = make([]*models.DoctorAdvice, 0)
  4855. for i := 0; i < len(arr); i++ {
  4856. repeat := false
  4857. for j := i + 1; j < len(arr); j++ {
  4858. if arr[i].ID == arr[j].ID {
  4859. repeat = true
  4860. break
  4861. }
  4862. }
  4863. if !repeat {
  4864. newArr = append(newArr, arr[i])
  4865. }
  4866. }
  4867. return
  4868. }
  4869. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4870. patient, _ := c.GetInt64("id", 0)
  4871. groupNo, _ := c.GetInt64("groupno", 0)
  4872. if patient <= 0 {
  4873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4874. return
  4875. }
  4876. adminUserInfo := c.GetMobileAdminUserInfo()
  4877. dataBody := make(map[string]interface{}, 0)
  4878. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4879. if err != nil {
  4880. utils.ErrorLog(err.Error())
  4881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4882. return
  4883. }
  4884. utils.ErrorLog("%v", dataBody)
  4885. timeLayout := "2006-01-02 15:04"
  4886. loc, _ := time.LoadLocation("Local")
  4887. timeLayout2 := "2006-01-02"
  4888. loc2, _ := time.LoadLocation("Local")
  4889. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4890. utils.ErrorLog("advice_type")
  4891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4892. return
  4893. }
  4894. adviceType := int64(2)
  4895. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4896. utils.ErrorLog("advice_date")
  4897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4898. return
  4899. }
  4900. adviceDate, _ := dataBody["advice_date"].(string)
  4901. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4902. AdviceDate := theTime.Unix()
  4903. RecordDate := theTime.Unix()
  4904. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4905. utils.ErrorLog("start_time")
  4906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4907. return
  4908. }
  4909. startTime, _ := dataBody["start_time"].(string)
  4910. if len(startTime) == 0 {
  4911. utils.ErrorLog("len(start_time) == 0")
  4912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4913. return
  4914. }
  4915. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4916. if err != nil {
  4917. utils.ErrorLog(err.Error())
  4918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4919. return
  4920. }
  4921. StartTime := theTime.Unix()
  4922. Remark := ""
  4923. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4924. remark, _ := dataBody["remark"].(string)
  4925. Remark = remark
  4926. }
  4927. var advices []*models.GroupAdvice
  4928. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4929. utils.ErrorLog("advices")
  4930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4931. return
  4932. }
  4933. adviceNames := dataBody["advices"].([]interface{})
  4934. for _, adviceNameMap := range adviceNames {
  4935. adviceNameM := adviceNameMap.(map[string]interface{})
  4936. var advice models.GroupAdvice
  4937. advice.Remark = Remark
  4938. advice.AdviceType = adviceType
  4939. advice.StartTime = StartTime
  4940. advice.AdviceDate = AdviceDate
  4941. advice.RecordDate = RecordDate
  4942. advice.Status = 1
  4943. advice.CreatedTime = time.Now().Unix()
  4944. advice.UpdatedTime = time.Now().Unix()
  4945. advice.StopState = 2
  4946. advice.ExecutionState = 2
  4947. advice.UserOrgId = adminUserInfo.Org.Id
  4948. advice.PatientId = patient
  4949. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4950. advice.IsSettle = 2
  4951. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4952. utils.ErrorLog("advice_name")
  4953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4954. return
  4955. }
  4956. adviceName, _ := adviceNameM["advice_name"].(string)
  4957. if len(adviceName) == 0 {
  4958. utils.ErrorLog("len(advice_name) == 0")
  4959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4960. return
  4961. }
  4962. advice.AdviceName = adviceName
  4963. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4964. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4965. advice.DrugSpec = drugSpec
  4966. }
  4967. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4968. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4969. advice.AdviceDesc = adviceDesc
  4970. }
  4971. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4972. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4973. advice.DrugSpecUnit = drugSpecUnit
  4974. }
  4975. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4976. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4977. // advice.SingleDose = singleDose
  4978. //}
  4979. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4980. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4981. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4982. }
  4983. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4984. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4985. advice.SingleDoseUnit = singleDoseUnit
  4986. }
  4987. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4988. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4989. // advice.PrescribingNumber = prescribingNumber
  4990. //}
  4991. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4992. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4993. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4994. }
  4995. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4996. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4997. advice.PrescribingNumberUnit = prescribingNumberUnit
  4998. }
  4999. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5000. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5001. advice.DeliveryWay = deliveryWay
  5002. }
  5003. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5004. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5005. advice.ExecutionFrequency = executionFrequency
  5006. }
  5007. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5008. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5009. advice.FrequencyType = frequency_type
  5010. }
  5011. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5012. day_count := int64(adviceNameM["day_count"].(float64))
  5013. advice.DayCount = day_count
  5014. }
  5015. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5016. week_day, _ := adviceNameM["week_day"].(string)
  5017. advice.WeekDay = week_day
  5018. }
  5019. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5020. way := int64(adviceNameM["way"].(float64))
  5021. advice.Way = way
  5022. }
  5023. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5024. drug_id := int64(adviceNameM["drug_id"].(float64))
  5025. advice.DrugId = drug_id
  5026. }
  5027. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5028. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5029. advice.DrugNameId = drug_name_id
  5030. }
  5031. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5032. remark, _ := adviceNameM["remark"].(string)
  5033. advice.Remark = remark
  5034. }
  5035. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5036. groupno := int64(adviceNameM["groupno"].(float64))
  5037. advice.GroupNo = groupno
  5038. }
  5039. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5040. template_id, _ := adviceNameM["template_id"].(string)
  5041. advice.TemplateId = template_id
  5042. }
  5043. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5044. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5045. advice.ExecutionFrequency = executionFrequency
  5046. }
  5047. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5048. children := adviceNameM["child"].([]interface{})
  5049. if len(children) > 0 {
  5050. for _, childrenMap := range children {
  5051. childMap := childrenMap.(map[string]interface{})
  5052. var child models.GroupAdvice
  5053. child.Remark = Remark
  5054. child.AdviceType = adviceType
  5055. child.StartTime = StartTime
  5056. child.AdviceDate = AdviceDate
  5057. child.RecordDate = RecordDate
  5058. child.Status = 1
  5059. child.CreatedTime = time.Now().Unix()
  5060. child.UpdatedTime = time.Now().Unix()
  5061. child.StopState = 2
  5062. child.ExecutionState = 2
  5063. child.UserOrgId = adminUserInfo.Org.Id
  5064. child.PatientId = patient
  5065. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5066. child.IsSettle = 1
  5067. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5068. utils.ErrorLog("child advice_name")
  5069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5070. return
  5071. }
  5072. childAdviceName, _ := childMap["advice_name"].(string)
  5073. if len(childAdviceName) == 0 {
  5074. utils.ErrorLog("len(child advice_name) == 0")
  5075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5076. return
  5077. }
  5078. child.AdviceName = childAdviceName
  5079. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5080. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5081. child.AdviceDesc = childAdviceDesc
  5082. }
  5083. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5084. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5085. child.DrugSpec = childDrugSpec
  5086. }
  5087. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5088. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5089. child.DrugSpecUnit = childDrugSpecUnit
  5090. }
  5091. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5092. child.SingleDose = childMap["single_dose"].(float64)
  5093. }
  5094. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5095. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5096. child.SingleDoseUnit = childSingleDoseUnit
  5097. }
  5098. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5099. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5100. }
  5101. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5102. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5103. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5104. }
  5105. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5106. groupno := int64(childMap["groupno"].(float64))
  5107. advice.GroupNo = groupno
  5108. }
  5109. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5110. remark, _ := childMap["remark"].(string)
  5111. child.Remark = remark
  5112. }
  5113. child.DeliveryWay = advice.DeliveryWay
  5114. child.ExecutionFrequency = advice.ExecutionFrequency
  5115. advice.Children = append(advice.Children, &child)
  5116. }
  5117. }
  5118. }
  5119. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5120. if temp_advice.ID == 0 {
  5121. advices = append(advices, &advice)
  5122. }
  5123. }
  5124. if len(advices) > 0 {
  5125. finish := models.XtDialysisFinish{
  5126. IsFinish: 1,
  5127. UserOrgId: adminUserInfo.Org.Id,
  5128. Status: 1,
  5129. Ctime: time.Now().Unix(),
  5130. Mtime: 0,
  5131. Module: 4,
  5132. RecordDate: AdviceDate,
  5133. Sourse: 1,
  5134. PatientId: patient,
  5135. }
  5136. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5137. if dialysisFinish.ID == 0 {
  5138. service.CreateDialysisFinish(finish)
  5139. }
  5140. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5141. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5142. for _, item := range advices {
  5143. byterequest, _ := json.Marshal(item)
  5144. adviceLog := models.XtDoctorAdviceLog{
  5145. UserOrgId: adminUserInfo.Org.Id,
  5146. PatientId: patient,
  5147. AdminUserId: adminUserInfo.AdminUser.Id,
  5148. Module: 1,
  5149. ErrLog: string(byterequest),
  5150. Status: 1,
  5151. Ctime: time.Now().Unix(),
  5152. Mtime: 0,
  5153. Source: "手机端医嘱推送",
  5154. RecordDate: item.AdviceDate,
  5155. }
  5156. service.CreateDoctorAdviceLog(adviceLog)
  5157. }
  5158. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5159. redis := service.RedisClient()
  5160. //清空key 值
  5161. redis.Set(key, "", time.Second)
  5162. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5163. redis.Set(keyOne, "", time.Second)
  5164. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5165. defer redis.Close()
  5166. redis.Set(keyThree, "", time.Second)
  5167. if err != nil {
  5168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5169. return
  5170. }
  5171. c.ServeSuccessJSON(map[string]interface{}{
  5172. "msg": "ok",
  5173. "advices": list,
  5174. })
  5175. } else {
  5176. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5177. for _, item := range advices {
  5178. byterequest, _ := json.Marshal(item)
  5179. adviceLog := models.XtDoctorAdviceLog{
  5180. UserOrgId: adminUserInfo.Org.Id,
  5181. PatientId: patient,
  5182. AdminUserId: adminUserInfo.AdminUser.Id,
  5183. Module: 1,
  5184. ErrLog: string(byterequest),
  5185. Status: 1,
  5186. Ctime: time.Now().Unix(),
  5187. Mtime: 0,
  5188. Source: "手机端医嘱推送",
  5189. RecordDate: item.AdviceDate,
  5190. }
  5191. service.CreateDoctorAdviceLog(adviceLog)
  5192. }
  5193. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5194. redis := service.RedisClient()
  5195. //清空key 值
  5196. redis.Set(key, "", time.Second)
  5197. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5198. redis.Set(keyOne, "", time.Second)
  5199. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5200. defer redis.Close()
  5201. redis.Set(keyThree, "", time.Second)
  5202. if err != nil {
  5203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5204. return
  5205. }
  5206. c.ServeSuccessJSON(map[string]interface{}{
  5207. "msg": "ok",
  5208. "advices": list,
  5209. })
  5210. }
  5211. } else {
  5212. c.ServeSuccessJSON(map[string]interface{}{
  5213. "msg": "ok",
  5214. })
  5215. }
  5216. return
  5217. }
  5218. func (c *DialysisAPIController) UploadDryWeight() {
  5219. patient_id, _ := c.GetInt64("id")
  5220. dry_weight, _ := c.GetFloat("dry_weight")
  5221. doctor_id, _ := c.GetInt64("doctor_id")
  5222. remark := c.GetString("remark")
  5223. adminUserInfo := c.GetMobileAdminUserInfo()
  5224. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5225. if err == gorm.ErrRecordNotFound {
  5226. dryWeight := &models.SgjPatientDryweight{
  5227. PatientId: patient_id,
  5228. DryWeight: dry_weight,
  5229. Remakes: remark,
  5230. Ctime: time.Now().Unix(),
  5231. Mtime: time.Now().Unix(),
  5232. Creator: doctor_id,
  5233. Status: 1,
  5234. UserOrgId: adminUserInfo.Org.Id,
  5235. AdjustedValue: "/",
  5236. UserId: adminUserInfo.AdminUser.Id,
  5237. }
  5238. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5239. redis := service.RedisClient()
  5240. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5241. redis.Set(keyOne, "", time.Second)
  5242. loc, _ := time.LoadLocation("Local")
  5243. nowTime := time.Now()
  5244. nowDay := nowTime.Format("2006-01-02")
  5245. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5246. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5247. redis.Set(key, "", time.Second)
  5248. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5249. redis.Set(keyTwo, "", time.Second)
  5250. redis.Close()
  5251. if createErr == nil {
  5252. c.ServeSuccessJSON(map[string]interface{}{
  5253. "msg": "提交成功",
  5254. "weight": dryWeight,
  5255. })
  5256. }
  5257. } else {
  5258. dryWeight := &models.SgjPatientDryweight{
  5259. PatientId: patient_id,
  5260. DryWeight: dry_weight,
  5261. Remakes: remark,
  5262. Ctime: time.Now().Unix(),
  5263. Mtime: time.Now().Unix(),
  5264. Creator: doctor_id,
  5265. Status: 1,
  5266. UserOrgId: adminUserInfo.Org.Id,
  5267. AdjustedValue: "/",
  5268. UserId: adminUserInfo.AdminUser.Id,
  5269. }
  5270. var value float64
  5271. value = dry_weight - weightAdjust.DryWeight
  5272. if value < 0 {
  5273. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5274. } else if value == 0 {
  5275. dryWeight.AdjustedValue = "/"
  5276. } else if value > 0 {
  5277. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5278. }
  5279. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5280. redis := service.RedisClient()
  5281. loc, _ := time.LoadLocation("Local")
  5282. nowTime := time.Now()
  5283. nowDay := nowTime.Format("2006-01-02")
  5284. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5285. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5286. redis.Set(keyOne, "", time.Second)
  5287. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5288. redis.Set(key, "", time.Second)
  5289. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5290. redis.Set(keyTwo, "", time.Second)
  5291. redis.Close()
  5292. if createErr == nil {
  5293. c.ServeSuccessJSON(map[string]interface{}{
  5294. "msg": "提交成功",
  5295. "weight": dryWeight,
  5296. })
  5297. }
  5298. }
  5299. }
  5300. func (c *DialysisAPIController) GetSolution() {
  5301. patient_id, _ := c.GetInt64("patient_id")
  5302. mode_id, _ := c.GetInt64("mode_id")
  5303. adminUserInfo := c.GetMobileAdminUserInfo()
  5304. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5305. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5306. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5307. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5308. if err != nil {
  5309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5310. return
  5311. }
  5312. c.ServeSuccessJSON(map[string]interface{}{
  5313. "solution": solution,
  5314. "prescription": prescription,
  5315. "system_prescription": system_prescription,
  5316. "dialysisPrescription": dialysisPrescription,
  5317. })
  5318. }
  5319. func (c *DialysisAPIController) GetSchedule() {
  5320. schedual_type, _ := c.GetInt64("schedual_type")
  5321. adminUserInfo := c.GetMobileAdminUserInfo()
  5322. scheduleTime, _ := c.GetInt64("record_date")
  5323. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5324. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5325. c.ServeSuccessJSON(map[string]interface{}{
  5326. "number": deviceNumber,
  5327. "list": list,
  5328. })
  5329. }
  5330. func (c *DialysisAPIController) GetPatientId() {
  5331. id, _ := c.GetInt64("id")
  5332. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5333. patientId, _ := service.GetPatientId(id)
  5334. //获取该患者的所有传染病
  5335. list, _ := service.GetPatientInfectious(id)
  5336. c.ServeSuccessJSON(map[string]interface{}{
  5337. "patient": patientId,
  5338. "infectioulist": list,
  5339. })
  5340. }
  5341. func (this *DialysisAPIController) GetDialysisSchedule() {
  5342. schedualDate := this.GetString("date")
  5343. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5344. if parseDateErr != nil {
  5345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5346. return
  5347. }
  5348. adminInfo := this.GetMobileAdminUserInfo()
  5349. orgID := adminInfo.Org.Id
  5350. redis := service.RedisClient()
  5351. defer redis.Close()
  5352. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5353. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5354. if len(scheduals) > 0 {
  5355. //缓存数据
  5356. scheduals_json, err := json.Marshal(scheduals)
  5357. if err == nil {
  5358. redis.Set(key, scheduals_json, time.Second*30)
  5359. }
  5360. }
  5361. this.ServeSuccessJSON(map[string]interface{}{
  5362. "scheduals": scheduals,
  5363. })
  5364. }
  5365. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5366. change_type, _ := this.GetInt64("type", 0)
  5367. record_date := this.GetString("record_time")
  5368. patient_id, _ := this.GetInt64("patient_id", 0)
  5369. timeLayout := "2006-01-02"
  5370. loc, _ := time.LoadLocation("Local")
  5371. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5372. record_time := theAdviceRecordTime.Unix()
  5373. adminUserInfo := this.GetMobileAdminUserInfo()
  5374. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5375. if err == nil {
  5376. if len(advices) == 0 {
  5377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5378. return
  5379. } else {
  5380. this.ServeSuccessJSON(map[string]interface{}{
  5381. "advices": advices,
  5382. "schedule": sch,
  5383. })
  5384. return
  5385. }
  5386. } else {
  5387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5388. return
  5389. }
  5390. }
  5391. func (c *DialysisAPIController) CreateConsumables() {
  5392. record_date := c.GetString("record_time")
  5393. patient_id, _ := c.GetInt64("patient_id", 0)
  5394. active, _ := c.GetInt64("active")
  5395. adminUser := c.GetMobileAdminUserInfo()
  5396. timeLayout := "2006-01-02"
  5397. loc, _ := time.LoadLocation("Local")
  5398. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5399. record_time := theRecordTime.Unix()
  5400. // 查询信息规挡的设置天数
  5401. orgid := c.GetMobileAdminUserInfo().Org.Id
  5402. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5403. if infor.ID > 0 {
  5404. var cha_time int64
  5405. timeNowStr := time.Now().Format("2006-01-02")
  5406. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5407. //今日的日期减去设置的日期
  5408. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5409. if cha_time >= record_time {
  5410. //查询审核是否允许
  5411. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5412. //申请状态不允许的情况 拒绝修改
  5413. if infor.ApplicationStatus != 1 {
  5414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5415. return
  5416. }
  5417. }
  5418. }
  5419. dataBody := make(map[string]interface{}, 0)
  5420. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5421. if err != nil {
  5422. utils.ErrorLog(err.Error())
  5423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5424. return
  5425. }
  5426. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5427. var beforePrepares []*models.DialysisBeforePrepareGoods
  5428. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5429. var dialysisBefor []*models.DialysisBeforePrepare
  5430. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5431. goods, _ := dataBody["goods"].([]interface{})
  5432. if len(goods) > 0 {
  5433. for _, item := range goods {
  5434. items := item.(map[string]interface{})
  5435. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5436. utils.ErrorLog("good_id")
  5437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5438. return
  5439. }
  5440. good_id := int64(items["good_id"].(float64))
  5441. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5442. utils.ErrorLog("good_type_id")
  5443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5444. return
  5445. }
  5446. good_type_id := int64(items["good_type_id"].(float64))
  5447. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5448. utils.ErrorLog("count")
  5449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5450. return
  5451. }
  5452. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5453. commdity_code := items["commdity_code"].(string)
  5454. fmt.Println("commdity", commdity_code)
  5455. prepareGoods := &models.DialysisBeforePrepareGoods{
  5456. GoodTypeId: good_type_id,
  5457. GoodId: good_id,
  5458. Count: count,
  5459. StorehouseId: houseConfig.StorehouseOutInfo,
  5460. }
  5461. beforePrepares = append(beforePrepares, prepareGoods)
  5462. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5463. GoodTypeId: good_type_id,
  5464. GoodId: good_id,
  5465. Count: count,
  5466. StorehouseId: houseConfig.StorehouseOutInfo,
  5467. }
  5468. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5469. prepare := &models.DialysisBeforePrepare{
  5470. GoodTypeId: good_type_id,
  5471. GoodId: good_id,
  5472. Count: count,
  5473. PatientId: patient_id,
  5474. RecordDate: record_time,
  5475. UserOrgId: adminUser.Org.Id,
  5476. Status: 1,
  5477. Ctime: time.Now().Unix(),
  5478. Creater: adminUser.AdminUser.Id,
  5479. CommdityCode: commdity_code,
  5480. StorehouseId: houseConfig.StorehouseOutInfo,
  5481. }
  5482. dialysisBefor = append(dialysisBefor, prepare)
  5483. }
  5484. }
  5485. //查询是否有库存
  5486. for _, item := range dialysisBefor {
  5487. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5488. if err == gorm.ErrRecordNotFound {
  5489. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5490. c.ServeSuccessJSON(map[string]interface{}{
  5491. "message": "1",
  5492. "good_name": goodObj.GoodName,
  5493. "specification_name": goodObj.SpecificationName,
  5494. })
  5495. return
  5496. }
  5497. if err != nil {
  5498. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5499. c.ServeSuccessJSON(map[string]interface{}{
  5500. "message": "1",
  5501. "good_name": goodObj.GoodName,
  5502. "specification_name": goodObj.SpecificationName,
  5503. })
  5504. return
  5505. }
  5506. }
  5507. //新增
  5508. if active == 1 && len(goods) > 0 {
  5509. for _, item := range dialysisBefor {
  5510. dialyPrepareOne := models.DialysisBeforePrepare{
  5511. GoodTypeId: item.GoodTypeId,
  5512. GoodId: item.GoodId,
  5513. PatientId: item.PatientId,
  5514. RecordDate: item.RecordDate,
  5515. UserOrgId: item.UserOrgId,
  5516. Count: item.Count,
  5517. Ctime: time.Now().Unix(),
  5518. Creater: item.Creater,
  5519. CommdityCode: item.CommdityCode,
  5520. Status: 1,
  5521. StorehouseId: houseConfig.StorehouseOutInfo,
  5522. }
  5523. //先清除再插入
  5524. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5525. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5526. //查询默认仓库
  5527. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5528. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5529. var total_count int64
  5530. for _, it := range stockList {
  5531. total_count += it.StockCount
  5532. }
  5533. //基础库插入数据
  5534. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5535. //更新库存
  5536. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5537. var flush_count int64
  5538. for _, it := range goodList {
  5539. flush_count += it.StockCount
  5540. }
  5541. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5542. }
  5543. if err == nil {
  5544. c.ServeSuccessJSON(map[string]interface{}{
  5545. "msg": "保存成功",
  5546. "message": "2",
  5547. })
  5548. return
  5549. } else {
  5550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5551. return
  5552. }
  5553. }
  5554. if len(beforePrepares) > 0 && active == 2 {
  5555. for _, item := range beforePrepares {
  5556. //1.查看该患者该耗材型号最后一次出库数量
  5557. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5558. //判断当前出库数量和最后一次出库数量的大小
  5559. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5560. if item.Count <= goodInfo.Count {
  5561. //退库
  5562. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5563. //查询今日出库数据
  5564. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5565. for _, it := range list {
  5566. prepare := models.DialysisBeforePrepare{
  5567. UserOrgId: it.OrgId,
  5568. PatientId: patient_id,
  5569. RecordDate: it.RecordTime,
  5570. GoodId: it.GoodId,
  5571. GoodTypeId: it.GoodTypeId,
  5572. Count: it.Count,
  5573. Ctime: time.Now().Unix(),
  5574. Creater: adminUser.AdminUser.Id,
  5575. Status: 1,
  5576. StorehouseId: houseConfig.StorehouseOutInfo,
  5577. }
  5578. //删除准备表数据
  5579. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5580. service.CreateDialysisBeforePrepareOne(&prepare)
  5581. }
  5582. }
  5583. var last_total int64
  5584. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5585. if item.Count >= goodInfo.Count {
  5586. //查询当前批次当前耗材最后一条出库数据
  5587. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5588. //计算当前出库和最后一次出库数据相差数据
  5589. last_total = item.Count - lastOutInfo.Count
  5590. //查询该批次剩余库存
  5591. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5592. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5593. if lastInfo.StockCount >= last_total {
  5594. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5595. //查询今日出库数据
  5596. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5597. for _, it := range list {
  5598. prepare := models.DialysisBeforePrepare{
  5599. UserOrgId: it.OrgId,
  5600. PatientId: patient_id,
  5601. RecordDate: it.RecordTime,
  5602. GoodId: it.GoodId,
  5603. GoodTypeId: it.GoodTypeId,
  5604. Count: it.Count,
  5605. Ctime: time.Now().Unix(),
  5606. Creater: adminUser.AdminUser.Id,
  5607. Status: 1,
  5608. StorehouseId: houseConfig.StorehouseOutInfo,
  5609. }
  5610. //删除准备表数据
  5611. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5612. service.CreateDialysisBeforePrepareOne(&prepare)
  5613. //查询默认仓库
  5614. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5615. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5616. var total_count int64
  5617. for _, it := range stockList {
  5618. total_count += it.StockCount
  5619. }
  5620. //基础库插入数据
  5621. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5622. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5623. var flush_count int64
  5624. for _, it := range goodList {
  5625. flush_count += it.StockCount
  5626. }
  5627. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5628. }
  5629. }
  5630. //如果库存不够,则出库到下一个批次
  5631. if lastInfo.StockCount < last_total {
  5632. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5633. //查询今日出库数据
  5634. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5635. for _, it := range list {
  5636. prepare := models.DialysisBeforePrepare{
  5637. UserOrgId: it.OrgId,
  5638. PatientId: patient_id,
  5639. RecordDate: it.RecordTime,
  5640. GoodId: it.GoodId,
  5641. GoodTypeId: it.GoodTypeId,
  5642. Count: it.Count,
  5643. Ctime: time.Now().Unix(),
  5644. Creater: adminUser.AdminUser.Id,
  5645. Status: 1,
  5646. StorehouseId: houseConfig.StorehouseOutInfo,
  5647. }
  5648. //删除准备表数据
  5649. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5650. service.CreateDialysisBeforePrepareOne(&prepare)
  5651. //查询默认仓库
  5652. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5653. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5654. var total_count int64
  5655. for _, it := range stockList {
  5656. total_count += it.StockCount
  5657. }
  5658. //基础库插入数据
  5659. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5660. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5661. var flush_count int64
  5662. for _, it := range goodList {
  5663. flush_count += it.StockCount
  5664. }
  5665. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5666. }
  5667. if err != nil {
  5668. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5669. c.ServeSuccessJSON(map[string]interface{}{
  5670. "message": "1",
  5671. "good_name": goodObj.GoodName,
  5672. "specification_name": goodObj.SpecificationName,
  5673. })
  5674. return
  5675. }
  5676. }
  5677. }
  5678. if err != nil {
  5679. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5680. c.ServeSuccessJSON(map[string]interface{}{
  5681. "message": "1",
  5682. "good_name": goodObj.GoodName,
  5683. "specification_name": goodObj.SpecificationName,
  5684. })
  5685. return
  5686. }
  5687. }
  5688. }
  5689. }
  5690. var errs error
  5691. if errs == nil {
  5692. c.ServeSuccessJSON(map[string]interface{}{
  5693. "msg": "提交成功",
  5694. "message": "2",
  5695. "good_name": "",
  5696. "specification_name": "",
  5697. })
  5698. return
  5699. } else {
  5700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5701. return
  5702. }
  5703. }
  5704. func (c *DialysisAPIController) CreateStockOutInfo() {
  5705. patient_id, _ := c.GetInt64("patient_id", 0)
  5706. record_date := c.GetString("record_time")
  5707. if patient_id <= 0 {
  5708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5709. return
  5710. }
  5711. adminInfo := c.GetMobileAdminUserInfo()
  5712. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5713. timeLayout := "2006-01-02"
  5714. loc, _ := time.LoadLocation("Local")
  5715. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5716. record_time := theRecordTime.Unix()
  5717. // 查询信息规挡的设置天数
  5718. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5719. if infor.ID > 0 && infor.WeekDay > 0 {
  5720. var cha_time int64
  5721. timeNowStr := time.Now().Format("2006-01-02")
  5722. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5723. //今日的日期减去设置的日期
  5724. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5725. if cha_time >= record_time {
  5726. //查询审核是否允许
  5727. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5728. //申请状态不允许的情况 拒绝修改
  5729. if infor.ApplicationStatus != 1 {
  5730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5731. return
  5732. }
  5733. }
  5734. }
  5735. //创建步骤表
  5736. finish := models.XtDialysisFinish{
  5737. IsFinish: 1,
  5738. UserOrgId: adminInfo.Org.Id,
  5739. Status: 1,
  5740. Ctime: time.Now().Unix(),
  5741. Mtime: 0,
  5742. Module: 11,
  5743. RecordDate: record_time,
  5744. Sourse: 1,
  5745. PatientId: patient_id,
  5746. }
  5747. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5748. if dialysisFinish.ID == 0 {
  5749. service.CreateDialysisFinish(finish)
  5750. }
  5751. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5752. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5753. //去重
  5754. consumables = RemoveRepeatedGood(consumables)
  5755. if adminInfo.Org.Id == 9919 {
  5756. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5757. //查询是否有库存
  5758. for _, item := range consumables {
  5759. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5760. if item.Count > warehouse.Count {
  5761. goodErrcode := models.XtGoodErrcode{
  5762. UserOrgId: item.UserOrgId,
  5763. Errcode: "自动出库库存不足",
  5764. GoodId: item.GoodId,
  5765. Status: 1,
  5766. Ctime: time.Now().Unix(),
  5767. Mtime: 0,
  5768. Count: 0,
  5769. StockCount: 0,
  5770. Creater: creator,
  5771. BatchNumberId: warehouse.ID,
  5772. WarehouseOutId: 0,
  5773. }
  5774. service.CreateGoodErrcode(goodErrcode)
  5775. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5776. c.ServeSuccessJSON(map[string]interface{}{
  5777. "message": "1",
  5778. "good_name": goodObj.GoodName,
  5779. "specification_name": goodObj.SpecificationName,
  5780. })
  5781. return
  5782. }
  5783. }
  5784. //查询是否有出库单
  5785. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5786. if err == gorm.ErrRecordNotFound {
  5787. //没有记录,则创建出库单
  5788. timeStr := time.Now().Format("2006-01-02")
  5789. timeArr := strings.Split(timeStr, "-")
  5790. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5791. total = total + 1
  5792. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5793. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5794. number = number + total
  5795. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5796. creater := adminInfo.AdminUser.Id
  5797. warehouseOut := models.WarehouseOut{
  5798. WarehouseOutOrderNumber: warehousing_out_order,
  5799. OperationTime: time.Now().Unix(),
  5800. OrgId: adminInfo.Org.Id,
  5801. Creater: creater,
  5802. Ctime: time.Now().Unix(),
  5803. Status: 1,
  5804. WarehouseOutTime: record_time,
  5805. Dealer: 0,
  5806. Manufacturer: 0,
  5807. Type: 1,
  5808. IsSys: 1,
  5809. StorehouseId: houseConfig.StorehouseOutInfo,
  5810. IsCheck: 1,
  5811. }
  5812. err := service.AddSigleWarehouseOut(&warehouseOut)
  5813. if err != nil {
  5814. goodErrcode := models.XtGoodErrcode{
  5815. UserOrgId: adminInfo.Org.Id,
  5816. Errcode: "创建出库单失败",
  5817. GoodId: 0,
  5818. Status: 1,
  5819. Ctime: time.Now().Unix(),
  5820. Mtime: 0,
  5821. Count: 0,
  5822. StockCount: 0,
  5823. Creater: creator,
  5824. BatchNumberId: 0,
  5825. WarehouseOutId: 0,
  5826. }
  5827. service.CreateGoodErrcode(goodErrcode)
  5828. utils.TraceLog("创建出库单失败 err = %v", err)
  5829. } else {
  5830. for _, item := range consumables {
  5831. //出库
  5832. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5833. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5834. if err == nil {
  5835. goodErrcode := models.XtGoodErrcode{
  5836. UserOrgId: adminInfo.Org.Id,
  5837. Errcode: "自动出库接口报错",
  5838. GoodId: 0,
  5839. Status: 1,
  5840. Ctime: time.Now().Unix(),
  5841. Mtime: 0,
  5842. Count: 0,
  5843. StockCount: 0,
  5844. Creater: creator,
  5845. BatchNumberId: 0,
  5846. WarehouseOutId: 0,
  5847. }
  5848. service.CreateGoodErrcode(goodErrcode)
  5849. utils.TraceLog("创建出库单失败 err = %v", err)
  5850. }
  5851. //查询
  5852. //出库数量相加
  5853. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5854. if errs != nil {
  5855. goodErrcode := models.XtGoodErrcode{
  5856. UserOrgId: item.UserOrgId,
  5857. Errcode: "创建剩余库存字段报错",
  5858. GoodId: item.GoodId,
  5859. Status: 1,
  5860. Ctime: time.Now().Unix(),
  5861. Mtime: 0,
  5862. Count: 0,
  5863. StockCount: 0,
  5864. Creater: creater,
  5865. BatchNumberId: 0,
  5866. WarehouseOutId: 0,
  5867. }
  5868. service.CreateGoodErrcode(goodErrcode)
  5869. }
  5870. }
  5871. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5872. if len(list) == 0 {
  5873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5874. return
  5875. }
  5876. for _, item := range list {
  5877. prepare := models.DialysisBeforePrepare{
  5878. UserOrgId: adminInfo.Org.Id,
  5879. PatientId: patient_id,
  5880. RecordDate: record_time,
  5881. GoodId: item.GoodId,
  5882. GoodTypeId: item.GoodTypeId,
  5883. Count: item.Count,
  5884. Creater: adminInfo.AdminUser.Id,
  5885. Status: 1,
  5886. Ctime: time.Now().Unix(),
  5887. StorehouseId: houseConfig.StorehouseOutInfo,
  5888. }
  5889. //清空准备表数据
  5890. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5891. if err != nil {
  5892. goodErrcode := models.XtGoodErrcode{
  5893. UserOrgId: item.OrgId,
  5894. Errcode: "自动出库清空准备表数据报错",
  5895. GoodId: item.GoodId,
  5896. Status: 1,
  5897. Ctime: time.Now().Unix(),
  5898. Mtime: 0,
  5899. Count: 0,
  5900. StockCount: 0,
  5901. Creater: creater,
  5902. BatchNumberId: 0,
  5903. WarehouseOutId: 0,
  5904. }
  5905. service.CreateGoodErrcode(goodErrcode)
  5906. }
  5907. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5908. if errs != nil {
  5909. goodErrcode := models.XtGoodErrcode{
  5910. UserOrgId: item.OrgId,
  5911. Errcode: "自动出库创建准备表数据报错",
  5912. GoodId: item.GoodId,
  5913. Status: 1,
  5914. Ctime: time.Now().Unix(),
  5915. Mtime: 0,
  5916. Count: 0,
  5917. StockCount: 0,
  5918. Creater: creater,
  5919. BatchNumberId: 0,
  5920. WarehouseOutId: 0,
  5921. }
  5922. service.CreateGoodErrcode(goodErrcode)
  5923. }
  5924. //查询默认仓库
  5925. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5926. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5927. var total_count int64
  5928. for _, it := range stockList {
  5929. total_count += it.StockCount
  5930. }
  5931. //基础库插入数据
  5932. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5933. if errcodes != nil {
  5934. goodErrcode := models.XtGoodErrcode{
  5935. UserOrgId: item.OrgId,
  5936. Errcode: "自动出库基础库插入数据",
  5937. GoodId: item.GoodId,
  5938. Status: 1,
  5939. Ctime: time.Now().Unix(),
  5940. Mtime: 0,
  5941. Count: 0,
  5942. StockCount: 0,
  5943. Creater: creater,
  5944. BatchNumberId: 0,
  5945. WarehouseOutId: 0,
  5946. }
  5947. service.CreateGoodErrcode(goodErrcode)
  5948. }
  5949. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5950. var flush_count int64
  5951. for _, it := range goodList {
  5952. flush_count += it.StockCount
  5953. }
  5954. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5955. if errsss != nil {
  5956. goodErrcode := models.XtGoodErrcode{
  5957. UserOrgId: item.OrgId,
  5958. Errcode: "自动出库剩余库存更新数据",
  5959. GoodId: item.GoodId,
  5960. Status: 1,
  5961. Ctime: time.Now().Unix(),
  5962. Mtime: 0,
  5963. Count: 0,
  5964. StockCount: 0,
  5965. Creater: creater,
  5966. BatchNumberId: 0,
  5967. WarehouseOutId: 0,
  5968. }
  5969. service.CreateGoodErrcode(goodErrcode)
  5970. }
  5971. }
  5972. }
  5973. //
  5974. } else if err == nil {
  5975. for _, item := range consumables {
  5976. //出库
  5977. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5978. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5979. if err != nil {
  5980. goodErrcode := models.XtGoodErrcode{
  5981. UserOrgId: adminInfo.Org.Id,
  5982. Errcode: "自动出库接口报错",
  5983. GoodId: 0,
  5984. Status: 1,
  5985. Ctime: time.Now().Unix(),
  5986. Mtime: 0,
  5987. Count: 0,
  5988. StockCount: 0,
  5989. Creater: creator,
  5990. BatchNumberId: 0,
  5991. WarehouseOutId: 0,
  5992. }
  5993. service.CreateGoodErrcode(goodErrcode)
  5994. }
  5995. //出库数量相加
  5996. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5997. if errss != nil {
  5998. goodErrcode := models.XtGoodErrcode{
  5999. UserOrgId: item.UserOrgId,
  6000. Errcode: "创建剩余库存字段报错",
  6001. GoodId: item.GoodId,
  6002. Status: 1,
  6003. Ctime: time.Now().Unix(),
  6004. Mtime: time.Now().Unix(),
  6005. Count: 0,
  6006. StockCount: 0,
  6007. Creater: item.Creater,
  6008. BatchNumberId: 0,
  6009. WarehouseOutId: 0,
  6010. }
  6011. service.CreateGoodErrcode(goodErrcode)
  6012. }
  6013. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6014. if len(list) == 0 {
  6015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6016. return
  6017. }
  6018. for _, item := range list {
  6019. prepare := models.DialysisBeforePrepare{
  6020. UserOrgId: adminInfo.Org.Id,
  6021. PatientId: patient_id,
  6022. RecordDate: record_time,
  6023. GoodId: item.GoodId,
  6024. GoodTypeId: item.GoodTypeId,
  6025. Count: item.Count,
  6026. Creater: adminInfo.AdminUser.Id,
  6027. Status: 1,
  6028. Ctime: time.Now().Unix(),
  6029. StorehouseId: houseConfig.StorehouseOutInfo,
  6030. }
  6031. //清空准备表数据
  6032. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6033. if errs != nil {
  6034. goodErrcode := models.XtGoodErrcode{
  6035. UserOrgId: adminInfo.Org.Id,
  6036. Errcode: "自动出库清空准备表数据报错",
  6037. GoodId: 0,
  6038. Status: 1,
  6039. Ctime: time.Now().Unix(),
  6040. Mtime: 0,
  6041. Count: 0,
  6042. StockCount: 0,
  6043. Creater: creator,
  6044. BatchNumberId: 0,
  6045. WarehouseOutId: 0,
  6046. }
  6047. service.CreateGoodErrcode(goodErrcode)
  6048. }
  6049. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6050. if errcodes != nil {
  6051. goodErrcode := models.XtGoodErrcode{
  6052. UserOrgId: adminInfo.Org.Id,
  6053. Errcode: "自动出库创建准备表数据报错",
  6054. GoodId: 0,
  6055. Status: 1,
  6056. Ctime: time.Now().Unix(),
  6057. Mtime: 0,
  6058. Count: 0,
  6059. StockCount: 0,
  6060. Creater: creator,
  6061. BatchNumberId: 0,
  6062. WarehouseOutId: 0,
  6063. }
  6064. service.CreateGoodErrcode(goodErrcode)
  6065. }
  6066. //查询默认仓库
  6067. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6068. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6069. var total_count int64
  6070. for _, it := range stockList {
  6071. total_count += it.StockCount
  6072. }
  6073. //基础库插入数据
  6074. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6075. if errcodes != nil {
  6076. goodErrcode := models.XtGoodErrcode{
  6077. UserOrgId: adminInfo.Org.Id,
  6078. Errcode: "自动出库基础库插入数据报错",
  6079. GoodId: 0,
  6080. Status: 1,
  6081. Ctime: time.Now().Unix(),
  6082. Mtime: 0,
  6083. Count: 0,
  6084. StockCount: 0,
  6085. Creater: creator,
  6086. BatchNumberId: 0,
  6087. WarehouseOutId: 0,
  6088. }
  6089. service.CreateGoodErrcode(goodErrcode)
  6090. }
  6091. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6092. var flush_count int64
  6093. for _, it := range goodList {
  6094. flush_count += it.StockCount
  6095. }
  6096. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6097. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6098. if errss != nil {
  6099. goodErrcode := models.XtGoodErrcode{
  6100. UserOrgId: item.OrgId,
  6101. Errcode: "自动出库剩余库存更新数据",
  6102. GoodId: item.GoodId,
  6103. Status: 1,
  6104. Ctime: time.Now().Unix(),
  6105. Mtime: 0,
  6106. Count: 0,
  6107. StockCount: 0,
  6108. Creater: creater,
  6109. BatchNumberId: 0,
  6110. WarehouseOutId: 0,
  6111. }
  6112. service.CreateGoodErrcode(goodErrcode)
  6113. }
  6114. }
  6115. }
  6116. }
  6117. c.ServeSuccessJSON(map[string]interface{}{
  6118. "msg": "提交成功",
  6119. "message": "2",
  6120. "good_name": "",
  6121. "specification_name": "",
  6122. })
  6123. return
  6124. }
  6125. if record.IsOpen == 1 {
  6126. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6127. //查询是否有库存
  6128. for _, item := range consumables {
  6129. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6130. if item.Count > warehouse.Count {
  6131. goodErrcode := models.XtGoodErrcode{
  6132. UserOrgId: item.UserOrgId,
  6133. Errcode: "自动出库库存不足",
  6134. GoodId: item.GoodId,
  6135. Status: 1,
  6136. Ctime: time.Now().Unix(),
  6137. Mtime: 0,
  6138. Count: 0,
  6139. StockCount: 0,
  6140. Creater: creator,
  6141. BatchNumberId: warehouse.ID,
  6142. WarehouseOutId: 0,
  6143. }
  6144. service.CreateGoodErrcode(goodErrcode)
  6145. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6146. c.ServeSuccessJSON(map[string]interface{}{
  6147. "message": "1",
  6148. "good_name": goodObj.GoodName,
  6149. "specification_name": goodObj.SpecificationName,
  6150. })
  6151. return
  6152. }
  6153. }
  6154. //查询是否有出库单
  6155. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6156. if err == gorm.ErrRecordNotFound {
  6157. //没有记录,则创建出库单
  6158. timeStr := time.Now().Format("2006-01-02")
  6159. timeArr := strings.Split(timeStr, "-")
  6160. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6161. total = total + 1
  6162. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6163. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6164. number = number + total
  6165. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6166. creater := adminInfo.AdminUser.Id
  6167. warehouseOut := models.WarehouseOut{
  6168. WarehouseOutOrderNumber: warehousing_out_order,
  6169. OperationTime: time.Now().Unix(),
  6170. OrgId: adminInfo.Org.Id,
  6171. Creater: creater,
  6172. Ctime: time.Now().Unix(),
  6173. Status: 1,
  6174. WarehouseOutTime: record_time,
  6175. Dealer: 0,
  6176. Manufacturer: 0,
  6177. Type: 1,
  6178. IsSys: 1,
  6179. StorehouseId: houseConfig.StorehouseOutInfo,
  6180. IsCheck: 1,
  6181. }
  6182. err := service.AddSigleWarehouseOut(&warehouseOut)
  6183. if err != nil {
  6184. goodErrcode := models.XtGoodErrcode{
  6185. UserOrgId: adminInfo.Org.Id,
  6186. Errcode: "创建出库单失败",
  6187. GoodId: 0,
  6188. Status: 1,
  6189. Ctime: time.Now().Unix(),
  6190. Mtime: 0,
  6191. Count: 0,
  6192. StockCount: 0,
  6193. Creater: creator,
  6194. BatchNumberId: 0,
  6195. WarehouseOutId: 0,
  6196. }
  6197. service.CreateGoodErrcode(goodErrcode)
  6198. utils.TraceLog("创建出库单失败 err = %v", err)
  6199. } else {
  6200. for _, item := range consumables {
  6201. //出库
  6202. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6203. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6204. if err == nil {
  6205. goodErrcode := models.XtGoodErrcode{
  6206. UserOrgId: adminInfo.Org.Id,
  6207. Errcode: "自动出库接口报错",
  6208. GoodId: 0,
  6209. Status: 1,
  6210. Ctime: time.Now().Unix(),
  6211. Mtime: 0,
  6212. Count: 0,
  6213. StockCount: 0,
  6214. Creater: creator,
  6215. BatchNumberId: 0,
  6216. WarehouseOutId: 0,
  6217. }
  6218. service.CreateGoodErrcode(goodErrcode)
  6219. utils.TraceLog("创建出库单失败 err = %v", err)
  6220. }
  6221. //查询
  6222. //出库数量相加
  6223. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6224. if errs != nil {
  6225. goodErrcode := models.XtGoodErrcode{
  6226. UserOrgId: item.UserOrgId,
  6227. Errcode: "创建剩余库存字段报错",
  6228. GoodId: item.GoodId,
  6229. Status: 1,
  6230. Ctime: time.Now().Unix(),
  6231. Mtime: 0,
  6232. Count: 0,
  6233. StockCount: 0,
  6234. Creater: creater,
  6235. BatchNumberId: 0,
  6236. WarehouseOutId: 0,
  6237. }
  6238. service.CreateGoodErrcode(goodErrcode)
  6239. }
  6240. }
  6241. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6242. if len(list) == 0 {
  6243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6244. return
  6245. }
  6246. for _, item := range list {
  6247. prepare := models.DialysisBeforePrepare{
  6248. UserOrgId: adminInfo.Org.Id,
  6249. PatientId: patient_id,
  6250. RecordDate: record_time,
  6251. GoodId: item.GoodId,
  6252. GoodTypeId: item.GoodTypeId,
  6253. Count: item.Count,
  6254. Creater: adminInfo.AdminUser.Id,
  6255. Status: 1,
  6256. Ctime: time.Now().Unix(),
  6257. StorehouseId: houseConfig.StorehouseOutInfo,
  6258. }
  6259. //清空准备表数据
  6260. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6261. if err != nil {
  6262. goodErrcode := models.XtGoodErrcode{
  6263. UserOrgId: item.OrgId,
  6264. Errcode: "自动出库清空准备表数据报错",
  6265. GoodId: item.GoodId,
  6266. Status: 1,
  6267. Ctime: time.Now().Unix(),
  6268. Mtime: 0,
  6269. Count: 0,
  6270. StockCount: 0,
  6271. Creater: creater,
  6272. BatchNumberId: 0,
  6273. WarehouseOutId: 0,
  6274. }
  6275. service.CreateGoodErrcode(goodErrcode)
  6276. }
  6277. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6278. if errs != nil {
  6279. goodErrcode := models.XtGoodErrcode{
  6280. UserOrgId: item.OrgId,
  6281. Errcode: "自动出库创建准备表数据报错",
  6282. GoodId: item.GoodId,
  6283. Status: 1,
  6284. Ctime: time.Now().Unix(),
  6285. Mtime: 0,
  6286. Count: 0,
  6287. StockCount: 0,
  6288. Creater: creater,
  6289. BatchNumberId: 0,
  6290. WarehouseOutId: 0,
  6291. }
  6292. service.CreateGoodErrcode(goodErrcode)
  6293. }
  6294. //查询默认仓库
  6295. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6296. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6297. var total_count int64
  6298. for _, it := range stockList {
  6299. total_count += it.StockCount
  6300. }
  6301. //基础库插入数据
  6302. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6303. if errcodes != nil {
  6304. goodErrcode := models.XtGoodErrcode{
  6305. UserOrgId: item.OrgId,
  6306. Errcode: "自动出库基础库插入数据",
  6307. GoodId: item.GoodId,
  6308. Status: 1,
  6309. Ctime: time.Now().Unix(),
  6310. Mtime: 0,
  6311. Count: 0,
  6312. StockCount: 0,
  6313. Creater: creater,
  6314. BatchNumberId: 0,
  6315. WarehouseOutId: 0,
  6316. }
  6317. service.CreateGoodErrcode(goodErrcode)
  6318. }
  6319. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6320. var flush_count int64
  6321. for _, it := range goodList {
  6322. flush_count += it.StockCount
  6323. }
  6324. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6325. if errsss != nil {
  6326. goodErrcode := models.XtGoodErrcode{
  6327. UserOrgId: item.OrgId,
  6328. Errcode: "自动出库剩余库存更新数据",
  6329. GoodId: item.GoodId,
  6330. Status: 1,
  6331. Ctime: time.Now().Unix(),
  6332. Mtime: 0,
  6333. Count: 0,
  6334. StockCount: 0,
  6335. Creater: creater,
  6336. BatchNumberId: 0,
  6337. WarehouseOutId: 0,
  6338. }
  6339. service.CreateGoodErrcode(goodErrcode)
  6340. }
  6341. }
  6342. }
  6343. //
  6344. } else if err == nil {
  6345. for _, item := range consumables {
  6346. //出库
  6347. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6348. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6349. if err != nil {
  6350. goodErrcode := models.XtGoodErrcode{
  6351. UserOrgId: adminInfo.Org.Id,
  6352. Errcode: "自动出库接口报错",
  6353. GoodId: 0,
  6354. Status: 1,
  6355. Ctime: time.Now().Unix(),
  6356. Mtime: 0,
  6357. Count: 0,
  6358. StockCount: 0,
  6359. Creater: creator,
  6360. BatchNumberId: 0,
  6361. WarehouseOutId: 0,
  6362. }
  6363. service.CreateGoodErrcode(goodErrcode)
  6364. }
  6365. //出库数量相加
  6366. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6367. if errss != nil {
  6368. goodErrcode := models.XtGoodErrcode{
  6369. UserOrgId: item.UserOrgId,
  6370. Errcode: "创建剩余库存字段报错",
  6371. GoodId: item.GoodId,
  6372. Status: 1,
  6373. Ctime: time.Now().Unix(),
  6374. Mtime: time.Now().Unix(),
  6375. Count: 0,
  6376. StockCount: 0,
  6377. Creater: item.Creater,
  6378. BatchNumberId: 0,
  6379. WarehouseOutId: 0,
  6380. }
  6381. service.CreateGoodErrcode(goodErrcode)
  6382. }
  6383. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6384. if len(list) == 0 {
  6385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6386. return
  6387. }
  6388. for _, item := range list {
  6389. prepare := models.DialysisBeforePrepare{
  6390. UserOrgId: adminInfo.Org.Id,
  6391. PatientId: patient_id,
  6392. RecordDate: record_time,
  6393. GoodId: item.GoodId,
  6394. GoodTypeId: item.GoodTypeId,
  6395. Count: item.Count,
  6396. Creater: adminInfo.AdminUser.Id,
  6397. Status: 1,
  6398. Ctime: time.Now().Unix(),
  6399. StorehouseId: houseConfig.StorehouseOutInfo,
  6400. }
  6401. //清空准备表数据
  6402. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6403. if errs != nil {
  6404. goodErrcode := models.XtGoodErrcode{
  6405. UserOrgId: adminInfo.Org.Id,
  6406. Errcode: "自动出库清空准备表数据报错",
  6407. GoodId: 0,
  6408. Status: 1,
  6409. Ctime: time.Now().Unix(),
  6410. Mtime: 0,
  6411. Count: 0,
  6412. StockCount: 0,
  6413. Creater: creator,
  6414. BatchNumberId: 0,
  6415. WarehouseOutId: 0,
  6416. }
  6417. service.CreateGoodErrcode(goodErrcode)
  6418. }
  6419. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6420. if errcodes != nil {
  6421. goodErrcode := models.XtGoodErrcode{
  6422. UserOrgId: adminInfo.Org.Id,
  6423. Errcode: "自动出库创建准备表数据报错",
  6424. GoodId: 0,
  6425. Status: 1,
  6426. Ctime: time.Now().Unix(),
  6427. Mtime: 0,
  6428. Count: 0,
  6429. StockCount: 0,
  6430. Creater: creator,
  6431. BatchNumberId: 0,
  6432. WarehouseOutId: 0,
  6433. }
  6434. service.CreateGoodErrcode(goodErrcode)
  6435. }
  6436. //查询默认仓库
  6437. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6438. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6439. var total_count int64
  6440. for _, it := range stockList {
  6441. total_count += it.StockCount
  6442. }
  6443. //基础库插入数据
  6444. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6445. if errcodes != nil {
  6446. goodErrcode := models.XtGoodErrcode{
  6447. UserOrgId: adminInfo.Org.Id,
  6448. Errcode: "自动出库基础库插入数据报错",
  6449. GoodId: 0,
  6450. Status: 1,
  6451. Ctime: time.Now().Unix(),
  6452. Mtime: 0,
  6453. Count: 0,
  6454. StockCount: 0,
  6455. Creater: creator,
  6456. BatchNumberId: 0,
  6457. WarehouseOutId: 0,
  6458. }
  6459. service.CreateGoodErrcode(goodErrcode)
  6460. }
  6461. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6462. var flush_count int64
  6463. for _, it := range goodList {
  6464. flush_count += it.StockCount
  6465. }
  6466. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6467. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6468. if errss != nil {
  6469. goodErrcode := models.XtGoodErrcode{
  6470. UserOrgId: item.OrgId,
  6471. Errcode: "自动出库剩余库存更新数据",
  6472. GoodId: item.GoodId,
  6473. Status: 1,
  6474. Ctime: time.Now().Unix(),
  6475. Mtime: 0,
  6476. Count: 0,
  6477. StockCount: 0,
  6478. Creater: creater,
  6479. BatchNumberId: 0,
  6480. WarehouseOutId: 0,
  6481. }
  6482. service.CreateGoodErrcode(goodErrcode)
  6483. }
  6484. }
  6485. }
  6486. }
  6487. c.ServeSuccessJSON(map[string]interface{}{
  6488. "msg": "提交成功",
  6489. "message": "2",
  6490. "good_name": "",
  6491. "specification_name": "",
  6492. })
  6493. return
  6494. } else {
  6495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6496. return
  6497. }
  6498. }
  6499. func (c *DialysisAPIController) EditConsumables() {
  6500. patient_id, _ := c.GetInt64("patient_id", 0)
  6501. record_date := c.GetString("record_time")
  6502. if patient_id <= 0 {
  6503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6504. return
  6505. }
  6506. adminInfo := c.GetMobileAdminUserInfo()
  6507. timeLayout := "2006-01-02"
  6508. loc, _ := time.LoadLocation("Local")
  6509. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6510. record_time := theRecordTime.Unix()
  6511. // 查询信息规挡的设置天数
  6512. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6513. if infor.ID > 0 && infor.WeekDay > 0 {
  6514. var cha_time int64
  6515. timeNowStr := time.Now().Format("2006-01-02")
  6516. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6517. //今日的日期减去设置的日期
  6518. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6519. if cha_time >= record_time {
  6520. //查询审核是否允许
  6521. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6522. //申请状态不允许的情况 拒绝修改
  6523. if infor.ApplicationStatus != 1 {
  6524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6525. return
  6526. }
  6527. }
  6528. }
  6529. dataBody := make(map[string]interface{}, 0)
  6530. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6531. if err != nil {
  6532. utils.ErrorLog(err.Error())
  6533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6534. return
  6535. }
  6536. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6537. var beforePrepares []*models.DialysisBeforePrepareGoods
  6538. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6539. var cancelbefor []*models.DialysisBeforePrepareGoods
  6540. var outbefor []*models.DialysisBeforePrepareGoods
  6541. //判断是否开启自动出库
  6542. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6543. if record.IsOpen == 1 {
  6544. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6545. goods, _ := dataBody["goods"].([]interface{})
  6546. if len(goods) > 0 {
  6547. for _, item := range goods {
  6548. items := item.(map[string]interface{})
  6549. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6550. utils.ErrorLog("good_id")
  6551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6552. return
  6553. }
  6554. good_id := int64(items["good_id"].(float64))
  6555. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6556. utils.ErrorLog("good_type_id")
  6557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6558. return
  6559. }
  6560. good_type_id := int64(items["good_type_id"].(float64))
  6561. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6562. utils.ErrorLog("count")
  6563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6564. return
  6565. }
  6566. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6567. commdity_code := items["commdity_code"].(string)
  6568. fmt.Println(commdity_code)
  6569. prepareGoods := &models.DialysisBeforePrepareGoods{
  6570. GoodTypeId: good_type_id,
  6571. GoodId: good_id,
  6572. Count: count,
  6573. StorehouseId: houseConfig.StorehouseOutInfo,
  6574. }
  6575. beforePrepares = append(beforePrepares, prepareGoods)
  6576. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6577. GoodTypeId: good_type_id,
  6578. GoodId: good_id,
  6579. Count: count,
  6580. StorehouseId: houseConfig.StorehouseOutInfo,
  6581. }
  6582. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6583. }
  6584. for _, item := range beforePrepares {
  6585. //1.查看该患者该耗材型号最后一次出库数量
  6586. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6587. //判断当前出库数量和最后一次出库数量的大小
  6588. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6589. if item.Count < goodInfo.Count {
  6590. cancelbefor = append(cancelbefor, item)
  6591. }
  6592. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6593. if item.Count > goodInfo.Count {
  6594. outbefor = append(outbefor, item)
  6595. }
  6596. //处理编辑耗材新增不了的问题
  6597. if goodInfo.Count == item.Count {
  6598. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6599. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6600. }
  6601. }
  6602. if len(cancelbefor) > 0 {
  6603. //退库
  6604. for _, item := range cancelbefor {
  6605. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6606. creater := adminInfo.AdminUser.Id
  6607. //查询该患者当天已经出库的耗材信息
  6608. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6609. var delete_count int64 = 0
  6610. delete_count = warehouseOutInfos.Count - item.Count
  6611. //增加库存数量
  6612. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6613. //减少实际出库库存数量
  6614. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6615. // 删除出库完成后,要增加对应批次的库存数量
  6616. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6617. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6618. //更新剩余库存
  6619. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6620. var flush_count int64
  6621. for _, it := range goodListOne {
  6622. flush_count += it.StockCount
  6623. }
  6624. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6625. //查询剩余库存
  6626. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6627. var sum_count int64
  6628. for _, item := range goodList {
  6629. sum_count += item.StockCount
  6630. }
  6631. // 在出库记录表里记录退库详情
  6632. warehouseOutInfo := &models.WarehouseOutInfo{
  6633. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6634. WarehouseOutId: warehouseOut.ID,
  6635. Status: 1,
  6636. Ctime: time.Now().Unix(),
  6637. OrgId: adminInfo.Org.Id,
  6638. Type: 1,
  6639. IsSys: 1,
  6640. SysRecordTime: record_time,
  6641. GoodTypeId: item.GoodTypeId,
  6642. GoodId: item.GoodId,
  6643. PatientId: patient_id,
  6644. ConsumableType: 2,
  6645. StorehouseId: houseConfig.StorehouseOutInfo,
  6646. IsCheck: 1,
  6647. OverCount: sum_count,
  6648. }
  6649. warehouseOutInfo.Count = item.Count
  6650. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6651. warehouseOutInfo.Price = stockInInfo.Price
  6652. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6653. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6654. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6655. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6656. warehouseOutInfo.Number = warehouseOutInfos.Number
  6657. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6658. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6659. //查找当天是否存在出库记录
  6660. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6661. if errcod == gorm.ErrRecordNotFound {
  6662. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6663. //插入详情明细表
  6664. stockFlow := models.VmStockFlow{
  6665. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6666. WarehouseOutId: warehouseOut.ID,
  6667. GoodId: item.GoodId,
  6668. Number: warehouseOutInfos.Number,
  6669. ProductDate: stockInInfo.ProductDate,
  6670. ExpireDate: stockInInfo.ExpiryDate,
  6671. Count: item.Count,
  6672. Price: stockInInfo.Price,
  6673. Status: 1,
  6674. Ctime: record_time,
  6675. UserOrgId: adminInfo.Org.Id,
  6676. Manufacturer: stockInInfo.Manufacturer,
  6677. Dealer: stockInInfo.Dealer,
  6678. LicenseNumber: stockInInfo.LicenseNumber,
  6679. IsEdit: 2,
  6680. Creator: creater,
  6681. SystemTime: record_time,
  6682. ConsumableType: 3,
  6683. WarehousingDetailId: 0,
  6684. IsSys: 1,
  6685. UpdateCreator: creater,
  6686. PatientId: patient_id,
  6687. StorehouseId: houseConfig.StorehouseOutInfo,
  6688. }
  6689. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6690. if errflow == gorm.ErrRecordNotFound {
  6691. //创建流水表
  6692. err := service.CreateStockFlowOne(stockFlow)
  6693. fmt.Println("err", err)
  6694. } else if errflow == nil {
  6695. //插入详情明细表
  6696. stockFlow := models.VmStockFlow{
  6697. ID: exsit.ID,
  6698. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6699. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6700. WarehouseOutId: warehouseOut.ID,
  6701. GoodId: item.GoodId,
  6702. Number: warehouseOutInfos.Number,
  6703. ProductDate: stockInInfo.ProductDate,
  6704. ExpireDate: stockInInfo.ExpiryDate,
  6705. Count: exsit.Count - delete_count,
  6706. Price: stockInInfo.Price,
  6707. Status: 1,
  6708. Ctime: record_time,
  6709. UserOrgId: adminInfo.Org.Id,
  6710. Manufacturer: stockInInfo.Manufacturer,
  6711. Dealer: stockInInfo.Dealer,
  6712. LicenseNumber: stockInInfo.LicenseNumber,
  6713. IsEdit: 2,
  6714. Creator: creater,
  6715. SystemTime: record_time,
  6716. ConsumableType: 3,
  6717. WarehousingDetailId: 0,
  6718. IsSys: 1,
  6719. UpdateCreator: creater,
  6720. PatientId: patient_id,
  6721. StorehouseId: houseConfig.StorehouseOutInfo,
  6722. }
  6723. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6724. }
  6725. } else if errcod == nil {
  6726. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6727. //查询剩余库存
  6728. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6729. var sum_count int64
  6730. for _, item := range goodList {
  6731. sum_count += item.StockCount
  6732. }
  6733. //创建退库单,生成退库数据
  6734. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6735. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6736. operation_time := time.Now().Unix()
  6737. creater := adminInfo.AdminUser.Id
  6738. //创建退库单
  6739. timeStr := time.Now().Format("2006-01-02")
  6740. timeArr := strings.Split(timeStr, "-")
  6741. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6742. total = total + 1
  6743. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6744. cancelStock := models.CancelStock{
  6745. OrderNumber: orderNumber,
  6746. OperaTime: operation_time,
  6747. OrgId: adminInfo.Org.Id,
  6748. Creater: creater,
  6749. Ctime: time.Now().Unix(),
  6750. Status: 1,
  6751. ReturnTime: record_time,
  6752. Type: 1,
  6753. StorehouseId: houseConfig.StorehouseOutInfo,
  6754. IsCheck: 1,
  6755. }
  6756. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6757. if msgerrkonde == gorm.ErrRecordNotFound {
  6758. service.AddSigleCancelStock(&cancelStock)
  6759. }
  6760. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6761. //查询是否有出库
  6762. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6763. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6764. deaerler, _ := service.GetDealerById(info.Dealer)
  6765. if info.ID > 0 {
  6766. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6767. cancelStockInfo := models.CancelStockInfo{
  6768. GoodId: item.GoodId,
  6769. CancelStockId: cancel.ID,
  6770. GoodTypeId: good.GoodTypeId,
  6771. Count: delete_count,
  6772. Price: info.Price,
  6773. Total: 0,
  6774. ProductDate: info.ProductDate,
  6775. ExpiryDate: info.ExpiryDate,
  6776. Ctime: time.Now().Unix(),
  6777. Status: 1,
  6778. OrgId: adminInfo.Org.Id,
  6779. OrderNumber: cancel.OrderNumber,
  6780. Type: 0,
  6781. Dealer: deaerler.DealerName,
  6782. Manufacturer: manufacturer.ManufacturerName,
  6783. Number: info.Number,
  6784. RegisterAccount: "",
  6785. Remark: "",
  6786. WarehouseInfoId: info.WarehouseInfotId,
  6787. PatientId: info.PatientId,
  6788. RecordDate: info.SysRecordTime,
  6789. StorehouseId: houseConfig.StorehouseOutInfo,
  6790. IsCheck: 1,
  6791. }
  6792. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6793. //退库数量增加
  6794. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6795. //查询剩余库存
  6796. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6797. var over_count int64
  6798. for _, it := range goodList {
  6799. over_count += it.StockCount
  6800. }
  6801. flow := models.VmStockFlow{
  6802. WarehousingId: info.WarehouseInfotId,
  6803. GoodId: item.GoodId,
  6804. Number: info.Number,
  6805. LicenseNumber: info.LicenseNumber,
  6806. Count: delete_count,
  6807. UserOrgId: adminInfo.Org.Id,
  6808. PatientId: patient_id,
  6809. SystemTime: info.SysRecordTime,
  6810. ConsumableType: 7,
  6811. IsSys: 0,
  6812. WarehousingOrder: "",
  6813. WarehouseOutId: info.WarehouseOutId,
  6814. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6815. IsEdit: 0,
  6816. CancelStockId: cancel.ID,
  6817. CancelOrderNumber: cancel.OrderNumber,
  6818. Manufacturer: manufacturer.ID,
  6819. Dealer: 0,
  6820. Creator: adminInfo.AdminUser.Id,
  6821. UpdateCreator: 0,
  6822. Status: 1,
  6823. Ctime: record_time,
  6824. Mtime: 0,
  6825. Price: info.Price,
  6826. WarehousingDetailId: info.WarehouseInfotId,
  6827. WarehouseOutDetailId: info.ID,
  6828. CancelOutDetailId: cancelInfo.ID,
  6829. ProductDate: info.ProductDate,
  6830. ExpireDate: info.ExpiryDate,
  6831. StorehouseId: houseConfig.StorehouseOutInfo,
  6832. OverCount: over_count,
  6833. }
  6834. service.CreateStockFlowOne(flow)
  6835. }
  6836. }
  6837. //更改自动出库的表格
  6838. details := models.BloodAutomaticReduceDetail{
  6839. WarehouseOutId: warehouseOutInfo.ID,
  6840. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6841. PatientId: patient_id,
  6842. Ctime: time.Now().Unix(),
  6843. Mtime: time.Now().Unix(),
  6844. Status: 1,
  6845. RecordTime: record_time,
  6846. OrgId: adminInfo.Org.Id,
  6847. GoodId: item.GoodId,
  6848. GoodTypeId: item.GoodTypeId,
  6849. Count: item.Count,
  6850. StorehouseId: houseConfig.StorehouseOutInfo,
  6851. }
  6852. //查询当天耗材是否已经存在数据
  6853. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6854. if errcode == gorm.ErrRecordNotFound {
  6855. service.CreateAutoReduceRecord(&details)
  6856. } else if errcode == nil {
  6857. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6858. service.CreateAutoReduceRecord(&details)
  6859. }
  6860. //查询默认仓库
  6861. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6862. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6863. var total_count int64
  6864. for _, it := range stockList {
  6865. total_count += it.StockCount
  6866. }
  6867. //基础库插入数据
  6868. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6869. }
  6870. }
  6871. if len(outbefor) > 0 {
  6872. //出库
  6873. for _, item := range outbefor {
  6874. var last_total int64
  6875. //1.查看该患者该耗材型号最后一次出库数量
  6876. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6877. //计算当前出库和最后一次出库数据相差数据
  6878. last_total = item.Count - goodInfoOne.Count
  6879. //查询该耗材的总库存
  6880. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6881. // 如果库存差大于剩余库存则提示库存不足
  6882. if last_total > wareinfo.StockCount {
  6883. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6884. c.ServeSuccessJSON(map[string]interface{}{
  6885. "message": "1",
  6886. "good_name": goodObj.GoodName,
  6887. "specification_name": goodObj.SpecificationName,
  6888. })
  6889. return
  6890. } else {
  6891. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6892. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6893. if err == gorm.ErrRecordNotFound {
  6894. //没有记录,则创建出库单
  6895. timeStr := time.Now().Format("2006-01-02")
  6896. timeArr := strings.Split(timeStr, "-")
  6897. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6898. total = total + 1
  6899. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6900. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6901. number = number + total
  6902. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6903. warehouseOut := models.WarehouseOut{
  6904. WarehouseOutOrderNumber: warehousing_out_order,
  6905. OperationTime: time.Now().Unix(),
  6906. OrgId: adminInfo.Org.Id,
  6907. Creater: adminInfo.AdminUser.Id,
  6908. Ctime: time.Now().Unix(),
  6909. Status: 1,
  6910. WarehouseOutTime: record_time,
  6911. Dealer: 0,
  6912. Manufacturer: 0,
  6913. Type: 1,
  6914. IsSys: 1,
  6915. StorehouseId: houseConfig.StorehouseOutInfo,
  6916. IsCheck: 1,
  6917. }
  6918. service.AddSigleWarehouseOut(&warehouseOut)
  6919. }
  6920. //出库
  6921. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6922. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6923. //1.查看该患者该耗材型号最后一次出库数量
  6924. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6925. prepare := models.DialysisBeforePrepare{
  6926. UserOrgId: adminInfo.Org.Id,
  6927. PatientId: patient_id,
  6928. RecordDate: record_time,
  6929. GoodId: item.GoodId,
  6930. GoodTypeId: item.GoodTypeId,
  6931. Count: item.Count - goodInfoTwo.Count,
  6932. Ctime: time.Now().Unix(),
  6933. Mtime: 0,
  6934. Creater: adminInfo.AdminUser.Id,
  6935. Modifier: adminInfo.AdminUser.Id,
  6936. Status: 1,
  6937. CommdityCode: "",
  6938. NewCount: 0,
  6939. ProjectId: 0,
  6940. StorehouseId: houseConfig.StorehouseOutInfo,
  6941. }
  6942. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6943. //增加出库数量
  6944. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6945. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6946. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6947. var total_count int64
  6948. for _, it := range stockList {
  6949. total_count += it.StockCount
  6950. }
  6951. //基础库插入数据
  6952. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6953. //剩余库存
  6954. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6955. var flush_count int64
  6956. for _, it := range goodList {
  6957. flush_count += it.StockCount
  6958. }
  6959. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6960. }
  6961. }
  6962. }
  6963. //查询今日出库数据
  6964. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6965. for _, it := range list {
  6966. prepare := models.DialysisBeforePrepare{
  6967. UserOrgId: it.OrgId,
  6968. PatientId: patient_id,
  6969. RecordDate: it.RecordTime,
  6970. GoodId: it.GoodId,
  6971. GoodTypeId: it.GoodTypeId,
  6972. Count: it.Count,
  6973. Ctime: time.Now().Unix(),
  6974. Creater: adminInfo.AdminUser.Id,
  6975. Status: 1,
  6976. StorehouseId: houseConfig.StorehouseOutInfo,
  6977. ProjectId: it.ProjectId,
  6978. }
  6979. //删除准备表数据
  6980. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6981. service.CreateDialysisBeforePrepareOne(&prepare)
  6982. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6983. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6984. var total_count int64
  6985. for _, it := range stockList {
  6986. total_count += it.StockCount
  6987. }
  6988. //基础库插入数据
  6989. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6990. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6991. var flush_count int64
  6992. for _, it := range goodList {
  6993. flush_count += it.StockCount
  6994. }
  6995. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6996. }
  6997. }
  6998. }
  6999. //更新自动出库的地方
  7000. var errs error
  7001. if errs == nil {
  7002. c.ServeSuccessJSON(map[string]interface{}{
  7003. "msg": "修改成功",
  7004. "message": "2",
  7005. "good_name": "",
  7006. "specification_name": "",
  7007. })
  7008. return
  7009. } else {
  7010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7011. return
  7012. }
  7013. }
  7014. }
  7015. func (c *DialysisAPIController) GetDialysisGoods() {
  7016. schedualDate := c.GetString("schedule_date")
  7017. schedule_type, _ := c.GetInt64("schedule_type")
  7018. partition_id, _ := c.GetInt64("partition_id")
  7019. page, _ := c.GetInt("page")
  7020. patient_id, _ := c.GetInt64("patient_id")
  7021. schedualEndDate := int64(0)
  7022. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7023. if parseDateErr != nil && len(schedualDate) != 0 {
  7024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7025. return
  7026. }
  7027. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7028. if parseDateErr != nil && len(schedualDate) != 0 {
  7029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7030. return
  7031. }
  7032. schedualEndDate = endDate.Unix()
  7033. adminUser := c.GetMobileAdminUserInfo()
  7034. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7035. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7036. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7037. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7038. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7039. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7040. //获取当天该病人的透析处方
  7041. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7042. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7043. if err == gorm.ErrRecordNotFound {
  7044. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7045. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7046. if patient_id != 0 {
  7047. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7048. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7049. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7050. //获取患者总的出库数据
  7051. item.LastAutomaticReduceDetail = goodUser
  7052. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7053. item.Project = project
  7054. for _, it := range item.AutomaticReduceDetail {
  7055. var total int64
  7056. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7057. for _, its := range auto {
  7058. total += its.Count
  7059. }
  7060. it.Count = total
  7061. }
  7062. }
  7063. }
  7064. c.ServeSuccessJSON(map[string]interface{}{
  7065. "dialysis_goods": dialysisGoods,
  7066. "good_type": goodTypes,
  7067. "total": total,
  7068. "prescribe": prescribe,
  7069. "good_info": good_info,
  7070. "warehouseOutList": warehouseOutList,
  7071. "config": config,
  7072. "outConfig": outConfig,
  7073. "settleConfig": settleConfig,
  7074. })
  7075. return
  7076. } else if err == nil {
  7077. //获取当天排班的每个患者的库存使用情况
  7078. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7079. //获取患者总的出库数据
  7080. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7081. if patient_id != 0 {
  7082. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7083. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7084. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7085. item.Project = project
  7086. item.LastAutomaticReduceDetail = goodUser
  7087. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7088. for _, it := range item.AutomaticReduceDetail {
  7089. var total int64
  7090. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7091. for _, its := range auto {
  7092. total += its.Count
  7093. }
  7094. it.Count = total
  7095. }
  7096. }
  7097. }
  7098. if err == nil {
  7099. c.ServeSuccessJSON(map[string]interface{}{
  7100. "dialysis_goods": dialysisGoods,
  7101. "good_type": goodTypes,
  7102. "total": total,
  7103. "prescribe": prescribe,
  7104. "good_info": good_info,
  7105. "project": project,
  7106. "warehouseOutList": warehouseOutList,
  7107. "config": config,
  7108. "outConfig": outConfig,
  7109. "settleConfig": settleConfig,
  7110. })
  7111. return
  7112. } else {
  7113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7114. return
  7115. }
  7116. } else if err != nil {
  7117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7118. return
  7119. }
  7120. }
  7121. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7122. start_time := c.GetString("start_time")
  7123. end_time := c.GetString("end_time")
  7124. timeLayout := "2006-01-02"
  7125. loc, _ := time.LoadLocation("Local")
  7126. var theStartTime int64
  7127. if len(start_time) > 0 {
  7128. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7129. if err != nil {
  7130. utils.ErrorLog(err.Error())
  7131. }
  7132. theStartTime = theTime.Unix()
  7133. }
  7134. var theEndtTime int64
  7135. if len(end_time) > 0 {
  7136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7137. if err != nil {
  7138. utils.ErrorLog(err.Error())
  7139. }
  7140. theEndtTime = theTime.Unix()
  7141. }
  7142. adminUser := c.GetMobileAdminUserInfo()
  7143. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7144. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7145. if err == nil {
  7146. c.ServeSuccessJSON(map[string]interface{}{
  7147. "stock_out": outInfo,
  7148. "stockCount": stockCount,
  7149. })
  7150. return
  7151. } else {
  7152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7153. return
  7154. }
  7155. }
  7156. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7157. patient_id, _ := c.GetInt64("patient_id", 0)
  7158. record_time := c.GetString("record_time")
  7159. adminUser := c.GetMobileAdminUserInfo()
  7160. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7161. if parseDateErr != nil && len(record_time) != 0 {
  7162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7163. return
  7164. }
  7165. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7166. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7167. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7168. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7169. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7170. //获取今日患者的透析处方参数
  7171. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7172. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7173. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7174. c.ServeSuccessJSON(map[string]interface{}{
  7175. "good_type": goodTypes,
  7176. "good_user": goodUser,
  7177. "good_info": good_info,
  7178. "last_good_user": lastGoodUserDetial,
  7179. "project": project,
  7180. "prescription": prescribe,
  7181. "outInfo": outInfo,
  7182. "configs": configs,
  7183. })
  7184. return
  7185. }
  7186. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7187. patient_id, _ := c.GetInt64("patient_id", 0)
  7188. record_date := c.GetString("record_time")
  7189. timeLayout := "2006-01-02"
  7190. loc, _ := time.LoadLocation("Local")
  7191. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7192. record_time := theRecordTime.Unix()
  7193. adminInfo := c.GetMobileAdminUserInfo()
  7194. dataBody := make(map[string]interface{}, 0)
  7195. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7196. if err != nil {
  7197. utils.ErrorLog(err.Error())
  7198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7199. return
  7200. }
  7201. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7202. var beforePrepares []*models.DialysisBeforePrepareGoods
  7203. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7204. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7205. goods, _ := dataBody["goods"].([]interface{})
  7206. if len(goods) > 0 {
  7207. for _, item := range goods {
  7208. items := item.(map[string]interface{})
  7209. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7210. utils.ErrorLog("good_id")
  7211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7212. return
  7213. }
  7214. good_id := int64(items["good_id"].(float64))
  7215. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7216. utils.ErrorLog("good_type_id")
  7217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7218. return
  7219. }
  7220. good_type_id := int64(items["good_type_id"].(float64))
  7221. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7222. utils.ErrorLog("count")
  7223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7224. return
  7225. }
  7226. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7227. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7228. utils.ErrorLog("project_id")
  7229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7230. return
  7231. }
  7232. project_id := int64(items["project_id"].(float64))
  7233. new_count := int64(items["new_count"].(float64))
  7234. old_count := int64(items["old_count"].(float64))
  7235. prepare := &models.DialysisBeforePrepareGoods{
  7236. GoodId: good_id,
  7237. GoodTypeId: good_type_id,
  7238. Count: count,
  7239. ProjectId: project_id,
  7240. StorehouseId: houseConfig.StorehouseOutInfo,
  7241. NewCount: new_count,
  7242. OldCount: old_count,
  7243. }
  7244. beforePrepares = append(beforePrepares, prepare)
  7245. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7246. GoodId: good_id,
  7247. GoodTypeId: good_type_id,
  7248. Count: count,
  7249. ProjectId: project_id,
  7250. StorehouseId: houseConfig.StorehouseOutInfo,
  7251. NewCount: new_count,
  7252. OldCount: old_count,
  7253. }
  7254. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7255. }
  7256. }
  7257. }
  7258. //查询是否有库存
  7259. for _, item := range beforePrepares {
  7260. if item.NewCount > 0 {
  7261. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7262. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7263. if item.Count > warehouse.Count {
  7264. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7265. c.ServeSuccessJSON(map[string]interface{}{
  7266. "message": "1",
  7267. "good_name": goodObj.GoodName,
  7268. "specification_name": goodObj.SpecificationName,
  7269. })
  7270. return
  7271. }
  7272. }
  7273. }
  7274. // 查询信息规挡的设置天数
  7275. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7276. if infor.ID > 0 && infor.WeekDay > 0 {
  7277. var cha_time int64
  7278. timeNowStr := time.Now().Format("2006-01-02")
  7279. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7280. //今日的日期减去设置的日期
  7281. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7282. if cha_time >= record_time {
  7283. //查询审核是否允许
  7284. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7285. //申请状态不允许的情况 拒绝修改
  7286. if infor.ApplicationStatus != 1 {
  7287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7288. return
  7289. }
  7290. }
  7291. }
  7292. //出库逻辑
  7293. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7294. if err != nil {
  7295. utils.ErrorLog(err.Error())
  7296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7297. return
  7298. }
  7299. finish := models.XtDialysisFinish{
  7300. IsFinish: 1,
  7301. UserOrgId: adminInfo.Org.Id,
  7302. Status: 1,
  7303. Ctime: time.Now().Unix(),
  7304. Mtime: 0,
  7305. Module: 11,
  7306. RecordDate: record_time,
  7307. Sourse: 1,
  7308. PatientId: patient_id,
  7309. }
  7310. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7311. if dialysisFinish.ID == 0 {
  7312. service.CreateDialysisFinish(finish)
  7313. }
  7314. //查询当天出库的数据
  7315. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7316. for _, item := range list {
  7317. prepare := models.DialysisBeforePrepare{
  7318. UserOrgId: item.OrgId,
  7319. PatientId: item.PatientId,
  7320. RecordDate: item.RecordTime,
  7321. GoodId: item.GoodId,
  7322. GoodTypeId: item.GoodTypeId,
  7323. Count: item.Count,
  7324. Creater: adminInfo.AdminUser.Id,
  7325. Status: 1,
  7326. Ctime: time.Now().Unix(),
  7327. ProjectId: item.ProjectId,
  7328. StorehouseId: houseConfig.StorehouseOutInfo,
  7329. }
  7330. //清空准备表的数据
  7331. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7332. //插入准备表数据
  7333. service.CreateDialysisBeforePrepareOne(&prepare)
  7334. //查询默认仓库
  7335. //查询默认仓库
  7336. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7337. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7338. var total_count int64
  7339. for _, it := range stockList {
  7340. total_count += it.StockCount
  7341. }
  7342. //基础库插入数据
  7343. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7344. ////更新剩余库存
  7345. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7346. var flush_count int64
  7347. for _, it := range goodList {
  7348. flush_count += it.StockCount
  7349. }
  7350. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7351. if errs != nil {
  7352. goodErrcode := models.XtGoodErrcode{
  7353. UserOrgId: item.OrgId,
  7354. Errcode: "手动出库更新剩余出库失败",
  7355. GoodId: item.GoodId,
  7356. Status: 1,
  7357. Ctime: time.Now().Unix(),
  7358. Mtime: 0,
  7359. Count: 0,
  7360. StockCount: 0,
  7361. Creater: adminInfo.AdminUser.Id,
  7362. BatchNumberId: 0,
  7363. WarehouseOutId: 0,
  7364. }
  7365. service.CreateGoodErrcode(goodErrcode)
  7366. }
  7367. }
  7368. //更新自动出库的地方
  7369. var errs error
  7370. if errs == nil {
  7371. c.ServeSuccessJSON(map[string]interface{}{
  7372. "msg": "修改成功",
  7373. "message": "2",
  7374. "good_name": "",
  7375. "specification_name": "",
  7376. })
  7377. return
  7378. } else {
  7379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7380. return
  7381. }
  7382. }
  7383. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7384. newArr = make([]*models.DialysisBeforePrepare, 0)
  7385. for i := 0; i < len(arr); i++ {
  7386. repeat := false
  7387. for j := i + 1; j < len(arr); j++ {
  7388. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7389. repeat = true
  7390. break
  7391. }
  7392. }
  7393. if !repeat {
  7394. newArr = append(newArr, arr[i])
  7395. }
  7396. }
  7397. return
  7398. }
  7399. func (c *DialysisAPIController) GetAllDrug() {
  7400. patient_id, _ := c.GetInt64("patient_id", 0)
  7401. adminInfo := c.GetMobileAdminUserInfo()
  7402. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7403. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7404. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7405. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7406. c.ServeSuccessJSON(map[string]interface{}{
  7407. "base_drug_config": drugStockConfig,
  7408. "private_drug_config": privateDrugConfig,
  7409. "base_drug_list": drugList,
  7410. "private_drug_list": privateDrugList,
  7411. })
  7412. }
  7413. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7414. newArr = make([]*models.DialysisBeforePrepare, 0)
  7415. for i := 0; i < len(arr); i++ {
  7416. repeat := false
  7417. for j := i + 1; j < len(arr); j++ {
  7418. if arr[i].GoodId == arr[j].GoodId {
  7419. repeat = true
  7420. break
  7421. }
  7422. }
  7423. if !repeat {
  7424. newArr = append(newArr, arr[i])
  7425. }
  7426. }
  7427. return
  7428. }
  7429. func (c *DialysisAPIController) GetDepartment() {
  7430. adminInfo := c.GetMobileAdminUserInfo()
  7431. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7432. if err == nil {
  7433. c.ServeSuccessJSON(map[string]interface{}{
  7434. "departments": departments,
  7435. })
  7436. } else {
  7437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7438. return
  7439. }
  7440. }
  7441. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7442. types, _ := c.GetInt("type", 0)
  7443. start_time := c.GetString("start_time")
  7444. end_time := c.GetString("end_time")
  7445. orgId := c.GetMobileAdminUserInfo().Org.Id
  7446. timeLayout := "2006-01-02"
  7447. loc, _ := time.LoadLocation("Local")
  7448. var startTime int64
  7449. if len(start_time) > 0 {
  7450. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7451. if err != nil {
  7452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7453. return
  7454. }
  7455. startTime = theTime.Unix()
  7456. }
  7457. var endTime int64
  7458. if len(end_time) > 0 {
  7459. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7460. if err != nil {
  7461. utils.ErrorLog(err.Error())
  7462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7463. return
  7464. }
  7465. endTime = theTime.Unix()
  7466. }
  7467. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7468. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7469. if err != nil {
  7470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7471. } else {
  7472. c.ServeSuccessJSON(map[string]interface{}{
  7473. "list": list,
  7474. "type": types,
  7475. "stockTotal": stockTotal,
  7476. })
  7477. }
  7478. }
  7479. func (c *DialysisAPIController) GetPrescriptionList() {
  7480. start_time := c.GetString("start_time")
  7481. end_time := c.GetString("end_time")
  7482. schedule_type, _ := c.GetInt64("schedule_type")
  7483. partion_id, _ := c.GetInt64("partion_id")
  7484. orgId := c.GetMobileAdminUserInfo().Org.Id
  7485. timeLayout := "2006-01-02"
  7486. loc, _ := time.LoadLocation("Local")
  7487. var startTime int64
  7488. if len(start_time) > 0 {
  7489. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7490. if err != nil {
  7491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7492. return
  7493. }
  7494. startTime = theTime.Unix()
  7495. }
  7496. var endTime int64
  7497. if len(end_time) > 0 {
  7498. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7499. if err != nil {
  7500. utils.ErrorLog(err.Error())
  7501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7502. return
  7503. }
  7504. endTime = theTime.Unix()
  7505. }
  7506. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7507. fmt.Println("schedulelist22222222", schedulelist)
  7508. c.ServeSuccessJSON(map[string]interface{}{
  7509. "list": schedulelist,
  7510. })
  7511. return
  7512. }
  7513. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7514. ids := c.GetString("ids")
  7515. //patient_id, _ := c.GetInt64("patient_id")
  7516. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7517. idArray := strings.Split(ids, ",")
  7518. err := service.BatchDeleteMonitor(idArray)
  7519. fmt.Print("err", err)
  7520. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7521. //redis := service.RedisClient()
  7522. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7523. //redis.Set(key, "", time.Second)
  7524. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7525. //redis.Set(keyOne, "", time.Second)
  7526. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7527. //redis.Close()
  7528. c.ServeSuccessJSON(map[string]interface{}{
  7529. "msg": "批量删除成功",
  7530. })
  7531. return
  7532. }
  7533. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7534. id, _ := c.GetInt64("id")
  7535. timeLayout := "2006-01-02"
  7536. loc, _ := time.LoadLocation("Local")
  7537. //start_time := time.Now().Format("2006-01-02")
  7538. start_time := c.GetString("start_time")
  7539. end_time := c.GetString("end_time")
  7540. var startdateunix int64
  7541. if len(start_time) > 0 {
  7542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7543. if err != nil {
  7544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7545. return
  7546. }
  7547. startdateunix = theTime.Unix()
  7548. }
  7549. var enddateunix int64
  7550. if len(end_time) > 0 {
  7551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7552. if err != nil {
  7553. utils.ErrorLog(err.Error())
  7554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7555. return
  7556. }
  7557. enddateunix = theTime.Unix()
  7558. }
  7559. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7560. //nowTime := time.Now()
  7561. //endTime := nowTime.AddDate(-30, 0, 0)
  7562. //endTimes := endTime.Format("2006-01-02")
  7563. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7564. org_id := c.GetMobileAdminUserInfo().Org.Id
  7565. //if org_id == 10579 {
  7566. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7567. // c.ServeSuccessJSON(map[string]interface{}{
  7568. // "list": list,
  7569. // })
  7570. // return
  7571. //} else {
  7572. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7573. // c.ServeSuccessJSON(map[string]interface{}{
  7574. // "list": list,
  7575. // })
  7576. // return
  7577. //}
  7578. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7579. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7580. c.ServeSuccessJSON(map[string]interface{}{
  7581. "list": list,
  7582. })
  7583. return
  7584. } else {
  7585. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7586. c.ServeSuccessJSON(map[string]interface{}{
  7587. "list": list,
  7588. })
  7589. }
  7590. return
  7591. }
  7592. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7593. dataBody := make(map[string]interface{}, 0)
  7594. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7595. ids := c.GetString("ids")
  7596. idArray := strings.Split(ids, ",")
  7597. origin, _ := c.GetInt64("origin")
  7598. if origin == 1 {
  7599. err = service.BatchDeleteAdvice(idArray)
  7600. fmt.Print("err", err)
  7601. c.ServeSuccessJSON(map[string]interface{}{
  7602. "msg": "批量删除成功",
  7603. })
  7604. return
  7605. }
  7606. if origin == 2 {
  7607. service.BatchDeleteHisAdvice(idArray)
  7608. }
  7609. }
  7610. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7611. good_id, _ := c.GetInt64("good_id")
  7612. count, _ := c.GetInt64("count")
  7613. record_time, _ := c.GetInt64("record_time")
  7614. patient_id, _ := c.GetInt64("patient_id")
  7615. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7616. c.ServeSuccessJSON(map[string]interface{}{
  7617. "detail": detail,
  7618. })
  7619. return
  7620. }
  7621. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7622. good_id, _ := c.GetInt64("good_id")
  7623. record_time, _ := c.GetInt64("record_time")
  7624. patient_id, _ := c.GetInt64("patient_id")
  7625. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7626. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7627. fmt.Print("err", err)
  7628. c.ServeSuccessJSON(map[string]interface{}{
  7629. "msg": "批量删除成功",
  7630. })
  7631. return
  7632. }
  7633. func (c *DialysisAPIController) BatchAdviceCheck() {
  7634. ids := c.GetString("ids")
  7635. idArray := strings.Split(ids, ",")
  7636. creator, _ := c.GetInt64("creator")
  7637. origin, _ := c.GetInt64("origin")
  7638. if origin == 1 {
  7639. err := service.BatchAdviceCheck(idArray, creator)
  7640. fmt.Println(err)
  7641. list, _ := service.GetAdviceExecutionById(idArray)
  7642. c.ServeSuccessJSON(map[string]interface{}{
  7643. "list": list,
  7644. })
  7645. return
  7646. }
  7647. if origin == 2 {
  7648. service.BatchHisAdviceCheck(idArray, creator)
  7649. list, _ := service.GetHisAdviceExecutionById(idArray)
  7650. c.ServeSuccessJSON(map[string]interface{}{
  7651. "list": list,
  7652. })
  7653. return
  7654. }
  7655. }
  7656. func (c *DialysisAPIController) BatchAdviceExecution() {
  7657. ids := c.GetString("ids")
  7658. idArray := strings.Split(ids, ",")
  7659. executionTime := c.GetString("execution_time")
  7660. creator, _ := c.GetInt64("creator")
  7661. timeLayout := "2006-01-02 15:04:05"
  7662. loc, _ := time.LoadLocation("Local")
  7663. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7664. orgin, _ := c.GetInt64("origin")
  7665. if orgin == 1 {
  7666. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7667. list, _ := service.GetAdviceExecutionById(idArray)
  7668. fmt.Println(err)
  7669. c.ServeSuccessJSON(map[string]interface{}{
  7670. "list": list,
  7671. })
  7672. return
  7673. }
  7674. if orgin == 2 {
  7675. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7676. list, _ := service.GetHisAdviceExecutionById(idArray)
  7677. fmt.Println(err)
  7678. c.ServeSuccessJSON(map[string]interface{}{
  7679. "list": list,
  7680. })
  7681. return
  7682. }
  7683. }
  7684. func (c *DialysisAPIController) UpdateStockGoods() {
  7685. good_id, _ := c.GetInt64("good_id")
  7686. record_time, _ := c.GetInt64("record_time")
  7687. patient_id, _ := c.GetInt64("patient_id")
  7688. count, _ := c.GetInt64("count")
  7689. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7690. fmt.Print("err", err)
  7691. c.ServeSuccessJSON(map[string]interface{}{
  7692. "msg": "更新成功",
  7693. })
  7694. return
  7695. }
  7696. // 当前数据比上一次出库数据少
  7697. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7698. //查询该患者当天已经出库的耗材信息
  7699. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7700. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7701. for i := len(goods_yc) - 1; i >= 0; i-- {
  7702. goods_yc_temp := goods_yc[i]
  7703. for j := len(goods) - 1; j >= 0; j-- {
  7704. goods_temp := goods[j]
  7705. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7706. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7707. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7708. if goods_yc_temp.Count == goods_temp.Count {
  7709. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7710. goods = append(goods[:j], goods[j+1:]...)
  7711. break
  7712. }
  7713. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7714. if goods_yc_temp.Count > goods_temp.Count {
  7715. temp_count := goods_yc_temp.Count - goods_temp.Count
  7716. goods_yc[i].Count = temp_count
  7717. goods = append(goods[:j], goods[j+1:]...)
  7718. break
  7719. }
  7720. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7721. if goods_yc_temp.Count < goods_temp.Count {
  7722. temp_count := goods_temp.Count - goods_yc_temp.Count
  7723. goods[j].Count = temp_count
  7724. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7725. break
  7726. }
  7727. }
  7728. }
  7729. }
  7730. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7731. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7732. //退库
  7733. if len(goods_yc) > 0 {
  7734. for _, good_yc := range goods_yc {
  7735. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7736. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7737. }
  7738. }
  7739. return nil
  7740. }
  7741. // 耗材出库删除
  7742. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7743. // 先根据相关信息查询当天该耗材的出库信息
  7744. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7745. if err != nil {
  7746. return err
  7747. }
  7748. var delete_count int64 = 0
  7749. delete_count = warehouseOutInfos.Count - count
  7750. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7751. // 在出库记录表里记录退库详情
  7752. warehouseOutInfo := &models.WarehouseOutInfo{
  7753. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7754. WarehouseOutId: warehouseOut.ID,
  7755. Status: 1,
  7756. Ctime: time.Now().Unix(),
  7757. OrgId: orgID,
  7758. Type: 1,
  7759. IsSys: 1,
  7760. SysRecordTime: record_time,
  7761. GoodTypeId: good_yc.GoodTypeId,
  7762. GoodId: good_yc.GoodId,
  7763. PatientId: good_yc.PatientId,
  7764. ConsumableType: 2,
  7765. StorehouseId: houseConfig.StorehouseOutInfo,
  7766. IsCheck: 1,
  7767. }
  7768. warehouseOutInfo.Count = count
  7769. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7770. warehouseOutInfo.Price = stockInInfo.Price
  7771. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7772. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7773. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7774. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7775. warehouseOutInfo.Number = warehouseOutInfos.Number
  7776. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7777. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7778. //查找当天是否存在出库记录
  7779. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7780. if errcod == gorm.ErrRecordNotFound {
  7781. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7782. //插入详情明细表
  7783. stockFlow := models.VmStockFlow{
  7784. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7785. WarehouseOutId: warehouseOut.ID,
  7786. GoodId: good_yc.GoodId,
  7787. Number: warehouseOutInfos.Number,
  7788. ProductDate: stockInInfo.ProductDate,
  7789. ExpireDate: stockInInfo.ExpiryDate,
  7790. Count: count,
  7791. Price: stockInInfo.Price,
  7792. Status: 1,
  7793. Ctime: time.Now().Unix(),
  7794. UserOrgId: good_yc.OrgId,
  7795. Manufacturer: stockInInfo.Manufacturer,
  7796. Dealer: stockInInfo.Dealer,
  7797. LicenseNumber: stockInInfo.LicenseNumber,
  7798. IsEdit: 2,
  7799. Creator: creater,
  7800. SystemTime: record_time,
  7801. ConsumableType: 3,
  7802. WarehousingDetailId: 0,
  7803. IsSys: 1,
  7804. UpdateCreator: creater,
  7805. PatientId: patient_id,
  7806. StorehouseId: houseConfig.StorehouseOutInfo,
  7807. }
  7808. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7809. if errflow == gorm.ErrRecordNotFound {
  7810. //创建流水表
  7811. err := service.CreateStockFlowOne(stockFlow)
  7812. fmt.Println("err", err)
  7813. } else if errflow == nil {
  7814. //插入详情明细表
  7815. stockFlow := models.VmStockFlow{
  7816. ID: exsit.ID,
  7817. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7818. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7819. WarehouseOutId: warehouseOut.ID,
  7820. GoodId: good_yc.GoodId,
  7821. Number: warehouseOutInfos.Number,
  7822. ProductDate: stockInInfo.ProductDate,
  7823. ExpireDate: stockInInfo.ExpiryDate,
  7824. Count: exsit.Count - delete_count,
  7825. Price: stockInInfo.Price,
  7826. Status: 1,
  7827. Ctime: time.Now().Unix(),
  7828. UserOrgId: good_yc.OrgId,
  7829. Manufacturer: stockInInfo.Manufacturer,
  7830. Dealer: stockInInfo.Dealer,
  7831. LicenseNumber: stockInInfo.LicenseNumber,
  7832. IsEdit: 2,
  7833. Creator: creater,
  7834. SystemTime: record_time,
  7835. ConsumableType: 3,
  7836. WarehousingDetailId: 0,
  7837. IsSys: 1,
  7838. UpdateCreator: creater,
  7839. PatientId: patient_id,
  7840. StorehouseId: houseConfig.StorehouseOutInfo,
  7841. }
  7842. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7843. }
  7844. if errOne != nil {
  7845. return errOne
  7846. }
  7847. } else if errcod == nil {
  7848. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7849. //插入详情明细表
  7850. stockFlow := models.VmStockFlow{
  7851. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7852. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7853. WarehouseOutId: warehouseOut.ID,
  7854. GoodId: good_yc.GoodId,
  7855. Number: warehouseOutInfos.Number,
  7856. ProductDate: stockInInfo.ProductDate,
  7857. ExpireDate: stockInInfo.ExpiryDate,
  7858. Count: count,
  7859. Price: stockInInfo.Price,
  7860. Status: 1,
  7861. Ctime: time.Now().Unix(),
  7862. UserOrgId: good_yc.OrgId,
  7863. Manufacturer: stockInInfo.Manufacturer,
  7864. Dealer: stockInInfo.Dealer,
  7865. LicenseNumber: stockInInfo.LicenseNumber,
  7866. IsEdit: 2,
  7867. Creator: creater,
  7868. SystemTime: record_time,
  7869. ConsumableType: 3,
  7870. WarehousingDetailId: 0,
  7871. IsSys: 1,
  7872. UpdateCreator: creater,
  7873. PatientId: patient_id,
  7874. ReturnCount: delete_count,
  7875. StorehouseId: houseConfig.StorehouseOutInfo,
  7876. }
  7877. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7878. if errflows == gorm.ErrRecordNotFound {
  7879. //创建流水表
  7880. service.CreateStockFlowOne(stockFlow)
  7881. } else if errflows == nil {
  7882. stockFlow := models.VmStockFlow{
  7883. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7884. ID: exsit.ID,
  7885. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7886. WarehouseOutId: warehouseOut.ID,
  7887. GoodId: good_yc.GoodId,
  7888. Number: warehouseOutInfos.Number,
  7889. ProductDate: stockInInfo.ProductDate,
  7890. ExpireDate: stockInInfo.ExpiryDate,
  7891. Count: exsit.Count - delete_count,
  7892. Price: stockInInfo.Price,
  7893. Status: 1,
  7894. Ctime: time.Now().Unix(),
  7895. UserOrgId: good_yc.OrgId,
  7896. Manufacturer: stockInInfo.Manufacturer,
  7897. Dealer: stockInInfo.Dealer,
  7898. LicenseNumber: stockInInfo.LicenseNumber,
  7899. IsEdit: 2,
  7900. Creator: creater,
  7901. SystemTime: record_time,
  7902. ConsumableType: 3,
  7903. WarehousingDetailId: 0,
  7904. IsSys: 1,
  7905. UpdateCreator: creater,
  7906. PatientId: patient_id,
  7907. ReturnCount: delete_count,
  7908. StorehouseId: houseConfig.StorehouseOutInfo,
  7909. }
  7910. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7911. }
  7912. }
  7913. //更改自动出库的表格
  7914. details := models.BloodAutomaticReduceDetail{
  7915. WarehouseOutId: warehouseOutInfo.ID,
  7916. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7917. PatientId: patient_id,
  7918. Ctime: time.Now().Unix(),
  7919. Mtime: time.Now().Unix(),
  7920. Status: 1,
  7921. RecordTime: record_time,
  7922. OrgId: orgID,
  7923. GoodId: good_yc.GoodId,
  7924. GoodTypeId: good_yc.GoodTypeId,
  7925. Count: count,
  7926. StorehouseId: houseConfig.StorehouseOutInfo,
  7927. }
  7928. //查询当天耗材是否已经存在数据
  7929. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7930. if errcode == gorm.ErrRecordNotFound {
  7931. errTwo := service.CreateAutoReduceRecord(&details)
  7932. if errTwo != nil {
  7933. return errTwo
  7934. }
  7935. } else if errcode == nil {
  7936. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7937. service.CreateAutoReduceRecord(&details)
  7938. }
  7939. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7940. //增加出库库存数量
  7941. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7942. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7943. fmt.Println("errOne", errOne)
  7944. // 删除出库完成后,要增加对应批次的库存数量
  7945. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7946. if errThree != nil {
  7947. return errThree
  7948. }
  7949. if good_yc.Count == 0 {
  7950. return nil
  7951. } else {
  7952. return errors.New("退库和出库数据不匹配")
  7953. }
  7954. }
  7955. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7956. //查询该患者当天已经出库的耗材信息
  7957. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7958. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7959. for i := len(goods_yc) - 1; i >= 0; i-- {
  7960. goods_yc_temp := goods_yc[i]
  7961. for j := len(goods) - 1; j >= 0; j-- {
  7962. goods_temp := goods[j]
  7963. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7964. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7965. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7966. if goods_yc_temp.Count == goods_temp.Count {
  7967. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7968. goods = append(goods[:j], goods[j+1:]...)
  7969. break
  7970. }
  7971. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7972. if goods_yc_temp.Count > goods_temp.Count {
  7973. temp_count := goods_yc_temp.Count - goods_temp.Count
  7974. goods_yc[i].Count = temp_count
  7975. goods = append(goods[:j], goods[j+1:]...)
  7976. break
  7977. }
  7978. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7979. if goods_yc_temp.Count < goods_temp.Count {
  7980. temp_count := goods_temp.Count - goods_yc_temp.Count
  7981. goods[j].Count = temp_count
  7982. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7983. break
  7984. }
  7985. }
  7986. }
  7987. }
  7988. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7989. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7990. fmt.Println("剩余需要出库的", len(goods))
  7991. if len(goods) > 0 {
  7992. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7993. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7994. if err == gorm.ErrRecordNotFound {
  7995. //没有记录,则创建出库单
  7996. timeStr := time.Now().Format("2006-01-02")
  7997. timeArr := strings.Split(timeStr, "-")
  7998. total, _ := service.FindAllWarehouseOut(orgID)
  7999. total = total + 1
  8000. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8001. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8002. number = number + total
  8003. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8004. warehouseOut := models.WarehouseOut{
  8005. WarehouseOutOrderNumber: warehousing_out_order,
  8006. OperationTime: time.Now().Unix(),
  8007. OrgId: orgID,
  8008. Creater: creater,
  8009. Ctime: time.Now().Unix(),
  8010. Status: 1,
  8011. WarehouseOutTime: record_time,
  8012. Dealer: 0,
  8013. Manufacturer: 0,
  8014. Type: 1,
  8015. IsSys: 1,
  8016. StorehouseId: houseConfig.StorehouseOutInfo,
  8017. IsCheck: 1,
  8018. }
  8019. err := service.AddSigleWarehouseOut(&warehouseOut)
  8020. if err != nil {
  8021. utils.TraceLog("创建出库单失败 err = %v", err)
  8022. return err
  8023. } else {
  8024. out = warehouseOut
  8025. }
  8026. }
  8027. for _, item := range goods {
  8028. var newCount int64 = 0
  8029. for _, it := range goodOne {
  8030. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8031. newCount = it.Count
  8032. }
  8033. }
  8034. prepare := models.DialysisBeforePrepare{
  8035. GoodTypeId: item.GoodTypeId,
  8036. GoodId: item.GoodId,
  8037. Count: item.Count,
  8038. StorehouseId: houseConfig.StorehouseOutInfo,
  8039. }
  8040. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8041. //增加出库数量
  8042. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8043. }
  8044. }
  8045. if len(goods_yc) > 0 {
  8046. for _, good_yc := range goods_yc {
  8047. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8048. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8049. }
  8050. }
  8051. return nil
  8052. }
  8053. // 耗材出库删除
  8054. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8055. // 先根据相关信息查询当天该耗材的出库信息
  8056. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8057. if err != nil {
  8058. return err
  8059. }
  8060. var delete_count int64 = 0
  8061. for _, ware := range warehouseOutInfos {
  8062. // 判断当前出库的数据和删除出库数量
  8063. if good_yc.Count <= ware.Count {
  8064. delete_count = good_yc.Count
  8065. } else {
  8066. delete_count = ware.Count
  8067. }
  8068. warehouseOutInfo := &models.WarehouseOutInfo{
  8069. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8070. WarehouseOutId: warehouseOut.ID,
  8071. Status: 1,
  8072. Ctime: time.Now().Unix(),
  8073. Remark: "",
  8074. OrgId: orgID,
  8075. Type: 1,
  8076. Manufacturer: 0,
  8077. Dealer: 0,
  8078. IsSys: 0,
  8079. SysRecordTime: record_time,
  8080. GoodTypeId: good_yc.GoodTypeId,
  8081. GoodId: good_yc.GoodId,
  8082. StorehouseId: warehouseOut.StorehouseId,
  8083. IsCheck: 1,
  8084. }
  8085. warehouseOutInfo.Count = delete_count
  8086. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8087. warehouseOutInfo.Price = stockInInfo.Price
  8088. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8089. if errOne != nil {
  8090. return errOne
  8091. }
  8092. // 删除出库完成后,要改变流水库存(有疑问)
  8093. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8094. fmt.Println("errOne", errOne)
  8095. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8096. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8097. //扣减出库数量
  8098. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8099. if errThree != nil {
  8100. return errThree
  8101. }
  8102. }
  8103. if good_yc.Count == 0 {
  8104. return nil
  8105. } else {
  8106. return errors.New("退库和出库数据不匹配")
  8107. }
  8108. }
  8109. func (this *DialysisAPIController) GetMobileScheduleList() {
  8110. limit, _ := this.GetInt64("limit")
  8111. page, _ := this.GetInt64("page")
  8112. type_options_visible, _ := this.GetInt64("type_options_visible")
  8113. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8114. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8115. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8116. }
  8117. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8118. newArr = make([]*models.HisPrescriptionProject, 0)
  8119. for i := 0; i < len(arr); i++ {
  8120. repeat := false
  8121. for j := i + 1; j < len(arr); j++ {
  8122. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8123. repeat = true
  8124. break
  8125. }
  8126. }
  8127. if !repeat {
  8128. newArr = append(newArr, arr[i])
  8129. }
  8130. }
  8131. return
  8132. }
  8133. func (this *DialysisAPIController) GetRoleList() {
  8134. admin_user_id, _ := this.GetInt64("admin_user_id")
  8135. orgid := this.GetMobileAdminUserInfo().Org.Id
  8136. list, err := service.GetRoleList(orgid, admin_user_id)
  8137. fmt.Println(err)
  8138. this.ServeSuccessJSON(map[string]interface{}{
  8139. "list": list,
  8140. })
  8141. return
  8142. }
  8143. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8144. // 先根据相关信息查询当天该耗材的出库信息
  8145. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8146. if err != nil {
  8147. return err
  8148. }
  8149. var delete_count int64 = 0
  8150. delete_count = warehouseOutInfos.Count - count
  8151. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8152. // 删除出库完成后,要增加对应批次的库存数量
  8153. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8154. if errThree != nil {
  8155. return errThree
  8156. }
  8157. //增加退库数量
  8158. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8159. //扣减出库数量
  8160. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8161. //查询剩余库存
  8162. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8163. var sum_count int64
  8164. for _, item := range goodList {
  8165. sum_count += item.StockCount
  8166. }
  8167. // 在出库记录表里记录退库详情
  8168. warehouseOutInfo := &models.WarehouseOutInfo{
  8169. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8170. WarehouseOutId: warehouseOut.ID,
  8171. Status: 1,
  8172. Ctime: time.Now().Unix(),
  8173. OrgId: orgID,
  8174. Type: 1,
  8175. IsSys: 1,
  8176. SysRecordTime: record_time,
  8177. GoodTypeId: good_yc.GoodTypeId,
  8178. GoodId: good_yc.GoodId,
  8179. PatientId: good_yc.PatientId,
  8180. ConsumableType: 2,
  8181. StorehouseId: houseConfig.StorehouseOutInfo,
  8182. IsCheck: 1,
  8183. OverCount: sum_count,
  8184. }
  8185. warehouseOutInfo.Count = count
  8186. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8187. warehouseOutInfo.Price = stockInInfo.Price
  8188. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8189. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8190. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8191. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8192. warehouseOutInfo.Number = warehouseOutInfos.Number
  8193. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8194. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8195. //查找当天是否存在出库记录
  8196. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8197. if errcod == gorm.ErrRecordNotFound {
  8198. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8199. //插入详情明细表
  8200. if errOne != nil {
  8201. return errOne
  8202. }
  8203. //插入详情明细表
  8204. stockFlow := models.VmStockFlow{
  8205. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8206. WarehouseOutId: warehouseOut.ID,
  8207. GoodId: good_yc.GoodId,
  8208. Number: warehouseOutInfos.Number,
  8209. ProductDate: stockInInfo.ProductDate,
  8210. ExpireDate: stockInInfo.ExpiryDate,
  8211. Count: count,
  8212. Price: stockInInfo.Price,
  8213. Status: 1,
  8214. Ctime: record_time,
  8215. UserOrgId: good_yc.OrgId,
  8216. Manufacturer: stockInInfo.Manufacturer,
  8217. Dealer: stockInInfo.Dealer,
  8218. LicenseNumber: stockInInfo.LicenseNumber,
  8219. IsEdit: 2,
  8220. Creator: creater,
  8221. SystemTime: record_time,
  8222. ConsumableType: 3,
  8223. WarehousingDetailId: 0,
  8224. IsSys: 1,
  8225. UpdateCreator: creater,
  8226. PatientId: patient_id,
  8227. StorehouseId: houseConfig.StorehouseOutInfo,
  8228. OverCount: sum_count,
  8229. ProjectId: good_yc.ProjectId,
  8230. }
  8231. err := service.CreateStockFlowOne(stockFlow)
  8232. fmt.Println("err", err)
  8233. } else if errcod == nil {
  8234. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8235. }
  8236. //创建退库单
  8237. operation_time := time.Now().Unix()
  8238. //创建退库单
  8239. timeStr := time.Now().Format("2006-01-02")
  8240. timeArr := strings.Split(timeStr, "-")
  8241. total, _ := service.FindAllCancelStockTotal(orgID)
  8242. total = total + 1
  8243. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8244. cancelStock := models.CancelStock{
  8245. OrderNumber: orderNumber,
  8246. OperaTime: operation_time,
  8247. OrgId: orgID,
  8248. Creater: warehouseOut.Creater,
  8249. Ctime: time.Now().Unix(),
  8250. Status: 1,
  8251. ReturnTime: record_time,
  8252. Type: 1,
  8253. StorehouseId: stockInInfo.StorehouseId,
  8254. IsCheck: 1,
  8255. }
  8256. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8257. if msgerrkonde == gorm.ErrRecordNotFound {
  8258. service.AddSigleCancelStock(&cancelStock)
  8259. }
  8260. cancel, _ := service.GetLastCancelStockById(orgID)
  8261. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8262. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8263. cancelStockInfo := models.CancelStockInfo{
  8264. GoodId: stockInInfo.GoodId,
  8265. CancelStockId: cancel.ID,
  8266. GoodTypeId: stockInInfo.GoodTypeId,
  8267. Count: delete_count,
  8268. Price: stockInInfo.PackingPrice,
  8269. Total: 0,
  8270. ProductDate: stockInInfo.ProductDate,
  8271. ExpiryDate: stockInInfo.ExpiryDate,
  8272. Ctime: record_time,
  8273. Status: 1,
  8274. OrgId: orgID,
  8275. OrderNumber: cancel.OrderNumber,
  8276. Type: 0,
  8277. Dealer: deaerler.DealerName,
  8278. Manufacturer: manufacturer.ManufacturerName,
  8279. Number: stockInInfo.Number,
  8280. RegisterAccount: "",
  8281. Remark: "",
  8282. WarehouseInfoId: stockInInfo.ID,
  8283. PatientId: patient_id,
  8284. RecordDate: record_time,
  8285. StorehouseId: stockInInfo.StorehouseId,
  8286. IsCheck: 1,
  8287. }
  8288. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8289. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8290. flow := models.VmStockFlow{
  8291. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8292. GoodId: good_yc.GoodId,
  8293. Number: warehouseOutInfos.Number,
  8294. LicenseNumber: stockInInfo.LicenseNumber,
  8295. Count: delete_count,
  8296. UserOrgId: orgID,
  8297. PatientId: patient_id,
  8298. SystemTime: record_time,
  8299. ConsumableType: 7,
  8300. IsSys: 0,
  8301. WarehousingOrder: "",
  8302. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8303. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8304. IsEdit: 0,
  8305. CancelStockId: cancel.ID,
  8306. CancelOrderNumber: cancel.OrderNumber,
  8307. Manufacturer: manufacturer.ID,
  8308. Dealer: 0,
  8309. Creator: warehouseOut.Creater,
  8310. UpdateCreator: 0,
  8311. Status: 1,
  8312. Ctime: record_time,
  8313. Mtime: 0,
  8314. Price: stockInInfo.Price,
  8315. WarehousingDetailId: stockInInfo.ID,
  8316. WarehouseOutDetailId: warehouseOutInfos.ID,
  8317. CancelOutDetailId: cancelInfo.ID,
  8318. ProductDate: stockInInfo.ProductDate,
  8319. ExpireDate: stockInInfo.ExpiryDate,
  8320. StorehouseId: houseConfig.StorehouseOutInfo,
  8321. OverCount: sum_count,
  8322. }
  8323. service.CreateStockFlowOne(flow)
  8324. //更改自动出库的表格
  8325. details := models.BloodAutomaticReduceDetail{
  8326. WarehouseOutId: warehouseOutInfo.ID,
  8327. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8328. PatientId: patient_id,
  8329. Ctime: time.Now().Unix(),
  8330. Mtime: time.Now().Unix(),
  8331. Status: 1,
  8332. RecordTime: record_time,
  8333. OrgId: orgID,
  8334. GoodId: good_yc.GoodId,
  8335. GoodTypeId: good_yc.GoodTypeId,
  8336. Count: count,
  8337. StorehouseId: houseConfig.StorehouseOutInfo,
  8338. }
  8339. //查询当天耗材是否已经存在数据
  8340. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8341. if errcode == gorm.ErrRecordNotFound {
  8342. errTwo := service.CreateAutoReduceRecord(&details)
  8343. if errTwo != nil {
  8344. return errTwo
  8345. }
  8346. } else if errcode == nil {
  8347. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8348. service.CreateAutoReduceRecord(&details)
  8349. }
  8350. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8351. //增加出库库存数量
  8352. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8353. if good_yc.Count == 0 {
  8354. return nil
  8355. } else {
  8356. return errors.New("退库和出库数据不匹配")
  8357. }
  8358. }
  8359. func (this *DialysisAPIController) SavePatientSign() {
  8360. adminUserInfo := this.GetMobileAdminUserInfo()
  8361. patient_id, _ := this.GetInt64("patient_id")
  8362. dialysis_date, _ := this.GetInt64("dialysis_date")
  8363. orgid := adminUserInfo.Org.Id
  8364. var esdata models.DialysisOrder
  8365. var err error
  8366. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8367. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8368. return
  8369. }
  8370. esdata.Hash = esdata.Hash
  8371. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8372. order := models.DialysisOrder{
  8373. Hash: esdata.Hash,
  8374. Url: esdata.Url,
  8375. }
  8376. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8377. redis := service.RedisClient()
  8378. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8379. redis.Set(key, "", time.Second)
  8380. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8381. //清空key 值
  8382. redis.Set(keyOne, "", time.Second)
  8383. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8384. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8385. //redis.Set(keyTwo, "", time.Second)
  8386. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8387. redis.Set(keyThree, "", time.Second)
  8388. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8389. redis.Set(keyFour, "", time.Second)
  8390. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8391. redis.Set(keyFive, "", time.Second)
  8392. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8393. redis.Set(keySix, "", time.Second)
  8394. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8395. redis.Set(keySeven, "", time.Second)
  8396. if err != nil {
  8397. fmt.Println(err)
  8398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8399. return
  8400. }
  8401. this.ServeSuccessJSON(map[string]interface{}{
  8402. "electronic_signature": esdata,
  8403. })
  8404. }
  8405. func (this *DialysisAPIController) GetPatientSign() {
  8406. patient_id, _ := this.GetInt64("patient_id")
  8407. dialysis_date, _ := this.GetInt64("dialysis_date")
  8408. adminUserInfo := this.GetMobileAdminUserInfo()
  8409. orgId := adminUserInfo.Org.Id
  8410. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8411. if err != nil {
  8412. fmt.Println(err)
  8413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8414. return
  8415. }
  8416. this.ServeSuccessJSON(map[string]interface{}{
  8417. "dialysisOrder": dialysisOrder,
  8418. })
  8419. }
  8420. func (this *DialysisAPIController) GetScheduleByPatient() {
  8421. patient_id, _ := this.GetInt64("patient_id")
  8422. schedule_date, _ := this.GetInt64("schedule_date")
  8423. orgid := this.GetMobileAdminUserInfo().Org.Id
  8424. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8425. this.ServeSuccessJSON(map[string]interface{}{
  8426. "schedule": schedule,
  8427. })
  8428. }
  8429. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8430. org_id := this.GetMobileAdminUserInfo().Org.Id
  8431. patient_id, _ := this.GetInt64("patient_id")
  8432. schedule_date, _ := this.GetInt64("schedule_date")
  8433. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8434. this.ServeSuccessJSON(map[string]interface{}{
  8435. "order": order,
  8436. })
  8437. }
  8438. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8439. org_id := this.GetMobileAdminUserInfo().Org.Id
  8440. schedule_date := this.GetString("schedule_date")
  8441. schedule_type, _ := this.GetInt64("schedule_type")
  8442. timeLayout := "2006-01-02"
  8443. loc, _ := time.LoadLocation("Local")
  8444. var startdateunix int64
  8445. if len(schedule_date) > 0 {
  8446. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8447. if err != nil {
  8448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8449. return
  8450. }
  8451. startdateunix = theTime.Unix()
  8452. }
  8453. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8454. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8455. devices, _ := service.GetAllDevicetByListSix(org_id)
  8456. for key, item := range scheduals {
  8457. // 床位信息
  8458. for _, device := range devices {
  8459. if item.BedId == device.ID {
  8460. scheduals[key].DeviceNumber = device
  8461. break
  8462. }
  8463. }
  8464. }
  8465. this.ServeSuccessJSON(map[string]interface{}{
  8466. "list": list,
  8467. "scheduals": scheduals,
  8468. })
  8469. }
  8470. func (this *DialysisAPIController) SavePatientPicture() {
  8471. patient_id, _ := this.GetInt64("patient_id")
  8472. dialysis_date, _ := this.GetInt64("schedule_date")
  8473. avatar := this.GetString("avatar")
  8474. fmt.Println("patient_id", patient_id)
  8475. orgId := this.GetMobileAdminUserInfo().Org.Id
  8476. order := models.DialysisOrder{
  8477. Url: avatar,
  8478. }
  8479. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8480. redis := service.RedisClient()
  8481. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8482. redis.Set(key, "", time.Second)
  8483. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8484. //清空key 值
  8485. redis.Set(keyOne, "", time.Second)
  8486. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8487. redis.Set(keyThree, "", time.Second)
  8488. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8489. redis.Set(keyFour, "", time.Second)
  8490. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8491. redis.Set(keyFive, "", time.Second)
  8492. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8493. redis.Set(keySix, "", time.Second)
  8494. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8495. redis.Set(keySeven, "", time.Second)
  8496. if err != nil {
  8497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8498. return
  8499. }
  8500. this.ServeSuccessJSON(map[string]interface{}{
  8501. "order": order,
  8502. })
  8503. }
  8504. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8505. ids := this.GetString("ids")
  8506. idSplit := strings.Split(ids, ",")
  8507. orgId := this.GetMobileAdminUserInfo().Org.Id
  8508. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8509. execution_time := this.GetString("exce_time")
  8510. timeLayout2 := "2006-01-02 15:04:05"
  8511. loc, _ := time.LoadLocation("Local")
  8512. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8513. if errs != nil {
  8514. utils.ErrorLog(errs.Error())
  8515. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8516. return
  8517. }
  8518. //his客户
  8519. if config.IsOpen == 1 {
  8520. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8521. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8522. for _, item := range list {
  8523. for _, it := range adviceList {
  8524. if item.DrugId == it.DrugId {
  8525. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8526. }
  8527. }
  8528. }
  8529. for _, item := range list {
  8530. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8531. var sum_out_count int64
  8532. for _, itemThree := range item.ChildDoctorAdvice {
  8533. var prescribing_number int64
  8534. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8535. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8536. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8537. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8538. }
  8539. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8540. prescribing_number = parseIntPrescribingNumber
  8541. }
  8542. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8543. prescribing_number = parseIntPrescribingNumber
  8544. }
  8545. sum_out_count += prescribing_number
  8546. }
  8547. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8548. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8549. //库存不足
  8550. if sum_out_count > drugStockOut.FlushCount {
  8551. this.ServeSuccessJSON(map[string]interface{}{
  8552. "msg": "2",
  8553. "drug": medical,
  8554. "ids": ids,
  8555. })
  8556. return
  8557. }
  8558. }
  8559. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8560. //执行医嘱
  8561. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8562. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8563. for _, item := range advices {
  8564. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8565. redis := service.RedisClient()
  8566. //清空key 值
  8567. redis.Set(key, "", time.Second)
  8568. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8569. redis.Set(keyTwo, "", time.Second)
  8570. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8571. redis.Set(keyThree, "", time.Second)
  8572. recordDate := theTime.Format("2006-01-02")
  8573. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8574. redis.Set(keyFour, "", time.Second)
  8575. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8576. redis.Set(keyFive, "", time.Second)
  8577. defer redis.Close()
  8578. }
  8579. if errs == nil {
  8580. //药品管理信息
  8581. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8582. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8583. if drugStockConfig.IsOpen == 1 {
  8584. for _, item := range advices {
  8585. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8586. config, _ := service.GetDrugOpenConfigOne(orgId)
  8587. if config.IsOpen != 1 {
  8588. //查询该药品是否有库存
  8589. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8590. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8591. if medical.IsUse == 2 {
  8592. if config.IsOpen != 1 {
  8593. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8594. service.HisDrugsDelivery(orgId, creater, &advice)
  8595. if orgId == 3877 || orgId == 10265 {
  8596. //查询该药品是否有出库记录
  8597. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8598. if len(flowMap) == 0 {
  8599. errs := service.UpdateHisAdviceById(advice.ID)
  8600. if errs != nil {
  8601. drugError := models.XtDrugError{
  8602. UserOrgId: orgId,
  8603. DrugId: item.DrugId,
  8604. RecordDate: item.AdviceDate,
  8605. PatientId: item.PatientId,
  8606. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8607. Status: 1,
  8608. Ctime: time.Now().Unix(),
  8609. Mtime: 0,
  8610. SumCount: 0,
  8611. Prescribingnumber: advice.PrescribingNumber,
  8612. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8613. }
  8614. service.CreateDrugError(drugError)
  8615. }
  8616. this.ServeSuccessJSON(map[string]interface{}{
  8617. "msg": "2",
  8618. "drug": medical,
  8619. "ids": ids,
  8620. })
  8621. return
  8622. }
  8623. }
  8624. }
  8625. if pharmacyConfig.IsOpen != 1 {
  8626. service.HisDrugsDelivery(orgId, creater, &advice)
  8627. if orgId == 3877 || orgId == 10265 {
  8628. //查询该药品是否有出库记录
  8629. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8630. if len(flowMap) == 0 {
  8631. errs := service.UpdateHisAdviceById(advice.ID)
  8632. if errs != nil {
  8633. drugError := models.XtDrugError{
  8634. UserOrgId: orgId,
  8635. DrugId: item.DrugId,
  8636. RecordDate: item.AdviceDate,
  8637. PatientId: item.PatientId,
  8638. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8639. Status: 1,
  8640. Ctime: time.Now().Unix(),
  8641. Mtime: 0,
  8642. SumCount: 0,
  8643. Prescribingnumber: advice.PrescribingNumber,
  8644. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8645. }
  8646. service.CreateDrugError(drugError)
  8647. }
  8648. this.ServeSuccessJSON(map[string]interface{}{
  8649. "msg": "2",
  8650. "drug": medical,
  8651. "ids": ids,
  8652. })
  8653. return
  8654. }
  8655. }
  8656. }
  8657. //更新字典里面的库存
  8658. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8659. var sum_count int64
  8660. for _, its := range stockInfo {
  8661. if its.MaxUnit == medical.MaxUnit {
  8662. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8663. }
  8664. sum_count += its.StockMaxNumber + its.StockMinNumber
  8665. }
  8666. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8667. //剩余库存
  8668. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8669. }
  8670. }
  8671. }
  8672. }
  8673. }
  8674. this.ServeSuccessJSON(map[string]interface{}{
  8675. "msg": "1",
  8676. "ids": ids,
  8677. })
  8678. return
  8679. } else {
  8680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8681. }
  8682. }
  8683. //血透客户
  8684. if config.IsOpen == 2 || config.IsOpen == 0 {
  8685. //药品管理信息
  8686. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8687. if drugStockConfig.IsOpen == 1 {
  8688. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8689. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8690. for _, item := range list {
  8691. for _, it := range adviceList {
  8692. if item.DrugId == it.DrugId {
  8693. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8694. }
  8695. }
  8696. }
  8697. for _, item := range list {
  8698. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8699. var sum_out_count int64
  8700. for _, itemThree := range item.ChildDoctorAdvice {
  8701. var prescribing_number int64
  8702. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8703. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8704. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8705. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8706. }
  8707. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8708. prescribing_number = parseIntPrescribingNumber
  8709. }
  8710. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8711. prescribing_number = parseIntPrescribingNumber
  8712. }
  8713. sum_out_count += prescribing_number
  8714. }
  8715. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8716. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8717. //库存不足
  8718. if sum_out_count > drugStockOut.FlushCount {
  8719. this.ServeSuccessJSON(map[string]interface{}{
  8720. "msg": "2",
  8721. "drug": medical,
  8722. "ids": ids,
  8723. })
  8724. return
  8725. }
  8726. }
  8727. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8728. //执行医嘱
  8729. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8730. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8731. for _, item := range advices {
  8732. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8733. redis := service.RedisClient()
  8734. //清空key 值
  8735. redis.Set(key, "", time.Second)
  8736. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8737. redis.Set(keyTwo, "", time.Second)
  8738. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8739. redis.Set(keyThree, "", time.Second)
  8740. recordDate := theTime.Format("2006-01-02")
  8741. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8742. redis.Set(keyFour, "", time.Second)
  8743. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8744. redis.Set(keyFive, "", time.Second)
  8745. defer redis.Close()
  8746. }
  8747. if errs == nil {
  8748. for _, item := range advices {
  8749. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8750. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8751. //查询是否出库按钮开启
  8752. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8753. if adviceSetting.IsAdviceOpen == 1 {
  8754. //查询是否出库按钮开启
  8755. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8756. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8757. if prescriptionConfig.IsOpen == 1 {
  8758. if medical.IsUse == 2 {
  8759. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8760. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8761. }
  8762. if pharmacyConfig.IsOpen != 1 {
  8763. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8764. }
  8765. //更新字典里面的库存
  8766. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8767. var sum_count int64
  8768. for _, its := range stockInfo {
  8769. if its.MaxUnit == medical.MaxUnit {
  8770. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8771. }
  8772. sum_count += its.StockMaxNumber + its.StockMinNumber
  8773. }
  8774. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8775. //剩余库存
  8776. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8777. }
  8778. }
  8779. } else {
  8780. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8781. if medical.IsUse == 2 {
  8782. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8783. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8784. }
  8785. if pharmacyConfig.IsOpen != 1 {
  8786. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8787. }
  8788. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8789. var sum_count int64
  8790. for _, its := range stockInfo {
  8791. if its.MaxUnit == medical.MaxUnit {
  8792. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8793. }
  8794. sum_count += its.StockMaxNumber + its.StockMinNumber
  8795. }
  8796. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8797. //剩余库存
  8798. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8799. }
  8800. }
  8801. }
  8802. }
  8803. this.ServeSuccessJSON(map[string]interface{}{
  8804. "msg": "1",
  8805. "ids": ids,
  8806. })
  8807. return
  8808. } else {
  8809. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8810. //执行医嘱
  8811. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8812. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8813. for _, item := range advices {
  8814. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8815. redis := service.RedisClient()
  8816. //清空key 值
  8817. redis.Set(key, "", time.Second)
  8818. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8819. redis.Set(keyTwo, "", time.Second)
  8820. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8821. redis.Set(keyThree, "", time.Second)
  8822. recordDate := theTime.Format("2006-01-02")
  8823. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8824. redis.Set(keyFour, "", time.Second)
  8825. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8826. redis.Set(keyFive, "", time.Second)
  8827. defer redis.Close()
  8828. }
  8829. this.ServeSuccessJSON(map[string]interface{}{
  8830. "msg": "1",
  8831. "ids": ids,
  8832. })
  8833. return
  8834. }
  8835. }
  8836. }
  8837. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8838. ids := this.GetString("ids")
  8839. idSplit := strings.Split(ids, ",")
  8840. orgId := this.GetMobileAdminUserInfo().Org.Id
  8841. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8842. if config.IsOpen == 1 {
  8843. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8844. this.ServeSuccessJSON(map[string]interface{}{
  8845. "msg": "1",
  8846. "ids": ids,
  8847. })
  8848. return
  8849. }
  8850. if config.IsOpen == 0 || config.IsOpen == 2 {
  8851. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8852. this.ServeSuccessJSON(map[string]interface{}{
  8853. "msg": "1",
  8854. "ids": ids,
  8855. })
  8856. return
  8857. }
  8858. }
  8859. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8860. ids := this.GetString("ids")
  8861. idSplit := strings.Split(ids, ",")
  8862. orgId := this.GetMobileAdminUserInfo().Org.Id
  8863. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8864. //his
  8865. if config.IsOpen == 1 {
  8866. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8867. theTime := time.Now()
  8868. advices := models.HisDoctorAdviceThirty{
  8869. CheckTime: theTime.Unix(),
  8870. Checker: checker,
  8871. UpdatedTime: time.Now().Unix(),
  8872. }
  8873. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8874. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8875. for _, item := range list {
  8876. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8877. redis := service.RedisClient()
  8878. //清空key 值
  8879. redis.Set(key, "", time.Second)
  8880. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8881. redis.Set(keyTwo, "", time.Second)
  8882. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8883. redis.Set(keyThree, "", time.Second)
  8884. recordDate := theTime.Format("2006-01-02")
  8885. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8886. redis.Set(keyFour, "", time.Second)
  8887. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8888. redis.Set(keyFive, "", time.Second)
  8889. defer redis.Close()
  8890. }
  8891. this.ServeSuccessJSON(map[string]interface{}{
  8892. "msg": "1",
  8893. "ids": ids,
  8894. })
  8895. return
  8896. }
  8897. //血透
  8898. if config.IsOpen == 0 || config.IsOpen == 2 {
  8899. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8900. theTime := time.Now()
  8901. advices := models.DoctorAdvice{
  8902. CheckTime: theTime.Unix(),
  8903. Checker: checker,
  8904. UpdatedTime: time.Now().Unix(),
  8905. }
  8906. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8907. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8908. for _, item := range list {
  8909. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8910. redis := service.RedisClient()
  8911. //清空key 值
  8912. redis.Set(key, "", time.Second)
  8913. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8914. redis.Set(keyTwo, "", time.Second)
  8915. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8916. redis.Set(keyThree, "", time.Second)
  8917. recordDate := theTime.Format("2006-01-02")
  8918. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8919. redis.Set(keyFour, "", time.Second)
  8920. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8921. redis.Set(keyFive, "", time.Second)
  8922. defer redis.Close()
  8923. }
  8924. this.ServeSuccessJSON(map[string]interface{}{
  8925. "msg": "1",
  8926. "ids": ids,
  8927. })
  8928. return
  8929. }
  8930. }
  8931. func (this *DialysisAPIController) CheckSchedule() {
  8932. patientID, _ := this.GetInt64("patient_id")
  8933. recordDateStr := this.GetString("record_date")
  8934. nurseID, _ := this.GetInt64("start_nurse")
  8935. schedual_type, _ := this.GetInt64("schedual_type")
  8936. bedID, _ := this.GetInt64("bed")
  8937. start_time := this.GetString("start_time")
  8938. fmt.Println("patientID", patientID)
  8939. fmt.Println("recordDateStr", recordDateStr)
  8940. fmt.Println("nurseID", nurseID)
  8941. fmt.Println("schedual_type------", schedual_type)
  8942. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8944. return
  8945. }
  8946. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8947. if parseStartDateErr != nil {
  8948. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8950. return
  8951. }
  8952. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8953. if parseErr != nil {
  8954. this.ErrorLog("时间解析失败:%v", parseErr)
  8955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8956. return
  8957. }
  8958. adminUserInfo := this.GetMobileAdminUserInfo()
  8959. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8960. if getPatientErr != nil {
  8961. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8963. return
  8964. } else if patient == nil {
  8965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8966. return
  8967. }
  8968. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8969. if getNurseErr != nil {
  8970. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8971. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8972. return
  8973. } else if nurse == nil {
  8974. this.ErrorLog("护士不存在")
  8975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8976. return
  8977. }
  8978. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8979. if getDeviceNumberErr != nil {
  8980. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8981. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8982. return
  8983. } else if deviceNumber == nil {
  8984. this.ErrorLog("床位号不存在")
  8985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8986. return
  8987. }
  8988. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8989. if getRecordErr != nil {
  8990. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8992. return
  8993. } else if dialysisRecord != nil {
  8994. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8995. return
  8996. }
  8997. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8998. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8999. timeLayout := "2006-01-02 15:04:05"
  9000. loc, _ := time.LoadLocation("Local")
  9001. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9002. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9003. schedulestartTime := theStartTime.Unix()
  9004. scheduleendTime := theEndTime.Unix()
  9005. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9006. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9007. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9008. //查询该床位是否有人用了
  9009. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9010. if err == nil {
  9011. if schedule.ID == 0 {
  9012. this.ServeSuccessJSON(map[string]interface{}{
  9013. "status": 0,
  9014. "msg": "请求失败",
  9015. })
  9016. } else {
  9017. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9018. if order.ID > 0 { //该机位被其他人占用了
  9019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9020. return
  9021. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9022. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9023. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9024. this.ServeSuccessJSON(map[string]interface{}{
  9025. "status": 1,
  9026. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9027. })
  9028. return
  9029. } else {
  9030. this.ServeSuccessJSON(map[string]interface{}{
  9031. "status": 0,
  9032. "msg": "",
  9033. })
  9034. }
  9035. }
  9036. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9037. this.ServeSuccessJSON(map[string]interface{}{
  9038. "status": 2,
  9039. "msg": "当前机位已有患者在使用,请重新选择!",
  9040. })
  9041. }
  9042. }
  9043. } else {
  9044. this.ServeSuccessJSON(map[string]interface{}{
  9045. "status": 0,
  9046. "msg": "",
  9047. })
  9048. }
  9049. }
  9050. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9051. orgId := this.GetMobileAdminUserInfo().Org.Id
  9052. schedule_type, _ := this.GetInt64("schedule_type")
  9053. partion_type, _ := this.GetInt64("partion_type")
  9054. start_time := this.GetString("start_time")
  9055. timeLayout := "2006-01-02"
  9056. loc, _ := time.LoadLocation("Local")
  9057. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9058. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9059. _, config := service.FindXTHisRecordByOrgId(orgId)
  9060. appId := this.GetMobileAdminUserInfo().App.Id
  9061. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9062. if err == nil {
  9063. this.ServeSuccessJSON(map[string]interface{}{
  9064. "list": list,
  9065. "config": config,
  9066. "doctorList": doctorList,
  9067. })
  9068. return
  9069. } else {
  9070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9071. return
  9072. }
  9073. }
  9074. func (this *DialysisAPIController) SaveMobileInformation() {
  9075. patient_id, _ := this.GetInt64("patient_id")
  9076. record_date, _ := this.GetInt64("record_date")
  9077. startTime := this.GetString("start_time")
  9078. module, _ := this.GetInt64("module")
  9079. remark := this.GetString("remark")
  9080. timeLayout := "2006-01-02 15:04"
  9081. loc, _ := time.LoadLocation("Local")
  9082. if len(startTime) == 0 {
  9083. utils.ErrorLog("len(start_time) == 0")
  9084. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9085. return
  9086. }
  9087. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9088. if err != nil {
  9089. utils.ErrorLog(err.Error())
  9090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9091. return
  9092. }
  9093. StartTime := theTime.Unix()
  9094. fmt.Println("startime-------------", StartTime)
  9095. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9096. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9097. information := models.XtDialysisInformation{
  9098. Module: module,
  9099. PatientId: patient_id,
  9100. RecordDate: record_date,
  9101. ApplicationDate: StartTime,
  9102. Creater: creater,
  9103. ApplicationStatus: 2,
  9104. Checker: 0,
  9105. CheckTime: 0,
  9106. Remark: remark,
  9107. UserOrgId: user_org_id,
  9108. Ctime: time.Now().Unix(),
  9109. Status: 1,
  9110. Mtime: 0,
  9111. }
  9112. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9113. if infor.ID == 0 {
  9114. service.SaveDialysisInformation(information)
  9115. }
  9116. if infor.ID > 0 {
  9117. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9118. }
  9119. this.ServeSuccessJSON(map[string]interface{}{
  9120. "information": information,
  9121. })
  9122. return
  9123. }
  9124. func (this *DialysisAPIController) GetMobileInformation() {
  9125. limit, _ := this.GetInt64("limit")
  9126. page, _ := this.GetInt64("page")
  9127. orgid := this.GetMobileAdminUserInfo().Org.Id
  9128. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9129. appid := this.GetMobileAdminUserInfo().App.Id
  9130. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9131. patients, _ := service.GetAllpatientThirty(orgid)
  9132. this.ServeSuccessJSON(map[string]interface{}{
  9133. "information": information,
  9134. "total": total,
  9135. "doclist": doclist,
  9136. "patients": patients,
  9137. })
  9138. return
  9139. }
  9140. func (this *DialysisAPIController) GetMobileInformationOne() {
  9141. limit, _ := this.GetInt64("limit")
  9142. page, _ := this.GetInt64("page")
  9143. orgid := this.GetMobileAdminUserInfo().Org.Id
  9144. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9145. appid := this.GetMobileAdminUserInfo().App.Id
  9146. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9147. patients, _ := service.GetAllpatientThirty(orgid)
  9148. this.ServeSuccessJSON(map[string]interface{}{
  9149. "information": information,
  9150. "total": total,
  9151. "doclist": doclist,
  9152. "patients": patients,
  9153. })
  9154. return
  9155. }
  9156. func (this *DialysisAPIController) CheckMobileInformation() {
  9157. id, _ := this.GetInt64("id")
  9158. application_status, _ := this.GetInt64("application_status")
  9159. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9160. checktime := time.Now().Unix()
  9161. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9162. if err == nil {
  9163. this.ServeSuccessJSON(map[string]interface{}{
  9164. "msg": "ok",
  9165. })
  9166. return
  9167. }
  9168. }
  9169. func (c *DialysisAPIController) GetControlMonitorList() {
  9170. partition, _ := c.GetInt64("partition")
  9171. monitorDate := c.GetString("date")
  9172. patient_id, _ := c.GetInt64("patient_id")
  9173. pat_type, _ := c.GetInt64("pat_type")
  9174. timeLayout := "2006-01-02"
  9175. loc, _ := time.LoadLocation("Local")
  9176. var theStartTime int64
  9177. if len(monitorDate) > 0 {
  9178. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9179. if err != nil {
  9180. theStartTime = 0
  9181. }
  9182. theStartTime = theTime.Unix()
  9183. }
  9184. adminInfo := c.GetMobileAdminUserInfo()
  9185. orgID := adminInfo.Org.Id
  9186. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9187. if err != nil {
  9188. c.ErrorLog("获取排班信息失败:%v", err)
  9189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9190. } else {
  9191. if len(monitor) > 0 {
  9192. //获取所有床位
  9193. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9194. //获取所有分区
  9195. zoneList, _ := service.GetAllZoneByList(orgID)
  9196. //获取透析处方
  9197. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9198. //获取透前评估
  9199. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9200. //获取上机
  9201. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9202. //获取透后
  9203. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9204. //获取透后监测
  9205. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9206. //获取所有的患者
  9207. patients, _ := service.GetAllPatientListByListOne(orgID)
  9208. //获取所有透析模式
  9209. treatments, _ := service.GetAllTreatModeByList(orgID)
  9210. //获取所有医嘱
  9211. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9212. //获取双人核对
  9213. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9214. //治疗小结
  9215. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9216. //待消毒
  9217. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9218. for key, item := range monitor {
  9219. // 获取床位信息
  9220. for _, it := range numberList {
  9221. if item.BedId == it.ID {
  9222. monitor[key].DeviceNumber = it
  9223. break
  9224. }
  9225. }
  9226. //获取分区信息
  9227. for _, it := range zoneList {
  9228. if item.PartitionId == it.ID {
  9229. monitor[key].DeviceZone = it
  9230. }
  9231. }
  9232. for _, prescription := range prescriptions {
  9233. if item.PatientId == prescription.PatientId {
  9234. monitor[key].Prescription = prescription
  9235. break
  9236. }
  9237. }
  9238. for _, it := range checkList {
  9239. if item.PatientId == it.PatientId {
  9240. monitor[key].DoubleCheck = it
  9241. break
  9242. }
  9243. }
  9244. for _, it := range summaryList {
  9245. if item.PatientId == it.PatientId {
  9246. monitor[key].TreatmentSummaryForList = it
  9247. break
  9248. }
  9249. }
  9250. // 透前评估
  9251. for _, assessmentBefore := range assessmentBefores {
  9252. if item.PatientId == assessmentBefore.PatientId {
  9253. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9254. break
  9255. }
  9256. }
  9257. // 透析上下机
  9258. for _, dialysisOrder := range dialysisOrders {
  9259. if item.PatientId == dialysisOrder.PatientId {
  9260. monitor[key].DialysisOrder = dialysisOrder
  9261. break
  9262. }
  9263. }
  9264. // 治疗小节
  9265. for _, afterDislysis := range AssessmentAfterDislysis {
  9266. if item.PatientId == afterDislysis.PatientId {
  9267. monitor[key].AssessmentAfterDislysis = afterDislysis
  9268. break
  9269. }
  9270. }
  9271. for _, it := range monitorlist {
  9272. if item.PatientId == it.PatientId {
  9273. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9274. }
  9275. }
  9276. for _, it := range adviceList {
  9277. if item.PatientId == it.PatientId {
  9278. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9279. }
  9280. }
  9281. for _, patient := range patients {
  9282. if item.PatientId == patient.ID {
  9283. monitor[key].MonitorPatients = patient
  9284. break
  9285. }
  9286. }
  9287. for _, treatment := range treatments {
  9288. if item.ModeId == treatment.ID {
  9289. monitor[key].TreatmentMode = treatment
  9290. break
  9291. }
  9292. }
  9293. for _, infor := range informationList {
  9294. if item.PatientId == infor.PatientId {
  9295. monitor[key].NewDeviceInformation = infor
  9296. break
  9297. }
  9298. }
  9299. }
  9300. }
  9301. }
  9302. patients, err := service.GetAllpatientFourty(orgID)
  9303. var mds []*models.NewMonitorDialysisScheduleList
  9304. if pat_type == 0 {
  9305. for _, item := range monitor {
  9306. mds = append(mds, item)
  9307. }
  9308. }
  9309. //待医嘱核对
  9310. if pat_type == 1 {
  9311. for _, item := range monitor {
  9312. if len(item.AdviceList) > 0 {
  9313. mds = append(mds, item)
  9314. }
  9315. }
  9316. }
  9317. //待开小结
  9318. if pat_type == 2 {
  9319. for _, item := range monitor {
  9320. if item.TreatmentSummaryForList == nil {
  9321. mds = append(mds, item)
  9322. }
  9323. }
  9324. }
  9325. //待下机
  9326. if pat_type == 3 {
  9327. for _, item := range monitor {
  9328. if item.DialysisOrder != nil {
  9329. if item.DialysisOrder.ID > 0 {
  9330. mds = append(mds, item)
  9331. }
  9332. }
  9333. }
  9334. }
  9335. //待消毒
  9336. if pat_type == 4 {
  9337. for _, item := range monitor {
  9338. if item.NewDeviceInformation == nil {
  9339. mds = append(mds, item)
  9340. }
  9341. }
  9342. }
  9343. //待双人核对
  9344. if pat_type == 5 {
  9345. for _, item := range monitor {
  9346. if item.DoubleCheck == nil {
  9347. mds = append(mds, item)
  9348. }
  9349. }
  9350. }
  9351. //医嘱未执行
  9352. if pat_type == 6 {
  9353. for _, item := range monitor {
  9354. if len(item.AdviceList) > 0 {
  9355. mds = append(mds, item)
  9356. }
  9357. }
  9358. }
  9359. //患者未签名
  9360. if pat_type == 7 {
  9361. for _, item := range monitor {
  9362. if item.DialysisOrder != nil {
  9363. if item.DialysisOrder.ID > 0 {
  9364. mds = append(mds, item)
  9365. }
  9366. }
  9367. }
  9368. }
  9369. //目标超滤于实际超滤不同
  9370. if pat_type == 8 {
  9371. for _, item := range monitor {
  9372. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9373. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9374. mds = append(mds, item)
  9375. }
  9376. }
  9377. }
  9378. }
  9379. //血压少于5次
  9380. if pat_type == 9 {
  9381. for _, item := range monitor {
  9382. if len(item.MonitoringRecord) < 5 {
  9383. mds = append(mds, item)
  9384. }
  9385. }
  9386. }
  9387. if pat_type == 10 {
  9388. for _, item := range monitor {
  9389. if len(item.MonitoringRecord) == 0 {
  9390. mds = append(mds, item)
  9391. }
  9392. }
  9393. }
  9394. if pat_type == 11 {
  9395. for _, item := range monitor {
  9396. if len(item.MonitoringRecord) > 0 {
  9397. mds = append(mds, item)
  9398. }
  9399. }
  9400. }
  9401. if pat_type == 12 {
  9402. for _, item := range monitor {
  9403. if len(item.MonitoringRecord) > 0 {
  9404. mds = append(mds, item)
  9405. }
  9406. }
  9407. }
  9408. if err == nil {
  9409. c.ServeSuccessJSON(map[string]interface{}{
  9410. "monitor": mds,
  9411. "patients": patients,
  9412. })
  9413. } else {
  9414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9415. }
  9416. }
  9417. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9418. admin_user_id, _ := c.GetInt64("admin_user_id")
  9419. timeStr := time.Now().Format("2006-01-02")
  9420. timeLayout := "2006-01-02 15:04:05"
  9421. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9422. timenow := timeStringToTime.Unix()
  9423. orgId := c.GetMobileAdminUserInfo().Org.Id
  9424. //查询当前护士的患者
  9425. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9426. var patientIds []int64
  9427. for _, item := range orderList {
  9428. patientIds = append(patientIds, item.PatientId)
  9429. }
  9430. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9431. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9432. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9433. //药品管理信息
  9434. _, drugStockConfig := service.FindHisConfig(orgId)
  9435. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9436. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9437. c.ServeSuccessJSON(map[string]interface{}{
  9438. "adviceList": adviceList,
  9439. "hisAdviceList": hisAdviceList,
  9440. "projectList": projectList,
  9441. "drugStockConfig": drugStockConfig,
  9442. "patientList": patientList,
  9443. "projectConfig": projectConfig,
  9444. })
  9445. }
  9446. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9447. patient_id, _ := c.GetInt64("patient_id")
  9448. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9449. c.ServeSuccessJSON(map[string]interface{}{
  9450. "recrods": recrods,
  9451. })
  9452. }
  9453. func (c *DialysisAPIController) ExMobileChangeSch() {
  9454. id_one, _ := c.GetInt64("id_one")
  9455. id_two, _ := c.GetInt64("id_two")
  9456. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9457. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9458. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9459. //if order2.ID > 0 {
  9460. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9461. // return
  9462. //}
  9463. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9464. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9465. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9466. if count > 0 {
  9467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9468. return
  9469. }
  9470. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9471. if count1 > 0 {
  9472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9473. return
  9474. }
  9475. }
  9476. err := service.UpdateScheduleThree(sch, sch_two)
  9477. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9478. if order.ID > 0 {
  9479. //查询该患者的排班机位
  9480. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9481. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9482. redis := service.RedisClient()
  9483. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9484. redis.Set(key, "", time.Second)
  9485. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9486. //清空key 值
  9487. redis.Set(keyOne, "", time.Second)
  9488. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9489. //return
  9490. }
  9491. if err == nil {
  9492. //去除当天患者排班中重复数据,保留最后一条数据
  9493. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9494. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9495. c.ServeSuccessJSON(map[string]interface{}{
  9496. "msg": "交换成功",
  9497. })
  9498. } else {
  9499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9500. return
  9501. }
  9502. }
  9503. func (c *DialysisAPIController) MobileCoverSch() {
  9504. id_one, _ := c.GetInt64("id_one")
  9505. id_two, _ := c.GetInt64("id_two")
  9506. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9507. //针对凤凰医院
  9508. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9509. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9510. if len(advice) > 0 {
  9511. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9512. }
  9513. }
  9514. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9515. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9516. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9517. if len(hisAdvice) > 0 {
  9518. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9519. }
  9520. if len(project) > 0 {
  9521. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9522. }
  9523. }
  9524. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9525. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9526. if order.ID > 0 {
  9527. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9528. redis := service.RedisClient()
  9529. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9530. redis.Set(key, "", time.Second)
  9531. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9532. //清空key 值
  9533. redis.Set(keyOne, "", time.Second)
  9534. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9535. //return
  9536. }
  9537. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9538. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9539. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9540. if count > 0 {
  9541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9542. return
  9543. }
  9544. }
  9545. var new_sch models.Schedule
  9546. new_sch = sch
  9547. new_sch.BedId = sch_two.BedId
  9548. new_sch.ScheduleDate = sch_two.ScheduleDate
  9549. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9550. new_sch.PartitionId = sch_two.PartitionId
  9551. new_sch.ScheduleType = sch_two.ScheduleType
  9552. new_sch.ID = 0
  9553. //删除原来的排班
  9554. err := service.SaveSchTwo(sch, sch_two)
  9555. //生成新的排班
  9556. if err == nil {
  9557. err2 := service.SaveSch(&new_sch)
  9558. if err2 == nil {
  9559. //去除当天患者排班中重复数据,保留最后一条数据
  9560. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9561. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9562. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9563. c.ServeSuccessJSON(map[string]interface{}{
  9564. "msg": "覆盖成功",
  9565. "new_sch": new_sch,
  9566. })
  9567. } else {
  9568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9569. return
  9570. }
  9571. } else {
  9572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9573. return
  9574. }
  9575. }
  9576. func (c *DialysisAPIController) BatchCheckAdvice() {
  9577. patient_id, _ := c.GetInt64("patient_id")
  9578. advice_date, _ := c.GetInt64("advice_date")
  9579. org_id := c.GetMobileAdminUserInfo().Org.Id
  9580. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9581. //查询是his系统还是血透系统
  9582. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9583. //his客户
  9584. if configs.IsOpen == 1 {
  9585. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9586. for _, item := range adviceList {
  9587. service.BatchCheckHisAdvice(item.ID, creater)
  9588. }
  9589. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9590. for _, item := range projectList {
  9591. service.BatchCheckProject(item.ID, creater)
  9592. }
  9593. c.ServeSuccessJSON(map[string]interface{}{
  9594. "adviceList": adviceList,
  9595. "projectList": projectList,
  9596. })
  9597. }
  9598. if configs.IsOpen != 1 {
  9599. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9600. for _, item := range adviceList {
  9601. service.BatchAdviceList(item.ID, creater)
  9602. }
  9603. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9604. for _, item := range projectList {
  9605. service.BatchCheckProject(item.ID, creater)
  9606. }
  9607. c.ServeSuccessJSON(map[string]interface{}{
  9608. "adviceList": adviceList,
  9609. "projectList": projectList,
  9610. })
  9611. }
  9612. return
  9613. }
  9614. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9615. org_id := c.GetMobileAdminUserInfo().Org.Id
  9616. drugList, _ := service.GetAllDrugList(org_id)
  9617. c.ServeSuccessJSON(map[string]interface{}{
  9618. "drugList": drugList,
  9619. })
  9620. }
  9621. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9622. org_id := c.GetMobileAdminUserInfo().Org.Id
  9623. dataBody := make(map[string]interface{}, 0)
  9624. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9625. if err != nil {
  9626. utils.ErrorLog(err.Error())
  9627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9628. return
  9629. }
  9630. timeLayout := "2006-01-02"
  9631. loc, _ := time.LoadLocation("Local")
  9632. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9633. utils.ErrorLog("advice_type")
  9634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9635. return
  9636. }
  9637. adviceType := int64(dataBody["advice_type"].(float64))
  9638. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9639. utils.ErrorLog("start_time")
  9640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9641. return
  9642. }
  9643. startTime2, _ := dataBody["start_time"].(string)
  9644. time_arr := strings.Split(startTime2, " ")
  9645. if len(time_arr) > 0 {
  9646. startTime2 = time_arr[0]
  9647. }
  9648. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9649. utils.ErrorLog("advice_date")
  9650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9651. return
  9652. }
  9653. advice_date, _ := dataBody["advice_date"].(string)
  9654. var advicedateunix int64
  9655. if len(advice_date) > 0 {
  9656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9657. if err != nil {
  9658. fmt.Println(err)
  9659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9660. return
  9661. }
  9662. advicedateunix = theTime.Unix()
  9663. }
  9664. adviceDate := startTime2
  9665. if len(adviceDate) == 0 {
  9666. utils.ErrorLog("len(adviceDate) == 0")
  9667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9668. return
  9669. }
  9670. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9671. if err != nil {
  9672. utils.ErrorLog(err.Error())
  9673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9674. return
  9675. }
  9676. AdviceDate := advicedateunix
  9677. RecordDate := advicedateunix
  9678. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9679. utils.ErrorLog("start_time")
  9680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9681. return
  9682. }
  9683. startTime, _ := dataBody["start_time"].(string)
  9684. if len(startTime) == 0 {
  9685. utils.ErrorLog("len(start_time) == 0")
  9686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9687. return
  9688. }
  9689. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9690. if err != nil {
  9691. utils.ErrorLog(err.Error())
  9692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9693. return
  9694. }
  9695. StartTime := theTime.Unix()
  9696. advice_name, _ := dataBody["advice_name"].(string)
  9697. advice_desc, _ := dataBody["advice_desc"].(string)
  9698. delivery_way, _ := dataBody["delivery_way"].(string)
  9699. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9700. frequency_type := int64(dataBody["frequency_type"].(float64))
  9701. frequency_week, _ := dataBody["frequency_week"].(string)
  9702. prescribing_number := dataBody["prescribing_number"].(float64)
  9703. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9704. remark := dataBody["remark"].(string)
  9705. single_dose := dataBody["single_dose"].(float64)
  9706. single_dose_unit := dataBody["single_dose_unit"].(string)
  9707. patient_id := int64(dataBody["patient_id"].(float64))
  9708. day_count := int64(dataBody["day_count"].(float64))
  9709. groupNo := int64(dataBody["group_no"].(float64))
  9710. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9711. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9712. if groupNo <= 0 {
  9713. group := service.GetMaxAdviceGroupID(org_id)
  9714. groupNo = group + 1
  9715. }
  9716. var template_id = ""
  9717. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9718. template_id = "M" + adviceLastId
  9719. advice := models.DoctorAdvice{
  9720. UserOrgId: org_id,
  9721. PatientId: patient_id,
  9722. AdviceType: adviceType,
  9723. AdviceDate: AdviceDate,
  9724. StartTime: StartTime,
  9725. AdviceName: advice_name,
  9726. AdviceDesc: advice_desc,
  9727. ReminderDate: 0,
  9728. SingleDose: single_dose,
  9729. SingleDoseUnit: single_dose_unit,
  9730. DrugSpec: 0,
  9731. DrugSpecUnit: "",
  9732. PrescribingNumber: prescribing_number,
  9733. PrescribingNumberUnit: prescribing_number_unit,
  9734. DeliveryWay: delivery_way,
  9735. ExecutionFrequency: execution_frequency,
  9736. AdviceDoctor: advice_doctor,
  9737. Status: 1,
  9738. CreatedTime: time.Now().Unix(),
  9739. UpdatedTime: 0,
  9740. AdviceAffirm: "",
  9741. Remark: remark,
  9742. StopTime: 0,
  9743. StopReason: "",
  9744. StopDoctor: 0,
  9745. StopState: 0,
  9746. ParentId: 0,
  9747. ExecutionTime: 0,
  9748. ExecutionStaff: 0,
  9749. ExecutionState: 0,
  9750. Checker: 0,
  9751. RecordDate: RecordDate,
  9752. DialysisOrderId: 0,
  9753. CheckTime: 0,
  9754. CheckState: 0,
  9755. AdviceId: 0,
  9756. RemindType: 0,
  9757. FrequencyType: frequency_type,
  9758. DayCount: day_count,
  9759. WeekDay: frequency_week,
  9760. ChildDoctorAdvice: nil,
  9761. TemplateId: template_id,
  9762. Modifier: 0,
  9763. IsCheck: 0,
  9764. Way: 0,
  9765. DrugId: 0,
  9766. DrugNameId: 0,
  9767. IsMedicine: 0,
  9768. PushStartTime: 0,
  9769. IsSettle: 0,
  9770. IsPrescription: 0,
  9771. GroupNo: groupNo,
  9772. }
  9773. service.CreateMobileAdivce(advice)
  9774. c.ServeSuccessJSON(map[string]interface{}{
  9775. "msg": "保存成功!",
  9776. })
  9777. }
  9778. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9779. patient_id, _ := c.GetInt64("patient_id")
  9780. org_id := c.GetMobileAdminUserInfo().Org.Id
  9781. app_id := c.GetMobileAdminUserInfo().App.Id
  9782. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9783. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9784. c.ServeSuccessJSON(map[string]interface{}{
  9785. "adviceList": adviceList,
  9786. "adminRoles": adminRoles,
  9787. })
  9788. }
  9789. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9790. org_id := c.GetMobileAdminUserInfo().Org.Id
  9791. dataBody := make(map[string]interface{}, 0)
  9792. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9793. if err != nil {
  9794. utils.ErrorLog(err.Error())
  9795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9796. return
  9797. }
  9798. timeLayout := "2006-01-02"
  9799. loc, _ := time.LoadLocation("Local")
  9800. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9801. utils.ErrorLog("start_time")
  9802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9803. return
  9804. }
  9805. startTime2, _ := dataBody["start_time"].(string)
  9806. time_arr := strings.Split(startTime2, " ")
  9807. if len(time_arr) > 0 {
  9808. startTime2 = time_arr[0]
  9809. }
  9810. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9811. utils.ErrorLog("advice_date")
  9812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9813. return
  9814. }
  9815. advice_date, _ := dataBody["advice_date"].(string)
  9816. var advicedateunix int64
  9817. if len(advice_date) > 0 {
  9818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9819. if err != nil {
  9820. fmt.Println(err)
  9821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9822. return
  9823. }
  9824. advicedateunix = theTime.Unix()
  9825. }
  9826. adviceDate := startTime2
  9827. if len(adviceDate) == 0 {
  9828. utils.ErrorLog("len(adviceDate) == 0")
  9829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9830. return
  9831. }
  9832. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9833. if err != nil {
  9834. utils.ErrorLog(err.Error())
  9835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9836. return
  9837. }
  9838. AdviceDate := advicedateunix
  9839. RecordDate := advicedateunix
  9840. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9841. utils.ErrorLog("start_time")
  9842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9843. return
  9844. }
  9845. startTime, _ := dataBody["start_time"].(string)
  9846. if len(startTime) == 0 {
  9847. utils.ErrorLog("len(start_time) == 0")
  9848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9849. return
  9850. }
  9851. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9852. if err != nil {
  9853. utils.ErrorLog(err.Error())
  9854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9855. return
  9856. }
  9857. StartTime := theTime.Unix()
  9858. advice_name, _ := dataBody["advice_name"].(string)
  9859. advice_desc, _ := dataBody["advice_desc"].(string)
  9860. delivery_way, _ := dataBody["delivery_way"].(string)
  9861. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9862. prescribing_number := dataBody["prescribing_number"].(float64)
  9863. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9864. remark := dataBody["remark"].(string)
  9865. single_dose := dataBody["single_dose"].(float64)
  9866. single_dose_unit := dataBody["single_dose_unit"].(string)
  9867. patient_id := int64(dataBody["patient_id"].(float64))
  9868. groupNo := int64(dataBody["group_no"].(float64))
  9869. parent_id := int64(dataBody["parent_id"].(float64))
  9870. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9871. advice := models.XtDoctorAdviceOne{
  9872. UserOrgId: org_id,
  9873. PatientId: patient_id,
  9874. AdviceType: 1,
  9875. AdviceDate: AdviceDate,
  9876. StartTime: StartTime,
  9877. AdviceName: advice_name,
  9878. AdviceDesc: advice_desc,
  9879. ReminderDate: 0,
  9880. SingleDose: single_dose,
  9881. SingleDoseUnit: single_dose_unit,
  9882. PrescribingNumber: prescribing_number,
  9883. PrescribingNumberUnit: prescribing_number_unit,
  9884. DeliveryWay: delivery_way,
  9885. ExecutionFrequency: execution_frequency,
  9886. AdviceDoctor: advice_doctor,
  9887. Status: 1,
  9888. CreatedTime: time.Now().Unix(),
  9889. UpdatedTime: time.Now().Unix(),
  9890. AdviceAffirm: "",
  9891. Remark: remark,
  9892. StopTime: 0,
  9893. StopReason: "",
  9894. StopDoctor: 0,
  9895. StopState: 0,
  9896. ParentId: parent_id,
  9897. ExecutionTime: 0,
  9898. ExecutionStaff: 0,
  9899. ExecutionState: 0,
  9900. Checker: 0,
  9901. RecordDate: RecordDate,
  9902. DialysisOrderId: 0,
  9903. CheckTime: 0,
  9904. CheckState: 0,
  9905. DrugSpec: 0,
  9906. DrugSpecUnit: "",
  9907. Groupno: groupNo,
  9908. RemindType: 0,
  9909. FrequencyType: 0,
  9910. DayCount: 0,
  9911. WeekDay: "",
  9912. TemplateId: "",
  9913. Modifier: 0,
  9914. }
  9915. service.CreateMobileAdivceOne(advice)
  9916. c.ServeSuccessJSON(map[string]interface{}{
  9917. "msg": "保存成功!",
  9918. })
  9919. }
  9920. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9921. id, _ := c.GetInt64("id")
  9922. service.DeleteSelfAdviceSubAdvice(id)
  9923. c.ServeSuccessJSON(map[string]interface{}{
  9924. "msg": "保存成功!",
  9925. })
  9926. }
  9927. func (c *DialysisAPIController) GetEditAdviceAction() {
  9928. id, _ := c.GetInt64("id")
  9929. org_id := c.GetMobileAdminUserInfo().Org.Id
  9930. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9931. drugList, _ := service.GetAllDrugList(org_id)
  9932. c.ServeSuccessJSON(map[string]interface{}{
  9933. "advice": advice,
  9934. "drugList": drugList,
  9935. })
  9936. }
  9937. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  9938. dataBody := make(map[string]interface{}, 0)
  9939. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9940. if err != nil {
  9941. utils.ErrorLog(err.Error())
  9942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9943. return
  9944. }
  9945. timeLayout := "2006-01-02"
  9946. loc, _ := time.LoadLocation("Local")
  9947. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9948. utils.ErrorLog("start_time")
  9949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9950. return
  9951. }
  9952. startTime2, _ := dataBody["start_time"].(string)
  9953. time_arr := strings.Split(startTime2, " ")
  9954. if len(time_arr) > 0 {
  9955. startTime2 = time_arr[0]
  9956. }
  9957. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9958. utils.ErrorLog("advice_date")
  9959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9960. return
  9961. }
  9962. advice_date, _ := dataBody["advice_date"].(string)
  9963. var advicedateunix int64
  9964. if len(advice_date) > 0 {
  9965. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9966. if err != nil {
  9967. fmt.Println(err)
  9968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9969. return
  9970. }
  9971. advicedateunix = theTime.Unix()
  9972. }
  9973. adviceDate := startTime2
  9974. if len(adviceDate) == 0 {
  9975. utils.ErrorLog("len(adviceDate) == 0")
  9976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9977. return
  9978. }
  9979. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9980. if err != nil {
  9981. utils.ErrorLog(err.Error())
  9982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9983. return
  9984. }
  9985. AdviceDate := advicedateunix
  9986. RecordDate := advicedateunix
  9987. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9988. utils.ErrorLog("start_time")
  9989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9990. return
  9991. }
  9992. startTime, _ := dataBody["start_time"].(string)
  9993. if len(startTime) == 0 {
  9994. utils.ErrorLog("len(start_time) == 0")
  9995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9996. return
  9997. }
  9998. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9999. if err != nil {
  10000. utils.ErrorLog(err.Error())
  10001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10002. return
  10003. }
  10004. StartTime := theTime.Unix()
  10005. advice_name, _ := dataBody["advice_name"].(string)
  10006. advice_desc, _ := dataBody["advice_desc"].(string)
  10007. delivery_way, _ := dataBody["delivery_way"].(string)
  10008. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10009. prescribing_number := dataBody["prescribing_number"].(float64)
  10010. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10011. remark := dataBody["remark"].(string)
  10012. single_dose := dataBody["single_dose"].(float64)
  10013. single_dose_unit := dataBody["single_dose_unit"].(string)
  10014. id := int64(dataBody["id"].(float64))
  10015. frequency_type := int64(dataBody["frequency_type"].(float64))
  10016. frequency_week, _ := dataBody["frequency_week"].(string)
  10017. day_count := int64(dataBody["day_count"].(float64))
  10018. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10019. advice := models.XtDoctorAdviceOne{
  10020. AdviceDate: AdviceDate,
  10021. StartTime: StartTime,
  10022. AdviceName: advice_name,
  10023. AdviceDesc: advice_desc,
  10024. SingleDose: single_dose,
  10025. SingleDoseUnit: single_dose_unit,
  10026. PrescribingNumber: prescribing_number,
  10027. PrescribingNumberUnit: prescribing_number_unit,
  10028. DeliveryWay: delivery_way,
  10029. ExecutionFrequency: execution_frequency,
  10030. AdviceDoctor: advice_doctor,
  10031. Remark: remark,
  10032. RecordDate: RecordDate,
  10033. FrequencyType: frequency_type,
  10034. DayCount: day_count,
  10035. WeekDay: frequency_week,
  10036. }
  10037. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10038. c.ServeSuccessJSON(map[string]interface{}{
  10039. "advice": advice,
  10040. })
  10041. }
  10042. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10043. dataBody := make(map[string]interface{}, 0)
  10044. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10045. if err != nil {
  10046. utils.ErrorLog(err.Error())
  10047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10048. return
  10049. }
  10050. timeLayout := "2006-01-02"
  10051. loc, _ := time.LoadLocation("Local")
  10052. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10053. utils.ErrorLog("start_time")
  10054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10055. return
  10056. }
  10057. startTime2, _ := dataBody["start_time"].(string)
  10058. time_arr := strings.Split(startTime2, " ")
  10059. if len(time_arr) > 0 {
  10060. startTime2 = time_arr[0]
  10061. }
  10062. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10063. utils.ErrorLog("advice_date")
  10064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10065. return
  10066. }
  10067. advice_date, _ := dataBody["advice_date"].(string)
  10068. var advicedateunix int64
  10069. if len(advice_date) > 0 {
  10070. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10071. if err != nil {
  10072. fmt.Println(err)
  10073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10074. return
  10075. }
  10076. advicedateunix = theTime.Unix()
  10077. }
  10078. adviceDate := startTime2
  10079. if len(adviceDate) == 0 {
  10080. utils.ErrorLog("len(adviceDate) == 0")
  10081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10082. return
  10083. }
  10084. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10085. if err != nil {
  10086. utils.ErrorLog(err.Error())
  10087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10088. return
  10089. }
  10090. AdviceDate := advicedateunix
  10091. RecordDate := advicedateunix
  10092. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10093. utils.ErrorLog("start_time")
  10094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10095. return
  10096. }
  10097. startTime, _ := dataBody["start_time"].(string)
  10098. if len(startTime) == 0 {
  10099. utils.ErrorLog("len(start_time) == 0")
  10100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10101. return
  10102. }
  10103. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10104. if err != nil {
  10105. utils.ErrorLog(err.Error())
  10106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10107. return
  10108. }
  10109. StartTime := theTime.Unix()
  10110. advice_name, _ := dataBody["advice_name"].(string)
  10111. advice_desc, _ := dataBody["advice_desc"].(string)
  10112. delivery_way, _ := dataBody["delivery_way"].(string)
  10113. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10114. prescribing_number := dataBody["prescribing_number"].(float64)
  10115. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10116. remark := dataBody["remark"].(string)
  10117. single_dose := dataBody["single_dose"].(float64)
  10118. single_dose_unit := dataBody["single_dose_unit"].(string)
  10119. id := int64(dataBody["id"].(float64))
  10120. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10121. advice := models.XtDoctorAdviceOne{
  10122. AdviceDate: AdviceDate,
  10123. StartTime: StartTime,
  10124. AdviceName: advice_name,
  10125. AdviceDesc: advice_desc,
  10126. SingleDose: single_dose,
  10127. SingleDoseUnit: single_dose_unit,
  10128. PrescribingNumber: prescribing_number,
  10129. PrescribingNumberUnit: prescribing_number_unit,
  10130. DeliveryWay: delivery_way,
  10131. ExecutionFrequency: execution_frequency,
  10132. AdviceDoctor: advice_doctor,
  10133. Remark: remark,
  10134. RecordDate: RecordDate,
  10135. }
  10136. service.UpdateMobileDoctorAdviceById(id, advice)
  10137. c.ServeSuccessJSON(map[string]interface{}{
  10138. "advice": advice,
  10139. })
  10140. }
  10141. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10142. dataBody := make(map[string]interface{}, 0)
  10143. timeLayout := "2006-01-02"
  10144. loc, _ := time.LoadLocation("Local")
  10145. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10146. if err != nil {
  10147. utils.ErrorLog(err.Error())
  10148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10149. return
  10150. }
  10151. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10152. utils.ErrorLog("start_time")
  10153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10154. return
  10155. }
  10156. startTime2, _ := dataBody["start_time"].(string)
  10157. time_arr := strings.Split(startTime2, " ")
  10158. if len(time_arr) > 0 {
  10159. startTime2 = time_arr[0]
  10160. }
  10161. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10162. utils.ErrorLog("advice_date")
  10163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10164. return
  10165. }
  10166. advice_date, _ := dataBody["advice_date"].(string)
  10167. var advicedateunix int64
  10168. if len(advice_date) > 0 {
  10169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10170. if err != nil {
  10171. fmt.Println(err)
  10172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10173. return
  10174. }
  10175. advicedateunix = theTime.Unix()
  10176. }
  10177. adviceDate := startTime2
  10178. if len(adviceDate) == 0 {
  10179. utils.ErrorLog("len(adviceDate) == 0")
  10180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10181. return
  10182. }
  10183. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10184. if err != nil {
  10185. utils.ErrorLog(err.Error())
  10186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10187. return
  10188. }
  10189. RecordDate := advicedateunix
  10190. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10191. utils.ErrorLog("start_time")
  10192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10193. return
  10194. }
  10195. startTime, _ := dataBody["start_time"].(string)
  10196. if len(startTime) == 0 {
  10197. utils.ErrorLog("len(start_time) == 0")
  10198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10199. return
  10200. }
  10201. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10202. if err != nil {
  10203. utils.ErrorLog(err.Error())
  10204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10205. return
  10206. }
  10207. StartTime := theTime.Unix()
  10208. patient_id := int64(dataBody["patient_id"].(float64))
  10209. group_no := int64(dataBody["group_no"].(float64))
  10210. org_id := c.GetMobileAdminUserInfo().Org.Id
  10211. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10212. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10213. utils.ErrorLog("advices")
  10214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10215. return
  10216. }
  10217. adviceNames := dataBody["advices"].([]interface{})
  10218. var advices []*models.GroupAdvice
  10219. for _, adviceNameMap := range adviceNames {
  10220. var advice models.GroupAdvice
  10221. adviceNameM := adviceNameMap.(map[string]interface{})
  10222. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10223. utils.ErrorLog("advice_name")
  10224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10225. return
  10226. }
  10227. adviceName, _ := adviceNameM["advice_name"].(string)
  10228. if len(adviceName) == 0 {
  10229. utils.ErrorLog("len(advice_name) == 0")
  10230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10231. return
  10232. }
  10233. advice.AdviceName = adviceName
  10234. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10235. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10236. advice.DrugSpec = drugSpec
  10237. }
  10238. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10239. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10240. advice.AdviceDesc = adviceDesc
  10241. }
  10242. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10243. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10244. advice.DrugSpecUnit = drugSpecUnit
  10245. }
  10246. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10247. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10248. advice.SingleDose = singleDose
  10249. }
  10250. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10251. singleDose := adviceNameM["single_dose"].(float64)
  10252. advice.SingleDose = singleDose
  10253. }
  10254. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10255. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10256. advice.SingleDoseUnit = singleDoseUnit
  10257. }
  10258. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10259. tmp := adviceNameM["single_dose_unit"].(float64)
  10260. singleDoseUnit := service.TypeConversion(tmp)
  10261. advice.SingleDoseUnit = singleDoseUnit
  10262. }
  10263. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10264. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10265. advice.PrescribingNumber = prescribingNumber
  10266. }
  10267. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10268. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10269. advice.PrescribingNumber = prescribingNumber
  10270. }
  10271. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10272. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10273. advice.PrescribingNumberUnit = prescribingNumberUnit
  10274. }
  10275. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10276. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10277. advice.DeliveryWay = deliveryWay
  10278. }
  10279. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10280. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10281. advice.ExecutionFrequency = executionFrequency
  10282. }
  10283. remark, _ := adviceNameM["remark"].(string)
  10284. advice.Remark = remark
  10285. advice.AdviceType = 1
  10286. advice.StartTime = StartTime
  10287. advice.RecordDate = RecordDate
  10288. advice.PatientId = patient_id
  10289. advice.UserOrgId = org_id
  10290. advice.AdviceDoctor = advice_doctor
  10291. advices = append(advices, &advice)
  10292. }
  10293. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10294. c.ServeSuccessJSON(map[string]interface{}{
  10295. "advice": newAdvices,
  10296. })
  10297. }