dialysis_api_controller.go 479KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455
  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. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. his_bed = lastAcceptTreatment.HisBed
  1124. his_department = lastAcceptTreatment.HisDepartment
  1125. tumble = lastAcceptTreatment.Tumble
  1126. }
  1127. }
  1128. }
  1129. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1130. UserOrgId: adminUserInfo.Org.Id,
  1131. PatientId: id,
  1132. RecordDate: recordDate.Unix(),
  1133. Way: way,
  1134. Consciousness: consciousness,
  1135. Appetite: appetite,
  1136. Condition: condition,
  1137. SickCondition: sick_condition,
  1138. DangerLevel: danger_level,
  1139. Intake: intake,
  1140. Nutrition: nutrition,
  1141. PsychologicalAssessment: psychological_assessment,
  1142. PsychologicalAssessmentOther: psychological_assessment_other,
  1143. SickConditionOther: sick_condition_other,
  1144. Posture: posture,
  1145. CreatedTime: time.Now().Unix(),
  1146. UpdateTime: time.Now().Unix(),
  1147. Status: 1,
  1148. Score: score,
  1149. Precaution: precaution,
  1150. PrecautionOther: precaution_other,
  1151. PsychologicalOther: psychological_other,
  1152. AdmissionNumber: admission_number,
  1153. Tumble: tumble,
  1154. Diacrisis: diacrisis,
  1155. HisBed: his_bed,
  1156. HisDepartment: his_department,
  1157. }
  1158. if receiveTreatment.ID == 0 { //新增
  1159. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1160. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1161. finish := models.XtDialysisFinish{
  1162. IsFinish: 1,
  1163. UserOrgId: adminUserInfo.Org.Id,
  1164. Status: 1,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: 0,
  1167. Module: 2,
  1168. RecordDate: recordDate.Unix(),
  1169. Sourse: 1,
  1170. PatientId: id,
  1171. }
  1172. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1173. if dialysisFinish.ID == 0 {
  1174. service.CreateDialysisFinish(finish)
  1175. }
  1176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1177. redis := service.RedisClient()
  1178. defer redis.Close()
  1179. //清空key 值
  1180. redis.Set(key, "", time.Second)
  1181. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1182. redis.Set(keyOne, "", time.Second)
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "receiveTreatmentAsses": receiveTreatmentAsses,
  1186. })
  1187. }
  1188. } else { //修改
  1189. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. // 查询信息规挡的设置天数
  1200. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1201. if infor.ID > 0 && infor.WeekDay > 0 {
  1202. var cha_time int64
  1203. timeNowStr := time.Now().Format("2006-01-02")
  1204. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1205. //今日的日期减去设置的日期
  1206. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1207. if cha_time >= recordDate.Unix() {
  1208. //查询审核是否允许
  1209. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1210. //申请状态不允许的情况 拒绝修改
  1211. if infor.ApplicationStatus != 1 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1213. return
  1214. }
  1215. }
  1216. }
  1217. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1218. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1219. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1220. receiveTreatmentAsses.ID = receiveTreatment.ID
  1221. if adminUserInfo.Org.Id == 10340 {
  1222. if condition == 1 {
  1223. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1224. if receiveTreatmentAsses.AdmissionNumber == "" {
  1225. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1226. }
  1227. }
  1228. }
  1229. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1230. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. //清空key 值
  1234. redis.Set(key, "", time.Second)
  1235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1236. redis.Set(keyOne, "", time.Second)
  1237. if err == nil {
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "receiveTreatmentAsses": receiveTreatmentAsses,
  1240. })
  1241. }
  1242. }
  1243. }
  1244. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1245. id, _ := c.GetInt64("patient", 0)
  1246. recordDateStr := c.GetString("record_date")
  1247. weightAfter, _ := c.GetFloat("weight_after", 0)
  1248. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1249. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1250. fmt.Println("weight_loss", weightReduce)
  1251. temperature, _ := c.GetFloat("temperature", 0)
  1252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1253. breathing_rate := c.GetString("breathing_rate")
  1254. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1255. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1256. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1257. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1258. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1259. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1260. cruor := c.GetString("cruor")
  1261. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1262. internalFistula := c.GetString("internal_fistula")
  1263. catheter := c.GetString("catheter")
  1264. complications := c.GetString("complication")
  1265. remark := c.GetString("remark")
  1266. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1267. dialysis_intakes := c.GetString("dialysis_intakes")
  1268. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1269. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1270. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1271. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1272. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1273. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1274. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1275. patientGose, _ := c.GetInt64("patient_gose", 0)
  1276. inpatientDepartment := c.GetString("inpatient_department")
  1277. observationContent := c.GetString("observation_content")
  1278. observationContentOther := c.GetString("observation_content_other")
  1279. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1280. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1281. in_advance_reason := c.GetString("in_advance_reason")
  1282. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1283. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1284. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1285. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1286. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1287. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1288. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1289. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1290. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1291. is_eat, _ := c.GetInt64("is_eat", 0)
  1292. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1293. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1294. channels, _ := c.GetInt64("channel", 0)
  1295. return_blood, _ := c.GetInt64("return_blood", 0)
  1296. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1297. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1298. dialysis_during, _ := c.GetFloat("dialysis_during")
  1299. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1300. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1301. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1302. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1303. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1304. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1305. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1306. setting_pressure := c.GetString("setting_pressure")
  1307. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1308. diastolic_pressure := c.GetString("diastolic_pressure")
  1309. other_complication := c.GetString("other_complication")
  1310. ktv := c.GetString("ktv")
  1311. urr := c.GetString("urr")
  1312. hypertenison, _ := c.GetInt64("hypertenison")
  1313. hypopiesia, _ := c.GetInt64("hypopiesia")
  1314. leave_office_method, _ := c.GetInt64("leave_office_method")
  1315. lapse, _ := c.GetInt64("lapse")
  1316. consciousness, _ := c.GetInt64("consciousness")
  1317. fallrisk, _ := c.GetInt64("fallrisk")
  1318. machine_run := c.GetString("machine_run")
  1319. after_urea := c.GetString("after_urea")
  1320. pip_coagulation := c.GetString("pip_coagulation")
  1321. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1322. transfusion_volume := c.GetString("transfusion_volume")
  1323. last_after_weight := c.GetString("last_after_weight")
  1324. displace_liqui_value := c.GetString("displace_liqui_value")
  1325. start_time := c.GetString("start_time")
  1326. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1327. if id <= 0 {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. adminUserInfo := c.GetMobileAdminUserInfo()
  1332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1333. if patient.ID == 0 {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1335. return
  1336. }
  1337. if len(recordDateStr) == 0 {
  1338. recordDateStr = time.Now().Format("2006-01-02")
  1339. }
  1340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1341. fmt.Println("parseDateErr", parseDateErr)
  1342. if parseDateErr != nil {
  1343. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1348. //now := time.Now()
  1349. //year, month, day := now.Date()
  1350. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1351. //todayTimeStamp := today_time.Unix()
  1352. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1353. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1354. UserOrgId: adminUserInfo.Org.Id,
  1355. PatientId: id,
  1356. AssessmentDate: recordDate.Unix(),
  1357. Temperature: temperature,
  1358. PulseFrequency: pulse_frequency,
  1359. BreathingRate: breathing_rate,
  1360. SystolicBloodPressure: systolic_blood_pressure,
  1361. DiastolicBloodPressure: diastolic_blood_pressure,
  1362. ActualUltrafiltration: actual_ultrafiltration,
  1363. ActualDisplacement: actual_displacement,
  1364. ActualTreatmentHour: actualtreatHour,
  1365. ActualTreatmentMinute: actualtreatmin,
  1366. WeightAfter: weightAfter,
  1367. AdditionalWeight: additionalWeight,
  1368. WeightLoss: weightReduce,
  1369. Cruor: cruor,
  1370. SymptomAfterDialysis: symptomsAfterDialysi,
  1371. InternalFistula: internalFistula,
  1372. Catheter: catheter,
  1373. Complication: complications,
  1374. DialysisIntakes: dialysateVolume,
  1375. CreatedTime: time.Now().Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. Status: 1,
  1378. Remark: remark,
  1379. BloodAccessPartId: blood_access_part_id,
  1380. BloodAccessPartOperaId: blood_access_part_opera_id,
  1381. DialysisIntakesUnit: dialysis_intakes_unit,
  1382. PuncturePointOozingBlood: puncturePointOozingBlood,
  1383. PuncturePointHaematoma: puncturePointHaematoma,
  1384. InternalFistulaTremorAc: internalFistulaTremorAc,
  1385. PatientGose: patientGose,
  1386. InpatientDepartment: inpatientDepartment,
  1387. ObservationContent: observationContent,
  1388. ObservationContentOther: observationContentOther,
  1389. DialysisProcess: dialysis_process,
  1390. InAdvanceMinute: in_advance_minute,
  1391. InAdvanceReason: in_advance_reason,
  1392. HemostasisMinute: hemostasis_minute,
  1393. HemostasisOpera: hemostasis_opera,
  1394. TremorNoise: tremor_noise,
  1395. DisequilibriumSyndrome: disequilibrium_syndrome,
  1396. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1397. ArterialTube: arterial_tube,
  1398. IntravenousTube: intravenous_tube,
  1399. Dialyzer: dialyzer,
  1400. InAdvanceReasonOther: in_advance_reason_other,
  1401. IsEat: is_eat,
  1402. CvcA: cvc_a,
  1403. CvcV: cvc_v,
  1404. Channel: channels,
  1405. ReturnBlood: return_blood,
  1406. RehydrationVolume: rehydration_volume,
  1407. DialysisDuring: dialysis_during,
  1408. StrokeVolume: stroke_volume,
  1409. BloodFlow: blood_flow,
  1410. SealingFluidDispose: sealing_fluid_dispose,
  1411. SealingFluidSpecial: sealing_fluid_special,
  1412. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1413. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1414. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1415. SettingPressure: setting_pressure,
  1416. DiastolicPressure: diastolic_pressure,
  1417. OtherComplication: other_complication,
  1418. Ktv: ktv,
  1419. Urr: urr,
  1420. Hypopiesia: hypopiesia,
  1421. Hypertenison: hypertenison,
  1422. Lapse: lapse,
  1423. LeaveOfficeMethod: leave_office_method,
  1424. Consciousness: consciousness,
  1425. Fallrisk: fallrisk,
  1426. MachineRun: machine_run,
  1427. AfterUrea: after_urea,
  1428. PipCoagulation: pip_coagulation,
  1429. AccumulatedBloodVolume: accumulated_blood_volume,
  1430. TransfusionVolume: transfusion_volume,
  1431. LastAfterWeight: last_after_weight,
  1432. DisplaceLiquiValue: displace_liqui_value,
  1433. RecordTime: startDate.Unix(),
  1434. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1435. }
  1436. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1437. // 查询信息规挡的设置天数
  1438. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1439. if infor.ID > 0 && infor.WeekDay > 0 {
  1440. var cha_time int64
  1441. timeNowStr := time.Now().Format("2006-01-02")
  1442. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1443. //今日的日期减去设置的日期
  1444. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1445. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1446. if cha_time >= recordDate.Unix() {
  1447. //查询审核是否允许
  1448. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1449. //申请状态不允许的情况 拒绝修改
  1450. if infor.ApplicationStatus != 1 {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1457. if assessmentAfter.ID == 0 { //新增
  1458. if appRole.UserType == 2 || appRole.UserType == 1 {
  1459. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1460. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1461. } else {
  1462. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1463. }
  1464. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1465. if assessmentAfterDislysis.UserOrgId != 10340 {
  1466. if assessmentAfterDislysis.WeightAfter == 0 {
  1467. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1468. }
  1469. }
  1470. if adminUserInfo.Org.Id == 10693 {
  1471. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1472. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1473. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1474. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1475. }
  1476. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1477. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1478. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1479. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1480. }
  1481. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1482. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1483. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1484. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1485. }
  1486. if assessmentAfterDislysis.PulseFrequency == 0 {
  1487. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1488. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1489. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1490. }
  1491. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1492. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1493. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1494. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1495. }
  1496. }
  1497. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1498. //记录日志
  1499. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1500. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1501. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1502. PatientId: assessmentAfterDislysis.PatientId,
  1503. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1504. Status: 1,
  1505. ErrLog: string(byterequest),
  1506. AdminUserId: adminUserInfo.AdminUser.Id,
  1507. Ctime: 0,
  1508. Mtime: 0,
  1509. Source: "手机端保存透后评估",
  1510. }
  1511. service.CreateAfterDialysisLog(afterDialysisLog)
  1512. finish := models.XtDialysisFinish{
  1513. IsFinish: 1,
  1514. UserOrgId: adminUserInfo.Org.Id,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: 0,
  1518. Module: 9,
  1519. RecordDate: recordDate.Unix(),
  1520. Sourse: 1,
  1521. PatientId: id,
  1522. }
  1523. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1524. if dialysisFinish.ID == 0 {
  1525. service.CreateDialysisFinish(finish)
  1526. }
  1527. redis := service.RedisClient()
  1528. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1529. redis.Set(keyTwo, "", time.Second)
  1530. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1531. //清空key 值
  1532. redis.Set(key, "", time.Second)
  1533. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1534. redis.Set(keyOne, "", time.Second)
  1535. defer redis.Close()
  1536. if err == nil {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "assessmentAfterDislysis": assessmentAfterDislysis,
  1539. })
  1540. }
  1541. return
  1542. } else { //修改
  1543. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1544. if infor.ID > 0 && infor.WeekDay > 0 {
  1545. var cha_time int64
  1546. timeNowStr := time.Now().Format("2006-01-02")
  1547. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1548. //今日的日期减去设置的日期
  1549. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1550. if cha_time >= recordDate.Unix() {
  1551. //查询审核是否允许
  1552. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1553. //申请状态不允许的情况 拒绝修改
  1554. if infor.ApplicationStatus != 1 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1556. return
  1557. }
  1558. }
  1559. }
  1560. if appRole.UserType == 2 || appRole.UserType == 1 {
  1561. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1562. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1563. } else {
  1564. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1565. if assessmentAfterDislysis.Creater == 0 {
  1566. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1570. assessmentAfterDislysis.ID = assessmentAfter.ID
  1571. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1572. if assessmentAfterDislysis.UserOrgId != 10340 {
  1573. if assessmentAfterDislysis.WeightAfter == 0 {
  1574. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1575. }
  1576. }
  1577. if adminUserInfo.Org.Id == 10693 {
  1578. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1579. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1580. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1581. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1582. }
  1583. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1584. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1585. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1586. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1587. }
  1588. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1589. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1590. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1591. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1592. }
  1593. if assessmentAfterDislysis.PulseFrequency == 0 {
  1594. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1595. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1596. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1597. }
  1598. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1599. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1600. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1601. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1602. }
  1603. }
  1604. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1605. //记录日志
  1606. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1607. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1608. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1609. PatientId: assessmentAfterDislysis.PatientId,
  1610. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1611. Status: 1,
  1612. ErrLog: string(byterequest),
  1613. AdminUserId: adminUserInfo.AdminUser.Id,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: 0,
  1616. Source: "手机端修改保存透后评估",
  1617. }
  1618. service.CreateAfterDialysisLog(afterDialysisLog)
  1619. redis := service.RedisClient()
  1620. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1621. redis.Set(keyTwo, "", time.Second)
  1622. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1623. //清空key 值
  1624. redis.Set(key, "", time.Second)
  1625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1626. redis.Set(keyOne, "", time.Second)
  1627. if err == nil {
  1628. c.ServeSuccessJSON(map[string]interface{}{
  1629. "assessmentAfterDislysis": assessmentAfterDislysis,
  1630. })
  1631. return
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func (c *DialysisAPIController) PostDialysisPrescription() {
  1637. id, _ := c.GetInt64("patient", 0)
  1638. recordDateStr := c.GetString("record_date")
  1639. if id <= 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. adminUserInfo := c.GetMobileAdminUserInfo()
  1644. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1645. if patient.ID == 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1647. return
  1648. }
  1649. if len(recordDateStr) == 0 {
  1650. recordDateStr = time.Now().Format("2006-01-02")
  1651. }
  1652. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1653. if parseDateErr != nil {
  1654. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. mode_id, _ := c.GetInt64("mode_id", 0)
  1659. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1660. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1661. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1662. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1663. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1664. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1665. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1673. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1674. kalium, _ := c.GetFloat("kalium", 0)
  1675. sodium, _ := c.GetFloat("sodium", 0)
  1676. calcium, _ := c.GetFloat("calcium", 0)
  1677. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1678. glucose, _ := c.GetFloat("glucose", 0)
  1679. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1683. conductivity, _ := c.GetFloat("conductivity", 0)
  1684. remark := c.GetString("remark")
  1685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1691. special_medicine_other := c.GetString("special_medicine_other")
  1692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1694. blood_access, _ := c.GetInt64("blood_access", 0)
  1695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1696. body_fluid_other := c.GetString("body_fluid_other")
  1697. niprocart, _ := c.GetInt64("niprocart", 0)
  1698. jms, _ := c.GetInt64("jms", 0)
  1699. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1700. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1701. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1702. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1703. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1704. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1705. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1706. injector, _ := c.GetInt64("injector", 0)
  1707. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1708. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1709. safe_package, _ := c.GetInt64("package", 0)
  1710. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1711. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1714. blood := c.GetString("blood")
  1715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1718. displace_speed := c.GetString("displace_speed")
  1719. illness, _ := c.GetInt64("illness")
  1720. amylaceum := c.GetString("amylaceum")
  1721. single_time := c.GetString("single_time")
  1722. single_water := c.GetString("single_water")
  1723. replacement_flow := c.GetString("replacement_flow")
  1724. plasma_separator := c.GetString("plasma_separator")
  1725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1727. oxygen_flow := c.GetString("oxygen_flow")
  1728. oxygen_time := c.GetString("oxygen_time")
  1729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1731. puncture_needle := c.GetString("puncture_needle")
  1732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1733. epo := c.GetString("epo")
  1734. epo_count, _ := c.GetFloat("epo_count", 0)
  1735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1736. admin_user_id, _ := c.GetInt64("admin_user_id")
  1737. is_water := c.GetString("is_water")
  1738. var is_war int64
  1739. if is_water == "是" {
  1740. is_war = 1
  1741. }
  1742. if is_water == "否" {
  1743. is_war = 2
  1744. }
  1745. if is_water == "请选择" {
  1746. is_war = 0
  1747. }
  1748. drhy_water := c.GetString("drhy_water")
  1749. dry_water_hour := c.GetString("dry_water_hour")
  1750. water_machine := c.GetString("water_machine")
  1751. add_amount, _ := c.GetFloat("add_amount")
  1752. reduce_amount, _ := c.GetFloat("reduce_amount")
  1753. dialysis_remark := c.GetString("dialysis_remark")
  1754. prescribing_number, _ := c.GetFloat("prescribing_number")
  1755. prescription_sodium := c.GetString("prescription_sodium")
  1756. start_sodium := c.GetString("start_sodium")
  1757. sodium_curve := c.GetString("sodium_curve")
  1758. treatment_remark := c.GetString("treatment_remark")
  1759. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1760. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1761. prescription_water, _ := c.GetFloat("prescription_water")
  1762. dialysis_strainer := c.GetString("dialysis_strainer")
  1763. chaptalization := c.GetString("chaptalization")
  1764. washing_time := c.GetString("washing_time")
  1765. warsh_count := c.GetString("warsh_count")
  1766. blood_access_part_id := c.GetString("blood_access_part_id")
  1767. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1768. dialyzate := c.GetString("dialyzate")
  1769. first_super := c.GetString("first_super")
  1770. sterilization_water := c.GetString("sterilization_water")
  1771. five_glucose := c.GetString("five_glucose")
  1772. fifty_glucose := c.GetString("fifty_glucose")
  1773. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  1774. calcium_gluconate := c.GetString("calcium_gluconate")
  1775. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  1776. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  1777. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  1778. new_sty := c.GetString("new_sty")
  1779. var first_sup int64
  1780. if first_super == "是" {
  1781. first_sup = 1
  1782. }
  1783. if first_super == "否" {
  1784. first_sup = 2
  1785. }
  1786. if first_super == "请选择" {
  1787. first_sup = 0
  1788. }
  1789. is_sequential := c.GetString("is_sequential")
  1790. var is_sequent int64
  1791. if is_sequential == "是" {
  1792. is_sequent = 1
  1793. }
  1794. if is_sequential == "否" {
  1795. is_sequent = 2
  1796. }
  1797. if is_sequential == "请选择" {
  1798. is_sequent = 0
  1799. }
  1800. conduct := c.GetString("conduct")
  1801. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1802. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1803. //
  1804. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1805. // if appRole.UserType == 3 {
  1806. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1807. // if getPermissionErr != nil {
  1808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1809. // return
  1810. // } else if headNursePermission == nil {
  1811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1812. // return
  1813. // }
  1814. // }
  1815. //}
  1816. // 查询信息规挡的设置天数
  1817. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1818. if infor.ID > 0 && infor.WeekDay > 0 {
  1819. var cha_time int64
  1820. timeNowStr := time.Now().Format("2006-01-02")
  1821. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1822. //今日的日期减去设置的日期
  1823. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1824. if cha_time >= recordDate.Unix() {
  1825. //查询审核是否允许
  1826. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1827. //申请状态不允许的情况 拒绝修改
  1828. if infor.ApplicationStatus != 1 {
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1830. return
  1831. }
  1832. }
  1833. }
  1834. if mode_id > 0 {
  1835. var str string
  1836. //查找该机构用的是什么透析器
  1837. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1838. if filedConfig.ID > 0 {
  1839. str = dialyzerPerfusionApparatus
  1840. } else {
  1841. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1842. }
  1843. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1844. }
  1845. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1846. var dialysis_dialyszers_id int64
  1847. var dialysis_strainer_id int64
  1848. var dialysis_irrigation_id int64
  1849. if len(goodList) > 0 {
  1850. for _, item := range goodList {
  1851. if item.SpecificationName == dialysis_dialyszers {
  1852. dialysis_dialyszers_id = item.ID
  1853. }
  1854. if item.SpecificationName == dialysis_irrigation {
  1855. dialysis_irrigation_id = item.ID
  1856. }
  1857. if item.SpecificationName == dialysis_strainer {
  1858. dialysis_strainer_id = item.ID
  1859. }
  1860. }
  1861. }
  1862. //TODO 需要根据角色去判断
  1863. prescription := models.DialysisPrescription{
  1864. UserOrgId: adminUserInfo.Org.Id,
  1865. PatientId: id,
  1866. RecordDate: recordDate.Unix(),
  1867. ModeId: mode_id,
  1868. DialysisDuration: dialysis_duration,
  1869. Dialyzer: dialyzer,
  1870. PerfusionApparatus: perfusion_apparatus,
  1871. BloodFlowVolume: blood_flow_volume,
  1872. DewaterAmount: dewater_amount,
  1873. DisplaceLiqui: displace_liqui,
  1874. ReplacementWay: replacement_way,
  1875. Anticoagulant: anticoagulant,
  1876. AnticoagulantShouji: anticoagulant_shouji,
  1877. AnticoagulantWeichi: anticoagulant_weichi,
  1878. AnticoagulantZongliang: anticoagulant_zongliang,
  1879. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1880. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1881. Kalium: kalium,
  1882. Sodium: sodium,
  1883. Calcium: calcium,
  1884. Bicarbonate: bicarbonate,
  1885. Glucose: glucose,
  1886. // DryWeight: dry_weight,
  1887. DialysateFlow: dialysate_flow,
  1888. DialysateTemperature: dialysate_temperature,
  1889. // PrescriptionDoctor: prescription_doctor,
  1890. ReplacementTotal: replacement_total,
  1891. Conductivity: conductivity,
  1892. Remark: remark,
  1893. Status: 1,
  1894. CreatedTime: time.Now().Unix(),
  1895. UpdatedTime: time.Now().Unix(),
  1896. DialysisDurationMinute: dialysisDurationMinute,
  1897. DialysisDurationHour: dialysisDurationHour,
  1898. TargetUltrafiltration: targetUltrafiltration,
  1899. DialysateFormulation: dialysateFormulation,
  1900. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1901. BodyFluid: body_fluid,
  1902. SpecialMedicine: special_medicine,
  1903. SpecialMedicineOther: special_medicine_other,
  1904. DisplaceLiquiPart: displace_liqui_part,
  1905. DisplaceLiquiValue: displace_liqui_value,
  1906. BloodAccess: blood_access,
  1907. Ultrafiltration: ultrafiltration,
  1908. BodyFluidOther: body_fluid_other,
  1909. Niprocart: niprocart,
  1910. Jms: jms,
  1911. FistulaNeedleSet: fistula_needle_set,
  1912. FistulaNeedleSet16: fistula_needle_set_16,
  1913. Hemoperfusion: hemoperfusion,
  1914. DialyserSterilised: dialyser_sterilised,
  1915. Filtryzer: filtryzer,
  1916. Dialyzers: dialyzers,
  1917. Injector: injector,
  1918. Bloodlines: bloodlines,
  1919. TubingHemodialysis: tubing_hemodialysis,
  1920. Package: safe_package,
  1921. ALiquid: a_liquid,
  1922. TargetKtv: target_ktv,
  1923. PreImpulse: pre_impulse,
  1924. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1925. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1926. Blood: blood,
  1927. DialysisDialyszers: dialysis_dialyszers,
  1928. DialysisIrrigation: dialysis_irrigation,
  1929. AntioxidantCommodityName: antioxidant_commodity_name,
  1930. DisplaceSpeed: displace_speed,
  1931. Illness: illness,
  1932. Amylaceum: amylaceum,
  1933. SingleTime: single_time,
  1934. SingleWater: single_water,
  1935. ReplacementFlow: replacement_flow,
  1936. PlasmaSeparator: plasma_separator,
  1937. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1938. OxygenUptake: oxygen_uptake,
  1939. OxygenFlow: oxygen_flow,
  1940. OxygenTime: oxygen_time,
  1941. HemodialysisPipelines: hemodialysis_pipelines,
  1942. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1943. PunctureNeedle: puncture_needle,
  1944. PunctureNeedleCount: puncture_needle_count,
  1945. Epo: epo,
  1946. EpoCount: epo_count,
  1947. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1948. AdminUserId: admin_user_id,
  1949. IsWater: is_war,
  1950. DrhyWater: drhy_water,
  1951. DryWaterHour: dry_water_hour,
  1952. WaterMachine: water_machine,
  1953. AddAmount: add_amount,
  1954. ReduceAmount: reduce_amount,
  1955. DialysisRemark: dialysis_remark,
  1956. PrescribingNumber: prescribing_number,
  1957. StartSodium: start_sodium,
  1958. SodiumCurve: sodium_curve,
  1959. TreatmentRemark: treatment_remark,
  1960. PrescriptionSodium: prescription_sodium,
  1961. DialysisFluidFlow: dialysis_fluid_flow,
  1962. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1963. PrescriptionWater: prescription_water,
  1964. DialysisStrainer: dialysis_strainer,
  1965. Chaptalization: chaptalization,
  1966. WashingTime: washing_time,
  1967. WarshCount: warsh_count,
  1968. BloodAccessPartId: blood_access_part_id,
  1969. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1970. Dialyzate: dialyzate,
  1971. DialysisDialyszersId: dialysis_dialyszers_id,
  1972. DialysisIrrigationId: dialysis_irrigation_id,
  1973. DialysisStrainerId: dialysis_strainer_id,
  1974. FirstSuper: first_sup,
  1975. IsSequential: is_sequent,
  1976. Conduct: conduct,
  1977. SterilizationWater: sterilization_water,
  1978. FiveGlucose: five_glucose,
  1979. FiftyGlucose: fifty_glucose,
  1980. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  1981. CalciumGluconate: calcium_gluconate,
  1982. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  1983. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  1984. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  1985. NewSty: new_sty,
  1986. }
  1987. if prescription.ModeId != 13 {
  1988. prescription.SterilizationWater = ""
  1989. prescription.FiveGlucose = ""
  1990. prescription.FiftyGlucose = ""
  1991. prescription.MagnesiumSulfateInjection = ""
  1992. prescription.CalciumGluconate = ""
  1993. prescription.FivePotassiumChlorideInjection = ""
  1994. prescription.TenPotassiumChlorideInjection = ""
  1995. prescription.FiveSodiumBicarbonateInjection = ""
  1996. prescription.NewSty = ""
  1997. }
  1998. if adminUserInfo.Org.Id == 10721 {
  1999. if prescription.ModeId == 2 {
  2000. if prescription.ReplacementTotal == 0 {
  2001. prescription.ReplacementTotal = 15
  2002. }
  2003. }
  2004. }
  2005. //查询最近透析准备表里是否存在 透析器 灌流器
  2006. //
  2007. //splitStr := strings.Split(dialysis_dialyszers, ",")
  2008. //
  2009. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  2010. //
  2011. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  2012. //if len(mation)>0{
  2013. // for _, item := range splitStr {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. //
  2017. // //查询最近一次的透析器
  2018. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2019. //
  2020. // if errcode == gorm.ErrRecordNotFound{
  2021. // //插入数据
  2022. // prepare := models.DialysisBeforePrepare{
  2023. // UserOrgId: adminUserInfo.Org.Id,
  2024. // PatientId: id,
  2025. // RecordDate: recordDate.Unix(),
  2026. // GoodTypeId: it.GoodTypeId,
  2027. // GoodId: it.ID,
  2028. // Count: 1,
  2029. // Ctime: time.Now().Unix(),
  2030. // Creater: adminUserInfo.AdminUser.Id,
  2031. // Status:1,
  2032. //
  2033. // }
  2034. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2035. // fmt.Println("",errcode)
  2036. // }
  2037. // }
  2038. // }
  2039. //
  2040. // }
  2041. //
  2042. // for _, item := range splitIrrigation {
  2043. // for _,it := range mation{
  2044. // if(item == it.SpecificationName){
  2045. // //查询最近一次的透析器
  2046. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2047. // if errcode == gorm.ErrRecordNotFound{
  2048. // //插入数据
  2049. // prepare := models.DialysisBeforePrepare{
  2050. // UserOrgId: adminUserInfo.Org.Id,
  2051. // PatientId: id,
  2052. // RecordDate: recordDate.Unix(),
  2053. // GoodTypeId: it.GoodTypeId,
  2054. // GoodId: it.ID,
  2055. // Count: 1,
  2056. // Ctime: time.Now().Unix(),
  2057. // Creater: adminUserInfo.AdminUser.Id,
  2058. // Status:1,
  2059. //
  2060. // }
  2061. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2062. // fmt.Println(errcode)
  2063. // }
  2064. // }
  2065. // }
  2066. // }
  2067. //}
  2068. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2069. if dialysisPrescription.ID == 0 { //新增
  2070. if appRole.UserType == 2 || appRole.UserType == 1 {
  2071. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2072. }
  2073. prescription.Creater = adminUserInfo.AdminUser.Id
  2074. //针对河间咸得
  2075. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2076. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2077. prescription.DisplaceLiquiPart = 0
  2078. prescription.DisplaceLiquiValue = 0
  2079. }
  2080. }
  2081. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2082. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2083. }
  2084. err := service.AddSigleRecord(&prescription)
  2085. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2086. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2087. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2088. if len(monitorList) > 0 {
  2089. var ultrafiltration_rate float64
  2090. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2091. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2092. var replacement_rate float64
  2093. if adminUserInfo.Org.Id == 10721 {
  2094. //乘10 除10是为了保留一位小数
  2095. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2096. }
  2097. if adminUserInfo.Org.Id == 9478 {
  2098. //乘10 除10是为了保留一位小数
  2099. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2100. }
  2101. if adminUserInfo.Org.Id == 10766 {
  2102. //乘10 除10是为了保留一位小数
  2103. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2104. }
  2105. var firstOpeateTime = monitorList[0].OperateTime
  2106. for _, item := range monitorList {
  2107. //超滤率
  2108. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2109. //置换率
  2110. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2111. //超滤量
  2112. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2113. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2114. //置换量
  2115. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2116. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2117. }
  2118. }
  2119. }
  2120. //记录日志
  2121. byterequest, _ := json.Marshal(prescription)
  2122. prescriptionLog := models.XtDialysisPrescriptionLog{
  2123. UserOrgId: prescription.UserOrgId,
  2124. Ctime: time.Now().Unix(),
  2125. Mtime: 0,
  2126. ErrLog: string(byterequest),
  2127. AdminUserId: adminUserInfo.AdminUser.Id,
  2128. RecordDate: prescription.RecordDate,
  2129. PatientId: prescription.PatientId,
  2130. Source: "手机端新增保存处方",
  2131. Status: 1,
  2132. }
  2133. service.CreatePrescriptionLog(prescriptionLog)
  2134. finish := models.XtDialysisFinish{
  2135. IsFinish: 1,
  2136. UserOrgId: adminUserInfo.Org.Id,
  2137. Status: 1,
  2138. Ctime: time.Now().Unix(),
  2139. Mtime: 0,
  2140. Module: 1,
  2141. RecordDate: recordDate.Unix(),
  2142. Sourse: 1,
  2143. PatientId: id,
  2144. }
  2145. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2146. if dialysisFinish.ID == 0 {
  2147. service.CreateDialysisFinish(finish)
  2148. }
  2149. //长沙南雅医院,自动生成抗凝剂的临时处方
  2150. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2151. if prescribing_number == 0 {
  2152. prescribing_number = 1
  2153. }
  2154. if prescribing_number == 0 && id == 14682 {
  2155. prescribing_number = 2
  2156. }
  2157. if prescribing_number == 0 && id == 18560 {
  2158. prescribing_number = 2
  2159. }
  2160. advice := models.DoctorAdvice{
  2161. UserOrgId: adminUserInfo.Org.Id,
  2162. PatientId: id,
  2163. GroupNo: 0,
  2164. AdviceType: 2,
  2165. RecordDate: recordDate.Unix(),
  2166. AdviceDate: recordDate.Unix(),
  2167. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2168. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2169. AdviceDesc: "",
  2170. ReminderDate: 0,
  2171. SingleDose: anticoagulant_zongliang,
  2172. SingleDoseUnit: "iu",
  2173. DrugSpec: 0,
  2174. DrugSpecUnit: "",
  2175. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2176. PrescribingNumberUnit: "支",
  2177. DeliveryWay: "静脉注射",
  2178. ExecutionFrequency: "上机前",
  2179. AdviceDoctor: 0,
  2180. Status: 1,
  2181. CreatedTime: time.Now().Unix(),
  2182. UpdatedTime: time.Now().Unix(),
  2183. IsPrescription: 1,
  2184. ExecutionState: 2,
  2185. StopState: 2,
  2186. IsSettle: 2,
  2187. }
  2188. // 查询排班信息
  2189. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2190. if schedulePatient.ID > 0 {
  2191. if schedulePatient.ScheduleType == 1 {
  2192. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2193. }
  2194. if schedulePatient.ScheduleType == 2 {
  2195. advice.StartTime = recordDate.Unix() + 9*60*60
  2196. }
  2197. }
  2198. // 抗凝剂名称
  2199. switch anticoagulant {
  2200. case 1:
  2201. advice.AdviceName = "无肝素"
  2202. break
  2203. case 2:
  2204. advice.AdviceName = "普通肝素"
  2205. break
  2206. case 3:
  2207. advice.AdviceName = "低分子肝素"
  2208. break
  2209. case 4:
  2210. advice.AdviceName = "阿加曲班"
  2211. break
  2212. case 5:
  2213. advice.AdviceName = "枸橼酸钠"
  2214. break
  2215. case 6:
  2216. advice.AdviceName = "低分子肝素钙"
  2217. break
  2218. case 7:
  2219. advice.AdviceName = "低分子肝素钠"
  2220. break
  2221. case 8:
  2222. advice.AdviceName = "依诺肝素"
  2223. break
  2224. case 9:
  2225. advice.AdviceName = "达肝素"
  2226. break
  2227. case 10:
  2228. advice.AdviceName = "体外抗凝"
  2229. break
  2230. case 11:
  2231. advice.AdviceName = "那曲肝素"
  2232. break
  2233. case 12:
  2234. advice.AdviceName = "无抗凝剂"
  2235. break
  2236. }
  2237. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2238. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2239. advice.AdviceDoctor = appRole.AdminUserId
  2240. }
  2241. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2242. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2243. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2244. advice.AdviceName = "低分子肝素钠注射液"
  2245. // 修改患者临时医嘱里的抗凝剂医嘱
  2246. advice.ID = advicePrescription.ID
  2247. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2248. } else {
  2249. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2250. advice.AdviceName = "低分子肝素钠注射液"
  2251. // 新增患者临时医嘱里的抗凝剂医嘱
  2252. service.CreateDoctorAdvice(&advice)
  2253. }
  2254. }
  2255. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2256. redis := service.RedisClient()
  2257. defer redis.Close()
  2258. //清空key 值
  2259. redis.Set(key, "", time.Second)
  2260. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2261. redis.Set(keyOne, "", time.Second)
  2262. }
  2263. //获取key,清空redis
  2264. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2265. redis := service.RedisClient()
  2266. //清空key 值
  2267. redis.Set(key, "", time.Second)
  2268. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2269. //清空key 值
  2270. redis.Set(keyOne, "", time.Second)
  2271. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2272. //清空key 值
  2273. redis.Set(keyTwo, "", time.Second)
  2274. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2275. redis.Set(keySix, "", time.Second)
  2276. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2277. redis.Set(keySeven, "", time.Second)
  2278. if err == nil {
  2279. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2280. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2281. //清空key 值
  2282. redis.Set(keyThree, "", time.Second)
  2283. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2284. //清空key 值
  2285. redis.Set(keyFour, "", time.Second)
  2286. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2287. redis.Set(keyFive, "", time.Second)
  2288. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2289. redis.Set(keySix, "", time.Second)
  2290. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2291. redis.Set(keySeven, "", time.Second)
  2292. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2293. //清空key 值
  2294. redis.Set(keyOne, "", time.Second)
  2295. if updateErr != nil {
  2296. utils.ErrorLog("%v", updateErr)
  2297. }
  2298. defer redis.Close()
  2299. c.ServeSuccessJSON(map[string]interface{}{
  2300. "prescription": prescription,
  2301. })
  2302. }
  2303. } else { //修改
  2304. //if mode_id > 0 {
  2305. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2306. //}
  2307. //if template.TemplateId == 1 {
  2308. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2309. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2310. // if getPermissionErr != nil {
  2311. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2312. // return
  2313. // } else if headNursePermission == nil {
  2314. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2315. // return
  2316. // }
  2317. // }
  2318. //}
  2319. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2320. prescription.Modifier = adminUserInfo.AdminUser.Id
  2321. if appRole.UserType == 2 || appRole.UserType == 1 {
  2322. prescription_doctor := adminUserInfo.AdminUser.Id
  2323. prescription.PrescriptionDoctor = prescription_doctor
  2324. } else {
  2325. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2326. }
  2327. if dialysisPrescription.Creater == 0 { //体重称
  2328. prescription.Creater = adminUserInfo.AdminUser.Id
  2329. } else {
  2330. prescription.Creater = dialysisPrescription.Creater
  2331. if adminUserInfo.Org.Id == 9882 {
  2332. if appRole.UserType == 2 || appRole.UserType == 1 {
  2333. prescription_doctor := adminUserInfo.AdminUser.Id
  2334. prescription.PrescriptionDoctor = prescription_doctor
  2335. prescription.Creater = prescription_doctor
  2336. }
  2337. }
  2338. }
  2339. prescription.ID = dialysisPrescription.ID
  2340. if adminUserInfo.Org.Id == 10721 {
  2341. if prescription.ModeId == 2 {
  2342. if prescription.ReplacementTotal == 0 {
  2343. prescription.ReplacementTotal = 15
  2344. }
  2345. }
  2346. }
  2347. service.UpDateDialysisPrescription(&prescription)
  2348. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2349. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  2350. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2351. if len(monitorList) > 0 {
  2352. var ultrafiltration_rate float64
  2353. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2354. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2355. var replacement_rate float64
  2356. if adminUserInfo.Org.Id == 10721 {
  2357. //乘10 除10是为了保留一位小数
  2358. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2359. }
  2360. if adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  2361. //乘10 除10是为了保留一位小数
  2362. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  2363. }
  2364. var firstOpeateTime = monitorList[0].OperateTime
  2365. for _, item := range monitorList {
  2366. //超滤率
  2367. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2368. //置换率
  2369. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2370. //超滤量
  2371. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2372. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2373. //置换量
  2374. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2375. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2376. }
  2377. }
  2378. }
  2379. //记录日志
  2380. byterequest, _ := json.Marshal(prescription)
  2381. prescriptionLog := models.XtDialysisPrescriptionLog{
  2382. UserOrgId: prescription.UserOrgId,
  2383. Ctime: time.Now().Unix(),
  2384. Mtime: 0,
  2385. ErrLog: string(byterequest),
  2386. AdminUserId: adminUserInfo.AdminUser.Id,
  2387. RecordDate: prescription.RecordDate,
  2388. PatientId: prescription.PatientId,
  2389. Source: "手机端修改处方",
  2390. Status: 1,
  2391. }
  2392. service.CreatePrescriptionLog(prescriptionLog)
  2393. finish := models.XtDialysisFinish{
  2394. IsFinish: 1,
  2395. UserOrgId: adminUserInfo.Org.Id,
  2396. Status: 1,
  2397. Ctime: time.Now().Unix(),
  2398. Mtime: 0,
  2399. Module: 1,
  2400. RecordDate: recordDate.Unix(),
  2401. Sourse: 1,
  2402. PatientId: id,
  2403. }
  2404. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2405. if dialysisFinish.ID == 0 {
  2406. service.CreateDialysisFinish(finish)
  2407. }
  2408. //修改处方
  2409. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2410. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2411. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2412. if advicePrescription.ID > 0 {
  2413. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2414. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2415. redis := service.RedisClient()
  2416. defer redis.Close()
  2417. //清空key 值
  2418. redis.Set(key, "", time.Second)
  2419. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2420. redis.Set(keyOne, "", time.Second)
  2421. }
  2422. }
  2423. //获取key,清空redis
  2424. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2425. redis := service.RedisClient()
  2426. //清空key 值
  2427. redis.Set(key, "", time.Second)
  2428. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2429. //清空key 值
  2430. redis.Set(keyOne, "", time.Second)
  2431. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2432. redis.Set(keySix, "", time.Second)
  2433. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2434. redis.Set(keySeven, "", time.Second)
  2435. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2436. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2437. //清空key 值
  2438. redis.Set(keyTwoOne, "", time.Second)
  2439. defer redis.Close()
  2440. if updateErr != nil {
  2441. utils.ErrorLog("%v", updateErr)
  2442. }
  2443. c.ServeSuccessJSON(map[string]interface{}{
  2444. "prescription": prescription,
  2445. })
  2446. }
  2447. }
  2448. func (c *DialysisAPIController) Finish() {
  2449. id, _ := c.GetInt64("patient", 0)
  2450. recordDateStr := c.GetString("record_date")
  2451. nurseID, _ := c.GetInt64("nurse")
  2452. end_time := c.GetString("end_time")
  2453. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2454. internal_fistula := c.GetString("blood_access_internal_fistula")
  2455. catheter := c.GetString("catheter")
  2456. cruor := c.GetString("cruor")
  2457. mission := c.GetString("mission")
  2458. condenser := c.GetString("condenser")
  2459. if id <= 0 || nurseID <= 0 {
  2460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2461. return
  2462. }
  2463. adminUserInfo := c.GetMobileAdminUserInfo()
  2464. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2465. if patient.ID == 0 {
  2466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2467. return
  2468. }
  2469. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2470. if getNurseErr != nil {
  2471. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. } else if nurse == nil {
  2475. c.ErrorLog("护士不存在")
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. if len(recordDateStr) == 0 {
  2480. recordDateStr = time.Now().Format("2006-01-02")
  2481. }
  2482. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2483. if parseDateErr != nil {
  2484. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2486. return
  2487. }
  2488. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2489. if parseEndDateErr != nil {
  2490. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2492. return
  2493. }
  2494. // 查询信息规挡的设置天数
  2495. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2496. if infor.ID > 0 && infor.WeekDay > 0 {
  2497. var cha_time int64
  2498. timeNowStr := time.Now().Format("2006-01-02")
  2499. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2500. //今日的日期减去设置的日期
  2501. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2502. if cha_time >= recordDate.Unix() {
  2503. //查询审核是否允许
  2504. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2505. //申请状态不允许的情况 拒绝修改
  2506. if infor.ApplicationStatus != 1 {
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2508. return
  2509. }
  2510. }
  2511. }
  2512. //now := time.Now()
  2513. //year, month, day := now.Date()
  2514. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2515. //todayTimeStamp := today_time.Unix()
  2516. // 获取当天的第一条透析纪录
  2517. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2518. if getMonitorRecordsErr != nil {
  2519. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2521. return
  2522. }
  2523. // 获取当前的最后一条透析纪录
  2524. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2525. if getMonitorRecordsErr != nil {
  2526. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2528. return
  2529. }
  2530. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2531. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2532. if getAADErr != nil {
  2533. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2535. return
  2536. }
  2537. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2538. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2539. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2540. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2541. if assessmentAfterDislysis != nil {
  2542. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2543. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2544. } else {
  2545. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2546. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2547. tempassessmentAfterDislysis.Status = 1
  2548. tempassessmentAfterDislysis.PatientId = id
  2549. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2550. }
  2551. //长沙南雅
  2552. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2553. //获取最后一条透析处方数据
  2554. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2555. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2556. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2557. }
  2558. if dialysisOrder.Stage == 1 {
  2559. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2560. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2561. fmt.Println(value)
  2562. a, b := math.Modf(value)
  2563. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2564. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2565. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2566. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2567. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2568. }
  2569. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2570. //var num1 int64
  2571. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2572. //fmt.Println(num1)
  2573. //sub := float64(num1 / 3600)
  2574. //fmt.Println(sub)
  2575. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2576. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2577. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2578. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2579. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2580. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2581. if adminUserInfo.Org.Id != 10375 {
  2582. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2583. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2584. }
  2585. if adminUserInfo.Org.Id == 10766 {
  2586. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2587. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2588. }
  2589. if adminUserInfo.Org.Id != 10445 {
  2590. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2591. }
  2592. //北方营口医院
  2593. if adminUserInfo.Org.Id == 10445 {
  2594. //获取最后一条透析处方数据
  2595. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2596. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2597. } else {
  2598. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2599. }
  2600. //新化博翔
  2601. if adminUserInfo.Org.Id == 10447 {
  2602. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2603. }
  2604. //阳春
  2605. if adminUserInfo.Org.Id == 10485 {
  2606. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2607. }
  2608. if adminUserInfo.Org.Id == 10551 {
  2609. //获取最后一条透析处方数据
  2610. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2611. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2612. }
  2613. if adminUserInfo.Org.Id == 10580 {
  2614. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2615. }
  2616. if adminUserInfo.Org.Id == 10612 {
  2617. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2618. }
  2619. //孝康
  2620. if adminUserInfo.Org.Id == 10693 {
  2621. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2622. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2623. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2624. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2625. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2626. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2627. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2628. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2629. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2630. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2631. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2632. }
  2633. if adminUserInfo.Org.Id == 10721 {
  2634. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2635. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2636. }
  2637. if adminUserInfo.Org.Id == 10697 {
  2638. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2639. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2640. lastWeightAfter.LastAfterWeight = floatAfeter
  2641. }
  2642. if adminUserInfo.Org.Id == 10624 {
  2643. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2644. }
  2645. }
  2646. 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 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10766 {
  2647. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2648. if adminUserInfo.Org.Id != 10702 {
  2649. if evaluation.SystolicBloodPressure == 0 {
  2650. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2651. if adminUserInfo.Org.Id == 10693 {
  2652. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2653. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2654. }
  2655. pre := models.PredialysisEvaluation{
  2656. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2657. }
  2658. fmt.Println("prew", pre)
  2659. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2661. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2662. redis := service.RedisClient()
  2663. redis.Set(key, "", time.Second)
  2664. redis.Set(keyOne, "", time.Second)
  2665. defer redis.Close()
  2666. fmt.Println(getNurseErr)
  2667. }
  2668. }
  2669. if adminUserInfo.Org.Id != 10702 {
  2670. if evaluation.DiastolicBloodPressure == 0 {
  2671. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2672. if adminUserInfo.Org.Id == 10693 {
  2673. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2674. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2675. }
  2676. pres := models.PredialysisEvaluation{
  2677. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2678. }
  2679. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2680. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2681. redis := service.RedisClient()
  2682. redis.Set(key, "", time.Second)
  2683. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2684. redis.Set(keyOne, "", time.Second)
  2685. defer redis.Close()
  2686. fmt.Println(getNurseErr)
  2687. }
  2688. }
  2689. if adminUserInfo.Org.Id != 10702 {
  2690. if evaluation.PulseFrequency == 0 {
  2691. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2692. if adminUserInfo.Org.Id == 10693 {
  2693. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2694. evaluation.PulseFrequency = pulseFrequency
  2695. }
  2696. press := models.PredialysisEvaluation{
  2697. PulseFrequency: evaluation.PulseFrequency,
  2698. }
  2699. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2701. redis := service.RedisClient()
  2702. redis.Set(key, "", time.Second)
  2703. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2704. redis.Set(keyOne, "", time.Second)
  2705. defer redis.Close()
  2706. fmt.Println(getNurseErr)
  2707. }
  2708. }
  2709. if evaluation.Temperature == 0 {
  2710. evaluation.Temperature = fmonitorRecords.Temperature
  2711. press := models.PredialysisEvaluation{
  2712. Temperature: evaluation.Temperature,
  2713. }
  2714. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2715. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2716. redis := service.RedisClient()
  2717. redis.Set(key, "", time.Second)
  2718. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2719. redis.Set(keyOne, "", time.Second)
  2720. defer redis.Close()
  2721. fmt.Println(getNurseErr)
  2722. }
  2723. }
  2724. if adminUserInfo.Org.Id == 9583 {
  2725. //获取透析处方的最后一条数据
  2726. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2727. if diaerr != nil {
  2728. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. }
  2732. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2733. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2734. }
  2735. }
  2736. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2737. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2738. }
  2739. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2740. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2741. }
  2742. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2743. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2744. }
  2745. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2746. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2747. }
  2748. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2749. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2750. }
  2751. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2752. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2753. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2754. }
  2755. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2756. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2757. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2758. }
  2759. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2760. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2761. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2762. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2763. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2764. }
  2765. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2766. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2767. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2768. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2769. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2770. }
  2771. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10766 {
  2772. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2773. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2774. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2775. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2776. }
  2777. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2778. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2779. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2780. }
  2781. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2782. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2783. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2784. }
  2785. if lastAssessmentAfterDislysis != nil {
  2786. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2787. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2788. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2789. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2790. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2791. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2792. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2793. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2794. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2795. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2796. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2797. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2798. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2799. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2800. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2801. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2802. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2803. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2804. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2805. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2806. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2807. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2808. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2809. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2810. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2811. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2812. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2813. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2814. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2815. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2816. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2817. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2818. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2819. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2820. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2821. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2822. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2823. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2824. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2825. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2826. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2827. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2828. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2829. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2830. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2831. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2832. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2833. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2834. if tempassessmentAfterDislysis.PatientId == 18695 {
  2835. tempassessmentAfterDislysis.ActualDisplacement = 0
  2836. }
  2837. if adminUserInfo.Org.Id != 10375 {
  2838. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2839. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2840. }
  2841. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2842. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2843. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2844. }
  2845. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2846. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2847. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2848. }
  2849. }
  2850. finish := models.XtDialysisFinish{
  2851. IsFinish: 1,
  2852. UserOrgId: adminUserInfo.Org.Id,
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Mtime: 0,
  2856. Module: 9,
  2857. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2858. Sourse: 1,
  2859. PatientId: tempassessmentAfterDislysis.PatientId,
  2860. }
  2861. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2862. if dialysisFinish.ID == 0 {
  2863. service.CreateDialysisFinish(finish)
  2864. }
  2865. //孝康
  2866. if adminUserInfo.Org.Id == 10693 {
  2867. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2868. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2869. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2870. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2871. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2872. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2873. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2874. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2875. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2876. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2877. }
  2878. if adminUserInfo.Org.Id == 10697 {
  2879. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2880. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2881. lastWeightAfter.LastAfterWeight = floatAfeter
  2882. }
  2883. if adminUserInfo.Org.Id == 10721 {
  2884. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2885. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2886. }
  2887. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2888. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2889. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2890. redis := service.RedisClient()
  2891. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2892. redis.Set(keyOne, "", time.Second)
  2893. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2894. redis.Set(keyTwo, "", time.Second)
  2895. defer redis.Close()
  2896. //清空key 值
  2897. redis.Set(key, "", time.Second)
  2898. if err != nil {
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2900. return
  2901. }
  2902. if dialysisOrder == nil {
  2903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2904. return
  2905. }
  2906. if dialysisOrder.Stage == 2 {
  2907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2908. return
  2909. }
  2910. if dialysisOrder.Stage == 1 {
  2911. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2912. finish := models.XtDialysisFinish{
  2913. IsFinish: 1,
  2914. UserOrgId: adminUserInfo.Org.Id,
  2915. Status: 1,
  2916. Ctime: time.Now().Unix(),
  2917. Mtime: 0,
  2918. Module: 8,
  2919. RecordDate: recordDate.Unix(),
  2920. Sourse: 1,
  2921. PatientId: id,
  2922. }
  2923. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2924. if dialysisFinish.ID == 0 {
  2925. service.CreateDialysisFinish(finish)
  2926. }
  2927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2928. redis := service.RedisClient()
  2929. defer redis.Close()
  2930. //清空key 值
  2931. redis.Set(key, "", time.Second)
  2932. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2933. redis.Set(keyOne, "", time.Second)
  2934. //结束时候透析次数加1
  2935. service.UpdateSolutionByPatientId(id)
  2936. //下机完自动消毒,针对长沙南雅
  2937. if dialysisOrder.Stage == 1 {
  2938. 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 {
  2939. //根据床位号获取设备型号
  2940. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2941. //查询使用消毒最后一条消毒记录
  2942. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2943. fmt.Println("err", err)
  2944. if err == gorm.ErrRecordNotFound {
  2945. //查找排班
  2946. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2947. //查询改设备是否有消毒计划
  2948. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2949. //根据床位号获取设备id
  2950. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2951. //查询病人信息
  2952. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2953. var con = ""
  2954. if patients.IsInfectious == 0 {
  2955. con = ""
  2956. }
  2957. if patients.IsInfectious == 1 {
  2958. con = "无"
  2959. }
  2960. if patients.IsInfectious == 2 {
  2961. con = "有"
  2962. }
  2963. if errcode == nil {
  2964. var end_time int64
  2965. end_time = endDate.Unix() + plan.DisinfecTime*60
  2966. //新增消毒
  2967. information := models.DeviceInformation{
  2968. Date: dialysisOrder.DialysisDate,
  2969. Zone: dialysisOrder.ZoneId,
  2970. Class: dialysisOrder.SchedualType,
  2971. BedNumber: dialysisOrder.BedID,
  2972. PatientId: dialysisOrder.PatientId,
  2973. DialysisMode: scheduleByPatient.ModeId,
  2974. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2975. Disinfection: 1,
  2976. DialysisConcentration: 1,
  2977. DisinfectionStatus: 1,
  2978. Move: 1,
  2979. UserOrgId: dialysisOrder.UserOrgId,
  2980. DisinfectType: plan.Way,
  2981. DisinfectantType: plan.MachineDisinfectant,
  2982. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2983. Disinfectant: plan.Disinfectant,
  2984. Ctime: time.Now().Unix(),
  2985. Status: 1,
  2986. SignName: nurseID,
  2987. EquimentId: addmacher.ID,
  2988. DisinfectionResidue: 2,
  2989. Bed: addmacher.BedNumber,
  2990. StartTime: dialysisOrder.StartTime,
  2991. EndTime: dialysisOrder.EndTime,
  2992. Contagion: con,
  2993. WeightLoss: 0,
  2994. Hyperfiltratio: 0,
  2995. DialysisHour: "",
  2996. MachineRun: 1,
  2997. DisinfecStartime: endDate.Unix(),
  2998. DisinfecEndtime: end_time,
  2999. }
  3000. err := service.CreateInformationTwo(&information)
  3001. fmt.Println("报错", err)
  3002. }
  3003. }
  3004. }
  3005. }
  3006. dialysisOrder.Stage = 2
  3007. dialysisOrder.FinishNurse = nurseID
  3008. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  3009. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  3010. dialysisOrder.EndTime = endDate.Unix()
  3011. // 长沙南雅需求
  3012. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  3013. //获取最后1条监测的数据
  3014. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3015. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  3016. var accumulatedBloodVolume float64
  3017. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  3018. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  3019. fmt.Println(err)
  3020. // 查询未执行的医嘱
  3021. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  3022. for _, item := range doctorAdvice {
  3023. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  3024. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  3025. redis := service.RedisClient()
  3026. //清空key 值
  3027. redis.Set(key, "", time.Second)
  3028. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  3029. redis.Set(keyTwo, "", time.Second)
  3030. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3031. redis.Set(keyThree, "", time.Second)
  3032. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  3033. theTime := toTime.Format("2006-01-02")
  3034. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3035. redis.Set(keyFour, "", time.Second)
  3036. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3037. redis.Set(keyFive, "", time.Second)
  3038. defer redis.Close()
  3039. }
  3040. }
  3041. go func() {
  3042. ssoDomain := beego.AppConfig.String("call_domain")
  3043. api := ssoDomain + "/index/downpatient"
  3044. values := make(url.Values)
  3045. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  3046. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3047. values.Set("patient_id", strconv.FormatInt(id, 10))
  3048. http.PostForm(api, values)
  3049. }()
  3050. if err == nil {
  3051. c.ServeSuccessJSON(map[string]interface{}{
  3052. "dialysisOrder": dialysisOrder,
  3053. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  3054. })
  3055. } else {
  3056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3057. }
  3058. }
  3059. //查找是否开启配置
  3060. //orderSetting, _ := service.GetDialysisOrderSetting(adminUserInfo.Org.Id)
  3061. ////开启下机扣减
  3062. //if orderSetting.IsOpen == 1 {
  3063. //
  3064. // //查询今日患者排班的模式
  3065. // db := service.XTWriteDB()
  3066. // // 开始外部循环的事务
  3067. // tx := db.Begin()
  3068. // // 在函数结束时处理事务回滚
  3069. // defer func() {
  3070. // if r := recover(); r != nil {
  3071. // tx.Rollback()
  3072. // }
  3073. // }()
  3074. //
  3075. // schedule, _ := service.GetDialysisOrderSchedule(id, recordDate.Unix(), adminUserInfo.Org.Id, tx)
  3076. //
  3077. // if schedule.ModeId == 1 {
  3078. // //扣减库存
  3079. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3080. //
  3081. // patient, _ := service.GetSfPatientById(tx, id)
  3082. // var over_count int64
  3083. // if schedule.ModeId == 1 {
  3084. // over_count = patient.HdCount
  3085. // }
  3086. // if schedule.ModeId == 2 {
  3087. // over_count = patient.HdfCount
  3088. // }
  3089. //
  3090. // if schedule.ModeId == 3 {
  3091. // over_count = patient.HdhpCount
  3092. // }
  3093. // if schedule.ModeId == 4 {
  3094. // over_count = patient.HpCount
  3095. // }
  3096. // if schedule.ModeId == 5 {
  3097. // over_count = patient.OtherCount
  3098. // }
  3099. // patientCountFlow := models.SfPatientCountFlow{
  3100. // PatientId: id,
  3101. // ModeId: schedule.ModeId,
  3102. // Count: 1,
  3103. // Status: 1,
  3104. // Ctime: time.Now().Unix(),
  3105. // Mtime: time.Now().Unix(),
  3106. // RecordDate: recordDate.Unix(),
  3107. // UserOrgId: adminUserInfo.Org.Id,
  3108. // Creater: adminUserInfo.AdminUser.Id,
  3109. // IsType: 1,
  3110. // OverCount: over_count,
  3111. // WarehouseOutId: 0,
  3112. // }
  3113. //
  3114. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3115. // }
  3116. //
  3117. // if schedule.ModeId == 2 {
  3118. //
  3119. // //扣减库存
  3120. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3121. //
  3122. // patient, _ := service.GetSfPatientById(tx, id)
  3123. // var over_count int64
  3124. // if schedule.ModeId == 1 {
  3125. // over_count = patient.HdCount
  3126. // }
  3127. // if schedule.ModeId == 2 {
  3128. // over_count = patient.HdfCount
  3129. // }
  3130. //
  3131. // if schedule.ModeId == 3 {
  3132. // over_count = patient.HdhpCount
  3133. // }
  3134. // if schedule.ModeId == 4 {
  3135. // over_count = patient.HpCount
  3136. // }
  3137. // if schedule.ModeId == 5 {
  3138. // over_count = patient.OtherCount
  3139. // }
  3140. // patientCountFlow := models.SfPatientCountFlow{
  3141. // PatientId: id,
  3142. // ModeId: schedule.ModeId,
  3143. // Count: 1,
  3144. // Status: 1,
  3145. // Ctime: time.Now().Unix(),
  3146. // Mtime: time.Now().Unix(),
  3147. // RecordDate: recordDate.Unix(),
  3148. // UserOrgId: adminUserInfo.Org.Id,
  3149. // Creater: adminUserInfo.AdminUser.Id,
  3150. // IsType: 2,
  3151. // OverCount: over_count,
  3152. // WarehouseOutId: 0,
  3153. // }
  3154. //
  3155. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3156. // }
  3157. //
  3158. // if schedule.ModeId == 3 {
  3159. //
  3160. // //扣减库存
  3161. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3162. //
  3163. // patient, _ := service.GetSfPatientById(tx, id)
  3164. // var over_count int64
  3165. // if schedule.ModeId == 1 {
  3166. // over_count = patient.HdCount
  3167. // }
  3168. // if schedule.ModeId == 2 {
  3169. // over_count = patient.HdfCount
  3170. // }
  3171. //
  3172. // if schedule.ModeId == 3 {
  3173. // over_count = patient.HdhpCount
  3174. // }
  3175. // if schedule.ModeId == 4 {
  3176. // over_count = patient.HpCount
  3177. // }
  3178. // if schedule.ModeId == 5 {
  3179. // over_count = patient.OtherCount
  3180. // }
  3181. // patientCountFlow := models.SfPatientCountFlow{
  3182. // PatientId: id,
  3183. // ModeId: schedule.ModeId,
  3184. // Count: 1,
  3185. // Status: 1,
  3186. // Ctime: time.Now().Unix(),
  3187. // Mtime: time.Now().Unix(),
  3188. // RecordDate: recordDate.Unix(),
  3189. // UserOrgId: adminUserInfo.Org.Id,
  3190. // Creater: adminUserInfo.AdminUser.Id,
  3191. // IsType: 3,
  3192. // OverCount: over_count,
  3193. // WarehouseOutId: 0,
  3194. // }
  3195. //
  3196. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3197. // }
  3198. // if schedule.ModeId == 4 {
  3199. //
  3200. // //扣减库存
  3201. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3202. //
  3203. // patient, _ := service.GetSfPatientById(tx, id)
  3204. // var over_count int64
  3205. // if schedule.ModeId == 1 {
  3206. // over_count = patient.HdCount
  3207. // }
  3208. // if schedule.ModeId == 2 {
  3209. // over_count = patient.HdfCount
  3210. // }
  3211. //
  3212. // if schedule.ModeId == 3 {
  3213. // over_count = patient.HdhpCount
  3214. // }
  3215. // if schedule.ModeId == 4 {
  3216. // over_count = patient.HpCount
  3217. // }
  3218. // if schedule.ModeId == 5 {
  3219. // over_count = patient.OtherCount
  3220. // }
  3221. // patientCountFlow := models.SfPatientCountFlow{
  3222. // PatientId: id,
  3223. // ModeId: schedule.ModeId,
  3224. // Count: 1,
  3225. // Status: 1,
  3226. // Ctime: time.Now().Unix(),
  3227. // Mtime: time.Now().Unix(),
  3228. // RecordDate: recordDate.Unix(),
  3229. // UserOrgId: adminUserInfo.Org.Id,
  3230. // Creater: adminUserInfo.AdminUser.Id,
  3231. // IsType: 4,
  3232. // OverCount: over_count,
  3233. // WarehouseOutId: 0,
  3234. // }
  3235. //
  3236. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3237. // }
  3238. // if schedule.ModeId != 1 && schedule.ModeId != 2 && schedule.ModeId != 3 && schedule.ModeId != 4 {
  3239. //
  3240. // //扣减库存
  3241. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3242. //
  3243. // patient, _ := service.GetSfPatientById(tx, id)
  3244. // var over_count int64
  3245. // if schedule.ModeId == 1 {
  3246. // over_count = patient.HdCount
  3247. // }
  3248. // if schedule.ModeId == 2 {
  3249. // over_count = patient.HdfCount
  3250. // }
  3251. //
  3252. // if schedule.ModeId == 3 {
  3253. // over_count = patient.HdhpCount
  3254. // }
  3255. // if schedule.ModeId == 4 {
  3256. // over_count = patient.HpCount
  3257. // }
  3258. // if schedule.ModeId == 5 {
  3259. // over_count = patient.OtherCount
  3260. // }
  3261. // patientCountFlow := models.SfPatientCountFlow{
  3262. // PatientId: id,
  3263. // ModeId: schedule.ModeId,
  3264. // Count: 1,
  3265. // Status: 1,
  3266. // Ctime: time.Now().Unix(),
  3267. // Mtime: time.Now().Unix(),
  3268. // RecordDate: recordDate.Unix(),
  3269. // UserOrgId: adminUserInfo.Org.Id,
  3270. // Creater: adminUserInfo.AdminUser.Id,
  3271. // IsType: 5,
  3272. // OverCount: over_count,
  3273. // WarehouseOutId: 0,
  3274. // }
  3275. //
  3276. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3277. // }
  3278. //
  3279. // tx.Commit()
  3280. // return
  3281. //}
  3282. }
  3283. func (c *DialysisAPIController) GetAllZone() {
  3284. adminUserInfo := c.GetMobileAdminUserInfo()
  3285. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3286. if err == nil {
  3287. c.ServeSuccessJSON(map[string]interface{}{
  3288. "zone": zone,
  3289. })
  3290. }
  3291. }
  3292. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3293. adminUserInfo := c.GetMobileAdminUserInfo()
  3294. page, _ := c.GetInt64("page", 1)
  3295. limit, _ := c.GetInt64("limit", 10)
  3296. schedulType, _ := c.GetInt64("schedul_type", 0)
  3297. startTime, _ := c.GetInt64("schedul_time", 0)
  3298. partitionType, _ := c.GetInt64("partition_type", 0)
  3299. keywords := c.GetString("keywords")
  3300. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3301. if err == nil {
  3302. c.ServeSuccessJSON(map[string]interface{}{
  3303. "schedule": dialysisSchedule,
  3304. })
  3305. }
  3306. return
  3307. }
  3308. // /m/api/dialysis/start [post]
  3309. // @param patient_id:int
  3310. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3311. // @param nurse:int 上机护士
  3312. // @param bed:int 床位号
  3313. func (this *DialysisAPIController) StartDialysis() {
  3314. patientID, _ := this.GetInt64("patient_id")
  3315. recordDateStr := this.GetString("record_date")
  3316. nurseID, _ := this.GetInt64("start_nurse")
  3317. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3318. blood_drawing, _ := this.GetInt64("blood_drawing")
  3319. schedual_type, _ := this.GetInt64("schedual_type")
  3320. bedID, _ := this.GetInt64("bed")
  3321. start_time := this.GetString("start_time")
  3322. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3323. change_nurse, _ := this.GetInt64("change_nurse")
  3324. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3325. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3326. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3327. puncture_needle := this.GetString("puncture_needle")
  3328. puncture_way := this.GetString("puncture_way")
  3329. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3330. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3331. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3332. zone_id, _ := this.GetInt64("zone_id")
  3333. elecsign := this.GetString("url")
  3334. nuclein_date_str := this.GetString("nuclein_date_str")
  3335. schedule_remark := this.GetString("schedule_remark")
  3336. order_remark := this.GetString("order_remark")
  3337. catheter_operation := this.GetString("catheter_operation")
  3338. blood_flow_volume := this.GetString("blood_flow_volume")
  3339. dialysis_strainer := this.GetString("dialysis_strainer")
  3340. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3342. return
  3343. }
  3344. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3345. if parseStartDateErr != nil {
  3346. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3348. return
  3349. }
  3350. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3351. if parseErr != nil {
  3352. this.ErrorLog("时间解析失败:%v", parseErr)
  3353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3354. return
  3355. }
  3356. adminUserInfo := this.GetMobileAdminUserInfo()
  3357. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3358. if getPatientErr != nil {
  3359. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3361. return
  3362. } else if patient == nil {
  3363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3364. return
  3365. }
  3366. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3367. if getNurseErr != nil {
  3368. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3370. return
  3371. } else if nurse == nil {
  3372. this.ErrorLog("护士不存在")
  3373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3374. return
  3375. }
  3376. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3377. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3378. if getDeviceNumberErr != nil {
  3379. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3381. return
  3382. } else if deviceNumber == nil {
  3383. this.ErrorLog("床位号不存在")
  3384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3385. return
  3386. }
  3387. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3388. if getRecordErr != nil {
  3389. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3391. return
  3392. } else if dialysisRecord != nil {
  3393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3394. return
  3395. }
  3396. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3397. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3398. timeLayout := "2006-01-02 15:04:05"
  3399. loc, _ := time.LoadLocation("Local")
  3400. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3401. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3402. schedulestartTime := theStartTime.Unix()
  3403. scheduleendTime := theEndTime.Unix()
  3404. var theNucleinDate int64
  3405. timeLayoutOne := "2006-01-02"
  3406. if len(nuclein_date_str) > 0 {
  3407. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3408. if err != nil {
  3409. utils.ErrorLog(err.Error())
  3410. }
  3411. theNucleinDate = theTime.Unix()
  3412. }
  3413. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3414. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3415. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3416. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3417. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3418. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3419. if record.ID == 0 {
  3420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3421. return
  3422. }
  3423. advices, _ := service.GetDialysisPrescriptionDoctorAdviceList(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3424. if len(advices) == 0 {
  3425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3426. return
  3427. }
  3428. }
  3429. //查询该床位是否有人用了
  3430. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3431. if err == gorm.ErrRecordNotFound { //空床位
  3432. // 修改了床位逻辑
  3433. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3434. if daySchedule.ID > 0 {
  3435. daySchedule.PartitionId = deviceNumber.ZoneID
  3436. daySchedule.BedId = bedID
  3437. daySchedule.ScheduleType = schedual_type
  3438. daySchedule.UpdatedTime = time.Now().Unix()
  3439. xtSchedule := models.Schedule{
  3440. PartitionId: deviceNumber.ZoneID,
  3441. BedId: bedID,
  3442. ScheduleType: schedual_type,
  3443. UpdatedTime: time.Now().Unix(),
  3444. }
  3445. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3446. if err != nil {
  3447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3448. return
  3449. }
  3450. }
  3451. } else if err == nil {
  3452. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3453. if order.ID > 0 { //该机位被其他人占用了
  3454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3455. return
  3456. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3457. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3458. if daySchedule.ID > 0 {
  3459. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3460. if err != nil {
  3461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3462. return
  3463. }
  3464. }
  3465. }
  3466. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3468. return
  3469. }
  3470. //else if order.ID == 0 { //该床位没被占用
  3471. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3472. // if daySchedule.ID > 0 {
  3473. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3474. // //daySchedule.BedId = bedID
  3475. // //daySchedule.ScheduleType = schedual_type
  3476. // //daySchedule.UpdatedTime = time.Now().Unix()
  3477. // //err := service.UpdateSchedule(&daySchedule)
  3478. // xtSchedule := models.Schedule{
  3479. // PartitionId: deviceNumber.ZoneID,
  3480. // BedId: bedID,
  3481. // ScheduleType: schedual_type,
  3482. // UpdatedTime: time.Now().Unix(),
  3483. // }
  3484. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3485. // if err != nil {
  3486. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3487. // return
  3488. // }
  3489. // }
  3490. //}
  3491. //}
  3492. } else if err != nil {
  3493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3494. return
  3495. }
  3496. // 查询信息规挡的设置天数
  3497. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3498. if infor.ID > 0 && infor.WeekDay > 0 {
  3499. var cha_time int64
  3500. timeNowStr := time.Now().Format("2006-01-02")
  3501. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3502. //今日的日期减去设置的日期
  3503. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3504. if cha_time >= recordDate.Unix() {
  3505. //查询审核是否允许
  3506. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3507. //申请状态不允许的情况 拒绝修改
  3508. if infor.ApplicationStatus != 1 {
  3509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3510. return
  3511. }
  3512. }
  3513. }
  3514. dialysisRecord = &models.DialysisOrder{
  3515. DialysisDate: recordDate.Unix(),
  3516. UserOrgId: adminUserInfo.Org.Id,
  3517. PatientId: patientID,
  3518. Stage: 1,
  3519. BedID: bedID,
  3520. StartNurse: nurseID,
  3521. Status: 1,
  3522. StartTime: startDate.Unix(),
  3523. CreatedTime: time.Now().Unix(),
  3524. UpdatedTime: time.Now().Unix(),
  3525. PunctureNurse: puncture_nurse,
  3526. Creator: adminUserInfo.AdminUser.Id,
  3527. Modifier: adminUserInfo.AdminUser.Id,
  3528. SchedualType: schedual_type,
  3529. WashpipeNurse: washpipe_nurse,
  3530. ChangeNurse: change_nurse,
  3531. DifficultPunctureNurse: difficult_puncture_nurse,
  3532. NewFistulaNurse: new_fistula_nurse,
  3533. ZoneId: zone_id,
  3534. QualityNurseId: quality_nurse_id,
  3535. PunctureNeedle: puncture_needle,
  3536. PunctureWay: puncture_way,
  3537. DialysisIrrigation: dialysis_irrigation,
  3538. DialysisDialyszers: dialysis_dialyszers,
  3539. BloodAccessId: blood_access_id,
  3540. Url: elecsign,
  3541. NucleinDate: theNucleinDate,
  3542. ScheduleRemark: schedule_remark,
  3543. OrderRemark: order_remark,
  3544. CatheterOperation: catheter_operation,
  3545. BloodFlowVolume: blood_flow_volume,
  3546. BloodDrawing: blood_drawing,
  3547. DialysisStrainer: dialysis_strainer,
  3548. }
  3549. //查询该床位是否有人用了
  3550. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3551. if errorscode == gorm.ErrRecordNotFound {
  3552. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3553. finish := models.XtDialysisFinish{
  3554. IsFinish: 1,
  3555. UserOrgId: adminUserInfo.Org.Id,
  3556. Status: 1,
  3557. Ctime: time.Now().Unix(),
  3558. Mtime: 0,
  3559. Module: 6,
  3560. RecordDate: schedulestartTime,
  3561. Sourse: 1,
  3562. PatientId: patientID,
  3563. }
  3564. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3565. if dialysisFinish.ID == 0 {
  3566. service.CreateDialysisFinish(finish)
  3567. }
  3568. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3569. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3570. //统计该患者总次数
  3571. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3572. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3573. }
  3574. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3575. //统计该患者总次数
  3576. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3577. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3578. }
  3579. redis := service.RedisClient()
  3580. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3581. redis.Set(key, "", time.Second)
  3582. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3583. //清空key 值
  3584. redis.Set(keyOne, "", time.Second)
  3585. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3586. //清空key 值
  3587. redis.Set(keyTwo, "", time.Second)
  3588. if createErr != nil {
  3589. this.ErrorLog("上机失败:%v", createErr)
  3590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3591. return
  3592. }
  3593. }
  3594. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3595. var tempdispose string
  3596. // 只针对中能建
  3597. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3598. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3599. }
  3600. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3601. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3602. }
  3603. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3604. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3605. //}
  3606. var ultrafiltration_rate float64
  3607. var ultrafiltration_rate_one string
  3608. var replacement_rate float64
  3609. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3610. //后期预增脱水量
  3611. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3612. if prescription.ID > 0 {
  3613. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3614. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3615. 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
  3616. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3617. }
  3618. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 || adminUserInfo.Org.Id == 9478 {
  3619. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3620. }
  3621. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3622. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3623. }
  3624. //针对医师汇
  3625. if adminUserInfo.Org.Id == 10121 {
  3626. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3627. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3628. }
  3629. //针对通道
  3630. if adminUserInfo.Org.Id == 10234 {
  3631. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3632. }
  3633. //针对监利大垸医院
  3634. if template.TemplateId == 41 {
  3635. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3636. }
  3637. //针对肇庆三鹤血液透析中心
  3638. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3639. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3640. }
  3641. if adminUserInfo.Org.Id == 10469 {
  3642. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3643. }
  3644. if adminUserInfo.Org.Id == 10667 {
  3645. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3646. }
  3647. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3648. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3649. }
  3650. // 只针对方济医院
  3651. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3652. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3653. ultrafiltration_rate = value
  3654. }
  3655. //针对
  3656. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3657. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3658. ultrafiltration_rate = ultrafiltration_rate / 1000
  3659. }
  3660. if adminUserInfo.Org.Id == 10551 {
  3661. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3662. ultrafiltration_rate = ultrafiltration_rate / 1000
  3663. }
  3664. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3665. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3666. ultrafiltration_rate = ultrafiltration_rate / 1000
  3667. }
  3668. if adminUserInfo.Org.Id == 10580 {
  3669. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3670. ultrafiltration_rate = ultrafiltration_rate / 1000
  3671. }
  3672. if adminUserInfo.Org.Id == 10629 {
  3673. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3674. ultrafiltration_rate = ultrafiltration_rate / 1000
  3675. }
  3676. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3677. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3678. ultrafiltration_rate = ultrafiltration_rate / 1000
  3679. }
  3680. if adminUserInfo.Org.Id == 10751 {
  3681. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3682. ultrafiltration_rate = ultrafiltration_rate / 1000
  3683. }
  3684. if adminUserInfo.Org.Id == 10768 {
  3685. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3686. ultrafiltration_rate = ultrafiltration_rate / 1000
  3687. }
  3688. if adminUserInfo.Org.Id == 10667 {
  3689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3690. ultrafiltration_rate = ultrafiltration_rate / 1000
  3691. }
  3692. if adminUserInfo.Org.Id == 10693 {
  3693. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3694. ultrafiltration_rate = ultrafiltration_rate
  3695. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3696. }
  3697. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3698. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3699. ultrafiltration_rate = ultrafiltration_rate
  3700. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3701. }
  3702. if adminUserInfo.Org.Id == 10206 {
  3703. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3704. ultrafiltration_rate = ultrafiltration_rate
  3705. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3706. }
  3707. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3708. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3709. ultrafiltration_rate = ultrafiltration_rate
  3710. }
  3711. if adminUserInfo.Org.Id == 10702 {
  3712. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3713. ultrafiltration_rate = ultrafiltration_rate / 1000
  3714. }
  3715. if adminUserInfo.Org.Id == 10752 {
  3716. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3717. ultrafiltration_rate = ultrafiltration_rate / 1000
  3718. }
  3719. if adminUserInfo.Org.Id == 10723 {
  3720. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3721. ultrafiltration_rate = ultrafiltration_rate / 1000
  3722. }
  3723. if adminUserInfo.Org.Id == 10721 {
  3724. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3725. ultrafiltration_rate = ultrafiltration_rate / 1000
  3726. }
  3727. if adminUserInfo.Org.Id == 10766 {
  3728. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3729. ultrafiltration_rate = ultrafiltration_rate / 1000
  3730. }
  3731. if adminUserInfo.Org.Id == 10757 {
  3732. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3733. ultrafiltration_rate = ultrafiltration_rate / 1000
  3734. }
  3735. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3736. if prescription.ModeId == 2 {
  3737. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3738. if totalMin == 0 {
  3739. totalMin = 240
  3740. }
  3741. if prescription.ReplacementTotal == 0 {
  3742. prescription.ReplacementTotal = 15
  3743. }
  3744. //乘10 除10是为了保留一位小数
  3745. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3746. }
  3747. }
  3748. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10768 || adminUserInfo.Org.Id == 9478 {
  3749. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  3750. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3751. if totalMin == 0 {
  3752. totalMin = 240
  3753. }
  3754. if prescription.DisplaceLiquiValue == 0 {
  3755. prescription.DisplaceLiquiValue = 15
  3756. }
  3757. //乘10 除10是为了保留一位小数
  3758. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3759. }
  3760. }
  3761. if adminUserInfo.Org.Id == 10752 {
  3762. if prescription.ModeId == 2 {
  3763. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3764. if totalMin == 0 {
  3765. totalMin = 240
  3766. }
  3767. if prescription.ReplacementTotal == 0 {
  3768. prescription.ReplacementTotal = 15
  3769. }
  3770. //乘10 除10是为了保留一位小数
  3771. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3772. }
  3773. }
  3774. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3775. if prescription.ModeId == 2 {
  3776. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3777. if totalMin == 0 {
  3778. totalMin = 240
  3779. }
  3780. if prescription.DisplaceLiquiValue == 0 {
  3781. prescription.ReplacementTotal = 32
  3782. }
  3783. //乘10 除10是为了保留一位小数
  3784. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3785. }
  3786. }
  3787. }
  3788. }
  3789. if adminUserInfo.Org.Id == 10172 {
  3790. if prescription.ID == 0 {
  3791. if prescription.ModeId == 2 {
  3792. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3793. if totalMin == 0 {
  3794. totalMin = 240
  3795. }
  3796. if prescription.ReplacementTotal == 0 {
  3797. prescription.ReplacementTotal = 15
  3798. }
  3799. //乘10 除10是为了保留一位小数
  3800. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3801. }
  3802. }
  3803. }
  3804. record := models.MonitoringRecord{
  3805. UserOrgId: adminUserInfo.Org.Id,
  3806. PatientId: patientID,
  3807. DialysisOrderId: dialysisRecord.ID,
  3808. MonitoringDate: schedulestartTime,
  3809. OperateTime: startDate.Unix(),
  3810. // MonitoringTime: recordTime,
  3811. MonitoringNurse: nurseID,
  3812. Dispose: tempdispose,
  3813. UltrafiltrationRate: ultrafiltration_rate,
  3814. UltrafiltrationVolume: 0,
  3815. Status: 1,
  3816. CreatedTime: time.Now().Unix(),
  3817. UpdatedTime: time.Now().Unix(),
  3818. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3819. ReplacementRate: replacement_rate,
  3820. }
  3821. //只针对广慈医院
  3822. 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 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10757 || adminUserInfo.Org.Id == 9478 || adminUserInfo.Org.Id == 10766 {
  3823. // 查询病人是否有透前评估数据
  3824. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3825. //如果有数据就插入
  3826. if errcode == nil {
  3827. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3828. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3829. record.BreathingRate = befor.BreathingRate
  3830. record.PulseFrequency = befor.PulseFrequency
  3831. record.Temperature = befor.Temperature
  3832. }
  3833. }
  3834. //孝昌
  3835. if adminUserInfo.Org.Id == 10693 {
  3836. // 查询病人是否有透前评估数据
  3837. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3838. //如果有数据就插入
  3839. if errcode == nil {
  3840. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3841. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3842. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3843. record.BreathingRate = befor.BreathingRate
  3844. }
  3845. }
  3846. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3847. if newdialysisRecord.ID > 0 {
  3848. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3849. record.Temperature = 36.5
  3850. record.ArterialPressure = -100
  3851. record.DialysateTemperature = 36.5
  3852. record.Conductivity = 14
  3853. record.BreathingRate = "20"
  3854. record.VenousPressure = 80
  3855. record.TransmembranePressure = 60
  3856. record.Dispose = catheter_operation
  3857. }
  3858. //针对新化博翔
  3859. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3860. record.BloodOxygenSaturation = "99"
  3861. record.Conductivity = 14
  3862. record.DialysateTemperature = 36.5
  3863. record.BreathingRate = "20"
  3864. }
  3865. //针对兰溪人民医院的需求
  3866. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3867. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3868. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3869. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3870. record.Temperature = befor.Temperature
  3871. record.PulseFrequency = befor.PulseFrequency
  3872. record.BreathingRate = befor.BreathingRate
  3873. }
  3874. //针对乐山友谊医院的需求
  3875. if adminUserInfo.Org.Id == 10677 {
  3876. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3877. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3878. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3879. record.Temperature = befor.Temperature
  3880. record.PulseFrequency = befor.PulseFrequency
  3881. record.BreathingRate = befor.BreathingRate
  3882. }
  3883. //新化博翔
  3884. if adminUserInfo.Org.Id == 10447 {
  3885. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3886. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3887. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3888. record.BreathingRate = befor.BreathingRate
  3889. }
  3890. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3891. record.PulseFrequency = 80
  3892. record.Temperature = 36.5
  3893. }
  3894. //诊断灵山圣康
  3895. if adminUserInfo.Org.Id == 10375 {
  3896. record.Conductivity = 13.8
  3897. record.DialysateTemperature = 37
  3898. record.DialysateFlow = 500
  3899. record.BloodFlowVolume = 200
  3900. record.BreathingRate = "18"
  3901. record.SodiumConcentration = 140
  3902. }
  3903. //江成肾病医院
  3904. if adminUserInfo.Org.Id == 10517 {
  3905. record.SodiumConcentration = 138
  3906. record.DialysateTemperature = 36.5
  3907. }
  3908. //濉溪杏康血液透析中心
  3909. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3910. record.BloodFlowVolume = prescription.BloodFlowVolume
  3911. }
  3912. //胶州少海医院
  3913. if adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 9478 {
  3914. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3915. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3916. record.BreathingRate = befor.BreathingRate
  3917. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3918. record.Temperature = befor.Temperature
  3919. record.PulseFrequency = befor.PulseFrequency
  3920. }
  3921. if adminUserInfo.Org.Id != 10683 {
  3922. err = service.CreateMonitor(&record)
  3923. }
  3924. //记录日志
  3925. byterequest, _ := json.Marshal(record)
  3926. monitorRecordLog := models.XtMonitorRecordLog{
  3927. RecordDate: record.MonitoringDate,
  3928. PatientId: record.PatientId,
  3929. Module: 1,
  3930. AdminUserId: adminUserInfo.AdminUser.Id,
  3931. Ctime: time.Now().Unix(),
  3932. Mtime: 0,
  3933. Status: 1,
  3934. UserOrgId: record.UserOrgId,
  3935. ErrLog: string(byterequest),
  3936. Source: "执行上机时新增监测",
  3937. }
  3938. service.CreateMonitorRecordLog(monitorRecordLog)
  3939. finish := models.XtDialysisFinish{
  3940. IsFinish: 1,
  3941. UserOrgId: adminUserInfo.Org.Id,
  3942. Status: 1,
  3943. Ctime: time.Now().Unix(),
  3944. Mtime: 0,
  3945. Module: 7,
  3946. RecordDate: schedulestartTime,
  3947. Sourse: 1,
  3948. PatientId: patientID,
  3949. }
  3950. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3951. if dialysisFinish.ID == 0 {
  3952. service.CreateDialysisFinish(finish)
  3953. }
  3954. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3955. redis := service.RedisClient()
  3956. //清空key 值
  3957. redis.Set(key, "", time.Second)
  3958. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3959. redis.Set(keyOne, "", time.Second)
  3960. defer redis.Close()
  3961. if err != nil {
  3962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3963. return
  3964. }
  3965. }
  3966. go func() {
  3967. ssoDomain := beego.AppConfig.String("call_domain")
  3968. api := ssoDomain + "/index/uppatient"
  3969. values := make(url.Values)
  3970. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3971. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3972. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3973. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3974. http.PostForm(api, values)
  3975. }()
  3976. this.ServeSuccessJSON(map[string]interface{}{
  3977. "dialysis_order": newdialysisRecord,
  3978. "monitor": record,
  3979. })
  3980. return
  3981. }
  3982. func (c *DialysisAPIController) PostSolution() {
  3983. id, _ := c.GetInt64("patient", 0)
  3984. recordDateStr := c.GetString("record_date")
  3985. if id <= 0 {
  3986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3987. return
  3988. }
  3989. adminUserInfo := c.GetMobileAdminUserInfo()
  3990. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3991. if patient.ID == 0 {
  3992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3993. return
  3994. }
  3995. if len(recordDateStr) == 0 {
  3996. recordDateStr = time.Now().Format("2006-01-02")
  3997. }
  3998. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3999. if parseDateErr != nil {
  4000. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4002. return
  4003. }
  4004. mode_id, _ := c.GetInt64("mode_id", 0)
  4005. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  4006. dialyzer, _ := c.GetInt64("dialyzer", 0)
  4007. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  4008. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  4009. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  4010. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  4011. replacement_way, _ := c.GetInt64("replacement_way", 0)
  4012. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  4013. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  4014. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  4015. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  4016. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  4017. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  4018. kalium, _ := c.GetFloat("kalium", 0)
  4019. sodium, _ := c.GetFloat("sodium", 0)
  4020. calcium, _ := c.GetFloat("calcium", 0)
  4021. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  4022. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  4023. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  4024. glucose, _ := c.GetFloat("glucose", 0)
  4025. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  4026. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  4027. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  4028. conductivity, _ := c.GetFloat("conductivity", 0)
  4029. remark := c.GetString("remark")
  4030. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  4031. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  4032. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  4033. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  4034. body_fluid, _ := c.GetInt64("body_fluid", 0)
  4035. special_medicine, _ := c.GetInt64("special_medicine", 0)
  4036. special_medicine_other := c.GetString("special_medicine_other")
  4037. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  4038. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  4039. blood_access, _ := c.GetInt64("blood_access", 0)
  4040. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  4041. body_fluid_other := c.GetString("body_fluid_other")
  4042. replacement_total, _ := c.GetFloat("replacement_total", 0)
  4043. niprocart, _ := c.GetInt64("niprocart", 0)
  4044. jms, _ := c.GetInt64("jms", 0)
  4045. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  4046. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  4047. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  4048. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  4049. filtryzer, _ := c.GetInt64("filtryzer", 0)
  4050. target_ktv, _ := c.GetFloat("target_ktv", 0)
  4051. dialyzers, _ := c.GetInt64("dialyzers", 0)
  4052. injector, _ := c.GetInt64("injector", 0)
  4053. bloodlines, _ := c.GetInt64("bloodlines", 0)
  4054. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  4055. safe_package, _ := c.GetInt64("package", 0)
  4056. a_liquid, _ := c.GetInt64("a_liquid", 0)
  4057. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  4058. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  4059. blood := c.GetString("blood")
  4060. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  4061. dialysis_irrigation := c.GetString("dialysis_irrigation")
  4062. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  4063. displace_speed := c.GetString("displace_speed")
  4064. illness, _ := c.GetInt64("illness")
  4065. amylaceum := c.GetString("amylaceum")
  4066. single_time := c.GetString("single_time")
  4067. single_water := c.GetString("single_water")
  4068. replacement_flow := c.GetString("replacement_flow")
  4069. plasma_separator := c.GetString("plasma_separator")
  4070. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  4071. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  4072. oxygen_flow := c.GetString("oxygen_flow")
  4073. oxygen_time := c.GetString("oxygen_time")
  4074. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  4075. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  4076. puncture_needle := c.GetString("puncture_needle")
  4077. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  4078. epo := c.GetString("epo")
  4079. epo_count, _ := c.GetFloat("epo_count", 0)
  4080. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  4081. pre_impulse := c.GetString("pre_impulse")
  4082. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  4083. admin_user_id, _ := c.GetInt64("admin_user_id")
  4084. is_water := c.GetString("is_water")
  4085. add_amount, _ := c.GetFloat("add_amount")
  4086. reduce_amount, _ := c.GetFloat("reduce_amount")
  4087. prescribing_number, _ := c.GetFloat("prescribing_number")
  4088. treatment_remark := c.GetString("treatment_remark")
  4089. prescription_sodium := c.GetString("prescription_sodium")
  4090. start_sodium := c.GetString("start_sodium")
  4091. sodium_curve := c.GetString("sodium_curve")
  4092. var is_war int64
  4093. if is_water == "是" {
  4094. is_war = 1
  4095. }
  4096. if is_water == "否" {
  4097. is_war = 2
  4098. }
  4099. if is_water == "请选择" {
  4100. is_war = 0
  4101. }
  4102. drhy_water := c.GetString("drhy_water")
  4103. dry_water_hour := c.GetString("dry_water_hour")
  4104. water_machine := c.GetString("water_machine")
  4105. dialysis_remark := c.GetString("dialysis_remark")
  4106. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4107. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4108. prescription_water, _ := c.GetFloat("prescription_water")
  4109. dialysis_strainer := c.GetString("dialysis_strainer")
  4110. chaptalization := c.GetString("chaptalization")
  4111. washing_time := c.GetString("washing_time")
  4112. warsh_count := c.GetString("warsh_count")
  4113. blood_access_part_id := c.GetString("blood_access_part_id")
  4114. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4115. dialyzate := c.GetString("dialyzate")
  4116. first_super := c.GetString("first_super")
  4117. is_sequential := c.GetString("is_sequential")
  4118. sterilization_water := c.GetString("sterilization_water")
  4119. five_glucose := c.GetString("five_glucose")
  4120. fifty_glucose := c.GetString("fifty_glucose")
  4121. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  4122. calcium_gluconate := c.GetString("calcium_gluconate")
  4123. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  4124. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  4125. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  4126. new_sty := c.GetString("new_sty")
  4127. var fisrt_sup int64
  4128. if first_super == "是" {
  4129. fisrt_sup = 1
  4130. }
  4131. if first_super == "否" {
  4132. fisrt_sup = 2
  4133. }
  4134. if first_super == "请选择" {
  4135. fisrt_sup = 0
  4136. }
  4137. var is_sequen int64
  4138. if is_sequential == "是" {
  4139. is_sequen = 1
  4140. }
  4141. if is_sequential == "否" {
  4142. is_sequen = 2
  4143. }
  4144. if is_sequential == "请选择" {
  4145. is_sequen = 0
  4146. }
  4147. conduct := c.GetString("conduct")
  4148. if mode_id > 0 {
  4149. var str string
  4150. //查找该机构用的是什么透析器
  4151. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4152. if filedConfig.ID > 0 {
  4153. str = dialyzerPerfusionApparatus
  4154. } else {
  4155. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4156. }
  4157. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4158. }
  4159. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4160. //
  4161. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4162. // if appRole.UserType == 3 {
  4163. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4164. // if getPermissionErr != nil {
  4165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4166. // return
  4167. // } else if headNursePermission == nil {
  4168. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4169. // return
  4170. // }
  4171. // }
  4172. //}
  4173. // 查询信息规挡的设置天数
  4174. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4175. if infor.ID > 0 && infor.WeekDay > 0 {
  4176. var cha_time int64
  4177. timeNowStr := time.Now().Format("2006-01-02")
  4178. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4179. //今日的日期减去设置的日期
  4180. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4181. if cha_time >= recordDate.Unix() {
  4182. //查询审核是否允许
  4183. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4184. //申请状态不允许的情况 拒绝修改
  4185. if infor.ApplicationStatus != 1 {
  4186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4187. return
  4188. }
  4189. }
  4190. }
  4191. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4192. var dialysis_dialyszers_id int64
  4193. var dialysis_strainer_id int64
  4194. var dialysis_irrigation_id int64
  4195. if len(goodList) > 0 {
  4196. for _, item := range goodList {
  4197. if item.SpecificationName == dialysis_dialyszers {
  4198. dialysis_dialyszers_id = item.ID
  4199. }
  4200. if item.SpecificationName == dialysis_irrigation {
  4201. dialysis_irrigation_id = item.ID
  4202. }
  4203. if item.SpecificationName == dialysis_strainer {
  4204. dialysis_strainer_id = item.ID
  4205. }
  4206. }
  4207. }
  4208. prescription := models.DialysisPrescription{
  4209. UserOrgId: adminUserInfo.Org.Id,
  4210. PatientId: id,
  4211. RecordDate: recordDate.Unix(),
  4212. ModeId: mode_id,
  4213. DialysisDuration: dialysis_duration,
  4214. Dialyzer: dialyzer,
  4215. PerfusionApparatus: perfusion_apparatus,
  4216. BloodFlowVolume: blood_flow_volume,
  4217. DewaterAmount: dewater_amount,
  4218. DisplaceLiqui: displace_liqui,
  4219. ReplacementWay: replacement_way,
  4220. Anticoagulant: anticoagulant,
  4221. AnticoagulantShouji: anticoagulant_shouji,
  4222. AnticoagulantWeichi: anticoagulant_weichi,
  4223. AnticoagulantZongliang: anticoagulant_zongliang,
  4224. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4225. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4226. Kalium: kalium,
  4227. Sodium: sodium,
  4228. Calcium: calcium,
  4229. Bicarbonate: bicarbonate,
  4230. Glucose: glucose,
  4231. // DryWeight: dry_weight,
  4232. DialysateFlow: dialysate_flow,
  4233. DialysateTemperature: dialysate_temperature,
  4234. Conductivity: conductivity,
  4235. Remark: remark,
  4236. Status: 1,
  4237. CreatedTime: time.Now().Unix(),
  4238. UpdatedTime: time.Now().Unix(),
  4239. DialysisDurationMinute: dialysisDurationMinute,
  4240. DialysisDurationHour: dialysisDurationHour,
  4241. TargetUltrafiltration: targetUltrafiltration,
  4242. DialysateFormulation: dialysateFormulation,
  4243. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4244. BodyFluid: body_fluid,
  4245. SpecialMedicine: special_medicine,
  4246. SpecialMedicineOther: special_medicine_other,
  4247. DisplaceLiquiPart: displace_liqui_part,
  4248. DisplaceLiquiValue: displace_liqui_value,
  4249. BloodAccess: blood_access,
  4250. Ultrafiltration: ultrafiltration,
  4251. BodyFluidOther: body_fluid_other,
  4252. ReplacementTotal: replacement_total,
  4253. Niprocart: niprocart,
  4254. Jms: jms,
  4255. FistulaNeedleSet: fistula_needle_set,
  4256. FistulaNeedleSet16: fistula_needle_set_16,
  4257. Hemoperfusion: hemoperfusion,
  4258. DialyserSterilised: dialyser_sterilised,
  4259. Filtryzer: filtryzer,
  4260. TargetKtv: target_ktv,
  4261. Dialyzers: dialyzers,
  4262. Injector: injector,
  4263. Bloodlines: bloodlines,
  4264. TubingHemodialysis: tubing_hemodialysis,
  4265. Package: safe_package,
  4266. ALiquid: a_liquid,
  4267. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4268. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4269. Blood: blood,
  4270. DialysisDialyszers: dialysis_dialyszers,
  4271. DialysisIrrigation: dialysis_irrigation,
  4272. AntioxidantCommodityName: antioxidant_commodity_name,
  4273. DisplaceSpeed: displace_speed,
  4274. Illness: illness,
  4275. Amylaceum: amylaceum,
  4276. SingleWater: single_water,
  4277. SingleTime: single_time,
  4278. ReplacementFlow: replacement_flow,
  4279. PlasmaSeparator: plasma_separator,
  4280. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4281. OxygenUptake: oxygen_uptake,
  4282. OxygenTime: oxygen_time,
  4283. OxygenFlow: oxygen_flow,
  4284. HemodialysisPipelines: hemodialysis_pipelines,
  4285. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4286. PunctureNeedle: puncture_needle,
  4287. PunctureNeedleCount: puncture_needle_count,
  4288. Epo: epo,
  4289. EpoCount: epo_count,
  4290. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4291. PreImpulse: impulse,
  4292. AdminUserId: admin_user_id,
  4293. IsWater: is_war,
  4294. DrhyWater: drhy_water,
  4295. DryWaterHour: dry_water_hour,
  4296. WaterMachine: water_machine,
  4297. AddAmount: add_amount,
  4298. ReduceAmount: reduce_amount,
  4299. DialysisRemark: dialysis_remark,
  4300. PrescribingNumber: prescribing_number,
  4301. PrescriptionSodium: prescription_sodium,
  4302. StartSodium: start_sodium,
  4303. SodiumCurve: sodium_curve,
  4304. TreatmentRemark: treatment_remark,
  4305. DialysisFluidFlow: dialysis_fluid_flow,
  4306. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4307. PrescriptionWater: prescription_water,
  4308. DialysisStrainer: dialysis_strainer,
  4309. Chaptalization: chaptalization,
  4310. WashingTime: washing_time,
  4311. WarshCount: warsh_count,
  4312. BloodAccessPartId: blood_access_part_id,
  4313. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4314. Dialyzate: dialyzate,
  4315. DialysisDialyszersId: dialysis_dialyszers_id,
  4316. DialysisIrrigationId: dialysis_irrigation_id,
  4317. DialysisStrainerId: dialysis_strainer_id,
  4318. FirstSuper: fisrt_sup,
  4319. IsSequential: is_sequen,
  4320. Conduct: conduct,
  4321. SterilizationWater: sterilization_water,
  4322. FiveGlucose: five_glucose,
  4323. FiftyGlucose: fifty_glucose,
  4324. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4325. CalciumGluconate: calcium_gluconate,
  4326. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4327. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4328. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4329. NewSty: new_sty,
  4330. }
  4331. if prescription.ModeId != 13 {
  4332. prescription.SterilizationWater = ""
  4333. prescription.FiveGlucose = ""
  4334. prescription.FiftyGlucose = ""
  4335. prescription.MagnesiumSulfateInjection = ""
  4336. prescription.CalciumGluconate = ""
  4337. prescription.FivePotassiumChlorideInjection = ""
  4338. prescription.TenPotassiumChlorideInjection = ""
  4339. prescription.FiveSodiumBicarbonateInjection = ""
  4340. prescription.NewSty = ""
  4341. }
  4342. if adminUserInfo.Org.Id == 10721 {
  4343. if prescription.ModeId == 2 {
  4344. if prescription.ReplacementTotal == 0 {
  4345. prescription.ReplacementTotal = 15
  4346. }
  4347. }
  4348. }
  4349. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 9478 {
  4350. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  4351. if prescription.ReplacementTotal == 0 {
  4352. prescription.ReplacementTotal = 15
  4353. }
  4354. }
  4355. }
  4356. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4357. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4358. //
  4359. if appRole.UserType == 2 || appRole.UserType == 1 {
  4360. prescription_doctor = adminUserInfo.AdminUser.Id
  4361. prescription.PrescriptionDoctor = prescription_doctor
  4362. }
  4363. if dialysisPrescription.ID == 0 { //新增
  4364. prescription.Creater = adminUserInfo.AdminUser.Id
  4365. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4366. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4367. }
  4368. } else { //修改
  4369. if dialysisPrescription.Creater == 0 {
  4370. prescription.Creater = adminUserInfo.AdminUser.Id
  4371. } else {
  4372. prescription.Creater = dialysisPrescription.Creater
  4373. if adminUserInfo.Org.Id == 9882 {
  4374. if appRole.UserType == 2 || appRole.UserType == 1 {
  4375. prescription.Creater = adminUserInfo.AdminUser.Id
  4376. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4377. }
  4378. }
  4379. }
  4380. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4381. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4382. }
  4383. //if/**/
  4384. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4385. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4386. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4387. // if getPermissionErr != nil {
  4388. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4389. // return
  4390. // } else if headNursePermission == nil {
  4391. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4392. // return
  4393. // }
  4394. //}
  4395. //prescription.Creater = dialysisPrescription.Creater
  4396. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4397. prescription.Modifier = adminUserInfo.AdminUser.Id
  4398. prescription.ID = dialysisPrescription.ID
  4399. }
  4400. solution := models.DialysisSolution{
  4401. RegistrarsId: adminUserInfo.AdminUser.Id,
  4402. UserOrgId: adminUserInfo.Org.Id,
  4403. Doctor: prescription_doctor,
  4404. PatientId: id,
  4405. ModeId: mode_id,
  4406. DialysisDuration: dialysis_duration,
  4407. PerfusionApparatus: perfusion_apparatus,
  4408. BloodFlowVolume: blood_flow_volume,
  4409. Dewater: dewater_amount,
  4410. DisplaceLiqui: displace_liqui,
  4411. ReplacementWay: replacement_way,
  4412. Anticoagulant: anticoagulant,
  4413. AnticoagulantShouji: anticoagulant_shouji,
  4414. AnticoagulantWeichi: anticoagulant_weichi,
  4415. AnticoagulantZongliang: anticoagulant_zongliang,
  4416. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4417. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4418. Kalium: kalium,
  4419. Sodium: sodium,
  4420. Calcium: calcium,
  4421. Bicarbonate: bicarbonate,
  4422. Glucose: glucose,
  4423. // DryWeight: dry_weight,
  4424. DialysateFlow: dialysate_flow,
  4425. DialysateTemperature: dialysate_temperature,
  4426. Conductivity: conductivity,
  4427. Remark: remark,
  4428. Status: 1,
  4429. CreatedTime: time.Now().Unix(),
  4430. UpdatedTime: time.Now().Unix(),
  4431. DialysisDurationMinute: dialysisDurationMinute,
  4432. DialysisDurationHour: dialysisDurationHour,
  4433. TargetUltrafiltration: targetUltrafiltration,
  4434. DialysateFormulation: dialysateFormulation,
  4435. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4436. BodyFluid: body_fluid,
  4437. SpecialMedicine: special_medicine,
  4438. SpecialMedicineOther: special_medicine_other,
  4439. DisplaceLiquiPart: displace_liqui_part,
  4440. DisplaceLiquiValue: displace_liqui_value,
  4441. BloodAccess: blood_access,
  4442. Ultrafiltration: ultrafiltration,
  4443. BodyFluidOther: body_fluid_other,
  4444. ReplacementTotal: replacement_total,
  4445. TargetKtv: target_ktv,
  4446. DialysisDialyszers: dialysis_dialyszers,
  4447. DialysisIrrigation: dialysis_irrigation,
  4448. HemodialysisPipelines: hemodialysis_pipelines,
  4449. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4450. PunctureNeedle: puncture_needle,
  4451. PunctureNeedleCount: puncture_needle_count,
  4452. Epo: epo,
  4453. EpoCount: epo_count,
  4454. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4455. PreImpulse: impulse,
  4456. SolutionStatus: 1,
  4457. DialysisRemark: dialysis_remark,
  4458. PrescribingNumber: prescribing_number,
  4459. PrescriptionSodium: prescription_sodium,
  4460. StartSodium: start_sodium,
  4461. SodiumCurve: sodium_curve,
  4462. TreatmentRemark: treatment_remark,
  4463. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4464. DialysisFluidFlow: dialysis_fluid_flow,
  4465. PrescriptionWater: prescription_water,
  4466. DialysisStrainer: dialysis_strainer,
  4467. Chaptalization: chaptalization,
  4468. WashingTime: washing_time,
  4469. WarshCount: warsh_count,
  4470. BloodAccessPartId: blood_access_part_id,
  4471. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4472. Dialyzate: dialyzate,
  4473. DialysisDialyszersId: dialysis_dialyszers_id,
  4474. DialysisIrrigationId: dialysis_irrigation_id,
  4475. DialysisStrainerId: dialysis_strainer_id,
  4476. FirstSuper: fisrt_sup,
  4477. IsSequential: is_sequen,
  4478. Conduct: conduct,
  4479. SterilizationWater: sterilization_water,
  4480. FiveGlucose: five_glucose,
  4481. FiftyGlucose: fifty_glucose,
  4482. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  4483. CalciumGluconate: calcium_gluconate,
  4484. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  4485. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  4486. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  4487. NewSty: new_sty,
  4488. }
  4489. if prescription.ModeId != 13 {
  4490. prescription.SterilizationWater = ""
  4491. prescription.FiveGlucose = ""
  4492. prescription.FiftyGlucose = ""
  4493. prescription.MagnesiumSulfateInjection = ""
  4494. prescription.CalciumGluconate = ""
  4495. prescription.FivePotassiumChlorideInjection = ""
  4496. prescription.TenPotassiumChlorideInjection = ""
  4497. prescription.FiveSodiumBicarbonateInjection = ""
  4498. prescription.NewSty = ""
  4499. }
  4500. //针对河间咸的
  4501. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4502. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4503. solution.DisplaceLiquiPart = 0
  4504. solution.DisplaceLiquiValue = 0
  4505. }
  4506. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4507. prescription.DisplaceLiquiPart = 0
  4508. prescription.DisplaceLiquiValue = 0
  4509. }
  4510. }
  4511. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4512. if solution.PrescribingNumber == 0 {
  4513. solution.PrescribingNumber = 1
  4514. }
  4515. if prescription.PrescribingNumber == 0 {
  4516. prescription.PrescribingNumber = 1
  4517. }
  4518. if solution.PrescribingNumber == 0 && id == 14682 {
  4519. solution.PrescribingNumber = 2
  4520. }
  4521. if solution.PrescribingNumber == 0 && id == 18560 {
  4522. solution.PrescribingNumber = 2
  4523. }
  4524. if prescription.PrescribingNumber == 0 && id == 14682 {
  4525. prescription.PrescribingNumber = 2
  4526. }
  4527. if prescription.PrescribingNumber == 0 && id == 18560 {
  4528. prescription.PrescribingNumber = 2
  4529. }
  4530. }
  4531. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4532. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9478 {
  4533. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4534. if len(monitorList) > 0 {
  4535. var ultrafiltration_rate float64
  4536. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4537. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4538. var replacement_rate float64
  4539. if adminUserInfo.Org.Id == 10721 {
  4540. //乘10 除10是为了保留一位小数
  4541. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4542. }
  4543. if adminUserInfo.Org.Id == 9478 {
  4544. //乘10 除10是为了保留一位小数
  4545. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4546. }
  4547. if adminUserInfo.Org.Id == 10766 {
  4548. //乘10 除10是为了保留一位小数
  4549. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4550. }
  4551. var firstOpeateTime = monitorList[0].OperateTime
  4552. for _, item := range monitorList {
  4553. //超滤率
  4554. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4555. //置换率
  4556. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4557. //超滤量
  4558. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4559. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4560. //置换量
  4561. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4562. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4563. }
  4564. }
  4565. }
  4566. //记录日志
  4567. byterequest, _ := json.Marshal(prescription)
  4568. prescriptionLog := models.XtDialysisPrescriptionLog{
  4569. UserOrgId: prescription.UserOrgId,
  4570. Ctime: time.Now().Unix(),
  4571. Mtime: 0,
  4572. ErrLog: string(byterequest),
  4573. AdminUserId: adminUserInfo.AdminUser.Id,
  4574. RecordDate: prescription.RecordDate,
  4575. PatientId: prescription.PatientId,
  4576. Source: "手机端新增长期处方",
  4577. Status: 1,
  4578. }
  4579. service.CreatePrescriptionLog(prescriptionLog)
  4580. finish := models.XtDialysisFinish{
  4581. IsFinish: 1,
  4582. UserOrgId: adminUserInfo.Org.Id,
  4583. Status: 1,
  4584. Ctime: time.Now().Unix(),
  4585. Mtime: 0,
  4586. Module: 1,
  4587. RecordDate: recordDate.Unix(),
  4588. Sourse: 1,
  4589. PatientId: id,
  4590. }
  4591. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4592. if dialysisFinish.ID == 0 {
  4593. service.CreateDialysisFinish(finish)
  4594. }
  4595. //获取最新1条
  4596. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4597. //更新状态
  4598. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4599. //长沙南雅医院,自动生成抗凝剂的临时处方
  4600. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4601. if prescribing_number == 0 {
  4602. prescribing_number = 1
  4603. }
  4604. advice := models.DoctorAdvice{
  4605. UserOrgId: adminUserInfo.Org.Id,
  4606. PatientId: id,
  4607. GroupNo: 0,
  4608. AdviceType: 2,
  4609. RecordDate: recordDate.Unix(),
  4610. AdviceDate: recordDate.Unix(),
  4611. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4612. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4613. AdviceDesc: "",
  4614. ReminderDate: 0,
  4615. SingleDose: prescription.AnticoagulantZongliang,
  4616. SingleDoseUnit: "iu",
  4617. DrugSpec: 0,
  4618. DrugSpecUnit: "",
  4619. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4620. PrescribingNumberUnit: "支",
  4621. DeliveryWay: "静脉注射",
  4622. ExecutionFrequency: "上机前",
  4623. AdviceDoctor: 0,
  4624. Status: 1,
  4625. CreatedTime: time.Now().Unix(),
  4626. UpdatedTime: time.Now().Unix(),
  4627. IsPrescription: 1,
  4628. ExecutionState: 2,
  4629. StopState: 2,
  4630. IsSettle: 2,
  4631. }
  4632. // 查询排班信息
  4633. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4634. if schedulePatient.ID > 0 {
  4635. if schedulePatient.ScheduleType == 1 {
  4636. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4637. }
  4638. if schedulePatient.ScheduleType == 2 {
  4639. advice.StartTime = recordDate.Unix() + 9*60*60
  4640. }
  4641. }
  4642. // 抗凝剂名称
  4643. switch anticoagulant {
  4644. case 1:
  4645. advice.AdviceName = "无肝素"
  4646. break
  4647. case 2:
  4648. advice.AdviceName = "普通肝素"
  4649. break
  4650. case 3:
  4651. advice.AdviceName = "低分子肝素"
  4652. break
  4653. case 4:
  4654. advice.AdviceName = "阿加曲班"
  4655. break
  4656. case 5:
  4657. advice.AdviceName = "枸橼酸钠"
  4658. break
  4659. case 6:
  4660. advice.AdviceName = "低分子肝素钙"
  4661. break
  4662. case 7:
  4663. advice.AdviceName = "低分子肝素钠"
  4664. break
  4665. case 8:
  4666. advice.AdviceName = "依诺肝素"
  4667. break
  4668. case 9:
  4669. advice.AdviceName = "达肝素"
  4670. break
  4671. case 10:
  4672. advice.AdviceName = "体外抗凝"
  4673. break
  4674. case 11:
  4675. advice.AdviceName = "那曲肝素"
  4676. break
  4677. case 12:
  4678. advice.AdviceName = "无抗凝剂"
  4679. break
  4680. }
  4681. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4682. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4683. advice.AdviceDoctor = appRole.AdminUserId
  4684. }
  4685. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4686. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4687. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4688. advice.AdviceName = "低分子肝素钠注射液"
  4689. // 修改患者临时医嘱里的抗凝剂医嘱
  4690. advice.ID = advicePrescription.ID
  4691. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4692. } else {
  4693. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4694. advice.AdviceName = "低分子肝素钠注射液"
  4695. service.CreateDoctorAdvice(&advice)
  4696. }
  4697. }
  4698. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4699. redis := service.RedisClient()
  4700. defer redis.Close()
  4701. //清空key 值
  4702. redis.Set(key, "", time.Second)
  4703. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4704. redis.Set(keyOne, "", time.Second)
  4705. }
  4706. //获取key,清空redis
  4707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4708. redis := service.RedisClient()
  4709. defer redis.Close()
  4710. //清空key 值
  4711. redis.Set(key, "", time.Second)
  4712. //清空长期医嘱的key
  4713. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4714. redis.Set(soulution_key, "", time.Second)
  4715. //查询最近透析准备表里是否存在 透析器 灌流器
  4716. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4717. redis.Set(keyOne, "", time.Second)
  4718. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4719. redis.Set(keyTwo, "", time.Second)
  4720. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4721. redis.Set(keyThree, "", time.Second)
  4722. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4723. redis.Set(keyFour, "", time.Second)
  4724. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4725. //
  4726. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4727. //
  4728. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4729. //if len(mation)>0{
  4730. // for _, item := range splitStr {
  4731. // for _,it := range mation{
  4732. // if(item == it.SpecificationName){
  4733. //
  4734. // //查询最近一次的透析器
  4735. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4736. //
  4737. // if errcode == gorm.ErrRecordNotFound{
  4738. // //插入数据
  4739. // prepare := models.DialysisBeforePrepare{
  4740. // UserOrgId: adminUserInfo.Org.Id,
  4741. // PatientId: id,
  4742. // RecordDate: recordDate.Unix(),
  4743. // GoodTypeId: it.GoodTypeId,
  4744. // GoodId: it.ID,
  4745. // Count: 1,
  4746. // Ctime: time.Now().Unix(),
  4747. // Creater: adminUserInfo.AdminUser.Id,
  4748. // Status:1,
  4749. //
  4750. // }
  4751. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4752. // fmt.Println("",errcode)
  4753. // }
  4754. // }
  4755. // }
  4756. //
  4757. // }
  4758. //
  4759. // for _, item := range splitIrrigation {
  4760. // for _,it := range mation{
  4761. // if(item == it.SpecificationName){
  4762. // //查询最近一次的透析器
  4763. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4764. // if errcode == gorm.ErrRecordNotFound{
  4765. // //插入数据
  4766. // prepare := models.DialysisBeforePrepare{
  4767. // UserOrgId: adminUserInfo.Org.Id,
  4768. // PatientId: id,
  4769. // RecordDate: recordDate.Unix(),
  4770. // GoodTypeId: it.GoodTypeId,
  4771. // GoodId: it.ID,
  4772. // Count: 1,
  4773. // Ctime: time.Now().Unix(),
  4774. // Creater: adminUserInfo.AdminUser.Id,
  4775. // Status:1,
  4776. //
  4777. // }
  4778. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4779. // fmt.Println(errcode)
  4780. // }
  4781. // }
  4782. // }
  4783. // }
  4784. //}
  4785. c.ServeSuccessJSON(map[string]interface{}{
  4786. "solution": &solution,
  4787. "prescription": &prescription,
  4788. })
  4789. }
  4790. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4791. patient, _ := c.GetInt64("patient", 0)
  4792. adminUserInfo := c.GetMobileAdminUserInfo()
  4793. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4794. c.ServeSuccessJSON(map[string]interface{}{
  4795. "receiveTreatmentAsses": receiveTreatmentAsses,
  4796. })
  4797. }
  4798. func (this *DialysisAPIController) PostSignInfo() {
  4799. patientID, _ := this.GetInt64("patient_id")
  4800. recordDateStr := this.GetString("date")
  4801. if patientID <= 0 {
  4802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4803. return
  4804. }
  4805. if len(recordDateStr) == 0 {
  4806. recordDateStr = time.Now().Format("2006-01-02")
  4807. }
  4808. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4809. if parseDateErr != nil {
  4810. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4812. return
  4813. }
  4814. adminInfo := this.GetMobileAdminUserInfo()
  4815. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4816. if err != nil {
  4817. this.ErrorLog("签名失败:%v", err)
  4818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4819. return
  4820. }
  4821. this.ServeSuccessJSON(map[string]interface{}{
  4822. "doctor_id": adminInfo.AdminUser.Id,
  4823. })
  4824. }
  4825. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4826. patientID, _ := this.GetInt64("patient_id")
  4827. adminInfo := this.GetMobileAdminUserInfo()
  4828. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4829. this.ServeSuccessJSON(map[string]interface{}{
  4830. "monitor": record,
  4831. })
  4832. }
  4833. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4834. thisTime := time.Now()
  4835. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4836. timeLayout := "2006-01-02 15:04:05"
  4837. loc, _ := time.LoadLocation("Local")
  4838. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4839. theAssessmentDateTime := theStartTime.Unix()
  4840. patientID, _ := this.GetInt64("patient_id")
  4841. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4842. adminInfo := this.GetMobileAdminUserInfo()
  4843. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4844. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4845. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4846. var ultrafiltration_rate float64
  4847. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4848. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4849. fmt.Println(evaluation)
  4850. fmt.Println("prescription.ID", prescription.ID)
  4851. if prescription.ID > 0 {
  4852. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4853. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4854. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4855. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4856. record.UltrafiltrationRate = ultrafiltration_rate
  4857. }
  4858. //重庆塘坝卫生院
  4859. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4860. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4861. record.UltrafiltrationRate = ultrafiltration_rate
  4862. }
  4863. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4864. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4865. record.UltrafiltrationRate = ultrafiltration_rate
  4866. }
  4867. if adminInfo.Org.Id == 10768 {
  4868. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60)
  4869. record.UltrafiltrationRate = ultrafiltration_rate
  4870. }
  4871. if adminInfo.Org.Id == 10510 {
  4872. record.UltrafiltrationRate = 0
  4873. }
  4874. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4875. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4876. record.UltrafiltrationRate = ultrafiltration_rate
  4877. }
  4878. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4879. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4880. record.UltrafiltrationRate = ultrafiltration_rate
  4881. }
  4882. // 只针对方济医院
  4883. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4884. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4885. ultrafiltration_rate = value
  4886. record.UltrafiltrationRate = ultrafiltration_rate
  4887. }
  4888. if template.TemplateId == 41 || template.TemplateId == 47 {
  4889. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4890. record.UltrafiltrationRate = ultrafiltration_rate
  4891. }
  4892. if template.TemplateId == 43 {
  4893. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4894. record.UltrafiltrationRate = ultrafiltration_rate
  4895. }
  4896. if template.TemplateId == 46 || template.TemplateId == 54 {
  4897. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4898. record.UltrafiltrationRate = ultrafiltration_rate
  4899. }
  4900. 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 {
  4901. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4902. record.UltrafiltrationRate = ultrafiltration_rate
  4903. }
  4904. if adminInfo.Org.Id == 10469 {
  4905. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4906. record.UltrafiltrationRate = ultrafiltration_rate
  4907. }
  4908. if adminInfo.Org.Id == 10667 {
  4909. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4910. record.UltrafiltrationRate = ultrafiltration_rate
  4911. }
  4912. if adminInfo.Org.Id == 10471 {
  4913. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4914. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4915. }
  4916. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4917. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4918. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4919. }
  4920. if adminInfo.Org.Id == 10751 {
  4921. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4922. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4923. }
  4924. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4925. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4926. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4927. }
  4928. if adminInfo.Org.Id == 10721 {
  4929. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4930. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4931. }
  4932. if adminInfo.Org.Id == 10766 {
  4933. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4934. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4935. }
  4936. if adminInfo.Org.Id == 10757 {
  4937. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4938. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4939. }
  4940. if adminInfo.Org.Id == 10752 {
  4941. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4942. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4943. }
  4944. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4945. record.UltrafiltrationRate = 0
  4946. }
  4947. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4948. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4949. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4950. }
  4951. if adminInfo.Org.Id == 10206 {
  4952. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4953. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4954. }
  4955. //湘潭爱心美白石
  4956. if adminInfo.Org.Id == 9850 {
  4957. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4958. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4959. }
  4960. if adminInfo.Org.Id == 9919 {
  4961. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4962. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4963. }
  4964. //if template.TemplateId == 47 {
  4965. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4966. // record.UltrafiltrationRate = ultrafiltration_rate
  4967. //}
  4968. }
  4969. }
  4970. // record.UltrafiltrationRate = ultrafiltration_rate
  4971. record.UltrafiltrationVolume = 0
  4972. 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
  4973. if ultrafiltration_rate > 0 {
  4974. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4975. record.UltrafiltrationVolume = value
  4976. }
  4977. }
  4978. 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
  4979. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4980. if adminInfo.Org.Id != 10735 {
  4981. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4982. record.UltrafiltrationVolume = ultrafiltration_volume
  4983. }
  4984. //胶州少海医院
  4985. if adminInfo.Org.Id == 10735 {
  4986. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4987. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4988. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4989. if lastMonitorRecordList.ID > 0 {
  4990. record.UltrafiltrationRate = ultrafiltration_rate_one
  4991. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4992. record.UltrafiltrationVolume = ultrafiltration_volume
  4993. } else {
  4994. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4995. record.UltrafiltrationVolume = ultrafiltration_volume
  4996. }
  4997. }
  4998. }
  4999. }
  5000. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  5001. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5002. record.UltrafiltrationVolume = ultrafiltration_volume
  5003. }
  5004. //长沙南雅
  5005. 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 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5006. if ultrafiltration_rate > 0 {
  5007. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5008. record.UltrafiltrationVolume = ultrafiltration_volume
  5009. }
  5010. }
  5011. if adminInfo.Org.Id == 10471 {
  5012. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5013. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5014. }
  5015. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  5016. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5017. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5018. }
  5019. if adminInfo.Org.Id == 10751 {
  5020. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5021. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5022. }
  5023. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  5024. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5025. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5026. }
  5027. //长沙南雅累计血容量自动计算
  5028. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  5029. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  5030. //}
  5031. if template.TemplateId == 47 || template.TemplateId == 54 {
  5032. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5033. }
  5034. if adminInfo.Org.Id == 10510 {
  5035. record.UltrafiltrationVolume = 0
  5036. }
  5037. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10766 {
  5038. if ultrafiltration_rate > 0 {
  5039. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5040. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5041. }
  5042. }
  5043. //古镇乐生
  5044. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  5045. if ultrafiltration_rate > 0 {
  5046. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5047. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5048. }
  5049. }
  5050. if adminInfo.Org.Id == 9919 {
  5051. if ultrafiltration_rate > 0 {
  5052. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5053. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  5054. }
  5055. }
  5056. if adminInfo.Org.Id == 10206 {
  5057. if ultrafiltration_rate > 0 {
  5058. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5059. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5060. }
  5061. }
  5062. if adminInfo.Org.Id == 10768 {
  5063. if ultrafiltration_rate > 0 {
  5064. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5065. record.UltrafiltrationVolume = ultrafiltration_volume
  5066. }
  5067. }
  5068. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 10290 {
  5069. var replacement_rate float64
  5070. var displacement_quantity float64
  5071. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5072. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  5073. record.ReplacementRate = replacement_rate
  5074. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5075. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5076. record.DisplacementQuantity = displacement_quantity
  5077. }
  5078. if adminInfo.Org.Id == 10766 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10768 {
  5079. var replacement_rate float64
  5080. var displacement_quantity float64
  5081. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5082. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5083. record.ReplacementRate = replacement_rate
  5084. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5085. record.DisplacementQuantity = displacement_quantity
  5086. }
  5087. if adminInfo.Org.Id == 10752 {
  5088. var replacement_rate float64
  5089. var displacement_quantity float64
  5090. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5091. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5092. record.ReplacementRate = replacement_rate
  5093. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5094. record.DisplacementQuantity = displacement_quantity
  5095. }
  5096. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10766 {
  5097. var replacement_rate float64
  5098. var displacement_quantity float64
  5099. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5100. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  5101. record.ReplacementRate = replacement_rate
  5102. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5103. record.DisplacementQuantity = displacement_quantity
  5104. }
  5105. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  5106. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5107. record.UltrafiltrationVolume = ultrafiltration_volume
  5108. }
  5109. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  5110. var replacement_rate float64
  5111. var displacement_quantity float64
  5112. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5113. if totalMin == 0 {
  5114. totalMin = 240
  5115. }
  5116. if prescription.DisplaceLiquiValue == 0 {
  5117. prescription.ReplacementTotal = 32
  5118. }
  5119. //乘10 除10是为了保留一位小数
  5120. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5121. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  5122. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  5123. record.DisplacementQuantity = displacement_quantity
  5124. }
  5125. if adminInfo.Org.Id == 9850 {
  5126. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5127. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5128. }
  5129. if adminInfo.Org.Id == 9478 {
  5130. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5131. if totalMin == 0 {
  5132. totalMin = 240
  5133. }
  5134. if prescription.DisplaceLiquiValue == 0 {
  5135. prescription.DisplaceLiquiValue = 15
  5136. }
  5137. var replacement_rate float64
  5138. //乘10 除10是为了保留一位小数
  5139. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  5140. fmt.Println("hahahahahhaahahah", replacement_rate)
  5141. record.ReplacementRate = replacement_rate
  5142. }
  5143. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5144. fisrtMonitorRecordList, _ := service.GetFisrtMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  5145. this.ServeSuccessJSON(map[string]interface{}{
  5146. "monitor": record,
  5147. "lastMonitorRecordList": lastMonitorRecordList,
  5148. "fisrtMonitorRecordList": fisrtMonitorRecordList,
  5149. })
  5150. }
  5151. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5152. record_id, _ := this.GetInt64("id")
  5153. nurseID, _ := this.GetInt64("start_nurse")
  5154. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5155. bedID, _ := this.GetInt64("bed")
  5156. start_time := this.GetString("start_time")
  5157. schedual_type, _ := this.GetInt64("schedual_type")
  5158. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  5159. change_nurse, _ := this.GetInt64("change_nurse")
  5160. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  5161. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  5162. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  5163. patient_id, _ := this.GetInt64("patient_id")
  5164. record_date, _ := this.GetInt64("record_date")
  5165. puncture_needle := this.GetString("puncture_needle")
  5166. puncture_way := this.GetString("puncture_way")
  5167. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  5168. dialysis_irrigation := this.GetString("dialysis_irrigation")
  5169. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  5170. nuclein_date_str := this.GetString("nuclein_date_str")
  5171. order_remark := this.GetString("order_remark")
  5172. schedule_remark := this.GetString("schedule_remark")
  5173. catheter_operation := this.GetString("catheter_operation")
  5174. blood_flow_volume := this.GetString("blood_flow_volume")
  5175. blood_drawing, _ := this.GetInt64("blood_drawing")
  5176. dialysis_strainer := this.GetString("dialysis_strainer")
  5177. if record_id == 0 {
  5178. this.ErrorLog("id:%v", record_id)
  5179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5180. return
  5181. }
  5182. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5183. if parseStartDateErr != nil {
  5184. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5186. return
  5187. }
  5188. adminUserInfo := this.GetMobileAdminUserInfo()
  5189. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5190. if getNurseErr != nil {
  5191. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5193. return
  5194. } else if nurse == nil {
  5195. this.ErrorLog("护士不存在")
  5196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5197. return
  5198. }
  5199. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5200. //if getNurseErr != nil {
  5201. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5202. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5203. // return
  5204. //} else if nurse == nil {
  5205. // this.ErrorLog("护士不存在")
  5206. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5207. // return
  5208. //}
  5209. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5210. if getDeviceNumberErr != nil {
  5211. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5213. return
  5214. } else if deviceNumber == nil {
  5215. this.ErrorLog("床位号不存在")
  5216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5217. return
  5218. }
  5219. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5220. //
  5221. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5222. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5223. // if getPermissionErr != nil {
  5224. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5225. // return
  5226. // } else if headNursePermission == nil {
  5227. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5228. // return
  5229. // }
  5230. //}
  5231. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5232. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5233. timeLayout := "2006-01-02 15:04:05"
  5234. loc, _ := time.LoadLocation("Local")
  5235. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5236. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5237. schedulestartTime := theStartTime.Unix()
  5238. scheduleendTime := theEndTime.Unix()
  5239. var theNucleinDate int64
  5240. timeLayoutOne := "2006-01-02"
  5241. if len(nuclein_date_str) > 0 {
  5242. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5243. if err != nil {
  5244. utils.ErrorLog(err.Error())
  5245. }
  5246. theNucleinDate = theTime.Unix()
  5247. }
  5248. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5249. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5250. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5251. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5252. if err == gorm.ErrRecordNotFound { //空床位
  5253. // 修改了床位逻辑
  5254. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5255. if daySchedule.ID > 0 {
  5256. //daySchedule.BedId = bedID
  5257. //daySchedule.PartitionId = deviceNumber.ZoneID
  5258. //daySchedule.ScheduleType = schedual_type
  5259. //daySchedule.UpdatedTime = time.Now().Unix()
  5260. //err := service.UpdateSchedule(&daySchedule)
  5261. xtSchedule := models.Schedule{
  5262. PartitionId: deviceNumber.ZoneID,
  5263. BedId: bedID,
  5264. ScheduleType: schedual_type,
  5265. UpdatedTime: time.Now().Unix(),
  5266. }
  5267. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5268. if err != nil {
  5269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5270. return
  5271. }
  5272. }
  5273. } else if err == nil {
  5274. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5275. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5276. if daySchedule.ID > 0 {
  5277. //daySchedule.BedId = bedID
  5278. //daySchedule.PartitionId = deviceNumber.ZoneID
  5279. //
  5280. //daySchedule.ScheduleType = schedual_type
  5281. //daySchedule.UpdatedTime = time.Now().Unix()
  5282. //err := service.UpdateSchedule(&daySchedule)
  5283. xtSchedule := models.Schedule{
  5284. PartitionId: deviceNumber.ZoneID,
  5285. BedId: bedID,
  5286. ScheduleType: schedual_type,
  5287. UpdatedTime: time.Now().Unix(),
  5288. }
  5289. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5290. if err != nil {
  5291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5292. return
  5293. }
  5294. }
  5295. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5297. return
  5298. }
  5299. } else if err != nil {
  5300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5301. return
  5302. }
  5303. }
  5304. dialysisRecord := &models.DialysisOrder{
  5305. ID: record_id,
  5306. UserOrgId: adminUserInfo.Org.Id,
  5307. BedID: bedID,
  5308. StartNurse: nurseID,
  5309. StartTime: startDate.Unix(),
  5310. PunctureNurse: puncture_nurse,
  5311. Creator: adminUserInfo.AdminUser.Id,
  5312. Modifier: adminUserInfo.AdminUser.Id,
  5313. WashpipeNurse: washpipe_nurse,
  5314. SchedualType: schedual_type,
  5315. ChangeNurse: change_nurse,
  5316. DifficultPunctureNurse: difficult_puncture_nurse,
  5317. NewFistulaNurse: new_fistula_nurse,
  5318. QualityNurseId: quality_nurse_id,
  5319. PunctureNeedle: puncture_needle,
  5320. PunctureWay: puncture_way,
  5321. DialysisDialyszers: dialysis_dialyszers,
  5322. DialysisIrrigation: dialysis_irrigation,
  5323. BloodAccessId: blood_access_id,
  5324. NucleinDate: theNucleinDate,
  5325. OrderRemark: order_remark,
  5326. ScheduleRemark: schedule_remark,
  5327. CatheterOperation: catheter_operation,
  5328. BloodFlowVolume: blood_flow_volume,
  5329. BloodDrawing: blood_drawing,
  5330. DialysisStrainer: dialysis_strainer,
  5331. }
  5332. _, prescription := service.FindDialysisPrescriptionByReordDate(patient_id, record_date, adminUserInfo.Org.Id)
  5333. if prescription.ID > 0 {
  5334. var endTime int64
  5335. endTime = dialysisRecord.StartTime + prescription.DialysisDurationHour*3600 + prescription.DialysisDurationMinute*60
  5336. dialysisRecord.EndTime = endTime
  5337. }
  5338. if adminUserInfo.Org.Id == 10766 || adminUserInfo.Org.Id == 10164 {
  5339. //查询第一条监测
  5340. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5341. service.UpdateFirstMoitorById(firstMonitor.ID, dialysisRecord.StartTime)
  5342. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5343. redis := service.RedisClient()
  5344. //清空key 值
  5345. redis.Set(key, "", time.Second)
  5346. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5347. redis.Set(keyOne, "", time.Second)
  5348. defer redis.Close()
  5349. }
  5350. //修改床位号需要重新消毒
  5351. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5352. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5353. //查询第一条监测
  5354. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5355. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5356. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5357. redis := service.RedisClient()
  5358. //清空key 值
  5359. redis.Set(key, "", time.Second)
  5360. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5361. redis.Set(keyOne, "", time.Second)
  5362. defer redis.Close()
  5363. }
  5364. // 查询信息规挡的设置天数
  5365. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5366. if infor.ID > 0 && infor.WeekDay > 0 {
  5367. var cha_time int64
  5368. timeNowStr := time.Now().Format("2006-01-02")
  5369. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5370. //今日的日期减去设置的日期
  5371. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5372. if cha_time >= record_date {
  5373. //查询审核是否允许
  5374. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5375. //申请状态不允许的情况 拒绝修改
  5376. if infor.ApplicationStatus != 1 {
  5377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5378. return
  5379. }
  5380. }
  5381. }
  5382. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5383. //修改床位后重新生成消毒计划
  5384. if adminUserInfo.Org.Id == 10340 {
  5385. //根据床位号获取设备型号
  5386. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5387. //查询使用消毒最后一条消毒记录
  5388. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5389. fmt.Println("err", err)
  5390. if err == gorm.ErrRecordNotFound {
  5391. //查找排班
  5392. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5393. //查询改设备是否有消毒计划
  5394. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5395. //根据床位号获取设备id
  5396. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5397. //查询病人信息
  5398. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5399. var con = ""
  5400. if patients.IsInfectious == 0 {
  5401. con = ""
  5402. }
  5403. if patients.IsInfectious == 1 {
  5404. con = "无"
  5405. }
  5406. if patients.IsInfectious == 2 {
  5407. con = "有"
  5408. }
  5409. if errcode == nil {
  5410. var end_time int64
  5411. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5412. //新增消毒
  5413. information := models.DeviceInformation{
  5414. Date: dialysisRecord.DialysisDate,
  5415. Zone: dialysisRecord.ZoneId,
  5416. Class: dialysisRecord.SchedualType,
  5417. BedNumber: dialysisRecord.BedID,
  5418. PatientId: dialysisRecord.PatientId,
  5419. DialysisMode: scheduleByPatient.ModeId,
  5420. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5421. Disinfection: 1,
  5422. DialysisConcentration: 1,
  5423. DisinfectionStatus: 1,
  5424. Move: 1,
  5425. UserOrgId: dialysisRecord.UserOrgId,
  5426. DisinfectType: plan.Way,
  5427. DisinfectantType: plan.MachineDisinfectant,
  5428. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5429. Disinfectant: plan.Disinfectant,
  5430. Ctime: time.Now().Unix(),
  5431. Status: 1,
  5432. SignName: nurseID,
  5433. EquimentId: addmacher.ID,
  5434. DisinfectionResidue: 2,
  5435. Bed: addmacher.BedNumber,
  5436. StartTime: dialysisRecord.StartTime,
  5437. EndTime: dialysisRecord.EndTime,
  5438. Contagion: con,
  5439. WeightLoss: 0,
  5440. Hyperfiltratio: 0,
  5441. DialysisHour: "",
  5442. MachineRun: 1,
  5443. DisinfecStartime: dialysisRecord.EndTime,
  5444. DisinfecEndtime: end_time,
  5445. }
  5446. err := service.CreateInformationTwo(&information)
  5447. fmt.Println("报错", err)
  5448. }
  5449. }
  5450. }
  5451. order, _ := service.GetLastPatientOrder(record_id)
  5452. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5453. redis := service.RedisClient()
  5454. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5455. redis.Set(key, "", time.Second)
  5456. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5457. //清空key 值
  5458. redis.Set(keyOne, "", time.Second)
  5459. scheduleDateStartOne := startDate.Format("2006-01-02")
  5460. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5461. redis.Set(keyTwo, "", time.Second)
  5462. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5463. redis.Set(keyThree, "", time.Second)
  5464. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5465. redis.Set(keyFour, "", time.Second)
  5466. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5467. redis.Set(keyFive, "", time.Second)
  5468. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5469. redis.Set(keySix, "", time.Second)
  5470. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5471. redis.Set(keySeven, "", time.Second)
  5472. if updateErr != nil {
  5473. this.ErrorLog("修改上机失败:%v", updateErr)
  5474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5475. return
  5476. }
  5477. if updateErr == nil {
  5478. if tempDialysisRecord.Stage == 2 {
  5479. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5480. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5481. fmt.Println(value)
  5482. a, b := math.Modf(value)
  5483. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5484. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5485. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5486. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5487. redis := service.RedisClient()
  5488. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5489. redis.Set(key, "", time.Second)
  5490. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5491. redis.Set(keyOne, "", time.Second)
  5492. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5493. //清空key 值
  5494. redis.Set(keySix, "", time.Second)
  5495. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5496. redis.Set(keySeven, "", time.Second)
  5497. redis.Close()
  5498. if updateAssessmentErr != nil {
  5499. utils.ErrorLog("%v", updateAssessmentErr)
  5500. }
  5501. }
  5502. }
  5503. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5504. this.ServeSuccessJSON(map[string]interface{}{
  5505. "dialysis_order": dialysisRecords,
  5506. })
  5507. }
  5508. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5509. record_id, _ := c.GetInt64("id")
  5510. nurseID, _ := c.GetInt64("nurse")
  5511. end_time := c.GetString("end_time")
  5512. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5513. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5514. catheter := c.GetString("catheter")
  5515. cruor := c.GetString("cruor")
  5516. mission := c.GetString("mission")
  5517. condenser := c.GetString("condenser")
  5518. if record_id <= 0 || nurseID <= 0 {
  5519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5520. return
  5521. }
  5522. adminUserInfo := c.GetMobileAdminUserInfo()
  5523. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5524. if getNurseErr != nil {
  5525. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5527. return
  5528. } else if nurse == nil {
  5529. c.ErrorLog("护士不存在")
  5530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5531. return
  5532. }
  5533. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5534. if parseEndDateErr != nil {
  5535. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5537. return
  5538. }
  5539. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5540. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5541. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5542. // if getPermissionErr != nil {
  5543. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5544. // return
  5545. // } else if headNursePermission == nil {
  5546. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5547. // return
  5548. // }
  5549. //}
  5550. // 查询信息规挡的设置天数
  5551. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5552. if infor.ID > 0 {
  5553. var cha_time int64
  5554. timeNowStr := time.Now().Format("2006-01-02")
  5555. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5556. //今日的日期减去设置的日期
  5557. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5558. if cha_time >= tempDialysisRecords.DialysisDate {
  5559. //查询审核是否允许
  5560. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5561. //申请状态不允许的情况 拒绝修改
  5562. if infor.ApplicationStatus != 1 {
  5563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5564. return
  5565. }
  5566. }
  5567. }
  5568. dialysisRecord := &models.DialysisOrder{
  5569. ID: record_id,
  5570. UserOrgId: adminUserInfo.Org.Id,
  5571. EndTime: endDate.Unix(),
  5572. FinishNurse: nurseID,
  5573. FinishModifier: adminUserInfo.AdminUser.Id,
  5574. PuncturePointHaematoma: puncture_point_haematoma,
  5575. BloodAccessInternalFistula: blood_access_internal_fistula,
  5576. Catheter: catheter,
  5577. Cruor: cruor,
  5578. Mission: mission,
  5579. Condenser: condenser,
  5580. }
  5581. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5582. redis := service.RedisClient()
  5583. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5584. //清空key 值
  5585. redis.Set(key, "", time.Second)
  5586. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5587. //清空key 值
  5588. redis.Set(keyOne, "", time.Second)
  5589. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5590. redis.Set(keySeven, "", time.Second)
  5591. redis.Close()
  5592. if updateErr != nil {
  5593. c.ErrorLog("修改下机失败:%v", updateErr)
  5594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5595. return
  5596. }
  5597. if updateErr == nil {
  5598. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5599. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5600. a, b := math.Modf(value)
  5601. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5602. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5603. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5604. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5605. redis := service.RedisClient()
  5606. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5607. redis.Set(keyTen, "", time.Second)
  5608. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5609. redis.Set(keyTwo, "", time.Second)
  5610. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5611. redis.Set(key, "", time.Second)
  5612. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5613. redis.Set(keyThree, "", time.Second)
  5614. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5615. redis.Set(keySeven, "", time.Second)
  5616. defer redis.Close()
  5617. if updateAssessmentErr != nil {
  5618. utils.ErrorLog("%v", updateAssessmentErr)
  5619. }
  5620. }
  5621. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5622. c.ServeSuccessJSON(map[string]interface{}{
  5623. "dialysis_order": dialysisRecords,
  5624. })
  5625. }
  5626. func (c *DialysisAPIController) GetLongAdvice() {
  5627. patient_id, _ := c.GetInt64("id")
  5628. adminUserInfo := c.GetMobileAdminUserInfo()
  5629. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5630. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5631. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5632. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5633. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5634. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5635. c.ServeSuccessJSON(map[string]interface{}{
  5636. "status": "1",
  5637. })
  5638. return
  5639. } else { //开启推送提醒
  5640. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5641. var advice_three []*models.DoctorAdvice
  5642. recordDateStr := time.Now().Format("2006-01-02")
  5643. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5644. nowtime := recordDate.Unix()
  5645. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5646. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5647. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5648. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5649. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5650. for _, advice := range advices {
  5651. if advice.FrequencyType == 3 {
  5652. t := time.Now()
  5653. week := int(t.Weekday())
  5654. fmt.Println(t.Weekday())
  5655. fmt.Println(week)
  5656. switch week {
  5657. case 1:
  5658. if strings.Index(advice.WeekDay, "周一") == -1 {
  5659. advice_three = append(advice_three, advice)
  5660. }
  5661. break
  5662. case 2:
  5663. if strings.Index(advice.WeekDay, "周二") == -1 {
  5664. advice_three = append(advice_three, advice)
  5665. }
  5666. break
  5667. case 3:
  5668. if strings.Index(advice.WeekDay, "周三") == -1 {
  5669. advice_three = append(advice_three, advice)
  5670. }
  5671. break
  5672. case 4:
  5673. if strings.Index(advice.WeekDay, "周四") == -1 {
  5674. advice_three = append(advice_three, advice)
  5675. }
  5676. break
  5677. case 5:
  5678. if strings.Index(advice.WeekDay, "周五") == -1 {
  5679. advice_three = append(advice_three, advice)
  5680. }
  5681. break
  5682. case 6:
  5683. if strings.Index(advice.WeekDay, "周六") == -1 {
  5684. advice_three = append(advice_three, advice)
  5685. }
  5686. break
  5687. case 0:
  5688. if strings.Index(advice.WeekDay, "周日") == -1 {
  5689. advice_three = append(advice_three, advice)
  5690. }
  5691. break
  5692. }
  5693. }
  5694. }
  5695. for _, advice := range advices_two {
  5696. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5697. now := p.Unix()
  5698. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5699. dayStr2 := "-" + dayStr
  5700. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5701. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5702. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5703. for _, ad := range advices {
  5704. advice_three = append(advice_three, ad)
  5705. }
  5706. }
  5707. if err == nil {
  5708. c.ServeSuccessJSON(map[string]interface{}{
  5709. "status": "2",
  5710. "advices": advices,
  5711. "advices_two": RemoveRepeatedElement(advice_three),
  5712. "is_open_remind": config.IsOpenRemind,
  5713. "his_config_open": hisConfig.IsOpen,
  5714. "is_advice_open": is_advice_open.IsAdviceOpen,
  5715. "prescription_open": prescription_open.IsOpen,
  5716. })
  5717. }
  5718. }
  5719. }
  5720. func (c *DialysisAPIController) GetLongAdviceOne() {
  5721. patient_id, _ := c.GetInt64("id")
  5722. startTime := c.GetString("schedule_date")
  5723. timeLayout := "2006-01-02"
  5724. loc, _ := time.LoadLocation("Local")
  5725. var theStartTime int64
  5726. if len(startTime) > 0 {
  5727. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5728. if err != nil {
  5729. utils.ErrorLog(err.Error())
  5730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5731. return
  5732. }
  5733. theStartTime = theTime.Unix()
  5734. }
  5735. adminUserInfo := c.GetMobileAdminUserInfo()
  5736. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5737. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5738. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5739. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5740. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5741. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5742. c.ServeSuccessJSON(map[string]interface{}{
  5743. "status": "1",
  5744. })
  5745. return
  5746. } else { //开启推送提醒
  5747. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5748. var advice_three []*models.DoctorAdvice
  5749. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5750. fmt.Println("theStartTime-----------------------", theStartTime)
  5751. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5752. for _, advice := range advices {
  5753. if advice.FrequencyType == 3 {
  5754. t := time.Now()
  5755. week := int(t.Weekday())
  5756. fmt.Println(t.Weekday())
  5757. fmt.Println(week)
  5758. switch week {
  5759. case 1:
  5760. if strings.Index(advice.WeekDay, "周一") == -1 {
  5761. advice_three = append(advice_three, advice)
  5762. }
  5763. break
  5764. case 2:
  5765. if strings.Index(advice.WeekDay, "周二") == -1 {
  5766. advice_three = append(advice_three, advice)
  5767. }
  5768. break
  5769. case 3:
  5770. if strings.Index(advice.WeekDay, "周三") == -1 {
  5771. advice_three = append(advice_three, advice)
  5772. }
  5773. break
  5774. case 4:
  5775. if strings.Index(advice.WeekDay, "周四") == -1 {
  5776. advice_three = append(advice_three, advice)
  5777. }
  5778. break
  5779. case 5:
  5780. if strings.Index(advice.WeekDay, "周五") == -1 {
  5781. advice_three = append(advice_three, advice)
  5782. }
  5783. break
  5784. case 6:
  5785. if strings.Index(advice.WeekDay, "周六") == -1 {
  5786. advice_three = append(advice_three, advice)
  5787. }
  5788. break
  5789. case 0:
  5790. if strings.Index(advice.WeekDay, "周日") == -1 {
  5791. advice_three = append(advice_three, advice)
  5792. }
  5793. break
  5794. }
  5795. }
  5796. }
  5797. for _, advice := range advices_two {
  5798. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5799. now := p.Unix()
  5800. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5801. dayStr2 := "-" + dayStr
  5802. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5803. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5804. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5805. fmt.Println("advices-==---------------", advices)
  5806. for _, ad := range advices {
  5807. advice_three = append(advice_three, ad)
  5808. }
  5809. }
  5810. if err == nil {
  5811. c.ServeSuccessJSON(map[string]interface{}{
  5812. "status": "2",
  5813. "advices": advices,
  5814. "advices_two": RemoveRepeatedElement(advice_three),
  5815. "is_open_remind": config.IsOpenRemind,
  5816. "his_config_open": hisConfig.IsOpen,
  5817. "is_advice_open": is_advice_open.IsAdviceOpen,
  5818. "prescription_open": prescription_open.IsOpen,
  5819. })
  5820. }
  5821. }
  5822. }
  5823. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5824. newArr = make([]*models.DoctorAdvice, 0)
  5825. for i := 0; i < len(arr); i++ {
  5826. repeat := false
  5827. for j := i + 1; j < len(arr); j++ {
  5828. if arr[i].ID == arr[j].ID {
  5829. repeat = true
  5830. break
  5831. }
  5832. }
  5833. if !repeat {
  5834. newArr = append(newArr, arr[i])
  5835. }
  5836. }
  5837. return
  5838. }
  5839. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5840. patient, _ := c.GetInt64("id", 0)
  5841. groupNo, _ := c.GetInt64("groupno", 0)
  5842. if patient <= 0 {
  5843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5844. return
  5845. }
  5846. adminUserInfo := c.GetMobileAdminUserInfo()
  5847. dataBody := make(map[string]interface{}, 0)
  5848. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5849. if err != nil {
  5850. utils.ErrorLog(err.Error())
  5851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5852. return
  5853. }
  5854. utils.ErrorLog("%v", dataBody)
  5855. timeLayout := "2006-01-02 15:04"
  5856. loc, _ := time.LoadLocation("Local")
  5857. timeLayout2 := "2006-01-02"
  5858. loc2, _ := time.LoadLocation("Local")
  5859. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5860. utils.ErrorLog("advice_type")
  5861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5862. return
  5863. }
  5864. adviceType := int64(2)
  5865. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5866. utils.ErrorLog("advice_date")
  5867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5868. return
  5869. }
  5870. adviceDate, _ := dataBody["advice_date"].(string)
  5871. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5872. AdviceDate := theTime.Unix()
  5873. RecordDate := theTime.Unix()
  5874. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5875. utils.ErrorLog("start_time")
  5876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5877. return
  5878. }
  5879. startTime, _ := dataBody["start_time"].(string)
  5880. if len(startTime) == 0 {
  5881. utils.ErrorLog("len(start_time) == 0")
  5882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5883. return
  5884. }
  5885. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5886. if err != nil {
  5887. utils.ErrorLog(err.Error())
  5888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5889. return
  5890. }
  5891. StartTime := theTime.Unix()
  5892. Remark := ""
  5893. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5894. remark, _ := dataBody["remark"].(string)
  5895. Remark = remark
  5896. }
  5897. var advices []*models.GroupAdvice
  5898. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5899. utils.ErrorLog("advices")
  5900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5901. return
  5902. }
  5903. adviceNames := dataBody["advices"].([]interface{})
  5904. for _, adviceNameMap := range adviceNames {
  5905. adviceNameM := adviceNameMap.(map[string]interface{})
  5906. var advice models.GroupAdvice
  5907. advice.Remark = Remark
  5908. advice.AdviceType = adviceType
  5909. advice.StartTime = StartTime
  5910. advice.AdviceDate = AdviceDate
  5911. advice.RecordDate = RecordDate
  5912. advice.Status = 1
  5913. advice.CreatedTime = time.Now().Unix()
  5914. advice.UpdatedTime = time.Now().Unix()
  5915. advice.StopState = 2
  5916. advice.ExecutionState = 2
  5917. advice.UserOrgId = adminUserInfo.Org.Id
  5918. advice.PatientId = patient
  5919. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5920. advice.IsSettle = 2
  5921. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5922. utils.ErrorLog("advice_name")
  5923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5924. return
  5925. }
  5926. adviceName, _ := adviceNameM["advice_name"].(string)
  5927. if len(adviceName) == 0 {
  5928. utils.ErrorLog("len(advice_name) == 0")
  5929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5930. return
  5931. }
  5932. advice.AdviceName = adviceName
  5933. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5934. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5935. advice.DrugSpec = drugSpec
  5936. }
  5937. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5938. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5939. advice.AdviceDesc = adviceDesc
  5940. }
  5941. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5942. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5943. advice.DrugSpecUnit = drugSpecUnit
  5944. }
  5945. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5946. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5947. // advice.SingleDose = singleDose
  5948. //}
  5949. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5950. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5951. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5952. }
  5953. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5954. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5955. advice.SingleDoseUnit = singleDoseUnit
  5956. }
  5957. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5958. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5959. // advice.PrescribingNumber = prescribingNumber
  5960. //}
  5961. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5962. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5963. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5964. }
  5965. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5966. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5967. advice.PrescribingNumberUnit = prescribingNumberUnit
  5968. }
  5969. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5970. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5971. advice.DeliveryWay = deliveryWay
  5972. }
  5973. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5974. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5975. advice.ExecutionFrequency = executionFrequency
  5976. }
  5977. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5978. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5979. advice.FrequencyType = frequency_type
  5980. }
  5981. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5982. day_count := int64(adviceNameM["day_count"].(float64))
  5983. advice.DayCount = day_count
  5984. }
  5985. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5986. week_day, _ := adviceNameM["week_day"].(string)
  5987. advice.WeekDay = week_day
  5988. }
  5989. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5990. way := int64(adviceNameM["way"].(float64))
  5991. advice.Way = way
  5992. }
  5993. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5994. drug_id := int64(adviceNameM["drug_id"].(float64))
  5995. advice.DrugId = drug_id
  5996. }
  5997. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5998. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5999. advice.DrugNameId = drug_name_id
  6000. }
  6001. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  6002. remark, _ := adviceNameM["remark"].(string)
  6003. advice.Remark = remark
  6004. }
  6005. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  6006. groupno := int64(adviceNameM["groupno"].(float64))
  6007. advice.GroupNo = groupno
  6008. }
  6009. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  6010. template_id, _ := adviceNameM["template_id"].(string)
  6011. advice.TemplateId = template_id
  6012. }
  6013. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  6014. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  6015. advice.ExecutionFrequency = executionFrequency
  6016. }
  6017. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  6018. children := adviceNameM["child"].([]interface{})
  6019. if len(children) > 0 {
  6020. for _, childrenMap := range children {
  6021. childMap := childrenMap.(map[string]interface{})
  6022. var child models.GroupAdvice
  6023. child.Remark = Remark
  6024. child.AdviceType = adviceType
  6025. child.StartTime = StartTime
  6026. child.AdviceDate = AdviceDate
  6027. child.RecordDate = RecordDate
  6028. child.Status = 1
  6029. child.CreatedTime = time.Now().Unix()
  6030. child.UpdatedTime = time.Now().Unix()
  6031. child.StopState = 2
  6032. child.ExecutionState = 2
  6033. child.UserOrgId = adminUserInfo.Org.Id
  6034. child.PatientId = patient
  6035. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  6036. child.IsSettle = 1
  6037. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  6038. utils.ErrorLog("child advice_name")
  6039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6040. return
  6041. }
  6042. childAdviceName, _ := childMap["advice_name"].(string)
  6043. if len(childAdviceName) == 0 {
  6044. utils.ErrorLog("len(child advice_name) == 0")
  6045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6046. return
  6047. }
  6048. child.AdviceName = childAdviceName
  6049. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  6050. childAdviceDesc, _ := childMap["advice_desc"].(string)
  6051. child.AdviceDesc = childAdviceDesc
  6052. }
  6053. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  6054. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  6055. child.DrugSpec = childDrugSpec
  6056. }
  6057. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  6058. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  6059. child.DrugSpecUnit = childDrugSpecUnit
  6060. }
  6061. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  6062. child.SingleDose = childMap["single_dose"].(float64)
  6063. }
  6064. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  6065. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  6066. child.SingleDoseUnit = childSingleDoseUnit
  6067. }
  6068. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  6069. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  6070. }
  6071. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  6072. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  6073. child.PrescribingNumberUnit = childPrescribingNumberUnit
  6074. }
  6075. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  6076. groupno := int64(childMap["groupno"].(float64))
  6077. advice.GroupNo = groupno
  6078. }
  6079. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  6080. remark, _ := childMap["remark"].(string)
  6081. child.Remark = remark
  6082. }
  6083. child.DeliveryWay = advice.DeliveryWay
  6084. child.ExecutionFrequency = advice.ExecutionFrequency
  6085. advice.Children = append(advice.Children, &child)
  6086. }
  6087. }
  6088. }
  6089. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  6090. if temp_advice.ID == 0 {
  6091. advices = append(advices, &advice)
  6092. }
  6093. }
  6094. if len(advices) > 0 {
  6095. finish := models.XtDialysisFinish{
  6096. IsFinish: 1,
  6097. UserOrgId: adminUserInfo.Org.Id,
  6098. Status: 1,
  6099. Ctime: time.Now().Unix(),
  6100. Mtime: 0,
  6101. Module: 4,
  6102. RecordDate: AdviceDate,
  6103. Sourse: 1,
  6104. PatientId: patient,
  6105. }
  6106. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  6107. if dialysisFinish.ID == 0 {
  6108. service.CreateDialysisFinish(finish)
  6109. }
  6110. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  6111. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  6112. for _, item := range advices {
  6113. byterequest, _ := json.Marshal(item)
  6114. adviceLog := models.XtDoctorAdviceLog{
  6115. UserOrgId: adminUserInfo.Org.Id,
  6116. PatientId: patient,
  6117. AdminUserId: adminUserInfo.AdminUser.Id,
  6118. Module: 1,
  6119. ErrLog: string(byterequest),
  6120. Status: 1,
  6121. Ctime: time.Now().Unix(),
  6122. Mtime: 0,
  6123. Source: "手机端医嘱推送",
  6124. RecordDate: item.AdviceDate,
  6125. }
  6126. service.CreateDoctorAdviceLog(adviceLog)
  6127. }
  6128. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6129. redis := service.RedisClient()
  6130. //清空key 值
  6131. redis.Set(key, "", time.Second)
  6132. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6133. redis.Set(keyOne, "", time.Second)
  6134. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6135. defer redis.Close()
  6136. redis.Set(keyThree, "", time.Second)
  6137. if err != nil {
  6138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6139. return
  6140. }
  6141. c.ServeSuccessJSON(map[string]interface{}{
  6142. "msg": "ok",
  6143. "advices": list,
  6144. })
  6145. } else {
  6146. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  6147. for _, item := range advices {
  6148. byterequest, _ := json.Marshal(item)
  6149. adviceLog := models.XtDoctorAdviceLog{
  6150. UserOrgId: adminUserInfo.Org.Id,
  6151. PatientId: patient,
  6152. AdminUserId: adminUserInfo.AdminUser.Id,
  6153. Module: 1,
  6154. ErrLog: string(byterequest),
  6155. Status: 1,
  6156. Ctime: time.Now().Unix(),
  6157. Mtime: 0,
  6158. Source: "手机端医嘱推送",
  6159. RecordDate: item.AdviceDate,
  6160. }
  6161. service.CreateDoctorAdviceLog(adviceLog)
  6162. }
  6163. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  6164. redis := service.RedisClient()
  6165. //清空key 值
  6166. redis.Set(key, "", time.Second)
  6167. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  6168. redis.Set(keyOne, "", time.Second)
  6169. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6170. defer redis.Close()
  6171. redis.Set(keyThree, "", time.Second)
  6172. if err != nil {
  6173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  6174. return
  6175. }
  6176. c.ServeSuccessJSON(map[string]interface{}{
  6177. "msg": "ok",
  6178. "advices": list,
  6179. })
  6180. }
  6181. } else {
  6182. c.ServeSuccessJSON(map[string]interface{}{
  6183. "msg": "ok",
  6184. })
  6185. }
  6186. return
  6187. }
  6188. func (c *DialysisAPIController) UploadDryWeight() {
  6189. patient_id, _ := c.GetInt64("id")
  6190. dry_weight, _ := c.GetFloat("dry_weight")
  6191. doctor_id, _ := c.GetInt64("doctor_id")
  6192. remark := c.GetString("remark")
  6193. adminUserInfo := c.GetMobileAdminUserInfo()
  6194. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  6195. if err == gorm.ErrRecordNotFound {
  6196. dryWeight := &models.SgjPatientDryweight{
  6197. PatientId: patient_id,
  6198. DryWeight: dry_weight,
  6199. Remakes: remark,
  6200. Ctime: time.Now().Unix(),
  6201. Mtime: time.Now().Unix(),
  6202. Creator: doctor_id,
  6203. Status: 1,
  6204. UserOrgId: adminUserInfo.Org.Id,
  6205. AdjustedValue: "/",
  6206. UserId: adminUserInfo.AdminUser.Id,
  6207. }
  6208. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6209. redis := service.RedisClient()
  6210. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6211. redis.Set(keyOne, "", time.Second)
  6212. loc, _ := time.LoadLocation("Local")
  6213. nowTime := time.Now()
  6214. nowDay := nowTime.Format("2006-01-02")
  6215. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6216. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6217. redis.Set(key, "", time.Second)
  6218. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6219. redis.Set(keyTwo, "", time.Second)
  6220. redis.Close()
  6221. if createErr == nil {
  6222. c.ServeSuccessJSON(map[string]interface{}{
  6223. "msg": "提交成功",
  6224. "weight": dryWeight,
  6225. })
  6226. }
  6227. } else {
  6228. dryWeight := &models.SgjPatientDryweight{
  6229. PatientId: patient_id,
  6230. DryWeight: dry_weight,
  6231. Remakes: remark,
  6232. Ctime: time.Now().Unix(),
  6233. Mtime: time.Now().Unix(),
  6234. Creator: doctor_id,
  6235. Status: 1,
  6236. UserOrgId: adminUserInfo.Org.Id,
  6237. AdjustedValue: "/",
  6238. UserId: adminUserInfo.AdminUser.Id,
  6239. }
  6240. var value float64
  6241. value = dry_weight - weightAdjust.DryWeight
  6242. if value < 0 {
  6243. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6244. } else if value == 0 {
  6245. dryWeight.AdjustedValue = "/"
  6246. } else if value > 0 {
  6247. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6248. }
  6249. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6250. //康桥
  6251. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6252. timeNowStr := time.Now().Format("2006-01-02")
  6253. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6254. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6255. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6256. if beforAssesment.ID > 0 {
  6257. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6258. var dewater_amount float64
  6259. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6260. if adminUserInfo.Org.Id != 10702 {
  6261. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6262. }
  6263. if adminUserInfo.Org.Id == 10702 {
  6264. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6265. }
  6266. //获取key,清空redis
  6267. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6268. redis := service.RedisClient()
  6269. //清空key 值
  6270. redis.Set(key, "", time.Second)
  6271. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6272. //清空key 值
  6273. redis.Set(keyOne, "", time.Second)
  6274. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6275. //清空key 值
  6276. redis.Set(keyTwo, "", time.Second)
  6277. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6278. redis.Set(keySix, "", time.Second)
  6279. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6280. redis.Set(keySeven, "", time.Second)
  6281. }
  6282. }
  6283. redis := service.RedisClient()
  6284. loc, _ := time.LoadLocation("Local")
  6285. nowTime := time.Now()
  6286. nowDay := nowTime.Format("2006-01-02")
  6287. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6288. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6289. redis.Set(keyOne, "", time.Second)
  6290. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6291. redis.Set(key, "", time.Second)
  6292. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6293. redis.Set(keyTwo, "", time.Second)
  6294. redis.Close()
  6295. if createErr == nil {
  6296. c.ServeSuccessJSON(map[string]interface{}{
  6297. "msg": "提交成功",
  6298. "weight": dryWeight,
  6299. })
  6300. }
  6301. }
  6302. }
  6303. func (c *DialysisAPIController) GetSolution() {
  6304. patient_id, _ := c.GetInt64("patient_id")
  6305. mode_id, _ := c.GetInt64("mode_id")
  6306. adminUserInfo := c.GetMobileAdminUserInfo()
  6307. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6308. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6309. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6310. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6311. if err != nil {
  6312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6313. return
  6314. }
  6315. c.ServeSuccessJSON(map[string]interface{}{
  6316. "solution": solution,
  6317. "prescription": prescription,
  6318. "system_prescription": system_prescription,
  6319. "dialysisPrescription": dialysisPrescription,
  6320. })
  6321. }
  6322. func (c *DialysisAPIController) GetSchedule() {
  6323. schedual_type, _ := c.GetInt64("schedual_type")
  6324. adminUserInfo := c.GetMobileAdminUserInfo()
  6325. scheduleTime, _ := c.GetInt64("record_date")
  6326. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6327. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6328. c.ServeSuccessJSON(map[string]interface{}{
  6329. "number": deviceNumber,
  6330. "list": list,
  6331. })
  6332. }
  6333. func (c *DialysisAPIController) GetPatientId() {
  6334. id, _ := c.GetInt64("id")
  6335. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6336. patientId, _ := service.GetPatientId(id)
  6337. //获取该患者的所有传染病
  6338. list, _ := service.GetPatientInfectious(id)
  6339. c.ServeSuccessJSON(map[string]interface{}{
  6340. "patient": patientId,
  6341. "infectioulist": list,
  6342. })
  6343. }
  6344. func (this *DialysisAPIController) GetDialysisSchedule() {
  6345. schedualDate := this.GetString("date")
  6346. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6347. if parseDateErr != nil {
  6348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6349. return
  6350. }
  6351. adminInfo := this.GetMobileAdminUserInfo()
  6352. orgID := adminInfo.Org.Id
  6353. redis := service.RedisClient()
  6354. defer redis.Close()
  6355. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6356. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6357. if len(scheduals) > 0 {
  6358. //缓存数据
  6359. scheduals_json, err := json.Marshal(scheduals)
  6360. if err == nil {
  6361. redis.Set(key, scheduals_json, time.Second*30)
  6362. }
  6363. }
  6364. this.ServeSuccessJSON(map[string]interface{}{
  6365. "scheduals": scheduals,
  6366. })
  6367. }
  6368. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6369. change_type, _ := this.GetInt64("type", 0)
  6370. record_date := this.GetString("record_time")
  6371. patient_id, _ := this.GetInt64("patient_id", 0)
  6372. timeLayout := "2006-01-02"
  6373. loc, _ := time.LoadLocation("Local")
  6374. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6375. record_time := theAdviceRecordTime.Unix()
  6376. adminUserInfo := this.GetMobileAdminUserInfo()
  6377. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6378. if err == nil {
  6379. if len(advices) == 0 {
  6380. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6381. return
  6382. } else {
  6383. this.ServeSuccessJSON(map[string]interface{}{
  6384. "advices": advices,
  6385. "schedule": sch,
  6386. })
  6387. return
  6388. }
  6389. } else {
  6390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6391. return
  6392. }
  6393. }
  6394. func (c *DialysisAPIController) CreateConsumables() {
  6395. record_date := c.GetString("record_time")
  6396. patient_id, _ := c.GetInt64("patient_id", 0)
  6397. active, _ := c.GetInt64("active")
  6398. adminUser := c.GetMobileAdminUserInfo()
  6399. timeLayout := "2006-01-02"
  6400. loc, _ := time.LoadLocation("Local")
  6401. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6402. record_time := theRecordTime.Unix()
  6403. // 查询信息规挡的设置天数
  6404. orgid := c.GetMobileAdminUserInfo().Org.Id
  6405. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6406. if infor.ID > 0 {
  6407. var cha_time int64
  6408. timeNowStr := time.Now().Format("2006-01-02")
  6409. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6410. //今日的日期减去设置的日期
  6411. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6412. if cha_time >= record_time {
  6413. //查询审核是否允许
  6414. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6415. //申请状态不允许的情况 拒绝修改
  6416. if infor.ApplicationStatus != 1 {
  6417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6418. return
  6419. }
  6420. }
  6421. }
  6422. dataBody := make(map[string]interface{}, 0)
  6423. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6424. if err != nil {
  6425. utils.ErrorLog(err.Error())
  6426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6427. return
  6428. }
  6429. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6430. var beforePrepares []*models.DialysisBeforePrepareGoods
  6431. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6432. var dialysisBefor []*models.DialysisBeforePrepare
  6433. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6434. goods, _ := dataBody["goods"].([]interface{})
  6435. if len(goods) > 0 {
  6436. for _, item := range goods {
  6437. items := item.(map[string]interface{})
  6438. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6439. utils.ErrorLog("good_id")
  6440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6441. return
  6442. }
  6443. good_id := int64(items["good_id"].(float64))
  6444. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6445. utils.ErrorLog("good_type_id")
  6446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6447. return
  6448. }
  6449. good_type_id := int64(items["good_type_id"].(float64))
  6450. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6451. utils.ErrorLog("count")
  6452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6453. return
  6454. }
  6455. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6456. commdity_code := items["commdity_code"].(string)
  6457. fmt.Println("commdity", commdity_code)
  6458. prepareGoods := &models.DialysisBeforePrepareGoods{
  6459. GoodTypeId: good_type_id,
  6460. GoodId: good_id,
  6461. Count: count,
  6462. StorehouseId: houseConfig.StorehouseOutInfo,
  6463. }
  6464. beforePrepares = append(beforePrepares, prepareGoods)
  6465. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6466. GoodTypeId: good_type_id,
  6467. GoodId: good_id,
  6468. Count: count,
  6469. StorehouseId: houseConfig.StorehouseOutInfo,
  6470. }
  6471. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6472. prepare := &models.DialysisBeforePrepare{
  6473. GoodTypeId: good_type_id,
  6474. GoodId: good_id,
  6475. Count: count,
  6476. PatientId: patient_id,
  6477. RecordDate: record_time,
  6478. UserOrgId: adminUser.Org.Id,
  6479. Status: 1,
  6480. Ctime: time.Now().Unix(),
  6481. Creater: adminUser.AdminUser.Id,
  6482. CommdityCode: commdity_code,
  6483. StorehouseId: houseConfig.StorehouseOutInfo,
  6484. }
  6485. dialysisBefor = append(dialysisBefor, prepare)
  6486. }
  6487. }
  6488. //查询是否有库存
  6489. for _, item := range dialysisBefor {
  6490. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6491. if err == gorm.ErrRecordNotFound {
  6492. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6493. c.ServeSuccessJSON(map[string]interface{}{
  6494. "message": "1",
  6495. "good_name": goodObj.GoodName,
  6496. "specification_name": goodObj.SpecificationName,
  6497. })
  6498. return
  6499. }
  6500. if err != nil {
  6501. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6502. c.ServeSuccessJSON(map[string]interface{}{
  6503. "message": "1",
  6504. "good_name": goodObj.GoodName,
  6505. "specification_name": goodObj.SpecificationName,
  6506. })
  6507. return
  6508. }
  6509. }
  6510. fmt.Println("active-----------------------", active)
  6511. fmt.Println("len(goods)-----------------------", len(goods))
  6512. //新增
  6513. if active == 1 && len(goods) > 0 {
  6514. for _, item := range dialysisBefor {
  6515. dialyPrepareOne := models.DialysisBeforePrepare{
  6516. GoodTypeId: item.GoodTypeId,
  6517. GoodId: item.GoodId,
  6518. PatientId: item.PatientId,
  6519. RecordDate: item.RecordDate,
  6520. UserOrgId: item.UserOrgId,
  6521. Count: item.Count,
  6522. Ctime: time.Now().Unix(),
  6523. Creater: item.Creater,
  6524. CommdityCode: item.CommdityCode,
  6525. Status: 1,
  6526. StorehouseId: houseConfig.StorehouseOutInfo,
  6527. }
  6528. //先清除再插入
  6529. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6530. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6531. //查询默认仓库
  6532. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6533. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6534. var total_count int64
  6535. for _, it := range stockList {
  6536. total_count += it.StockCount
  6537. }
  6538. //基础库插入数据
  6539. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6540. //更新库存
  6541. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6542. var flush_count int64
  6543. for _, it := range goodList {
  6544. flush_count += it.StockCount
  6545. }
  6546. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6547. }
  6548. if err == nil {
  6549. c.ServeSuccessJSON(map[string]interface{}{
  6550. "msg": "保存成功",
  6551. "message": "2",
  6552. })
  6553. return
  6554. } else {
  6555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6556. return
  6557. }
  6558. }
  6559. if len(beforePrepares) > 0 && active == 2 {
  6560. for _, item := range beforePrepares {
  6561. //1.查看该患者该耗材型号最后一次出库数量
  6562. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6563. //判断当前出库数量和最后一次出库数量的大小
  6564. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6565. if item.Count <= goodInfo.Count {
  6566. //退库
  6567. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6568. //查询今日出库数据
  6569. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6570. for _, it := range list {
  6571. prepare := models.DialysisBeforePrepare{
  6572. UserOrgId: it.OrgId,
  6573. PatientId: patient_id,
  6574. RecordDate: it.RecordTime,
  6575. GoodId: it.GoodId,
  6576. GoodTypeId: it.GoodTypeId,
  6577. Count: it.Count,
  6578. Ctime: time.Now().Unix(),
  6579. Creater: adminUser.AdminUser.Id,
  6580. Status: 1,
  6581. StorehouseId: houseConfig.StorehouseOutInfo,
  6582. }
  6583. //删除准备表数据
  6584. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6585. service.CreateDialysisBeforePrepareOne(&prepare)
  6586. }
  6587. }
  6588. var last_total int64
  6589. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6590. if item.Count >= goodInfo.Count {
  6591. //查询当前批次当前耗材最后一条出库数据
  6592. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6593. //计算当前出库和最后一次出库数据相差数据
  6594. last_total = item.Count - lastOutInfo.Count
  6595. //查询该批次剩余库存
  6596. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6597. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6598. if lastInfo.StockCount >= last_total {
  6599. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6600. //查询今日出库数据
  6601. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6602. for _, it := range list {
  6603. prepare := models.DialysisBeforePrepare{
  6604. UserOrgId: it.OrgId,
  6605. PatientId: patient_id,
  6606. RecordDate: it.RecordTime,
  6607. GoodId: it.GoodId,
  6608. GoodTypeId: it.GoodTypeId,
  6609. Count: it.Count,
  6610. Ctime: time.Now().Unix(),
  6611. Creater: adminUser.AdminUser.Id,
  6612. Status: 1,
  6613. StorehouseId: houseConfig.StorehouseOutInfo,
  6614. }
  6615. //删除准备表数据
  6616. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6617. service.CreateDialysisBeforePrepareOne(&prepare)
  6618. //查询默认仓库
  6619. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6620. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6621. var total_count int64
  6622. for _, it := range stockList {
  6623. total_count += it.StockCount
  6624. }
  6625. //基础库插入数据
  6626. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6627. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6628. var flush_count int64
  6629. for _, it := range goodList {
  6630. flush_count += it.StockCount
  6631. }
  6632. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6633. }
  6634. }
  6635. //如果库存不够,则出库到下一个批次
  6636. if lastInfo.StockCount < last_total {
  6637. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6638. //查询今日出库数据
  6639. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6640. for _, it := range list {
  6641. prepare := models.DialysisBeforePrepare{
  6642. UserOrgId: it.OrgId,
  6643. PatientId: patient_id,
  6644. RecordDate: it.RecordTime,
  6645. GoodId: it.GoodId,
  6646. GoodTypeId: it.GoodTypeId,
  6647. Count: it.Count,
  6648. Ctime: time.Now().Unix(),
  6649. Creater: adminUser.AdminUser.Id,
  6650. Status: 1,
  6651. StorehouseId: houseConfig.StorehouseOutInfo,
  6652. }
  6653. //删除准备表数据
  6654. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6655. service.CreateDialysisBeforePrepareOne(&prepare)
  6656. //查询默认仓库
  6657. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6658. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6659. var total_count int64
  6660. for _, it := range stockList {
  6661. total_count += it.StockCount
  6662. }
  6663. //基础库插入数据
  6664. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6665. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6666. var flush_count int64
  6667. for _, it := range goodList {
  6668. flush_count += it.StockCount
  6669. }
  6670. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6671. }
  6672. if err != nil {
  6673. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6674. c.ServeSuccessJSON(map[string]interface{}{
  6675. "message": "1",
  6676. "good_name": goodObj.GoodName,
  6677. "specification_name": goodObj.SpecificationName,
  6678. })
  6679. return
  6680. }
  6681. }
  6682. }
  6683. if err != nil {
  6684. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6685. c.ServeSuccessJSON(map[string]interface{}{
  6686. "message": "1",
  6687. "good_name": goodObj.GoodName,
  6688. "specification_name": goodObj.SpecificationName,
  6689. })
  6690. return
  6691. }
  6692. }
  6693. }
  6694. }
  6695. var errs error
  6696. if errs == nil {
  6697. c.ServeSuccessJSON(map[string]interface{}{
  6698. "msg": "提交成功",
  6699. "message": "2",
  6700. "good_name": "",
  6701. "specification_name": "",
  6702. })
  6703. return
  6704. } else {
  6705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6706. return
  6707. }
  6708. }
  6709. func (c *DialysisAPIController) CreateStockOutInfo() {
  6710. patient_id, _ := c.GetInt64("patient_id", 0)
  6711. record_date := c.GetString("record_time")
  6712. if patient_id <= 0 {
  6713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6714. return
  6715. }
  6716. adminInfo := c.GetMobileAdminUserInfo()
  6717. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6718. timeLayout := "2006-01-02"
  6719. loc, _ := time.LoadLocation("Local")
  6720. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6721. record_time := theRecordTime.Unix()
  6722. // 查询信息规挡的设置天数
  6723. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6724. if infor.ID > 0 && infor.WeekDay > 0 {
  6725. var cha_time int64
  6726. timeNowStr := time.Now().Format("2006-01-02")
  6727. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6728. //今日的日期减去设置的日期
  6729. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6730. if cha_time >= record_time {
  6731. //查询审核是否允许
  6732. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6733. //申请状态不允许的情况 拒绝修改
  6734. if infor.ApplicationStatus != 1 {
  6735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6736. return
  6737. }
  6738. }
  6739. }
  6740. //创建步骤表
  6741. finish := models.XtDialysisFinish{
  6742. IsFinish: 1,
  6743. UserOrgId: adminInfo.Org.Id,
  6744. Status: 1,
  6745. Ctime: time.Now().Unix(),
  6746. Mtime: 0,
  6747. Module: 11,
  6748. RecordDate: record_time,
  6749. Sourse: 1,
  6750. PatientId: patient_id,
  6751. }
  6752. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6753. if dialysisFinish.ID == 0 {
  6754. service.CreateDialysisFinish(finish)
  6755. }
  6756. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6757. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6758. //去重
  6759. consumables = RemoveRepeatedGood(consumables)
  6760. if adminInfo.Org.Id == 9919 {
  6761. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6762. //查询是否有库存
  6763. for _, item := range consumables {
  6764. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6765. if item.Count > warehouse.Count {
  6766. goodErrcode := models.XtGoodErrcode{
  6767. UserOrgId: item.UserOrgId,
  6768. Errcode: "自动出库库存不足",
  6769. GoodId: item.GoodId,
  6770. Status: 1,
  6771. Ctime: time.Now().Unix(),
  6772. Mtime: 0,
  6773. Count: 0,
  6774. StockCount: 0,
  6775. Creater: creator,
  6776. BatchNumberId: warehouse.ID,
  6777. WarehouseOutId: 0,
  6778. }
  6779. service.CreateGoodErrcode(goodErrcode)
  6780. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6781. c.ServeSuccessJSON(map[string]interface{}{
  6782. "message": "1",
  6783. "good_name": goodObj.GoodName,
  6784. "specification_name": goodObj.SpecificationName,
  6785. })
  6786. return
  6787. }
  6788. }
  6789. //查询是否有出库单
  6790. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6791. if err == gorm.ErrRecordNotFound {
  6792. //没有记录,则创建出库单
  6793. timeStr := time.Now().Format("2006-01-02")
  6794. timeArr := strings.Split(timeStr, "-")
  6795. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6796. total = total + 1
  6797. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6798. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6799. number = number + total
  6800. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6801. creater := adminInfo.AdminUser.Id
  6802. warehouseOut := models.WarehouseOut{
  6803. WarehouseOutOrderNumber: warehousing_out_order,
  6804. OperationTime: time.Now().Unix(),
  6805. OrgId: adminInfo.Org.Id,
  6806. Creater: creater,
  6807. Ctime: time.Now().Unix(),
  6808. Status: 1,
  6809. WarehouseOutTime: record_time,
  6810. Dealer: 0,
  6811. Manufacturer: 0,
  6812. Type: 1,
  6813. IsSys: 1,
  6814. StorehouseId: houseConfig.StorehouseOutInfo,
  6815. IsCheck: 1,
  6816. }
  6817. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6818. if err != nil {
  6819. goodErrcode := models.XtGoodErrcode{
  6820. UserOrgId: adminInfo.Org.Id,
  6821. Errcode: "创建出库单失败",
  6822. GoodId: 0,
  6823. Status: 1,
  6824. Ctime: time.Now().Unix(),
  6825. Mtime: 0,
  6826. Count: 0,
  6827. StockCount: 0,
  6828. Creater: creator,
  6829. BatchNumberId: 0,
  6830. WarehouseOutId: 0,
  6831. }
  6832. service.CreateGoodErrcode(goodErrcode)
  6833. utils.TraceLog("创建出库单失败 err = %v", err)
  6834. } else {
  6835. for _, item := range consumables {
  6836. //出库
  6837. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6838. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6839. if err == nil {
  6840. goodErrcode := models.XtGoodErrcode{
  6841. UserOrgId: adminInfo.Org.Id,
  6842. Errcode: "自动出库接口报错",
  6843. GoodId: 0,
  6844. Status: 1,
  6845. Ctime: time.Now().Unix(),
  6846. Mtime: 0,
  6847. Count: 0,
  6848. StockCount: 0,
  6849. Creater: creator,
  6850. BatchNumberId: 0,
  6851. WarehouseOutId: 0,
  6852. }
  6853. service.CreateGoodErrcode(goodErrcode)
  6854. utils.TraceLog("创建出库单失败 err = %v", err)
  6855. }
  6856. //查询
  6857. //出库数量相加
  6858. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6859. if errs != nil {
  6860. goodErrcode := models.XtGoodErrcode{
  6861. UserOrgId: item.UserOrgId,
  6862. Errcode: "创建剩余库存字段报错",
  6863. GoodId: item.GoodId,
  6864. Status: 1,
  6865. Ctime: time.Now().Unix(),
  6866. Mtime: 0,
  6867. Count: 0,
  6868. StockCount: 0,
  6869. Creater: creater,
  6870. BatchNumberId: 0,
  6871. WarehouseOutId: 0,
  6872. }
  6873. service.CreateGoodErrcode(goodErrcode)
  6874. }
  6875. }
  6876. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6877. if len(list) == 0 {
  6878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6879. return
  6880. }
  6881. for _, item := range list {
  6882. prepare := models.DialysisBeforePrepare{
  6883. UserOrgId: adminInfo.Org.Id,
  6884. PatientId: patient_id,
  6885. RecordDate: record_time,
  6886. GoodId: item.GoodId,
  6887. GoodTypeId: item.GoodTypeId,
  6888. Count: item.Count,
  6889. Creater: adminInfo.AdminUser.Id,
  6890. Status: 1,
  6891. Ctime: time.Now().Unix(),
  6892. StorehouseId: houseConfig.StorehouseOutInfo,
  6893. }
  6894. //清空准备表数据
  6895. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6896. if err != nil {
  6897. goodErrcode := models.XtGoodErrcode{
  6898. UserOrgId: item.OrgId,
  6899. Errcode: "自动出库清空准备表数据报错",
  6900. GoodId: item.GoodId,
  6901. Status: 1,
  6902. Ctime: time.Now().Unix(),
  6903. Mtime: 0,
  6904. Count: 0,
  6905. StockCount: 0,
  6906. Creater: creater,
  6907. BatchNumberId: 0,
  6908. WarehouseOutId: 0,
  6909. }
  6910. service.CreateGoodErrcode(goodErrcode)
  6911. }
  6912. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6913. if errs != nil {
  6914. goodErrcode := models.XtGoodErrcode{
  6915. UserOrgId: item.OrgId,
  6916. Errcode: "自动出库创建准备表数据报错",
  6917. GoodId: item.GoodId,
  6918. Status: 1,
  6919. Ctime: time.Now().Unix(),
  6920. Mtime: 0,
  6921. Count: 0,
  6922. StockCount: 0,
  6923. Creater: creater,
  6924. BatchNumberId: 0,
  6925. WarehouseOutId: 0,
  6926. }
  6927. service.CreateGoodErrcode(goodErrcode)
  6928. }
  6929. //查询默认仓库
  6930. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6931. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6932. var total_count int64
  6933. for _, it := range stockList {
  6934. total_count += it.StockCount
  6935. }
  6936. //基础库插入数据
  6937. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6938. if errcodes != nil {
  6939. goodErrcode := models.XtGoodErrcode{
  6940. UserOrgId: item.OrgId,
  6941. Errcode: "自动出库基础库插入数据",
  6942. GoodId: item.GoodId,
  6943. Status: 1,
  6944. Ctime: time.Now().Unix(),
  6945. Mtime: 0,
  6946. Count: 0,
  6947. StockCount: 0,
  6948. Creater: creater,
  6949. BatchNumberId: 0,
  6950. WarehouseOutId: 0,
  6951. }
  6952. service.CreateGoodErrcode(goodErrcode)
  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. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6960. if errsss != nil {
  6961. goodErrcode := models.XtGoodErrcode{
  6962. UserOrgId: item.OrgId,
  6963. Errcode: "自动出库剩余库存更新数据",
  6964. GoodId: item.GoodId,
  6965. Status: 1,
  6966. Ctime: time.Now().Unix(),
  6967. Mtime: 0,
  6968. Count: 0,
  6969. StockCount: 0,
  6970. Creater: creater,
  6971. BatchNumberId: 0,
  6972. WarehouseOutId: 0,
  6973. }
  6974. service.CreateGoodErrcode(goodErrcode)
  6975. }
  6976. }
  6977. }
  6978. //
  6979. } else if err == nil {
  6980. for _, item := range consumables {
  6981. //出库
  6982. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6983. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6984. if err != nil {
  6985. goodErrcode := models.XtGoodErrcode{
  6986. UserOrgId: adminInfo.Org.Id,
  6987. Errcode: "自动出库接口报错",
  6988. GoodId: 0,
  6989. Status: 1,
  6990. Ctime: time.Now().Unix(),
  6991. Mtime: 0,
  6992. Count: 0,
  6993. StockCount: 0,
  6994. Creater: creator,
  6995. BatchNumberId: 0,
  6996. WarehouseOutId: 0,
  6997. }
  6998. service.CreateGoodErrcode(goodErrcode)
  6999. }
  7000. //出库数量相加
  7001. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7002. if errss != nil {
  7003. goodErrcode := models.XtGoodErrcode{
  7004. UserOrgId: item.UserOrgId,
  7005. Errcode: "创建剩余库存字段报错",
  7006. GoodId: item.GoodId,
  7007. Status: 1,
  7008. Ctime: time.Now().Unix(),
  7009. Mtime: time.Now().Unix(),
  7010. Count: 0,
  7011. StockCount: 0,
  7012. Creater: item.Creater,
  7013. BatchNumberId: 0,
  7014. WarehouseOutId: 0,
  7015. }
  7016. service.CreateGoodErrcode(goodErrcode)
  7017. }
  7018. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7019. if len(list) == 0 {
  7020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7021. return
  7022. }
  7023. for _, item := range list {
  7024. prepare := models.DialysisBeforePrepare{
  7025. UserOrgId: adminInfo.Org.Id,
  7026. PatientId: patient_id,
  7027. RecordDate: record_time,
  7028. GoodId: item.GoodId,
  7029. GoodTypeId: item.GoodTypeId,
  7030. Count: item.Count,
  7031. Creater: adminInfo.AdminUser.Id,
  7032. Status: 1,
  7033. Ctime: time.Now().Unix(),
  7034. StorehouseId: houseConfig.StorehouseOutInfo,
  7035. }
  7036. //清空准备表数据
  7037. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7038. if errs != nil {
  7039. goodErrcode := models.XtGoodErrcode{
  7040. UserOrgId: adminInfo.Org.Id,
  7041. Errcode: "自动出库清空准备表数据报错",
  7042. GoodId: 0,
  7043. Status: 1,
  7044. Ctime: time.Now().Unix(),
  7045. Mtime: 0,
  7046. Count: 0,
  7047. StockCount: 0,
  7048. Creater: creator,
  7049. BatchNumberId: 0,
  7050. WarehouseOutId: 0,
  7051. }
  7052. service.CreateGoodErrcode(goodErrcode)
  7053. }
  7054. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7055. if errcodes != nil {
  7056. goodErrcode := models.XtGoodErrcode{
  7057. UserOrgId: adminInfo.Org.Id,
  7058. Errcode: "自动出库创建准备表数据报错",
  7059. GoodId: 0,
  7060. Status: 1,
  7061. Ctime: time.Now().Unix(),
  7062. Mtime: 0,
  7063. Count: 0,
  7064. StockCount: 0,
  7065. Creater: creator,
  7066. BatchNumberId: 0,
  7067. WarehouseOutId: 0,
  7068. }
  7069. service.CreateGoodErrcode(goodErrcode)
  7070. }
  7071. //查询默认仓库
  7072. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7073. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7074. var total_count int64
  7075. for _, it := range stockList {
  7076. total_count += it.StockCount
  7077. }
  7078. //基础库插入数据
  7079. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7080. if errcodes != nil {
  7081. goodErrcode := models.XtGoodErrcode{
  7082. UserOrgId: adminInfo.Org.Id,
  7083. Errcode: "自动出库基础库插入数据报错",
  7084. GoodId: 0,
  7085. Status: 1,
  7086. Ctime: time.Now().Unix(),
  7087. Mtime: 0,
  7088. Count: 0,
  7089. StockCount: 0,
  7090. Creater: creator,
  7091. BatchNumberId: 0,
  7092. WarehouseOutId: 0,
  7093. }
  7094. service.CreateGoodErrcode(goodErrcode)
  7095. }
  7096. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7097. var flush_count int64
  7098. for _, it := range goodList {
  7099. flush_count += it.StockCount
  7100. }
  7101. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7102. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7103. if errss != nil {
  7104. goodErrcode := models.XtGoodErrcode{
  7105. UserOrgId: item.OrgId,
  7106. Errcode: "自动出库剩余库存更新数据",
  7107. GoodId: item.GoodId,
  7108. Status: 1,
  7109. Ctime: time.Now().Unix(),
  7110. Mtime: 0,
  7111. Count: 0,
  7112. StockCount: 0,
  7113. Creater: creater,
  7114. BatchNumberId: 0,
  7115. WarehouseOutId: 0,
  7116. }
  7117. service.CreateGoodErrcode(goodErrcode)
  7118. }
  7119. }
  7120. }
  7121. }
  7122. c.ServeSuccessJSON(map[string]interface{}{
  7123. "msg": "提交成功",
  7124. "message": "2",
  7125. "good_name": "",
  7126. "specification_name": "",
  7127. })
  7128. return
  7129. }
  7130. if record.IsOpen == 1 {
  7131. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7132. //查询是否有库存
  7133. for _, item := range consumables {
  7134. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  7135. if item.Count > warehouse.Count {
  7136. goodErrcode := models.XtGoodErrcode{
  7137. UserOrgId: item.UserOrgId,
  7138. Errcode: "自动出库库存不足",
  7139. GoodId: item.GoodId,
  7140. Status: 1,
  7141. Ctime: time.Now().Unix(),
  7142. Mtime: 0,
  7143. Count: 0,
  7144. StockCount: 0,
  7145. Creater: creator,
  7146. BatchNumberId: warehouse.ID,
  7147. WarehouseOutId: 0,
  7148. }
  7149. service.CreateGoodErrcode(goodErrcode)
  7150. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7151. c.ServeSuccessJSON(map[string]interface{}{
  7152. "message": "1",
  7153. "good_name": goodObj.GoodName,
  7154. "specification_name": goodObj.SpecificationName,
  7155. })
  7156. return
  7157. }
  7158. }
  7159. //查询是否有出库单
  7160. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7161. if err == gorm.ErrRecordNotFound {
  7162. //没有记录,则创建出库单
  7163. timeStr := time.Now().Format("2006-01-02")
  7164. timeArr := strings.Split(timeStr, "-")
  7165. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7166. total = total + 1
  7167. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7168. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7169. number = number + total
  7170. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7171. creater := adminInfo.AdminUser.Id
  7172. warehouseOut := models.WarehouseOut{
  7173. WarehouseOutOrderNumber: warehousing_out_order,
  7174. OperationTime: time.Now().Unix(),
  7175. OrgId: adminInfo.Org.Id,
  7176. Creater: creater,
  7177. Ctime: time.Now().Unix(),
  7178. Status: 1,
  7179. WarehouseOutTime: record_time,
  7180. Dealer: 0,
  7181. Manufacturer: 0,
  7182. Type: 1,
  7183. IsSys: 1,
  7184. StorehouseId: houseConfig.StorehouseOutInfo,
  7185. IsCheck: 1,
  7186. }
  7187. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  7188. if err != nil {
  7189. goodErrcode := models.XtGoodErrcode{
  7190. UserOrgId: adminInfo.Org.Id,
  7191. Errcode: "创建出库单失败",
  7192. GoodId: 0,
  7193. Status: 1,
  7194. Ctime: time.Now().Unix(),
  7195. Mtime: 0,
  7196. Count: 0,
  7197. StockCount: 0,
  7198. Creater: creator,
  7199. BatchNumberId: 0,
  7200. WarehouseOutId: 0,
  7201. }
  7202. service.CreateGoodErrcode(goodErrcode)
  7203. utils.TraceLog("创建出库单失败 err = %v", err)
  7204. } else {
  7205. for _, item := range consumables {
  7206. //出库
  7207. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7208. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7209. if err == nil {
  7210. goodErrcode := models.XtGoodErrcode{
  7211. UserOrgId: adminInfo.Org.Id,
  7212. Errcode: "自动出库接口报错",
  7213. GoodId: 0,
  7214. Status: 1,
  7215. Ctime: time.Now().Unix(),
  7216. Mtime: 0,
  7217. Count: 0,
  7218. StockCount: 0,
  7219. Creater: creator,
  7220. BatchNumberId: 0,
  7221. WarehouseOutId: 0,
  7222. }
  7223. service.CreateGoodErrcode(goodErrcode)
  7224. utils.TraceLog("创建出库单失败 err = %v", err)
  7225. }
  7226. //查询
  7227. //出库数量相加
  7228. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7229. if errs != nil {
  7230. goodErrcode := models.XtGoodErrcode{
  7231. UserOrgId: item.UserOrgId,
  7232. Errcode: "创建剩余库存字段报错",
  7233. GoodId: item.GoodId,
  7234. Status: 1,
  7235. Ctime: time.Now().Unix(),
  7236. Mtime: 0,
  7237. Count: 0,
  7238. StockCount: 0,
  7239. Creater: creater,
  7240. BatchNumberId: 0,
  7241. WarehouseOutId: 0,
  7242. }
  7243. service.CreateGoodErrcode(goodErrcode)
  7244. }
  7245. }
  7246. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7247. if len(list) == 0 {
  7248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7249. return
  7250. }
  7251. for _, item := range list {
  7252. prepare := models.DialysisBeforePrepare{
  7253. UserOrgId: adminInfo.Org.Id,
  7254. PatientId: patient_id,
  7255. RecordDate: record_time,
  7256. GoodId: item.GoodId,
  7257. GoodTypeId: item.GoodTypeId,
  7258. Count: item.Count,
  7259. Creater: adminInfo.AdminUser.Id,
  7260. Status: 1,
  7261. Ctime: time.Now().Unix(),
  7262. StorehouseId: houseConfig.StorehouseOutInfo,
  7263. }
  7264. //清空准备表数据
  7265. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7266. if err != nil {
  7267. goodErrcode := models.XtGoodErrcode{
  7268. UserOrgId: item.OrgId,
  7269. Errcode: "自动出库清空准备表数据报错",
  7270. GoodId: item.GoodId,
  7271. Status: 1,
  7272. Ctime: time.Now().Unix(),
  7273. Mtime: 0,
  7274. Count: 0,
  7275. StockCount: 0,
  7276. Creater: creater,
  7277. BatchNumberId: 0,
  7278. WarehouseOutId: 0,
  7279. }
  7280. service.CreateGoodErrcode(goodErrcode)
  7281. }
  7282. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7283. if errs != nil {
  7284. goodErrcode := models.XtGoodErrcode{
  7285. UserOrgId: item.OrgId,
  7286. Errcode: "自动出库创建准备表数据报错",
  7287. GoodId: item.GoodId,
  7288. Status: 1,
  7289. Ctime: time.Now().Unix(),
  7290. Mtime: 0,
  7291. Count: 0,
  7292. StockCount: 0,
  7293. Creater: creater,
  7294. BatchNumberId: 0,
  7295. WarehouseOutId: 0,
  7296. }
  7297. service.CreateGoodErrcode(goodErrcode)
  7298. }
  7299. //查询默认仓库
  7300. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7301. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7302. var total_count int64
  7303. for _, it := range stockList {
  7304. total_count += it.StockCount
  7305. }
  7306. //基础库插入数据
  7307. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7308. if errcodes != nil {
  7309. goodErrcode := models.XtGoodErrcode{
  7310. UserOrgId: item.OrgId,
  7311. Errcode: "自动出库基础库插入数据",
  7312. GoodId: item.GoodId,
  7313. Status: 1,
  7314. Ctime: time.Now().Unix(),
  7315. Mtime: 0,
  7316. Count: 0,
  7317. StockCount: 0,
  7318. Creater: creater,
  7319. BatchNumberId: 0,
  7320. WarehouseOutId: 0,
  7321. }
  7322. service.CreateGoodErrcode(goodErrcode)
  7323. }
  7324. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7325. var flush_count int64
  7326. for _, it := range goodList {
  7327. flush_count += it.StockCount
  7328. }
  7329. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7330. if errsss != nil {
  7331. goodErrcode := models.XtGoodErrcode{
  7332. UserOrgId: item.OrgId,
  7333. Errcode: "自动出库剩余库存更新数据",
  7334. GoodId: item.GoodId,
  7335. Status: 1,
  7336. Ctime: time.Now().Unix(),
  7337. Mtime: 0,
  7338. Count: 0,
  7339. StockCount: 0,
  7340. Creater: creater,
  7341. BatchNumberId: 0,
  7342. WarehouseOutId: 0,
  7343. }
  7344. service.CreateGoodErrcode(goodErrcode)
  7345. }
  7346. }
  7347. }
  7348. //
  7349. } else if err == nil {
  7350. for _, item := range consumables {
  7351. //出库
  7352. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7353. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7354. if err != nil {
  7355. goodErrcode := models.XtGoodErrcode{
  7356. UserOrgId: adminInfo.Org.Id,
  7357. Errcode: "自动出库接口报错",
  7358. GoodId: 0,
  7359. Status: 1,
  7360. Ctime: time.Now().Unix(),
  7361. Mtime: 0,
  7362. Count: 0,
  7363. StockCount: 0,
  7364. Creater: creator,
  7365. BatchNumberId: 0,
  7366. WarehouseOutId: 0,
  7367. }
  7368. service.CreateGoodErrcode(goodErrcode)
  7369. }
  7370. //出库数量相加
  7371. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7372. if errss != nil {
  7373. goodErrcode := models.XtGoodErrcode{
  7374. UserOrgId: item.UserOrgId,
  7375. Errcode: "创建剩余库存字段报错",
  7376. GoodId: item.GoodId,
  7377. Status: 1,
  7378. Ctime: time.Now().Unix(),
  7379. Mtime: time.Now().Unix(),
  7380. Count: 0,
  7381. StockCount: 0,
  7382. Creater: item.Creater,
  7383. BatchNumberId: 0,
  7384. WarehouseOutId: 0,
  7385. }
  7386. service.CreateGoodErrcode(goodErrcode)
  7387. }
  7388. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7389. if len(list) == 0 {
  7390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7391. return
  7392. }
  7393. for _, item := range list {
  7394. prepare := models.DialysisBeforePrepare{
  7395. UserOrgId: adminInfo.Org.Id,
  7396. PatientId: patient_id,
  7397. RecordDate: record_time,
  7398. GoodId: item.GoodId,
  7399. GoodTypeId: item.GoodTypeId,
  7400. Count: item.Count,
  7401. Creater: adminInfo.AdminUser.Id,
  7402. Status: 1,
  7403. Ctime: time.Now().Unix(),
  7404. StorehouseId: houseConfig.StorehouseOutInfo,
  7405. }
  7406. //清空准备表数据
  7407. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7408. if errs != nil {
  7409. goodErrcode := models.XtGoodErrcode{
  7410. UserOrgId: adminInfo.Org.Id,
  7411. Errcode: "自动出库清空准备表数据报错",
  7412. GoodId: 0,
  7413. Status: 1,
  7414. Ctime: time.Now().Unix(),
  7415. Mtime: 0,
  7416. Count: 0,
  7417. StockCount: 0,
  7418. Creater: creator,
  7419. BatchNumberId: 0,
  7420. WarehouseOutId: 0,
  7421. }
  7422. service.CreateGoodErrcode(goodErrcode)
  7423. }
  7424. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7425. if errcodes != nil {
  7426. goodErrcode := models.XtGoodErrcode{
  7427. UserOrgId: adminInfo.Org.Id,
  7428. Errcode: "自动出库创建准备表数据报错",
  7429. GoodId: 0,
  7430. Status: 1,
  7431. Ctime: time.Now().Unix(),
  7432. Mtime: 0,
  7433. Count: 0,
  7434. StockCount: 0,
  7435. Creater: creator,
  7436. BatchNumberId: 0,
  7437. WarehouseOutId: 0,
  7438. }
  7439. service.CreateGoodErrcode(goodErrcode)
  7440. }
  7441. //查询默认仓库
  7442. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7443. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7444. var total_count int64
  7445. for _, it := range stockList {
  7446. total_count += it.StockCount
  7447. }
  7448. //基础库插入数据
  7449. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7450. if errcodes != nil {
  7451. goodErrcode := models.XtGoodErrcode{
  7452. UserOrgId: adminInfo.Org.Id,
  7453. Errcode: "自动出库基础库插入数据报错",
  7454. GoodId: 0,
  7455. Status: 1,
  7456. Ctime: time.Now().Unix(),
  7457. Mtime: 0,
  7458. Count: 0,
  7459. StockCount: 0,
  7460. Creater: creator,
  7461. BatchNumberId: 0,
  7462. WarehouseOutId: 0,
  7463. }
  7464. service.CreateGoodErrcode(goodErrcode)
  7465. }
  7466. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7467. var flush_count int64
  7468. for _, it := range goodList {
  7469. flush_count += it.StockCount
  7470. }
  7471. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7472. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7473. if errss != nil {
  7474. goodErrcode := models.XtGoodErrcode{
  7475. UserOrgId: item.OrgId,
  7476. Errcode: "自动出库剩余库存更新数据",
  7477. GoodId: item.GoodId,
  7478. Status: 1,
  7479. Ctime: time.Now().Unix(),
  7480. Mtime: 0,
  7481. Count: 0,
  7482. StockCount: 0,
  7483. Creater: creater,
  7484. BatchNumberId: 0,
  7485. WarehouseOutId: 0,
  7486. }
  7487. service.CreateGoodErrcode(goodErrcode)
  7488. }
  7489. }
  7490. }
  7491. }
  7492. c.ServeSuccessJSON(map[string]interface{}{
  7493. "msg": "提交成功",
  7494. "message": "2",
  7495. "good_name": "",
  7496. "specification_name": "",
  7497. })
  7498. return
  7499. } else {
  7500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7501. return
  7502. }
  7503. }
  7504. func (c *DialysisAPIController) EditConsumables() {
  7505. patient_id, _ := c.GetInt64("patient_id", 0)
  7506. record_date := c.GetString("record_time")
  7507. if patient_id <= 0 {
  7508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7509. return
  7510. }
  7511. adminInfo := c.GetMobileAdminUserInfo()
  7512. timeLayout := "2006-01-02"
  7513. loc, _ := time.LoadLocation("Local")
  7514. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7515. record_time := theRecordTime.Unix()
  7516. // 查询信息规挡的设置天数
  7517. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7518. if infor.ID > 0 && infor.WeekDay > 0 {
  7519. var cha_time int64
  7520. timeNowStr := time.Now().Format("2006-01-02")
  7521. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7522. //今日的日期减去设置的日期
  7523. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7524. if cha_time >= record_time {
  7525. //查询审核是否允许
  7526. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7527. //申请状态不允许的情况 拒绝修改
  7528. if infor.ApplicationStatus != 1 {
  7529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7530. return
  7531. }
  7532. }
  7533. }
  7534. dataBody := make(map[string]interface{}, 0)
  7535. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7536. if err != nil {
  7537. utils.ErrorLog(err.Error())
  7538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7539. return
  7540. }
  7541. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7542. var beforePrepares []*models.DialysisBeforePrepareGoods
  7543. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7544. var cancelbefor []*models.DialysisBeforePrepareGoods
  7545. var outbefor []*models.DialysisBeforePrepareGoods
  7546. //判断是否开启自动出库
  7547. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7548. if record.IsOpen == 1 {
  7549. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7550. goods, _ := dataBody["goods"].([]interface{})
  7551. if len(goods) > 0 {
  7552. for _, item := range goods {
  7553. items := item.(map[string]interface{})
  7554. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7555. utils.ErrorLog("good_id")
  7556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7557. return
  7558. }
  7559. good_id := int64(items["good_id"].(float64))
  7560. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7561. utils.ErrorLog("good_type_id")
  7562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7563. return
  7564. }
  7565. good_type_id := int64(items["good_type_id"].(float64))
  7566. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7567. utils.ErrorLog("count")
  7568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7569. return
  7570. }
  7571. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7572. commdity_code := items["commdity_code"].(string)
  7573. fmt.Println(commdity_code)
  7574. prepareGoods := &models.DialysisBeforePrepareGoods{
  7575. GoodTypeId: good_type_id,
  7576. GoodId: good_id,
  7577. Count: count,
  7578. StorehouseId: houseConfig.StorehouseOutInfo,
  7579. }
  7580. beforePrepares = append(beforePrepares, prepareGoods)
  7581. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7582. GoodTypeId: good_type_id,
  7583. GoodId: good_id,
  7584. Count: count,
  7585. StorehouseId: houseConfig.StorehouseOutInfo,
  7586. }
  7587. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7588. }
  7589. for _, item := range beforePrepares {
  7590. //1.查看该患者该耗材型号最后一次出库数量
  7591. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7592. //判断当前出库数量和最后一次出库数量的大小
  7593. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7594. if item.Count < goodInfo.Count {
  7595. cancelbefor = append(cancelbefor, item)
  7596. }
  7597. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7598. if item.Count > goodInfo.Count {
  7599. outbefor = append(outbefor, item)
  7600. }
  7601. //处理编辑耗材新增不了的问题
  7602. if goodInfo.Count == item.Count {
  7603. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7604. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7605. }
  7606. }
  7607. if len(cancelbefor) > 0 {
  7608. //退库
  7609. for _, item := range cancelbefor {
  7610. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7611. creater := adminInfo.AdminUser.Id
  7612. //查询该患者当天已经出库的耗材信息
  7613. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7614. var delete_count int64 = 0
  7615. delete_count = warehouseOutInfos.Count - item.Count
  7616. //增加库存数量
  7617. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7618. //减少实际出库库存数量
  7619. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7620. // 删除出库完成后,要增加对应批次的库存数量
  7621. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7622. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7623. //更新剩余库存
  7624. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7625. var flush_count int64
  7626. for _, it := range goodListOne {
  7627. flush_count += it.StockCount
  7628. }
  7629. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7630. //查询剩余库存
  7631. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7632. var sum_count int64
  7633. for _, item := range goodList {
  7634. sum_count += item.StockCount
  7635. }
  7636. // 在出库记录表里记录退库详情
  7637. warehouseOutInfo := &models.WarehouseOutInfo{
  7638. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7639. WarehouseOutId: warehouseOut.ID,
  7640. Status: 1,
  7641. Ctime: time.Now().Unix(),
  7642. OrgId: adminInfo.Org.Id,
  7643. Type: 1,
  7644. IsSys: 1,
  7645. SysRecordTime: record_time,
  7646. GoodTypeId: item.GoodTypeId,
  7647. GoodId: item.GoodId,
  7648. PatientId: patient_id,
  7649. ConsumableType: 2,
  7650. StorehouseId: houseConfig.StorehouseOutInfo,
  7651. IsCheck: 1,
  7652. OverCount: sum_count,
  7653. }
  7654. warehouseOutInfo.Count = item.Count
  7655. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7656. warehouseOutInfo.Price = stockInInfo.Price
  7657. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7658. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7659. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7660. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7661. warehouseOutInfo.Number = warehouseOutInfos.Number
  7662. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7663. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7664. //查找当天是否存在出库记录
  7665. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7666. if errcod == gorm.ErrRecordNotFound {
  7667. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7668. //插入详情明细表
  7669. stockFlow := models.VmStockFlow{
  7670. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7671. WarehouseOutId: warehouseOut.ID,
  7672. GoodId: item.GoodId,
  7673. Number: warehouseOutInfos.Number,
  7674. ProductDate: stockInInfo.ProductDate,
  7675. ExpireDate: stockInInfo.ExpiryDate,
  7676. Count: item.Count,
  7677. Price: stockInInfo.Price,
  7678. Status: 1,
  7679. Ctime: record_time,
  7680. UserOrgId: adminInfo.Org.Id,
  7681. Manufacturer: stockInInfo.Manufacturer,
  7682. Dealer: stockInInfo.Dealer,
  7683. LicenseNumber: stockInInfo.LicenseNumber,
  7684. IsEdit: 2,
  7685. Creator: creater,
  7686. SystemTime: record_time,
  7687. ConsumableType: 3,
  7688. WarehousingDetailId: 0,
  7689. IsSys: 1,
  7690. UpdateCreator: creater,
  7691. PatientId: patient_id,
  7692. StorehouseId: houseConfig.StorehouseOutInfo,
  7693. }
  7694. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7695. if errflow == gorm.ErrRecordNotFound {
  7696. //创建流水表
  7697. err := service.CreateStockFlowOne(stockFlow)
  7698. fmt.Println("err", err)
  7699. } else if errflow == nil {
  7700. //插入详情明细表
  7701. stockFlow := models.VmStockFlow{
  7702. ID: exsit.ID,
  7703. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7704. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7705. WarehouseOutId: warehouseOut.ID,
  7706. GoodId: item.GoodId,
  7707. Number: warehouseOutInfos.Number,
  7708. ProductDate: stockInInfo.ProductDate,
  7709. ExpireDate: stockInInfo.ExpiryDate,
  7710. Count: exsit.Count - delete_count,
  7711. Price: stockInInfo.Price,
  7712. Status: 1,
  7713. Ctime: record_time,
  7714. UserOrgId: adminInfo.Org.Id,
  7715. Manufacturer: stockInInfo.Manufacturer,
  7716. Dealer: stockInInfo.Dealer,
  7717. LicenseNumber: stockInInfo.LicenseNumber,
  7718. IsEdit: 2,
  7719. Creator: creater,
  7720. SystemTime: record_time,
  7721. ConsumableType: 3,
  7722. WarehousingDetailId: 0,
  7723. IsSys: 1,
  7724. UpdateCreator: creater,
  7725. PatientId: patient_id,
  7726. StorehouseId: houseConfig.StorehouseOutInfo,
  7727. }
  7728. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7729. }
  7730. } else if errcod == nil {
  7731. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7732. //查询剩余库存
  7733. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7734. var sum_count int64
  7735. for _, item := range goodList {
  7736. sum_count += item.StockCount
  7737. }
  7738. //创建退库单,生成退库数据
  7739. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7740. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7741. operation_time := time.Now().Unix()
  7742. creater := adminInfo.AdminUser.Id
  7743. //创建退库单
  7744. timeStr := time.Now().Format("2006-01-02")
  7745. timeArr := strings.Split(timeStr, "-")
  7746. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7747. total = total + 1
  7748. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7749. cancelStock := models.CancelStock{
  7750. OrderNumber: orderNumber,
  7751. OperaTime: operation_time,
  7752. OrgId: adminInfo.Org.Id,
  7753. Creater: creater,
  7754. Ctime: time.Now().Unix(),
  7755. Status: 1,
  7756. ReturnTime: record_time,
  7757. Type: 1,
  7758. StorehouseId: houseConfig.StorehouseOutInfo,
  7759. IsCheck: 1,
  7760. }
  7761. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7762. if msgerrkonde == gorm.ErrRecordNotFound {
  7763. service.AddSigleCancelStock(&cancelStock)
  7764. }
  7765. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7766. //查询是否有出库
  7767. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7768. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7769. deaerler, _ := service.GetDealerById(info.Dealer)
  7770. if info.ID > 0 {
  7771. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7772. cancelStockInfo := models.CancelStockInfo{
  7773. GoodId: item.GoodId,
  7774. CancelStockId: cancel.ID,
  7775. GoodTypeId: good.GoodTypeId,
  7776. Count: delete_count,
  7777. Price: info.Price,
  7778. Total: 0,
  7779. ProductDate: info.ProductDate,
  7780. ExpiryDate: info.ExpiryDate,
  7781. Ctime: time.Now().Unix(),
  7782. Status: 1,
  7783. OrgId: adminInfo.Org.Id,
  7784. OrderNumber: cancel.OrderNumber,
  7785. Type: 0,
  7786. Dealer: deaerler.DealerName,
  7787. Manufacturer: manufacturer.ManufacturerName,
  7788. Number: info.Number,
  7789. RegisterAccount: "",
  7790. Remark: "",
  7791. WarehouseInfoId: info.WarehouseInfotId,
  7792. PatientId: info.PatientId,
  7793. RecordDate: info.SysRecordTime,
  7794. StorehouseId: houseConfig.StorehouseOutInfo,
  7795. IsCheck: 1,
  7796. }
  7797. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7798. //退库数量增加
  7799. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7800. //查询剩余库存
  7801. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7802. var over_count int64
  7803. for _, it := range goodList {
  7804. over_count += it.StockCount
  7805. }
  7806. flow := models.VmStockFlow{
  7807. WarehousingId: info.WarehouseInfotId,
  7808. GoodId: item.GoodId,
  7809. Number: info.Number,
  7810. LicenseNumber: info.LicenseNumber,
  7811. Count: delete_count,
  7812. UserOrgId: adminInfo.Org.Id,
  7813. PatientId: patient_id,
  7814. SystemTime: info.SysRecordTime,
  7815. ConsumableType: 7,
  7816. IsSys: 0,
  7817. WarehousingOrder: "",
  7818. WarehouseOutId: info.WarehouseOutId,
  7819. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7820. IsEdit: 0,
  7821. CancelStockId: cancel.ID,
  7822. CancelOrderNumber: cancel.OrderNumber,
  7823. Manufacturer: manufacturer.ID,
  7824. Dealer: 0,
  7825. Creator: adminInfo.AdminUser.Id,
  7826. UpdateCreator: 0,
  7827. Status: 1,
  7828. Ctime: record_time,
  7829. Mtime: 0,
  7830. Price: info.Price,
  7831. WarehousingDetailId: info.WarehouseInfotId,
  7832. WarehouseOutDetailId: info.ID,
  7833. CancelOutDetailId: cancelInfo.ID,
  7834. ProductDate: info.ProductDate,
  7835. ExpireDate: info.ExpiryDate,
  7836. StorehouseId: houseConfig.StorehouseOutInfo,
  7837. OverCount: over_count,
  7838. }
  7839. service.CreateStockFlowOne(flow)
  7840. }
  7841. }
  7842. //更改自动出库的表格
  7843. details := models.BloodAutomaticReduceDetail{
  7844. WarehouseOutId: warehouseOutInfo.ID,
  7845. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7846. PatientId: patient_id,
  7847. Ctime: time.Now().Unix(),
  7848. Mtime: time.Now().Unix(),
  7849. Status: 1,
  7850. RecordTime: record_time,
  7851. OrgId: adminInfo.Org.Id,
  7852. GoodId: item.GoodId,
  7853. GoodTypeId: item.GoodTypeId,
  7854. Count: item.Count,
  7855. StorehouseId: houseConfig.StorehouseOutInfo,
  7856. }
  7857. //查询当天耗材是否已经存在数据
  7858. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7859. if errcode == gorm.ErrRecordNotFound {
  7860. service.CreateAutoReduceRecord(&details)
  7861. } else if errcode == nil {
  7862. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7863. service.CreateAutoReduceRecord(&details)
  7864. }
  7865. //查询默认仓库
  7866. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7867. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7868. var total_count int64
  7869. for _, it := range stockList {
  7870. total_count += it.StockCount
  7871. }
  7872. //基础库插入数据
  7873. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7874. }
  7875. }
  7876. if len(outbefor) > 0 {
  7877. //出库
  7878. for _, item := range outbefor {
  7879. var last_total int64
  7880. //1.查看该患者该耗材型号最后一次出库数量
  7881. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7882. //计算当前出库和最后一次出库数据相差数据
  7883. last_total = item.Count - goodInfoOne.Count
  7884. //查询该耗材的总库存
  7885. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7886. // 如果库存差大于剩余库存则提示库存不足
  7887. if last_total > wareinfo.StockCount {
  7888. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7889. c.ServeSuccessJSON(map[string]interface{}{
  7890. "message": "1",
  7891. "good_name": goodObj.GoodName,
  7892. "specification_name": goodObj.SpecificationName,
  7893. })
  7894. return
  7895. } else {
  7896. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7897. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7898. if err == gorm.ErrRecordNotFound {
  7899. //没有记录,则创建出库单
  7900. timeStr := time.Now().Format("2006-01-02")
  7901. timeArr := strings.Split(timeStr, "-")
  7902. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7903. total = total + 1
  7904. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7905. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7906. number = number + total
  7907. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7908. warehouseOut := models.WarehouseOut{
  7909. WarehouseOutOrderNumber: warehousing_out_order,
  7910. OperationTime: time.Now().Unix(),
  7911. OrgId: adminInfo.Org.Id,
  7912. Creater: adminInfo.AdminUser.Id,
  7913. Ctime: time.Now().Unix(),
  7914. Status: 1,
  7915. WarehouseOutTime: record_time,
  7916. Dealer: 0,
  7917. Manufacturer: 0,
  7918. Type: 1,
  7919. IsSys: 1,
  7920. StorehouseId: houseConfig.StorehouseOutInfo,
  7921. IsCheck: 1,
  7922. }
  7923. service.AddSigleWarehouseOutOne(&warehouseOut)
  7924. }
  7925. //出库
  7926. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7927. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7928. //1.查看该患者该耗材型号最后一次出库数量
  7929. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7930. prepare := models.DialysisBeforePrepare{
  7931. UserOrgId: adminInfo.Org.Id,
  7932. PatientId: patient_id,
  7933. RecordDate: record_time,
  7934. GoodId: item.GoodId,
  7935. GoodTypeId: item.GoodTypeId,
  7936. Count: item.Count - goodInfoTwo.Count,
  7937. Ctime: time.Now().Unix(),
  7938. Mtime: 0,
  7939. Creater: adminInfo.AdminUser.Id,
  7940. Modifier: adminInfo.AdminUser.Id,
  7941. Status: 1,
  7942. CommdityCode: "",
  7943. NewCount: 0,
  7944. ProjectId: 0,
  7945. StorehouseId: houseConfig.StorehouseOutInfo,
  7946. }
  7947. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7948. //增加出库数量
  7949. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7950. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7951. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7952. var total_count int64
  7953. for _, it := range stockList {
  7954. total_count += it.StockCount
  7955. }
  7956. //基础库插入数据
  7957. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7958. //剩余库存
  7959. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7960. var flush_count int64
  7961. for _, it := range goodList {
  7962. flush_count += it.StockCount
  7963. }
  7964. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7965. }
  7966. }
  7967. }
  7968. //查询今日出库数据
  7969. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7970. for _, it := range list {
  7971. prepare := models.DialysisBeforePrepare{
  7972. UserOrgId: it.OrgId,
  7973. PatientId: patient_id,
  7974. RecordDate: it.RecordTime,
  7975. GoodId: it.GoodId,
  7976. GoodTypeId: it.GoodTypeId,
  7977. Count: it.Count,
  7978. Ctime: time.Now().Unix(),
  7979. Creater: adminInfo.AdminUser.Id,
  7980. Status: 1,
  7981. StorehouseId: houseConfig.StorehouseOutInfo,
  7982. ProjectId: it.ProjectId,
  7983. }
  7984. //删除准备表数据
  7985. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7986. service.CreateDialysisBeforePrepareOne(&prepare)
  7987. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7988. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7989. var total_count int64
  7990. for _, it := range stockList {
  7991. total_count += it.StockCount
  7992. }
  7993. //基础库插入数据
  7994. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7995. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7996. var flush_count int64
  7997. for _, it := range goodList {
  7998. flush_count += it.StockCount
  7999. }
  8000. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  8001. }
  8002. }
  8003. }
  8004. //更新自动出库的地方
  8005. var errs error
  8006. if errs == nil {
  8007. c.ServeSuccessJSON(map[string]interface{}{
  8008. "msg": "修改成功",
  8009. "message": "2",
  8010. "good_name": "",
  8011. "specification_name": "",
  8012. })
  8013. return
  8014. } else {
  8015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8016. return
  8017. }
  8018. }
  8019. }
  8020. func (c *DialysisAPIController) GetDialysisGoods() {
  8021. schedualDate := c.GetString("schedule_date")
  8022. schedule_type, _ := c.GetInt64("schedule_type")
  8023. partition_id, _ := c.GetInt64("partition_id")
  8024. page, _ := c.GetInt("page")
  8025. patient_id, _ := c.GetInt64("patient_id")
  8026. schedualEndDate := int64(0)
  8027. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  8028. if parseDateErr != nil && len(schedualDate) != 0 {
  8029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8030. return
  8031. }
  8032. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  8033. if parseDateErr != nil && len(schedualDate) != 0 {
  8034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8035. return
  8036. }
  8037. schedualEndDate = endDate.Unix()
  8038. adminUser := c.GetMobileAdminUserInfo()
  8039. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  8040. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  8041. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8042. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8043. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  8044. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  8045. //获取当天该病人的透析处方
  8046. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8047. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8048. if err == gorm.ErrRecordNotFound {
  8049. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8050. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8051. if patient_id != 0 {
  8052. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8053. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8054. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8055. //获取患者总的出库数据
  8056. item.LastAutomaticReduceDetail = goodUser
  8057. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8058. item.Project = project
  8059. for _, it := range item.AutomaticReduceDetail {
  8060. var total int64
  8061. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8062. for _, its := range auto {
  8063. total += its.Count
  8064. }
  8065. it.Count = total
  8066. }
  8067. }
  8068. }
  8069. c.ServeSuccessJSON(map[string]interface{}{
  8070. "dialysis_goods": dialysisGoods,
  8071. "good_type": goodTypes,
  8072. "total": total,
  8073. "prescribe": prescribe,
  8074. "good_info": good_info,
  8075. "warehouseOutList": warehouseOutList,
  8076. "config": config,
  8077. "outConfig": outConfig,
  8078. "settleConfig": settleConfig,
  8079. })
  8080. return
  8081. } else if err == nil {
  8082. //获取当天排班的每个患者的库存使用情况
  8083. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  8084. //获取患者总的出库数据
  8085. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  8086. if patient_id != 0 {
  8087. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  8088. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  8089. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  8090. item.Project = project
  8091. item.LastAutomaticReduceDetail = goodUser
  8092. item.LastDialysisBeforePrepare = lastGoodUserDetial
  8093. for _, it := range item.AutomaticReduceDetail {
  8094. var total int64
  8095. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  8096. for _, its := range auto {
  8097. total += its.Count
  8098. }
  8099. it.Count = total
  8100. }
  8101. }
  8102. }
  8103. if err == nil {
  8104. c.ServeSuccessJSON(map[string]interface{}{
  8105. "dialysis_goods": dialysisGoods,
  8106. "good_type": goodTypes,
  8107. "total": total,
  8108. "prescribe": prescribe,
  8109. "good_info": good_info,
  8110. "project": project,
  8111. "warehouseOutList": warehouseOutList,
  8112. "config": config,
  8113. "outConfig": outConfig,
  8114. "settleConfig": settleConfig,
  8115. })
  8116. return
  8117. } else {
  8118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8119. return
  8120. }
  8121. } else if err != nil {
  8122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8123. return
  8124. }
  8125. }
  8126. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  8127. start_time := c.GetString("start_time")
  8128. end_time := c.GetString("end_time")
  8129. timeLayout := "2006-01-02"
  8130. loc, _ := time.LoadLocation("Local")
  8131. var theStartTime int64
  8132. if len(start_time) > 0 {
  8133. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8134. if err != nil {
  8135. utils.ErrorLog(err.Error())
  8136. }
  8137. theStartTime = theTime.Unix()
  8138. }
  8139. var theEndtTime int64
  8140. if len(end_time) > 0 {
  8141. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8142. if err != nil {
  8143. utils.ErrorLog(err.Error())
  8144. }
  8145. theEndtTime = theTime.Unix()
  8146. }
  8147. adminUser := c.GetMobileAdminUserInfo()
  8148. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  8149. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  8150. if err == nil {
  8151. c.ServeSuccessJSON(map[string]interface{}{
  8152. "stock_out": outInfo,
  8153. "stockCount": stockCount,
  8154. })
  8155. return
  8156. } else {
  8157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8158. return
  8159. }
  8160. }
  8161. func (c *DialysisAPIController) GetStockInGoodInfo() {
  8162. patient_id, _ := c.GetInt64("patient_id", 0)
  8163. record_time := c.GetString("record_time")
  8164. adminUser := c.GetMobileAdminUserInfo()
  8165. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  8166. if parseDateErr != nil && len(record_time) != 0 {
  8167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8168. return
  8169. }
  8170. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  8171. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  8172. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  8173. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  8174. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  8175. //获取今日患者的透析处方参数
  8176. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  8177. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  8178. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  8179. c.ServeSuccessJSON(map[string]interface{}{
  8180. "good_type": goodTypes,
  8181. "good_user": goodUser,
  8182. "good_info": good_info,
  8183. "last_good_user": lastGoodUserDetial,
  8184. "project": project,
  8185. "prescription": prescribe,
  8186. "outInfo": outInfo,
  8187. "configs": configs,
  8188. })
  8189. return
  8190. }
  8191. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  8192. patient_id, _ := c.GetInt64("patient_id", 0)
  8193. record_date := c.GetString("record_time")
  8194. timeLayout := "2006-01-02"
  8195. loc, _ := time.LoadLocation("Local")
  8196. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8197. record_time := theRecordTime.Unix()
  8198. adminInfo := c.GetMobileAdminUserInfo()
  8199. dataBody := make(map[string]interface{}, 0)
  8200. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8201. if err != nil {
  8202. utils.ErrorLog(err.Error())
  8203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8204. return
  8205. }
  8206. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8207. var beforePrepares []*models.DialysisBeforePrepareGoods
  8208. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8209. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8210. goods, _ := dataBody["goods"].([]interface{})
  8211. if len(goods) > 0 {
  8212. for _, item := range goods {
  8213. items := item.(map[string]interface{})
  8214. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8215. utils.ErrorLog("good_id")
  8216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8217. return
  8218. }
  8219. good_id := int64(items["good_id"].(float64))
  8220. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8221. utils.ErrorLog("good_type_id")
  8222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8223. return
  8224. }
  8225. good_type_id := int64(items["good_type_id"].(float64))
  8226. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8227. utils.ErrorLog("count")
  8228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8229. return
  8230. }
  8231. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8232. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8233. utils.ErrorLog("project_id")
  8234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8235. return
  8236. }
  8237. project_id := int64(items["project_id"].(float64))
  8238. new_count := int64(items["new_count"].(float64))
  8239. old_count := int64(items["old_count"].(float64))
  8240. prepare := &models.DialysisBeforePrepareGoods{
  8241. GoodId: good_id,
  8242. GoodTypeId: good_type_id,
  8243. Count: count,
  8244. ProjectId: project_id,
  8245. StorehouseId: houseConfig.StorehouseOutInfo,
  8246. NewCount: new_count,
  8247. OldCount: old_count,
  8248. }
  8249. beforePrepares = append(beforePrepares, prepare)
  8250. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8251. GoodId: good_id,
  8252. GoodTypeId: good_type_id,
  8253. Count: count,
  8254. ProjectId: project_id,
  8255. StorehouseId: houseConfig.StorehouseOutInfo,
  8256. NewCount: new_count,
  8257. OldCount: old_count,
  8258. }
  8259. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8260. }
  8261. }
  8262. }
  8263. //查询是否有库存
  8264. for _, item := range beforePrepares {
  8265. if item.NewCount > 0 {
  8266. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8267. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8268. if item.Count > warehouse.Count {
  8269. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8270. c.ServeSuccessJSON(map[string]interface{}{
  8271. "message": "1",
  8272. "good_name": goodObj.GoodName,
  8273. "specification_name": goodObj.SpecificationName,
  8274. })
  8275. return
  8276. }
  8277. }
  8278. }
  8279. // 查询信息规挡的设置天数
  8280. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8281. if infor.ID > 0 && infor.WeekDay > 0 {
  8282. var cha_time int64
  8283. timeNowStr := time.Now().Format("2006-01-02")
  8284. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8285. //今日的日期减去设置的日期
  8286. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8287. if cha_time >= record_time {
  8288. //查询审核是否允许
  8289. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8290. //申请状态不允许的情况 拒绝修改
  8291. if infor.ApplicationStatus != 1 {
  8292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8293. return
  8294. }
  8295. }
  8296. }
  8297. //出库逻辑
  8298. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8299. if err != nil {
  8300. utils.ErrorLog(err.Error())
  8301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8302. return
  8303. }
  8304. finish := models.XtDialysisFinish{
  8305. IsFinish: 1,
  8306. UserOrgId: adminInfo.Org.Id,
  8307. Status: 1,
  8308. Ctime: time.Now().Unix(),
  8309. Mtime: 0,
  8310. Module: 11,
  8311. RecordDate: record_time,
  8312. Sourse: 1,
  8313. PatientId: patient_id,
  8314. }
  8315. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8316. if dialysisFinish.ID == 0 {
  8317. service.CreateDialysisFinish(finish)
  8318. }
  8319. //查询当天出库的数据
  8320. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8321. for _, item := range list {
  8322. prepare := models.DialysisBeforePrepare{
  8323. UserOrgId: item.OrgId,
  8324. PatientId: item.PatientId,
  8325. RecordDate: item.RecordTime,
  8326. GoodId: item.GoodId,
  8327. GoodTypeId: item.GoodTypeId,
  8328. Count: item.Count,
  8329. Creater: adminInfo.AdminUser.Id,
  8330. Status: 1,
  8331. Ctime: time.Now().Unix(),
  8332. ProjectId: item.ProjectId,
  8333. StorehouseId: houseConfig.StorehouseOutInfo,
  8334. }
  8335. //清空准备表的数据
  8336. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8337. //插入准备表数据
  8338. service.CreateDialysisBeforePrepareOne(&prepare)
  8339. //查询默认仓库
  8340. //查询默认仓库
  8341. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8342. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8343. var total_count int64
  8344. for _, it := range stockList {
  8345. total_count += it.StockCount
  8346. }
  8347. //基础库插入数据
  8348. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8349. ////更新剩余库存
  8350. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8351. var flush_count int64
  8352. for _, it := range goodList {
  8353. flush_count += it.StockCount
  8354. }
  8355. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8356. if errs != nil {
  8357. goodErrcode := models.XtGoodErrcode{
  8358. UserOrgId: item.OrgId,
  8359. Errcode: "手动出库更新剩余出库失败",
  8360. GoodId: item.GoodId,
  8361. Status: 1,
  8362. Ctime: time.Now().Unix(),
  8363. Mtime: 0,
  8364. Count: 0,
  8365. StockCount: 0,
  8366. Creater: adminInfo.AdminUser.Id,
  8367. BatchNumberId: 0,
  8368. WarehouseOutId: 0,
  8369. }
  8370. service.CreateGoodErrcode(goodErrcode)
  8371. }
  8372. }
  8373. //更新自动出库的地方
  8374. var errs error
  8375. if errs == nil {
  8376. c.ServeSuccessJSON(map[string]interface{}{
  8377. "msg": "修改成功",
  8378. "message": "2",
  8379. "good_name": "",
  8380. "specification_name": "",
  8381. })
  8382. return
  8383. } else {
  8384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8385. return
  8386. }
  8387. }
  8388. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8389. newArr = make([]*models.DialysisBeforePrepare, 0)
  8390. for i := 0; i < len(arr); i++ {
  8391. repeat := false
  8392. for j := i + 1; j < len(arr); j++ {
  8393. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8394. repeat = true
  8395. break
  8396. }
  8397. }
  8398. if !repeat {
  8399. newArr = append(newArr, arr[i])
  8400. }
  8401. }
  8402. return
  8403. }
  8404. func (c *DialysisAPIController) GetAllDrug() {
  8405. patient_id, _ := c.GetInt64("patient_id", 0)
  8406. adminInfo := c.GetMobileAdminUserInfo()
  8407. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8408. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8409. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8410. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8411. c.ServeSuccessJSON(map[string]interface{}{
  8412. "base_drug_config": drugStockConfig,
  8413. "private_drug_config": privateDrugConfig,
  8414. "base_drug_list": drugList,
  8415. "private_drug_list": privateDrugList,
  8416. })
  8417. }
  8418. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8419. newArr = make([]*models.DialysisBeforePrepare, 0)
  8420. for i := 0; i < len(arr); i++ {
  8421. repeat := false
  8422. for j := i + 1; j < len(arr); j++ {
  8423. if arr[i].GoodId == arr[j].GoodId {
  8424. repeat = true
  8425. break
  8426. }
  8427. }
  8428. if !repeat {
  8429. newArr = append(newArr, arr[i])
  8430. }
  8431. }
  8432. return
  8433. }
  8434. func (c *DialysisAPIController) GetDepartment() {
  8435. adminInfo := c.GetMobileAdminUserInfo()
  8436. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8437. if err == nil {
  8438. c.ServeSuccessJSON(map[string]interface{}{
  8439. "departments": departments,
  8440. })
  8441. } else {
  8442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8443. return
  8444. }
  8445. }
  8446. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8447. types, _ := c.GetInt("type", 0)
  8448. start_time := c.GetString("start_time")
  8449. end_time := c.GetString("end_time")
  8450. orgId := c.GetMobileAdminUserInfo().Org.Id
  8451. timeLayout := "2006-01-02"
  8452. loc, _ := time.LoadLocation("Local")
  8453. var startTime int64
  8454. if len(start_time) > 0 {
  8455. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8456. if err != nil {
  8457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8458. return
  8459. }
  8460. startTime = theTime.Unix()
  8461. }
  8462. var endTime int64
  8463. if len(end_time) > 0 {
  8464. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8465. if err != nil {
  8466. utils.ErrorLog(err.Error())
  8467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8468. return
  8469. }
  8470. endTime = theTime.Unix()
  8471. }
  8472. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8473. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8474. if err != nil {
  8475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8476. } else {
  8477. c.ServeSuccessJSON(map[string]interface{}{
  8478. "list": list,
  8479. "type": types,
  8480. "stockTotal": stockTotal,
  8481. })
  8482. }
  8483. }
  8484. func (c *DialysisAPIController) GetPrescriptionList() {
  8485. start_time := c.GetString("start_time")
  8486. end_time := c.GetString("end_time")
  8487. schedule_type, _ := c.GetInt64("schedule_type")
  8488. partion_id, _ := c.GetInt64("partion_id")
  8489. orgId := c.GetMobileAdminUserInfo().Org.Id
  8490. timeLayout := "2006-01-02"
  8491. loc, _ := time.LoadLocation("Local")
  8492. var startTime int64
  8493. if len(start_time) > 0 {
  8494. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8495. if err != nil {
  8496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8497. return
  8498. }
  8499. startTime = theTime.Unix()
  8500. }
  8501. var endTime int64
  8502. if len(end_time) > 0 {
  8503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8504. if err != nil {
  8505. utils.ErrorLog(err.Error())
  8506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8507. return
  8508. }
  8509. endTime = theTime.Unix()
  8510. }
  8511. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8512. fmt.Println("schedulelist22222222", schedulelist)
  8513. c.ServeSuccessJSON(map[string]interface{}{
  8514. "list": schedulelist,
  8515. })
  8516. return
  8517. }
  8518. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8519. ids := c.GetString("ids")
  8520. //patient_id, _ := c.GetInt64("patient_id")
  8521. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8522. idArray := strings.Split(ids, ",")
  8523. err := service.BatchDeleteMonitor(idArray)
  8524. fmt.Print("err", err)
  8525. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8526. //redis := service.RedisClient()
  8527. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8528. //redis.Set(key, "", time.Second)
  8529. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8530. //redis.Set(keyOne, "", time.Second)
  8531. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8532. //redis.Close()
  8533. c.ServeSuccessJSON(map[string]interface{}{
  8534. "msg": "批量删除成功",
  8535. })
  8536. return
  8537. }
  8538. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8539. id, _ := c.GetInt64("id")
  8540. timeLayout := "2006-01-02"
  8541. loc, _ := time.LoadLocation("Local")
  8542. //start_time := time.Now().Format("2006-01-02")
  8543. start_time := c.GetString("start_time")
  8544. end_time := c.GetString("end_time")
  8545. var startdateunix int64
  8546. if len(start_time) > 0 {
  8547. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8548. if err != nil {
  8549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8550. return
  8551. }
  8552. startdateunix = theTime.Unix()
  8553. }
  8554. var enddateunix int64
  8555. if len(end_time) > 0 {
  8556. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8557. if err != nil {
  8558. utils.ErrorLog(err.Error())
  8559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8560. return
  8561. }
  8562. enddateunix = theTime.Unix()
  8563. }
  8564. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8565. //nowTime := time.Now()
  8566. //endTime := nowTime.AddDate(-30, 0, 0)
  8567. //endTimes := endTime.Format("2006-01-02")
  8568. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8569. org_id := c.GetMobileAdminUserInfo().Org.Id
  8570. //if org_id == 10579 {
  8571. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8572. // c.ServeSuccessJSON(map[string]interface{}{
  8573. // "list": list,
  8574. // })
  8575. // return
  8576. //} else {
  8577. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8578. // c.ServeSuccessJSON(map[string]interface{}{
  8579. // "list": list,
  8580. // })
  8581. // return
  8582. //}
  8583. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8584. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8585. c.ServeSuccessJSON(map[string]interface{}{
  8586. "list": list,
  8587. })
  8588. return
  8589. } else {
  8590. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8591. c.ServeSuccessJSON(map[string]interface{}{
  8592. "list": list,
  8593. })
  8594. }
  8595. return
  8596. }
  8597. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8598. dataBody := make(map[string]interface{}, 0)
  8599. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8600. ids := c.GetString("ids")
  8601. idArray := strings.Split(ids, ",")
  8602. origin, _ := c.GetInt64("origin")
  8603. if origin == 1 {
  8604. err = service.BatchDeleteAdvice(idArray)
  8605. fmt.Print("err", err)
  8606. c.ServeSuccessJSON(map[string]interface{}{
  8607. "msg": "批量删除成功",
  8608. })
  8609. return
  8610. }
  8611. if origin == 2 {
  8612. service.BatchDeleteHisAdvice(idArray)
  8613. }
  8614. }
  8615. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8616. good_id, _ := c.GetInt64("good_id")
  8617. count, _ := c.GetInt64("count")
  8618. record_time, _ := c.GetInt64("record_time")
  8619. patient_id, _ := c.GetInt64("patient_id")
  8620. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8621. c.ServeSuccessJSON(map[string]interface{}{
  8622. "detail": detail,
  8623. })
  8624. return
  8625. }
  8626. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8627. good_id, _ := c.GetInt64("good_id")
  8628. record_time, _ := c.GetInt64("record_time")
  8629. patient_id, _ := c.GetInt64("patient_id")
  8630. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8631. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8632. fmt.Print("err", err)
  8633. c.ServeSuccessJSON(map[string]interface{}{
  8634. "msg": "批量删除成功",
  8635. })
  8636. return
  8637. }
  8638. func (c *DialysisAPIController) BatchAdviceCheck() {
  8639. ids := c.GetString("ids")
  8640. idArray := strings.Split(ids, ",")
  8641. creator, _ := c.GetInt64("creator")
  8642. origin, _ := c.GetInt64("origin")
  8643. if origin == 1 {
  8644. err := service.BatchAdviceCheck(idArray, creator)
  8645. fmt.Println(err)
  8646. list, _ := service.GetAdviceExecutionById(idArray)
  8647. c.ServeSuccessJSON(map[string]interface{}{
  8648. "list": list,
  8649. })
  8650. return
  8651. }
  8652. if origin == 2 {
  8653. service.BatchHisAdviceCheck(idArray, creator)
  8654. list, _ := service.GetHisAdviceExecutionById(idArray)
  8655. c.ServeSuccessJSON(map[string]interface{}{
  8656. "list": list,
  8657. })
  8658. return
  8659. }
  8660. }
  8661. func (c *DialysisAPIController) BatchAdviceExecution() {
  8662. ids := c.GetString("ids")
  8663. idArray := strings.Split(ids, ",")
  8664. executionTime := c.GetString("execution_time")
  8665. creator, _ := c.GetInt64("creator")
  8666. timeLayout := "2006-01-02 15:04:05"
  8667. loc, _ := time.LoadLocation("Local")
  8668. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8669. orgin, _ := c.GetInt64("origin")
  8670. if orgin == 1 {
  8671. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8672. list, _ := service.GetAdviceExecutionById(idArray)
  8673. fmt.Println(err)
  8674. c.ServeSuccessJSON(map[string]interface{}{
  8675. "list": list,
  8676. })
  8677. return
  8678. }
  8679. if orgin == 2 {
  8680. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8681. list, _ := service.GetHisAdviceExecutionById(idArray)
  8682. fmt.Println(err)
  8683. c.ServeSuccessJSON(map[string]interface{}{
  8684. "list": list,
  8685. })
  8686. return
  8687. }
  8688. }
  8689. func (c *DialysisAPIController) UpdateStockGoods() {
  8690. good_id, _ := c.GetInt64("good_id")
  8691. record_time, _ := c.GetInt64("record_time")
  8692. patient_id, _ := c.GetInt64("patient_id")
  8693. count, _ := c.GetInt64("count")
  8694. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8695. fmt.Print("err", err)
  8696. c.ServeSuccessJSON(map[string]interface{}{
  8697. "msg": "更新成功",
  8698. })
  8699. return
  8700. }
  8701. // 当前数据比上一次出库数据少
  8702. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8703. //查询该患者当天已经出库的耗材信息
  8704. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8705. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8706. for i := len(goods_yc) - 1; i >= 0; i-- {
  8707. goods_yc_temp := goods_yc[i]
  8708. for j := len(goods) - 1; j >= 0; j-- {
  8709. goods_temp := goods[j]
  8710. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8711. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8712. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8713. if goods_yc_temp.Count == goods_temp.Count {
  8714. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8715. goods = append(goods[:j], goods[j+1:]...)
  8716. break
  8717. }
  8718. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8719. if goods_yc_temp.Count > goods_temp.Count {
  8720. temp_count := goods_yc_temp.Count - goods_temp.Count
  8721. goods_yc[i].Count = temp_count
  8722. goods = append(goods[:j], goods[j+1:]...)
  8723. break
  8724. }
  8725. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8726. if goods_yc_temp.Count < goods_temp.Count {
  8727. temp_count := goods_temp.Count - goods_yc_temp.Count
  8728. goods[j].Count = temp_count
  8729. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8730. break
  8731. }
  8732. }
  8733. }
  8734. }
  8735. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8736. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8737. //退库
  8738. if len(goods_yc) > 0 {
  8739. for _, good_yc := range goods_yc {
  8740. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8741. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8742. }
  8743. }
  8744. return nil
  8745. }
  8746. // 耗材出库删除
  8747. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8748. // 先根据相关信息查询当天该耗材的出库信息
  8749. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8750. if err != nil {
  8751. return err
  8752. }
  8753. var delete_count int64 = 0
  8754. delete_count = warehouseOutInfos.Count - count
  8755. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8756. // 在出库记录表里记录退库详情
  8757. warehouseOutInfo := &models.WarehouseOutInfo{
  8758. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8759. WarehouseOutId: warehouseOut.ID,
  8760. Status: 1,
  8761. Ctime: time.Now().Unix(),
  8762. OrgId: orgID,
  8763. Type: 1,
  8764. IsSys: 1,
  8765. SysRecordTime: record_time,
  8766. GoodTypeId: good_yc.GoodTypeId,
  8767. GoodId: good_yc.GoodId,
  8768. PatientId: good_yc.PatientId,
  8769. ConsumableType: 2,
  8770. StorehouseId: houseConfig.StorehouseOutInfo,
  8771. IsCheck: 1,
  8772. }
  8773. warehouseOutInfo.Count = count
  8774. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8775. warehouseOutInfo.Price = stockInInfo.Price
  8776. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8777. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8778. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8779. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8780. warehouseOutInfo.Number = warehouseOutInfos.Number
  8781. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8782. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8783. //查找当天是否存在出库记录
  8784. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8785. if errcod == gorm.ErrRecordNotFound {
  8786. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8787. //插入详情明细表
  8788. stockFlow := models.VmStockFlow{
  8789. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8790. WarehouseOutId: warehouseOut.ID,
  8791. GoodId: good_yc.GoodId,
  8792. Number: warehouseOutInfos.Number,
  8793. ProductDate: stockInInfo.ProductDate,
  8794. ExpireDate: stockInInfo.ExpiryDate,
  8795. Count: count,
  8796. Price: stockInInfo.Price,
  8797. Status: 1,
  8798. Ctime: time.Now().Unix(),
  8799. UserOrgId: good_yc.OrgId,
  8800. Manufacturer: stockInInfo.Manufacturer,
  8801. Dealer: stockInInfo.Dealer,
  8802. LicenseNumber: stockInInfo.LicenseNumber,
  8803. IsEdit: 2,
  8804. Creator: creater,
  8805. SystemTime: record_time,
  8806. ConsumableType: 3,
  8807. WarehousingDetailId: 0,
  8808. IsSys: 1,
  8809. UpdateCreator: creater,
  8810. PatientId: patient_id,
  8811. StorehouseId: houseConfig.StorehouseOutInfo,
  8812. }
  8813. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8814. if errflow == gorm.ErrRecordNotFound {
  8815. //创建流水表
  8816. err := service.CreateStockFlowOne(stockFlow)
  8817. fmt.Println("err", err)
  8818. } else if errflow == nil {
  8819. //插入详情明细表
  8820. stockFlow := models.VmStockFlow{
  8821. ID: exsit.ID,
  8822. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8823. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8824. WarehouseOutId: warehouseOut.ID,
  8825. GoodId: good_yc.GoodId,
  8826. Number: warehouseOutInfos.Number,
  8827. ProductDate: stockInInfo.ProductDate,
  8828. ExpireDate: stockInInfo.ExpiryDate,
  8829. Count: exsit.Count - delete_count,
  8830. Price: stockInInfo.Price,
  8831. Status: 1,
  8832. Ctime: time.Now().Unix(),
  8833. UserOrgId: good_yc.OrgId,
  8834. Manufacturer: stockInInfo.Manufacturer,
  8835. Dealer: stockInInfo.Dealer,
  8836. LicenseNumber: stockInInfo.LicenseNumber,
  8837. IsEdit: 2,
  8838. Creator: creater,
  8839. SystemTime: record_time,
  8840. ConsumableType: 3,
  8841. WarehousingDetailId: 0,
  8842. IsSys: 1,
  8843. UpdateCreator: creater,
  8844. PatientId: patient_id,
  8845. StorehouseId: houseConfig.StorehouseOutInfo,
  8846. }
  8847. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8848. }
  8849. if errOne != nil {
  8850. return errOne
  8851. }
  8852. } else if errcod == nil {
  8853. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8854. //插入详情明细表
  8855. stockFlow := models.VmStockFlow{
  8856. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8857. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8858. WarehouseOutId: warehouseOut.ID,
  8859. GoodId: good_yc.GoodId,
  8860. Number: warehouseOutInfos.Number,
  8861. ProductDate: stockInInfo.ProductDate,
  8862. ExpireDate: stockInInfo.ExpiryDate,
  8863. Count: count,
  8864. Price: stockInInfo.Price,
  8865. Status: 1,
  8866. Ctime: time.Now().Unix(),
  8867. UserOrgId: good_yc.OrgId,
  8868. Manufacturer: stockInInfo.Manufacturer,
  8869. Dealer: stockInInfo.Dealer,
  8870. LicenseNumber: stockInInfo.LicenseNumber,
  8871. IsEdit: 2,
  8872. Creator: creater,
  8873. SystemTime: record_time,
  8874. ConsumableType: 3,
  8875. WarehousingDetailId: 0,
  8876. IsSys: 1,
  8877. UpdateCreator: creater,
  8878. PatientId: patient_id,
  8879. ReturnCount: delete_count,
  8880. StorehouseId: houseConfig.StorehouseOutInfo,
  8881. }
  8882. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8883. if errflows == gorm.ErrRecordNotFound {
  8884. //创建流水表
  8885. service.CreateStockFlowOne(stockFlow)
  8886. } else if errflows == nil {
  8887. stockFlow := models.VmStockFlow{
  8888. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8889. ID: exsit.ID,
  8890. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8891. WarehouseOutId: warehouseOut.ID,
  8892. GoodId: good_yc.GoodId,
  8893. Number: warehouseOutInfos.Number,
  8894. ProductDate: stockInInfo.ProductDate,
  8895. ExpireDate: stockInInfo.ExpiryDate,
  8896. Count: exsit.Count - delete_count,
  8897. Price: stockInInfo.Price,
  8898. Status: 1,
  8899. Ctime: time.Now().Unix(),
  8900. UserOrgId: good_yc.OrgId,
  8901. Manufacturer: stockInInfo.Manufacturer,
  8902. Dealer: stockInInfo.Dealer,
  8903. LicenseNumber: stockInInfo.LicenseNumber,
  8904. IsEdit: 2,
  8905. Creator: creater,
  8906. SystemTime: record_time,
  8907. ConsumableType: 3,
  8908. WarehousingDetailId: 0,
  8909. IsSys: 1,
  8910. UpdateCreator: creater,
  8911. PatientId: patient_id,
  8912. ReturnCount: delete_count,
  8913. StorehouseId: houseConfig.StorehouseOutInfo,
  8914. }
  8915. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8916. }
  8917. }
  8918. //更改自动出库的表格
  8919. details := models.BloodAutomaticReduceDetail{
  8920. WarehouseOutId: warehouseOutInfo.ID,
  8921. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8922. PatientId: patient_id,
  8923. Ctime: time.Now().Unix(),
  8924. Mtime: time.Now().Unix(),
  8925. Status: 1,
  8926. RecordTime: record_time,
  8927. OrgId: orgID,
  8928. GoodId: good_yc.GoodId,
  8929. GoodTypeId: good_yc.GoodTypeId,
  8930. Count: count,
  8931. StorehouseId: houseConfig.StorehouseOutInfo,
  8932. }
  8933. //查询当天耗材是否已经存在数据
  8934. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8935. if errcode == gorm.ErrRecordNotFound {
  8936. errTwo := service.CreateAutoReduceRecord(&details)
  8937. if errTwo != nil {
  8938. return errTwo
  8939. }
  8940. } else if errcode == nil {
  8941. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8942. service.CreateAutoReduceRecord(&details)
  8943. }
  8944. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8945. //增加出库库存数量
  8946. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8947. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8948. fmt.Println("errOne", errOne)
  8949. // 删除出库完成后,要增加对应批次的库存数量
  8950. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8951. if errThree != nil {
  8952. return errThree
  8953. }
  8954. if good_yc.Count == 0 {
  8955. return nil
  8956. } else {
  8957. return errors.New("退库和出库数据不匹配")
  8958. }
  8959. }
  8960. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8961. //查询该患者当天已经出库的耗材信息
  8962. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8963. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8964. for i := len(goods_yc) - 1; i >= 0; i-- {
  8965. goods_yc_temp := goods_yc[i]
  8966. for j := len(goods) - 1; j >= 0; j-- {
  8967. goods_temp := goods[j]
  8968. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8969. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8970. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8971. if goods_yc_temp.Count == goods_temp.Count {
  8972. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8973. goods = append(goods[:j], goods[j+1:]...)
  8974. break
  8975. }
  8976. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8977. if goods_yc_temp.Count > goods_temp.Count {
  8978. temp_count := goods_yc_temp.Count - goods_temp.Count
  8979. goods_yc[i].Count = temp_count
  8980. goods = append(goods[:j], goods[j+1:]...)
  8981. break
  8982. }
  8983. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8984. if goods_yc_temp.Count < goods_temp.Count {
  8985. temp_count := goods_temp.Count - goods_yc_temp.Count
  8986. goods[j].Count = temp_count
  8987. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8988. break
  8989. }
  8990. }
  8991. }
  8992. }
  8993. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8994. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8995. fmt.Println("剩余需要出库的", len(goods))
  8996. if len(goods) > 0 {
  8997. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8998. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8999. if err == gorm.ErrRecordNotFound {
  9000. //没有记录,则创建出库单
  9001. timeStr := time.Now().Format("2006-01-02")
  9002. timeArr := strings.Split(timeStr, "-")
  9003. total, _ := service.FindAllWarehouseOut(orgID)
  9004. total = total + 1
  9005. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9006. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9007. number = number + total
  9008. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9009. warehouseOut := models.WarehouseOut{
  9010. WarehouseOutOrderNumber: warehousing_out_order,
  9011. OperationTime: time.Now().Unix(),
  9012. OrgId: orgID,
  9013. Creater: creater,
  9014. Ctime: time.Now().Unix(),
  9015. Status: 1,
  9016. WarehouseOutTime: record_time,
  9017. Dealer: 0,
  9018. Manufacturer: 0,
  9019. Type: 1,
  9020. IsSys: 1,
  9021. StorehouseId: houseConfig.StorehouseOutInfo,
  9022. IsCheck: 1,
  9023. }
  9024. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  9025. if err != nil {
  9026. utils.TraceLog("创建出库单失败 err = %v", err)
  9027. return err
  9028. } else {
  9029. out = warehouseOut
  9030. }
  9031. }
  9032. for _, item := range goods {
  9033. var newCount int64 = 0
  9034. for _, it := range goodOne {
  9035. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  9036. newCount = it.Count
  9037. }
  9038. }
  9039. prepare := models.DialysisBeforePrepare{
  9040. GoodTypeId: item.GoodTypeId,
  9041. GoodId: item.GoodId,
  9042. Count: item.Count,
  9043. StorehouseId: houseConfig.StorehouseOutInfo,
  9044. }
  9045. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  9046. //增加出库数量
  9047. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  9048. }
  9049. }
  9050. if len(goods_yc) > 0 {
  9051. for _, good_yc := range goods_yc {
  9052. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  9053. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  9054. }
  9055. }
  9056. return nil
  9057. }
  9058. // 耗材出库删除
  9059. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  9060. // 先根据相关信息查询当天该耗材的出库信息
  9061. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  9062. if err != nil {
  9063. return err
  9064. }
  9065. var delete_count int64 = 0
  9066. for _, ware := range warehouseOutInfos {
  9067. // 判断当前出库的数据和删除出库数量
  9068. if good_yc.Count <= ware.Count {
  9069. delete_count = good_yc.Count
  9070. } else {
  9071. delete_count = ware.Count
  9072. }
  9073. warehouseOutInfo := &models.WarehouseOutInfo{
  9074. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9075. WarehouseOutId: warehouseOut.ID,
  9076. Status: 1,
  9077. Ctime: time.Now().Unix(),
  9078. Remark: "",
  9079. OrgId: orgID,
  9080. Type: 1,
  9081. Manufacturer: 0,
  9082. Dealer: 0,
  9083. IsSys: 0,
  9084. SysRecordTime: record_time,
  9085. GoodTypeId: good_yc.GoodTypeId,
  9086. GoodId: good_yc.GoodId,
  9087. StorehouseId: warehouseOut.StorehouseId,
  9088. IsCheck: 1,
  9089. }
  9090. warehouseOutInfo.Count = delete_count
  9091. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9092. warehouseOutInfo.Price = stockInInfo.Price
  9093. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9094. if errOne != nil {
  9095. return errOne
  9096. }
  9097. // 删除出库完成后,要改变流水库存(有疑问)
  9098. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  9099. fmt.Println("errOne", errOne)
  9100. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  9101. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9102. //扣减出库数量
  9103. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  9104. if errThree != nil {
  9105. return errThree
  9106. }
  9107. }
  9108. if good_yc.Count == 0 {
  9109. return nil
  9110. } else {
  9111. return errors.New("退库和出库数据不匹配")
  9112. }
  9113. }
  9114. func (this *DialysisAPIController) GetMobileScheduleList() {
  9115. limit, _ := this.GetInt64("limit")
  9116. page, _ := this.GetInt64("page")
  9117. type_options_visible, _ := this.GetInt64("type_options_visible")
  9118. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  9119. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  9120. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  9121. }
  9122. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  9123. newArr = make([]*models.HisPrescriptionProject, 0)
  9124. for i := 0; i < len(arr); i++ {
  9125. repeat := false
  9126. for j := i + 1; j < len(arr); j++ {
  9127. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  9128. repeat = true
  9129. break
  9130. }
  9131. }
  9132. if !repeat {
  9133. newArr = append(newArr, arr[i])
  9134. }
  9135. }
  9136. return
  9137. }
  9138. func (this *DialysisAPIController) GetRoleList() {
  9139. admin_user_id, _ := this.GetInt64("admin_user_id")
  9140. orgid := this.GetMobileAdminUserInfo().Org.Id
  9141. list, err := service.GetRoleList(orgid, admin_user_id)
  9142. fmt.Println(err)
  9143. this.ServeSuccessJSON(map[string]interface{}{
  9144. "list": list,
  9145. })
  9146. return
  9147. }
  9148. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  9149. // 先根据相关信息查询当天该耗材的出库信息
  9150. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  9151. if err != nil {
  9152. return err
  9153. }
  9154. var delete_count int64 = 0
  9155. delete_count = warehouseOutInfos.Count - count
  9156. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  9157. // 删除出库完成后,要增加对应批次的库存数量
  9158. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  9159. if errThree != nil {
  9160. return errThree
  9161. }
  9162. //增加退库数量
  9163. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  9164. //扣减出库数量
  9165. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  9166. //查询剩余库存
  9167. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  9168. var sum_count int64
  9169. for _, item := range goodList {
  9170. sum_count += item.StockCount
  9171. }
  9172. // 在出库记录表里记录退库详情
  9173. warehouseOutInfo := &models.WarehouseOutInfo{
  9174. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9175. WarehouseOutId: warehouseOut.ID,
  9176. Status: 1,
  9177. Ctime: time.Now().Unix(),
  9178. OrgId: orgID,
  9179. Type: 1,
  9180. IsSys: 1,
  9181. SysRecordTime: record_time,
  9182. GoodTypeId: good_yc.GoodTypeId,
  9183. GoodId: good_yc.GoodId,
  9184. PatientId: good_yc.PatientId,
  9185. ConsumableType: 2,
  9186. StorehouseId: houseConfig.StorehouseOutInfo,
  9187. IsCheck: 1,
  9188. OverCount: sum_count,
  9189. }
  9190. warehouseOutInfo.Count = count
  9191. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  9192. warehouseOutInfo.Price = stockInInfo.Price
  9193. warehouseOutInfo.Dealer = stockInInfo.Dealer
  9194. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  9195. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  9196. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  9197. warehouseOutInfo.Number = warehouseOutInfos.Number
  9198. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  9199. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  9200. //查找当天是否存在出库记录
  9201. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9202. if errcod == gorm.ErrRecordNotFound {
  9203. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9204. //插入详情明细表
  9205. if errOne != nil {
  9206. return errOne
  9207. }
  9208. //插入详情明细表
  9209. stockFlow := models.VmStockFlow{
  9210. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9211. WarehouseOutId: warehouseOut.ID,
  9212. GoodId: good_yc.GoodId,
  9213. Number: warehouseOutInfos.Number,
  9214. ProductDate: stockInInfo.ProductDate,
  9215. ExpireDate: stockInInfo.ExpiryDate,
  9216. Count: count,
  9217. Price: stockInInfo.Price,
  9218. Status: 1,
  9219. Ctime: record_time,
  9220. UserOrgId: good_yc.OrgId,
  9221. Manufacturer: stockInInfo.Manufacturer,
  9222. Dealer: stockInInfo.Dealer,
  9223. LicenseNumber: stockInInfo.LicenseNumber,
  9224. IsEdit: 2,
  9225. Creator: creater,
  9226. SystemTime: record_time,
  9227. ConsumableType: 3,
  9228. WarehousingDetailId: 0,
  9229. IsSys: 1,
  9230. UpdateCreator: creater,
  9231. PatientId: patient_id,
  9232. StorehouseId: houseConfig.StorehouseOutInfo,
  9233. OverCount: sum_count,
  9234. ProjectId: good_yc.ProjectId,
  9235. }
  9236. err := service.CreateStockFlowOne(stockFlow)
  9237. fmt.Println("err", err)
  9238. } else if errcod == nil {
  9239. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9240. }
  9241. //创建退库单
  9242. operation_time := time.Now().Unix()
  9243. //创建退库单
  9244. timeStr := time.Now().Format("2006-01-02")
  9245. timeArr := strings.Split(timeStr, "-")
  9246. total, _ := service.FindAllCancelStockTotal(orgID)
  9247. total = total + 1
  9248. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9249. cancelStock := models.CancelStock{
  9250. OrderNumber: orderNumber,
  9251. OperaTime: operation_time,
  9252. OrgId: orgID,
  9253. Creater: warehouseOut.Creater,
  9254. Ctime: time.Now().Unix(),
  9255. Status: 1,
  9256. ReturnTime: record_time,
  9257. Type: 1,
  9258. StorehouseId: stockInInfo.StorehouseId,
  9259. IsCheck: 1,
  9260. }
  9261. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9262. if msgerrkonde == gorm.ErrRecordNotFound {
  9263. service.AddSigleCancelStock(&cancelStock)
  9264. }
  9265. cancel, _ := service.GetLastCancelStockById(orgID)
  9266. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9267. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9268. cancelStockInfo := models.CancelStockInfo{
  9269. GoodId: stockInInfo.GoodId,
  9270. CancelStockId: cancel.ID,
  9271. GoodTypeId: stockInInfo.GoodTypeId,
  9272. Count: delete_count,
  9273. Price: stockInInfo.PackingPrice,
  9274. Total: 0,
  9275. ProductDate: stockInInfo.ProductDate,
  9276. ExpiryDate: stockInInfo.ExpiryDate,
  9277. Ctime: record_time,
  9278. Status: 1,
  9279. OrgId: orgID,
  9280. OrderNumber: cancel.OrderNumber,
  9281. Type: 0,
  9282. Dealer: deaerler.DealerName,
  9283. Manufacturer: manufacturer.ManufacturerName,
  9284. Number: stockInInfo.Number,
  9285. RegisterAccount: "",
  9286. Remark: "",
  9287. WarehouseInfoId: stockInInfo.ID,
  9288. PatientId: patient_id,
  9289. RecordDate: record_time,
  9290. StorehouseId: stockInInfo.StorehouseId,
  9291. IsCheck: 1,
  9292. }
  9293. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9294. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9295. flow := models.VmStockFlow{
  9296. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9297. GoodId: good_yc.GoodId,
  9298. Number: warehouseOutInfos.Number,
  9299. LicenseNumber: stockInInfo.LicenseNumber,
  9300. Count: delete_count,
  9301. UserOrgId: orgID,
  9302. PatientId: patient_id,
  9303. SystemTime: record_time,
  9304. ConsumableType: 7,
  9305. IsSys: 0,
  9306. WarehousingOrder: "",
  9307. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9308. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9309. IsEdit: 0,
  9310. CancelStockId: cancel.ID,
  9311. CancelOrderNumber: cancel.OrderNumber,
  9312. Manufacturer: manufacturer.ID,
  9313. Dealer: 0,
  9314. Creator: warehouseOut.Creater,
  9315. UpdateCreator: 0,
  9316. Status: 1,
  9317. Ctime: record_time,
  9318. Mtime: 0,
  9319. Price: stockInInfo.Price,
  9320. WarehousingDetailId: stockInInfo.ID,
  9321. WarehouseOutDetailId: warehouseOutInfos.ID,
  9322. CancelOutDetailId: cancelInfo.ID,
  9323. ProductDate: stockInInfo.ProductDate,
  9324. ExpireDate: stockInInfo.ExpiryDate,
  9325. StorehouseId: houseConfig.StorehouseOutInfo,
  9326. OverCount: sum_count,
  9327. }
  9328. service.CreateStockFlowOne(flow)
  9329. //更改自动出库的表格
  9330. details := models.BloodAutomaticReduceDetail{
  9331. WarehouseOutId: warehouseOutInfo.ID,
  9332. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9333. PatientId: patient_id,
  9334. Ctime: time.Now().Unix(),
  9335. Mtime: time.Now().Unix(),
  9336. Status: 1,
  9337. RecordTime: record_time,
  9338. OrgId: orgID,
  9339. GoodId: good_yc.GoodId,
  9340. GoodTypeId: good_yc.GoodTypeId,
  9341. Count: count,
  9342. StorehouseId: houseConfig.StorehouseOutInfo,
  9343. }
  9344. //查询当天耗材是否已经存在数据
  9345. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9346. if errcode == gorm.ErrRecordNotFound {
  9347. errTwo := service.CreateAutoReduceRecord(&details)
  9348. if errTwo != nil {
  9349. return errTwo
  9350. }
  9351. } else if errcode == nil {
  9352. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9353. service.CreateAutoReduceRecord(&details)
  9354. }
  9355. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9356. //增加出库库存数量
  9357. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9358. if good_yc.Count == 0 {
  9359. return nil
  9360. } else {
  9361. return errors.New("退库和出库数据不匹配")
  9362. }
  9363. }
  9364. func (this *DialysisAPIController) SavePatientSign() {
  9365. adminUserInfo := this.GetMobileAdminUserInfo()
  9366. patient_id, _ := this.GetInt64("patient_id")
  9367. dialysis_date, _ := this.GetInt64("dialysis_date")
  9368. orgid := adminUserInfo.Org.Id
  9369. var esdata models.DialysisOrder
  9370. var err error
  9371. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9373. return
  9374. }
  9375. esdata.Hash = esdata.Hash
  9376. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9377. order := models.DialysisOrder{
  9378. Hash: esdata.Hash,
  9379. Url: esdata.Url,
  9380. }
  9381. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9382. redis := service.RedisClient()
  9383. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9384. redis.Set(key, "", time.Second)
  9385. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9386. //清空key 值
  9387. redis.Set(keyOne, "", time.Second)
  9388. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9389. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9390. //redis.Set(keyTwo, "", time.Second)
  9391. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9392. redis.Set(keyThree, "", time.Second)
  9393. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9394. redis.Set(keyFour, "", time.Second)
  9395. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9396. redis.Set(keyFive, "", time.Second)
  9397. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9398. redis.Set(keySix, "", time.Second)
  9399. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9400. redis.Set(keySeven, "", time.Second)
  9401. if err != nil {
  9402. fmt.Println(err)
  9403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9404. return
  9405. }
  9406. this.ServeSuccessJSON(map[string]interface{}{
  9407. "electronic_signature": esdata,
  9408. })
  9409. }
  9410. func (this *DialysisAPIController) GetPatientSign() {
  9411. patient_id, _ := this.GetInt64("patient_id")
  9412. dialysis_date, _ := this.GetInt64("dialysis_date")
  9413. adminUserInfo := this.GetMobileAdminUserInfo()
  9414. orgId := adminUserInfo.Org.Id
  9415. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9416. if err != nil {
  9417. fmt.Println(err)
  9418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9419. return
  9420. }
  9421. this.ServeSuccessJSON(map[string]interface{}{
  9422. "dialysisOrder": dialysisOrder,
  9423. })
  9424. }
  9425. func (this *DialysisAPIController) GetScheduleByPatient() {
  9426. patient_id, _ := this.GetInt64("patient_id")
  9427. schedule_date, _ := this.GetInt64("schedule_date")
  9428. orgid := this.GetMobileAdminUserInfo().Org.Id
  9429. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9430. this.ServeSuccessJSON(map[string]interface{}{
  9431. "schedule": schedule,
  9432. })
  9433. }
  9434. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9435. org_id := this.GetMobileAdminUserInfo().Org.Id
  9436. patient_id, _ := this.GetInt64("patient_id")
  9437. schedule_date, _ := this.GetInt64("schedule_date")
  9438. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9439. this.ServeSuccessJSON(map[string]interface{}{
  9440. "order": order,
  9441. })
  9442. }
  9443. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9444. org_id := this.GetMobileAdminUserInfo().Org.Id
  9445. schedule_date := this.GetString("schedule_date")
  9446. schedule_type, _ := this.GetInt64("schedule_type")
  9447. timeLayout := "2006-01-02"
  9448. loc, _ := time.LoadLocation("Local")
  9449. var startdateunix int64
  9450. if len(schedule_date) > 0 {
  9451. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9452. if err != nil {
  9453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9454. return
  9455. }
  9456. startdateunix = theTime.Unix()
  9457. }
  9458. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9459. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9460. devices, _ := service.GetAllDevicetByListSix(org_id)
  9461. for key, item := range scheduals {
  9462. // 床位信息
  9463. for _, device := range devices {
  9464. if item.BedId == device.ID {
  9465. scheduals[key].DeviceNumber = device
  9466. break
  9467. }
  9468. }
  9469. }
  9470. this.ServeSuccessJSON(map[string]interface{}{
  9471. "list": list,
  9472. "scheduals": scheduals,
  9473. })
  9474. }
  9475. func (this *DialysisAPIController) SavePatientPicture() {
  9476. patient_id, _ := this.GetInt64("patient_id")
  9477. dialysis_date, _ := this.GetInt64("schedule_date")
  9478. avatar := this.GetString("avatar")
  9479. fmt.Println("patient_id", patient_id)
  9480. orgId := this.GetMobileAdminUserInfo().Org.Id
  9481. order := models.DialysisOrder{
  9482. Url: avatar,
  9483. }
  9484. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9485. redis := service.RedisClient()
  9486. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9487. redis.Set(key, "", time.Second)
  9488. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9489. //清空key 值
  9490. redis.Set(keyOne, "", time.Second)
  9491. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9492. redis.Set(keyThree, "", time.Second)
  9493. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9494. redis.Set(keyFour, "", time.Second)
  9495. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9496. redis.Set(keyFive, "", time.Second)
  9497. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9498. redis.Set(keySix, "", time.Second)
  9499. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9500. redis.Set(keySeven, "", time.Second)
  9501. if err != nil {
  9502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9503. return
  9504. }
  9505. this.ServeSuccessJSON(map[string]interface{}{
  9506. "order": order,
  9507. })
  9508. }
  9509. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9510. ids := this.GetString("ids")
  9511. idSplit := strings.Split(ids, ",")
  9512. orgId := this.GetMobileAdminUserInfo().Org.Id
  9513. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9514. execution_time := this.GetString("exce_time")
  9515. timeLayout2 := "2006-01-02 15:04:05"
  9516. loc, _ := time.LoadLocation("Local")
  9517. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9518. if errs != nil {
  9519. utils.ErrorLog(errs.Error())
  9520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9521. return
  9522. }
  9523. //his客户
  9524. if config.IsOpen == 1 {
  9525. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9526. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9527. for _, item := range list {
  9528. for _, it := range adviceList {
  9529. if item.DrugId == it.DrugId {
  9530. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9531. }
  9532. }
  9533. }
  9534. for _, item := range list {
  9535. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9536. var sum_out_count int64
  9537. for _, itemThree := range item.ChildDoctorAdvice {
  9538. var prescribing_number int64
  9539. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9540. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9541. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9542. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9543. }
  9544. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9545. prescribing_number = parseIntPrescribingNumber
  9546. }
  9547. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9548. prescribing_number = parseIntPrescribingNumber
  9549. }
  9550. sum_out_count += prescribing_number
  9551. }
  9552. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9553. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9554. //库存不足
  9555. if sum_out_count > drugStockOut.FlushCount {
  9556. this.ServeSuccessJSON(map[string]interface{}{
  9557. "msg": "2",
  9558. "drug": medical,
  9559. "ids": ids,
  9560. })
  9561. return
  9562. }
  9563. }
  9564. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9565. //执行医嘱
  9566. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9567. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9568. for _, item := range advices {
  9569. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9570. redis := service.RedisClient()
  9571. //清空key 值
  9572. redis.Set(key, "", time.Second)
  9573. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9574. redis.Set(keyTwo, "", time.Second)
  9575. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9576. redis.Set(keyThree, "", time.Second)
  9577. recordDate := theTime.Format("2006-01-02")
  9578. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9579. redis.Set(keyFour, "", time.Second)
  9580. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9581. redis.Set(keyFive, "", time.Second)
  9582. defer redis.Close()
  9583. }
  9584. if errs == nil {
  9585. //药品管理信息
  9586. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9587. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9588. if drugStockConfig.IsOpen == 1 {
  9589. for _, item := range advices {
  9590. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9591. config, _ := service.GetDrugOpenConfigOne(orgId)
  9592. if config.IsOpen != 1 {
  9593. //查询该药品是否有库存
  9594. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9595. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9596. if medical.IsUse == 2 {
  9597. if config.IsOpen != 1 {
  9598. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9599. service.HisDrugsDelivery(orgId, creater, &advice)
  9600. if orgId == 3877 || orgId == 10265 {
  9601. //查询该药品是否有出库记录
  9602. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9603. if len(flowMap) == 0 {
  9604. errs := service.UpdateHisAdviceById(advice.ID)
  9605. if errs != nil {
  9606. drugError := models.XtDrugError{
  9607. UserOrgId: orgId,
  9608. DrugId: item.DrugId,
  9609. RecordDate: item.AdviceDate,
  9610. PatientId: item.PatientId,
  9611. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9612. Status: 1,
  9613. Ctime: time.Now().Unix(),
  9614. Mtime: 0,
  9615. SumCount: 0,
  9616. Prescribingnumber: advice.PrescribingNumber,
  9617. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9618. }
  9619. service.CreateDrugError(drugError)
  9620. }
  9621. this.ServeSuccessJSON(map[string]interface{}{
  9622. "msg": "2",
  9623. "drug": medical,
  9624. "ids": ids,
  9625. })
  9626. return
  9627. }
  9628. }
  9629. }
  9630. if pharmacyConfig.IsOpen != 1 {
  9631. service.HisDrugsDelivery(orgId, creater, &advice)
  9632. if orgId == 3877 || orgId == 10265 {
  9633. //查询该药品是否有出库记录
  9634. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9635. if len(flowMap) == 0 {
  9636. errs := service.UpdateHisAdviceById(advice.ID)
  9637. if errs != nil {
  9638. drugError := models.XtDrugError{
  9639. UserOrgId: orgId,
  9640. DrugId: item.DrugId,
  9641. RecordDate: item.AdviceDate,
  9642. PatientId: item.PatientId,
  9643. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9644. Status: 1,
  9645. Ctime: time.Now().Unix(),
  9646. Mtime: 0,
  9647. SumCount: 0,
  9648. Prescribingnumber: advice.PrescribingNumber,
  9649. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9650. }
  9651. service.CreateDrugError(drugError)
  9652. }
  9653. this.ServeSuccessJSON(map[string]interface{}{
  9654. "msg": "2",
  9655. "drug": medical,
  9656. "ids": ids,
  9657. })
  9658. return
  9659. }
  9660. }
  9661. }
  9662. //更新字典里面的库存
  9663. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9664. var sum_count int64
  9665. for _, its := range stockInfo {
  9666. if its.MaxUnit == medical.MaxUnit {
  9667. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9668. }
  9669. sum_count += its.StockMaxNumber + its.StockMinNumber
  9670. }
  9671. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9672. //剩余库存
  9673. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9674. }
  9675. }
  9676. }
  9677. }
  9678. }
  9679. this.ServeSuccessJSON(map[string]interface{}{
  9680. "msg": "1",
  9681. "ids": ids,
  9682. })
  9683. return
  9684. } else {
  9685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9686. }
  9687. }
  9688. //血透客户
  9689. if config.IsOpen == 2 || config.IsOpen == 0 {
  9690. //药品管理信息
  9691. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9692. if drugStockConfig.IsOpen == 1 {
  9693. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9694. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9695. for _, item := range list {
  9696. for _, it := range adviceList {
  9697. if item.DrugId == it.DrugId {
  9698. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9699. }
  9700. }
  9701. }
  9702. for _, item := range list {
  9703. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9704. var sum_out_count int64
  9705. for _, itemThree := range item.ChildDoctorAdvice {
  9706. var prescribing_number int64
  9707. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9708. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9709. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9710. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9711. }
  9712. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9713. prescribing_number = parseIntPrescribingNumber
  9714. }
  9715. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9716. prescribing_number = parseIntPrescribingNumber
  9717. }
  9718. sum_out_count += prescribing_number
  9719. }
  9720. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9721. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9722. //库存不足
  9723. if sum_out_count > drugStockOut.FlushCount {
  9724. this.ServeSuccessJSON(map[string]interface{}{
  9725. "msg": "2",
  9726. "drug": medical,
  9727. "ids": ids,
  9728. })
  9729. return
  9730. }
  9731. }
  9732. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9733. //执行医嘱
  9734. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9735. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9736. for _, item := range advices {
  9737. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9738. redis := service.RedisClient()
  9739. //清空key 值
  9740. redis.Set(key, "", time.Second)
  9741. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9742. redis.Set(keyTwo, "", time.Second)
  9743. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9744. redis.Set(keyThree, "", time.Second)
  9745. recordDate := theTime.Format("2006-01-02")
  9746. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9747. redis.Set(keyFour, "", time.Second)
  9748. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9749. redis.Set(keyFive, "", time.Second)
  9750. defer redis.Close()
  9751. }
  9752. if errs == nil {
  9753. for _, item := range advices {
  9754. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9755. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9756. //查询是否出库按钮开启
  9757. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9758. if adviceSetting.IsAdviceOpen == 1 {
  9759. //查询是否出库按钮开启
  9760. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9761. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9762. if prescriptionConfig.IsOpen == 1 {
  9763. if medical.IsUse == 2 {
  9764. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9765. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9766. }
  9767. if pharmacyConfig.IsOpen != 1 {
  9768. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9769. }
  9770. //更新字典里面的库存
  9771. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9772. var sum_count int64
  9773. for _, its := range stockInfo {
  9774. if its.MaxUnit == medical.MaxUnit {
  9775. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9776. }
  9777. sum_count += its.StockMaxNumber + its.StockMinNumber
  9778. }
  9779. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9780. //剩余库存
  9781. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9782. }
  9783. }
  9784. } else {
  9785. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9786. if medical.IsUse == 2 {
  9787. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9788. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9789. }
  9790. if pharmacyConfig.IsOpen != 1 {
  9791. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9792. }
  9793. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9794. var sum_count int64
  9795. for _, its := range stockInfo {
  9796. if its.MaxUnit == medical.MaxUnit {
  9797. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9798. }
  9799. sum_count += its.StockMaxNumber + its.StockMinNumber
  9800. }
  9801. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9802. //剩余库存
  9803. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9804. }
  9805. }
  9806. }
  9807. }
  9808. this.ServeSuccessJSON(map[string]interface{}{
  9809. "msg": "1",
  9810. "ids": ids,
  9811. })
  9812. return
  9813. } else {
  9814. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9815. //执行医嘱
  9816. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9817. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9818. for _, item := range advices {
  9819. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9820. redis := service.RedisClient()
  9821. //清空key 值
  9822. redis.Set(key, "", time.Second)
  9823. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9824. redis.Set(keyTwo, "", time.Second)
  9825. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9826. redis.Set(keyThree, "", time.Second)
  9827. recordDate := theTime.Format("2006-01-02")
  9828. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9829. redis.Set(keyFour, "", time.Second)
  9830. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9831. redis.Set(keyFive, "", time.Second)
  9832. defer redis.Close()
  9833. }
  9834. this.ServeSuccessJSON(map[string]interface{}{
  9835. "msg": "1",
  9836. "ids": ids,
  9837. })
  9838. return
  9839. }
  9840. }
  9841. }
  9842. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9843. ids := this.GetString("ids")
  9844. idSplit := strings.Split(ids, ",")
  9845. orgId := this.GetMobileAdminUserInfo().Org.Id
  9846. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9847. if config.IsOpen == 1 {
  9848. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9849. this.ServeSuccessJSON(map[string]interface{}{
  9850. "msg": "1",
  9851. "ids": ids,
  9852. })
  9853. return
  9854. }
  9855. if config.IsOpen == 0 || config.IsOpen == 2 {
  9856. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9857. this.ServeSuccessJSON(map[string]interface{}{
  9858. "msg": "1",
  9859. "ids": ids,
  9860. })
  9861. return
  9862. }
  9863. }
  9864. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9865. ids := this.GetString("ids")
  9866. idSplit := strings.Split(ids, ",")
  9867. orgId := this.GetMobileAdminUserInfo().Org.Id
  9868. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9869. //his
  9870. if config.IsOpen == 1 {
  9871. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9872. theTime := time.Now()
  9873. advices := models.HisDoctorAdviceThirty{
  9874. CheckTime: theTime.Unix(),
  9875. Checker: checker,
  9876. UpdatedTime: time.Now().Unix(),
  9877. }
  9878. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9879. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9880. for _, item := range list {
  9881. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9882. redis := service.RedisClient()
  9883. //清空key 值
  9884. redis.Set(key, "", time.Second)
  9885. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9886. redis.Set(keyTwo, "", time.Second)
  9887. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9888. redis.Set(keyThree, "", time.Second)
  9889. recordDate := theTime.Format("2006-01-02")
  9890. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9891. redis.Set(keyFour, "", time.Second)
  9892. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9893. redis.Set(keyFive, "", time.Second)
  9894. defer redis.Close()
  9895. }
  9896. this.ServeSuccessJSON(map[string]interface{}{
  9897. "msg": "1",
  9898. "ids": ids,
  9899. })
  9900. return
  9901. }
  9902. //血透
  9903. if config.IsOpen == 0 || config.IsOpen == 2 {
  9904. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9905. theTime := time.Now()
  9906. advices := models.DoctorAdvice{
  9907. CheckTime: theTime.Unix(),
  9908. Checker: checker,
  9909. UpdatedTime: time.Now().Unix(),
  9910. }
  9911. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9912. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9913. for _, item := range list {
  9914. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9915. redis := service.RedisClient()
  9916. //清空key 值
  9917. redis.Set(key, "", time.Second)
  9918. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9919. redis.Set(keyTwo, "", time.Second)
  9920. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9921. redis.Set(keyThree, "", time.Second)
  9922. recordDate := theTime.Format("2006-01-02")
  9923. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9924. redis.Set(keyFour, "", time.Second)
  9925. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9926. redis.Set(keyFive, "", time.Second)
  9927. defer redis.Close()
  9928. }
  9929. this.ServeSuccessJSON(map[string]interface{}{
  9930. "msg": "1",
  9931. "ids": ids,
  9932. })
  9933. return
  9934. }
  9935. }
  9936. func (this *DialysisAPIController) CheckSchedule() {
  9937. patientID, _ := this.GetInt64("patient_id")
  9938. recordDateStr := this.GetString("record_date")
  9939. nurseID, _ := this.GetInt64("start_nurse")
  9940. schedual_type, _ := this.GetInt64("schedual_type")
  9941. bedID, _ := this.GetInt64("bed")
  9942. start_time := this.GetString("start_time")
  9943. fmt.Println("patientID", patientID)
  9944. fmt.Println("recordDateStr", recordDateStr)
  9945. fmt.Println("nurseID", nurseID)
  9946. fmt.Println("schedual_type------", schedual_type)
  9947. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9948. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9949. return
  9950. }
  9951. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9952. if parseStartDateErr != nil {
  9953. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9954. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9955. return
  9956. }
  9957. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9958. if parseErr != nil {
  9959. this.ErrorLog("时间解析失败:%v", parseErr)
  9960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9961. return
  9962. }
  9963. adminUserInfo := this.GetMobileAdminUserInfo()
  9964. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9965. if getPatientErr != nil {
  9966. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9968. return
  9969. } else if patient == nil {
  9970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9971. return
  9972. }
  9973. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9974. if getNurseErr != nil {
  9975. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9977. return
  9978. } else if nurse == nil {
  9979. this.ErrorLog("护士不存在")
  9980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9981. return
  9982. }
  9983. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9984. if getDeviceNumberErr != nil {
  9985. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9987. return
  9988. } else if deviceNumber == nil {
  9989. this.ErrorLog("床位号不存在")
  9990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9991. return
  9992. }
  9993. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9994. if getRecordErr != nil {
  9995. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9997. return
  9998. } else if dialysisRecord != nil {
  9999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  10000. return
  10001. }
  10002. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  10003. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  10004. timeLayout := "2006-01-02 15:04:05"
  10005. loc, _ := time.LoadLocation("Local")
  10006. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  10007. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  10008. schedulestartTime := theStartTime.Unix()
  10009. scheduleendTime := theEndTime.Unix()
  10010. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  10011. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  10012. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10013. //查询该床位是否有人用了
  10014. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  10015. if err == nil {
  10016. if schedule.ID == 0 {
  10017. this.ServeSuccessJSON(map[string]interface{}{
  10018. "status": 0,
  10019. "msg": "请求失败",
  10020. })
  10021. } else {
  10022. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  10023. if order.ID > 0 { //该机位被其他人占用了
  10024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  10025. return
  10026. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  10027. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  10028. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  10029. this.ServeSuccessJSON(map[string]interface{}{
  10030. "status": 1,
  10031. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  10032. })
  10033. return
  10034. } else {
  10035. this.ServeSuccessJSON(map[string]interface{}{
  10036. "status": 0,
  10037. "msg": "",
  10038. })
  10039. }
  10040. }
  10041. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  10042. this.ServeSuccessJSON(map[string]interface{}{
  10043. "status": 2,
  10044. "msg": "当前机位已有患者在使用,请重新选择!",
  10045. })
  10046. }
  10047. }
  10048. } else {
  10049. this.ServeSuccessJSON(map[string]interface{}{
  10050. "status": 0,
  10051. "msg": "",
  10052. })
  10053. }
  10054. }
  10055. func (this *DialysisAPIController) GetNewDoctorListToday() {
  10056. orgId := this.GetMobileAdminUserInfo().Org.Id
  10057. schedule_type, _ := this.GetInt64("schedule_type")
  10058. partion_type, _ := this.GetInt64("partion_type")
  10059. start_time := this.GetString("start_time")
  10060. timeLayout := "2006-01-02"
  10061. loc, _ := time.LoadLocation("Local")
  10062. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10063. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  10064. _, config := service.FindXTHisRecordByOrgId(orgId)
  10065. appId := this.GetMobileAdminUserInfo().App.Id
  10066. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  10067. if err == nil {
  10068. this.ServeSuccessJSON(map[string]interface{}{
  10069. "list": list,
  10070. "config": config,
  10071. "doctorList": doctorList,
  10072. })
  10073. return
  10074. } else {
  10075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10076. return
  10077. }
  10078. }
  10079. func (this *DialysisAPIController) SaveMobileInformation() {
  10080. patient_id, _ := this.GetInt64("patient_id")
  10081. record_date, _ := this.GetInt64("record_date")
  10082. startTime := this.GetString("start_time")
  10083. module, _ := this.GetInt64("module")
  10084. remark := this.GetString("remark")
  10085. timeLayout := "2006-01-02 15:04"
  10086. loc, _ := time.LoadLocation("Local")
  10087. if len(startTime) == 0 {
  10088. utils.ErrorLog("len(start_time) == 0")
  10089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10090. return
  10091. }
  10092. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  10093. if err != nil {
  10094. utils.ErrorLog(err.Error())
  10095. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10096. return
  10097. }
  10098. StartTime := theTime.Unix()
  10099. fmt.Println("startime-------------", StartTime)
  10100. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  10101. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  10102. information := models.XtDialysisInformation{
  10103. Module: module,
  10104. PatientId: patient_id,
  10105. RecordDate: record_date,
  10106. ApplicationDate: StartTime,
  10107. Creater: creater,
  10108. ApplicationStatus: 2,
  10109. Checker: 0,
  10110. CheckTime: 0,
  10111. Remark: remark,
  10112. UserOrgId: user_org_id,
  10113. Ctime: time.Now().Unix(),
  10114. Status: 1,
  10115. Mtime: 0,
  10116. }
  10117. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  10118. if infor.ID == 0 {
  10119. service.SaveDialysisInformation(information)
  10120. }
  10121. if infor.ID > 0 {
  10122. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  10123. }
  10124. this.ServeSuccessJSON(map[string]interface{}{
  10125. "information": information,
  10126. })
  10127. return
  10128. }
  10129. func (this *DialysisAPIController) GetMobileInformation() {
  10130. limit, _ := this.GetInt64("limit")
  10131. page, _ := this.GetInt64("page")
  10132. orgid := this.GetMobileAdminUserInfo().Org.Id
  10133. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  10134. appid := this.GetMobileAdminUserInfo().App.Id
  10135. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10136. patients, _ := service.GetAllpatientThirty(orgid)
  10137. this.ServeSuccessJSON(map[string]interface{}{
  10138. "information": information,
  10139. "total": total,
  10140. "doclist": doclist,
  10141. "patients": patients,
  10142. })
  10143. return
  10144. }
  10145. func (this *DialysisAPIController) GetMobileInformationOne() {
  10146. limit, _ := this.GetInt64("limit")
  10147. page, _ := this.GetInt64("page")
  10148. orgid := this.GetMobileAdminUserInfo().Org.Id
  10149. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  10150. appid := this.GetMobileAdminUserInfo().App.Id
  10151. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  10152. patients, _ := service.GetAllpatientThirty(orgid)
  10153. this.ServeSuccessJSON(map[string]interface{}{
  10154. "information": information,
  10155. "total": total,
  10156. "doclist": doclist,
  10157. "patients": patients,
  10158. })
  10159. return
  10160. }
  10161. func (this *DialysisAPIController) CheckMobileInformation() {
  10162. id, _ := this.GetInt64("id")
  10163. application_status, _ := this.GetInt64("application_status")
  10164. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  10165. checktime := time.Now().Unix()
  10166. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  10167. if err == nil {
  10168. this.ServeSuccessJSON(map[string]interface{}{
  10169. "msg": "ok",
  10170. })
  10171. return
  10172. }
  10173. }
  10174. func (c *DialysisAPIController) GetControlMonitorList() {
  10175. partition, _ := c.GetInt64("partition")
  10176. monitorDate := c.GetString("date")
  10177. patient_id, _ := c.GetInt64("patient_id")
  10178. pat_type, _ := c.GetInt64("pat_type")
  10179. timeLayout := "2006-01-02"
  10180. loc, _ := time.LoadLocation("Local")
  10181. var theStartTime int64
  10182. if len(monitorDate) > 0 {
  10183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  10184. if err != nil {
  10185. theStartTime = 0
  10186. }
  10187. theStartTime = theTime.Unix()
  10188. }
  10189. adminInfo := c.GetMobileAdminUserInfo()
  10190. orgID := adminInfo.Org.Id
  10191. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  10192. if err != nil {
  10193. c.ErrorLog("获取排班信息失败:%v", err)
  10194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10195. } else {
  10196. if len(monitor) > 0 {
  10197. //获取所有床位
  10198. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  10199. //获取所有分区
  10200. zoneList, _ := service.GetAllZoneByList(orgID)
  10201. //获取透析处方
  10202. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  10203. //获取透前评估
  10204. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10205. //获取上机
  10206. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10207. //获取透后
  10208. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10209. //获取透后监测
  10210. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10211. //获取所有的患者
  10212. patients, _ := service.GetAllPatientListByListOne(orgID)
  10213. //获取所有透析模式
  10214. treatments, _ := service.GetAllTreatModeByList(orgID)
  10215. //获取所有医嘱
  10216. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10217. //获取双人核对
  10218. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10219. //治疗小结
  10220. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10221. //待消毒
  10222. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10223. for key, item := range monitor {
  10224. // 获取床位信息
  10225. for _, it := range numberList {
  10226. if item.BedId == it.ID {
  10227. monitor[key].DeviceNumber = it
  10228. break
  10229. }
  10230. }
  10231. //获取分区信息
  10232. for _, it := range zoneList {
  10233. if item.PartitionId == it.ID {
  10234. monitor[key].DeviceZone = it
  10235. }
  10236. }
  10237. for _, prescription := range prescriptions {
  10238. if item.PatientId == prescription.PatientId {
  10239. monitor[key].Prescription = prescription
  10240. break
  10241. }
  10242. }
  10243. for _, it := range checkList {
  10244. if item.PatientId == it.PatientId {
  10245. monitor[key].DoubleCheck = it
  10246. break
  10247. }
  10248. }
  10249. for _, it := range summaryList {
  10250. if item.PatientId == it.PatientId {
  10251. monitor[key].TreatmentSummaryForList = it
  10252. break
  10253. }
  10254. }
  10255. // 透前评估
  10256. for _, assessmentBefore := range assessmentBefores {
  10257. if item.PatientId == assessmentBefore.PatientId {
  10258. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10259. break
  10260. }
  10261. }
  10262. // 透析上下机
  10263. for _, dialysisOrder := range dialysisOrders {
  10264. if item.PatientId == dialysisOrder.PatientId {
  10265. monitor[key].DialysisOrder = dialysisOrder
  10266. break
  10267. }
  10268. }
  10269. // 治疗小节
  10270. for _, afterDislysis := range AssessmentAfterDislysis {
  10271. if item.PatientId == afterDislysis.PatientId {
  10272. monitor[key].AssessmentAfterDislysis = afterDislysis
  10273. break
  10274. }
  10275. }
  10276. for _, it := range monitorlist {
  10277. if item.PatientId == it.PatientId {
  10278. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10279. }
  10280. }
  10281. for _, it := range adviceList {
  10282. if item.PatientId == it.PatientId {
  10283. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10284. }
  10285. }
  10286. for _, patient := range patients {
  10287. if item.PatientId == patient.ID {
  10288. monitor[key].MonitorPatients = patient
  10289. break
  10290. }
  10291. }
  10292. for _, treatment := range treatments {
  10293. if item.ModeId == treatment.ID {
  10294. monitor[key].TreatmentMode = treatment
  10295. break
  10296. }
  10297. }
  10298. for _, infor := range informationList {
  10299. if item.PatientId == infor.PatientId {
  10300. monitor[key].NewDeviceInformation = infor
  10301. break
  10302. }
  10303. }
  10304. }
  10305. }
  10306. }
  10307. patients, err := service.GetAllpatientFourty(orgID)
  10308. var mds []*models.NewMonitorDialysisScheduleList
  10309. if pat_type == 0 {
  10310. for _, item := range monitor {
  10311. mds = append(mds, item)
  10312. }
  10313. }
  10314. //待医嘱核对
  10315. if pat_type == 1 {
  10316. for _, item := range monitor {
  10317. if len(item.AdviceList) > 0 {
  10318. mds = append(mds, item)
  10319. }
  10320. }
  10321. }
  10322. //待开小结
  10323. if pat_type == 2 {
  10324. for _, item := range monitor {
  10325. if item.TreatmentSummaryForList == nil {
  10326. mds = append(mds, item)
  10327. }
  10328. }
  10329. }
  10330. //待下机
  10331. if pat_type == 3 {
  10332. for _, item := range monitor {
  10333. if item.DialysisOrder != nil {
  10334. if item.DialysisOrder.ID > 0 {
  10335. mds = append(mds, item)
  10336. }
  10337. }
  10338. }
  10339. }
  10340. //待消毒
  10341. if pat_type == 4 {
  10342. for _, item := range monitor {
  10343. if item.NewDeviceInformation == nil {
  10344. mds = append(mds, item)
  10345. }
  10346. }
  10347. }
  10348. //待双人核对
  10349. if pat_type == 5 {
  10350. for _, item := range monitor {
  10351. if item.DoubleCheck == nil {
  10352. mds = append(mds, item)
  10353. }
  10354. }
  10355. }
  10356. //医嘱未执行
  10357. if pat_type == 6 {
  10358. for _, item := range monitor {
  10359. if len(item.AdviceList) > 0 {
  10360. mds = append(mds, item)
  10361. }
  10362. }
  10363. }
  10364. //患者未签名
  10365. if pat_type == 7 {
  10366. for _, item := range monitor {
  10367. if item.DialysisOrder != nil {
  10368. if item.DialysisOrder.ID > 0 {
  10369. mds = append(mds, item)
  10370. }
  10371. }
  10372. }
  10373. }
  10374. //目标超滤于实际超滤不同
  10375. if pat_type == 8 {
  10376. for _, item := range monitor {
  10377. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10378. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10379. mds = append(mds, item)
  10380. }
  10381. }
  10382. }
  10383. }
  10384. //血压少于5次
  10385. if pat_type == 9 {
  10386. for _, item := range monitor {
  10387. if len(item.MonitoringRecord) < 5 {
  10388. mds = append(mds, item)
  10389. }
  10390. }
  10391. }
  10392. if pat_type == 13 {
  10393. for _, item := range monitor {
  10394. if len(item.MonitoringRecord) < 3 {
  10395. mds = append(mds, item)
  10396. }
  10397. }
  10398. }
  10399. if pat_type == 10 {
  10400. for _, item := range monitor {
  10401. if len(item.MonitoringRecord) == 0 {
  10402. mds = append(mds, item)
  10403. }
  10404. }
  10405. }
  10406. if pat_type == 11 {
  10407. for _, item := range monitor {
  10408. if len(item.MonitoringRecord) > 0 {
  10409. mds = append(mds, item)
  10410. }
  10411. }
  10412. }
  10413. if pat_type == 12 {
  10414. for _, item := range monitor {
  10415. if len(item.MonitoringRecord) > 0 {
  10416. mds = append(mds, item)
  10417. }
  10418. }
  10419. }
  10420. if err == nil {
  10421. c.ServeSuccessJSON(map[string]interface{}{
  10422. "monitor": mds,
  10423. "patients": patients,
  10424. })
  10425. } else {
  10426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10427. }
  10428. }
  10429. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10430. admin_user_id, _ := c.GetInt64("admin_user_id")
  10431. timeStr := time.Now().Format("2006-01-02")
  10432. timeLayout := "2006-01-02 15:04:05"
  10433. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10434. timenow := timeStringToTime.Unix()
  10435. orgId := c.GetMobileAdminUserInfo().Org.Id
  10436. //查询当前护士的患者
  10437. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10438. var patientIds []int64
  10439. for _, item := range orderList {
  10440. patientIds = append(patientIds, item.PatientId)
  10441. }
  10442. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10443. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10444. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10445. //药品管理信息
  10446. _, drugStockConfig := service.FindHisConfig(orgId)
  10447. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10448. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10449. c.ServeSuccessJSON(map[string]interface{}{
  10450. "adviceList": adviceList,
  10451. "hisAdviceList": hisAdviceList,
  10452. "projectList": projectList,
  10453. "drugStockConfig": drugStockConfig,
  10454. "patientList": patientList,
  10455. "projectConfig": projectConfig,
  10456. })
  10457. }
  10458. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10459. patient_id, _ := c.GetInt64("patient_id")
  10460. org_id := c.GetMobileAdminUserInfo().Org.Id
  10461. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10462. c.ServeSuccessJSON(map[string]interface{}{
  10463. "recrods": recrods,
  10464. })
  10465. }
  10466. func (c *DialysisAPIController) ExMobileChangeSch() {
  10467. id_one, _ := c.GetInt64("id_one")
  10468. id_two, _ := c.GetInt64("id_two")
  10469. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10470. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10471. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10472. //if order2.ID > 0 {
  10473. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10474. // return
  10475. //}
  10476. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10477. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10478. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10479. if count > 0 {
  10480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10481. return
  10482. }
  10483. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10484. if count1 > 0 {
  10485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10486. return
  10487. }
  10488. }
  10489. err := service.UpdateScheduleThree(sch, sch_two)
  10490. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10491. if order.ID > 0 {
  10492. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10493. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10494. redis := service.RedisClient()
  10495. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10496. redis.Set(key, "", time.Second)
  10497. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10498. //清空key 值
  10499. redis.Set(keyOne, "", time.Second)
  10500. }
  10501. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10502. if orderOne.ID > 0 {
  10503. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10504. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10505. redis := service.RedisClient()
  10506. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10507. redis.Set(key, "", time.Second)
  10508. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10509. //清空key 值
  10510. redis.Set(keyOne, "", time.Second)
  10511. }
  10512. if err == nil {
  10513. //去除当天患者排班中重复数据,保留最后一条数据
  10514. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10515. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10516. c.ServeSuccessJSON(map[string]interface{}{
  10517. "msg": "交换成功",
  10518. })
  10519. } else {
  10520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10521. return
  10522. }
  10523. }
  10524. func (c *DialysisAPIController) MobileCoverSch() {
  10525. id_one, _ := c.GetInt64("id_one")
  10526. id_two, _ := c.GetInt64("id_two")
  10527. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10528. //针对凤凰医院
  10529. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10530. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10531. if len(advice) > 0 {
  10532. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10533. }
  10534. }
  10535. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10536. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10537. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10538. if len(hisAdvice) > 0 {
  10539. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10540. }
  10541. if len(project) > 0 {
  10542. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10543. }
  10544. }
  10545. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10546. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10547. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10548. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10549. if count > 0 {
  10550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10551. return
  10552. }
  10553. }
  10554. var new_sch models.Schedule
  10555. new_sch = sch
  10556. new_sch.BedId = sch_two.BedId
  10557. new_sch.ScheduleDate = sch_two.ScheduleDate
  10558. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10559. new_sch.PartitionId = sch_two.PartitionId
  10560. new_sch.ScheduleType = sch_two.ScheduleType
  10561. new_sch.ID = 0
  10562. //删除原来的排班
  10563. err := service.SaveSchTwo(sch, sch_two)
  10564. //生成新的排班
  10565. if err == nil {
  10566. err2 := service.SaveSch(&new_sch)
  10567. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10568. if order.ID > 0 {
  10569. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10570. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10571. redis := service.RedisClient()
  10572. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10573. redis.Set(key, "", time.Second)
  10574. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10575. //清空key 值
  10576. redis.Set(keyOne, "", time.Second)
  10577. }
  10578. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10579. if orderOne.ID > 0 {
  10580. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10581. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10582. redis := service.RedisClient()
  10583. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10584. redis.Set(key, "", time.Second)
  10585. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10586. //清空key 值
  10587. redis.Set(keyOne, "", time.Second)
  10588. }
  10589. if err2 == nil {
  10590. //去除当天患者排班中重复数据,保留最后一条数据
  10591. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10592. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10593. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10594. c.ServeSuccessJSON(map[string]interface{}{
  10595. "msg": "覆盖成功",
  10596. "new_sch": new_sch,
  10597. })
  10598. } else {
  10599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10600. return
  10601. }
  10602. } else {
  10603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10604. return
  10605. }
  10606. }
  10607. func (c *DialysisAPIController) BatchCheckAdvice() {
  10608. patient_id, _ := c.GetInt64("patient_id")
  10609. advice_date, _ := c.GetInt64("advice_date")
  10610. org_id := c.GetMobileAdminUserInfo().Org.Id
  10611. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10612. //查询是his系统还是血透系统
  10613. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10614. //his客户
  10615. if configs.IsOpen == 1 {
  10616. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10617. for _, item := range adviceList {
  10618. service.BatchCheckHisAdvice(item.ID, creater)
  10619. }
  10620. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10621. for _, item := range projectList {
  10622. service.BatchCheckProject(item.ID, creater)
  10623. }
  10624. c.ServeSuccessJSON(map[string]interface{}{
  10625. "adviceList": adviceList,
  10626. "projectList": projectList,
  10627. })
  10628. }
  10629. if configs.IsOpen != 1 {
  10630. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10631. for _, item := range adviceList {
  10632. service.BatchAdviceList(item.ID, creater)
  10633. }
  10634. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10635. for _, item := range projectList {
  10636. service.BatchCheckProject(item.ID, creater)
  10637. }
  10638. c.ServeSuccessJSON(map[string]interface{}{
  10639. "adviceList": adviceList,
  10640. "projectList": projectList,
  10641. })
  10642. }
  10643. return
  10644. }
  10645. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10646. org_id := c.GetMobileAdminUserInfo().Org.Id
  10647. drugList, _ := service.GetAllDrugList(org_id)
  10648. c.ServeSuccessJSON(map[string]interface{}{
  10649. "drugList": drugList,
  10650. })
  10651. }
  10652. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10653. org_id := c.GetMobileAdminUserInfo().Org.Id
  10654. dataBody := make(map[string]interface{}, 0)
  10655. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10656. if err != nil {
  10657. utils.ErrorLog(err.Error())
  10658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10659. return
  10660. }
  10661. timeLayout := "2006-01-02"
  10662. loc, _ := time.LoadLocation("Local")
  10663. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10664. utils.ErrorLog("advice_type")
  10665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10666. return
  10667. }
  10668. adviceType := int64(dataBody["advice_type"].(float64))
  10669. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10670. utils.ErrorLog("start_time")
  10671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10672. return
  10673. }
  10674. startTime2, _ := dataBody["start_time"].(string)
  10675. time_arr := strings.Split(startTime2, " ")
  10676. if len(time_arr) > 0 {
  10677. startTime2 = time_arr[0]
  10678. }
  10679. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10680. utils.ErrorLog("advice_date")
  10681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10682. return
  10683. }
  10684. advice_date, _ := dataBody["advice_date"].(string)
  10685. var advicedateunix int64
  10686. if len(advice_date) > 0 {
  10687. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10688. if err != nil {
  10689. fmt.Println(err)
  10690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10691. return
  10692. }
  10693. advicedateunix = theTime.Unix()
  10694. }
  10695. adviceDate := startTime2
  10696. if len(adviceDate) == 0 {
  10697. utils.ErrorLog("len(adviceDate) == 0")
  10698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10699. return
  10700. }
  10701. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10702. if err != nil {
  10703. utils.ErrorLog(err.Error())
  10704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10705. return
  10706. }
  10707. AdviceDate := advicedateunix
  10708. RecordDate := advicedateunix
  10709. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10710. utils.ErrorLog("start_time")
  10711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10712. return
  10713. }
  10714. startTime, _ := dataBody["start_time"].(string)
  10715. if len(startTime) == 0 {
  10716. utils.ErrorLog("len(start_time) == 0")
  10717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10718. return
  10719. }
  10720. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10721. if err != nil {
  10722. utils.ErrorLog(err.Error())
  10723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10724. return
  10725. }
  10726. StartTime := theTime.Unix()
  10727. advice_name, _ := dataBody["advice_name"].(string)
  10728. advice_desc, _ := dataBody["advice_desc"].(string)
  10729. delivery_way, _ := dataBody["delivery_way"].(string)
  10730. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10731. frequency_type := int64(dataBody["frequency_type"].(float64))
  10732. frequency_week, _ := dataBody["frequency_week"].(string)
  10733. prescribing_number := dataBody["prescribing_number"].(float64)
  10734. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10735. remark := dataBody["remark"].(string)
  10736. single_dose := dataBody["single_dose"].(float64)
  10737. single_dose_unit := dataBody["single_dose_unit"].(string)
  10738. patient_id := int64(dataBody["patient_id"].(float64))
  10739. day_count := int64(dataBody["day_count"].(float64))
  10740. groupNo := int64(dataBody["group_no"].(float64))
  10741. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10742. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10743. if groupNo <= 0 {
  10744. group := service.GetMaxAdviceGroupID(org_id)
  10745. groupNo = group + 1
  10746. }
  10747. var template_id = ""
  10748. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10749. template_id = "M" + adviceLastId
  10750. advice := models.DoctorAdvice{
  10751. UserOrgId: org_id,
  10752. PatientId: patient_id,
  10753. AdviceType: adviceType,
  10754. AdviceDate: AdviceDate,
  10755. StartTime: StartTime,
  10756. AdviceName: advice_name,
  10757. AdviceDesc: advice_desc,
  10758. ReminderDate: 0,
  10759. SingleDose: single_dose,
  10760. SingleDoseUnit: single_dose_unit,
  10761. DrugSpec: 0,
  10762. DrugSpecUnit: "",
  10763. PrescribingNumber: prescribing_number,
  10764. PrescribingNumberUnit: prescribing_number_unit,
  10765. DeliveryWay: delivery_way,
  10766. ExecutionFrequency: execution_frequency,
  10767. AdviceDoctor: advice_doctor,
  10768. Status: 1,
  10769. CreatedTime: time.Now().Unix(),
  10770. UpdatedTime: 0,
  10771. AdviceAffirm: "",
  10772. Remark: remark,
  10773. StopTime: 0,
  10774. StopReason: "",
  10775. StopDoctor: 0,
  10776. StopState: 2,
  10777. ParentId: 0,
  10778. ExecutionTime: 0,
  10779. ExecutionStaff: 0,
  10780. ExecutionState: 0,
  10781. Checker: 0,
  10782. RecordDate: RecordDate,
  10783. DialysisOrderId: 0,
  10784. CheckTime: 0,
  10785. CheckState: 0,
  10786. AdviceId: 0,
  10787. RemindType: 0,
  10788. FrequencyType: frequency_type,
  10789. DayCount: day_count,
  10790. WeekDay: frequency_week,
  10791. ChildDoctorAdvice: nil,
  10792. TemplateId: template_id,
  10793. Modifier: 0,
  10794. IsCheck: 0,
  10795. Way: 0,
  10796. DrugId: 0,
  10797. DrugNameId: 0,
  10798. IsMedicine: 0,
  10799. PushStartTime: 0,
  10800. IsSettle: 0,
  10801. IsPrescription: 0,
  10802. GroupNo: groupNo,
  10803. }
  10804. service.CreateMobileAdivce(advice)
  10805. c.ServeSuccessJSON(map[string]interface{}{
  10806. "msg": "保存成功!",
  10807. })
  10808. }
  10809. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10810. patient_id, _ := c.GetInt64("patient_id")
  10811. org_id := c.GetMobileAdminUserInfo().Org.Id
  10812. app_id := c.GetMobileAdminUserInfo().App.Id
  10813. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10814. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10815. c.ServeSuccessJSON(map[string]interface{}{
  10816. "adviceList": adviceList,
  10817. "adminRoles": adminRoles,
  10818. })
  10819. }
  10820. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10821. org_id := c.GetMobileAdminUserInfo().Org.Id
  10822. dataBody := make(map[string]interface{}, 0)
  10823. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10824. if err != nil {
  10825. utils.ErrorLog(err.Error())
  10826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10827. return
  10828. }
  10829. timeLayout := "2006-01-02"
  10830. loc, _ := time.LoadLocation("Local")
  10831. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10832. utils.ErrorLog("start_time")
  10833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10834. return
  10835. }
  10836. startTime2, _ := dataBody["start_time"].(string)
  10837. time_arr := strings.Split(startTime2, " ")
  10838. if len(time_arr) > 0 {
  10839. startTime2 = time_arr[0]
  10840. }
  10841. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10842. utils.ErrorLog("advice_date")
  10843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10844. return
  10845. }
  10846. advice_date, _ := dataBody["advice_date"].(string)
  10847. var advicedateunix int64
  10848. if len(advice_date) > 0 {
  10849. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10850. if err != nil {
  10851. fmt.Println(err)
  10852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10853. return
  10854. }
  10855. advicedateunix = theTime.Unix()
  10856. }
  10857. adviceDate := startTime2
  10858. if len(adviceDate) == 0 {
  10859. utils.ErrorLog("len(adviceDate) == 0")
  10860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10861. return
  10862. }
  10863. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10864. if err != nil {
  10865. utils.ErrorLog(err.Error())
  10866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10867. return
  10868. }
  10869. AdviceDate := advicedateunix
  10870. RecordDate := advicedateunix
  10871. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10872. utils.ErrorLog("start_time")
  10873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10874. return
  10875. }
  10876. startTime, _ := dataBody["start_time"].(string)
  10877. if len(startTime) == 0 {
  10878. utils.ErrorLog("len(start_time) == 0")
  10879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10880. return
  10881. }
  10882. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10883. if err != nil {
  10884. utils.ErrorLog(err.Error())
  10885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10886. return
  10887. }
  10888. StartTime := theTime.Unix()
  10889. advice_name, _ := dataBody["advice_name"].(string)
  10890. advice_desc, _ := dataBody["advice_desc"].(string)
  10891. delivery_way, _ := dataBody["delivery_way"].(string)
  10892. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10893. prescribing_number := dataBody["prescribing_number"].(float64)
  10894. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10895. remark := dataBody["remark"].(string)
  10896. single_dose := dataBody["single_dose"].(float64)
  10897. single_dose_unit := dataBody["single_dose_unit"].(string)
  10898. patient_id := int64(dataBody["patient_id"].(float64))
  10899. groupNo := int64(dataBody["group_no"].(float64))
  10900. parent_id := int64(dataBody["parent_id"].(float64))
  10901. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10902. advice := models.XtDoctorAdviceOne{
  10903. UserOrgId: org_id,
  10904. PatientId: patient_id,
  10905. AdviceType: 1,
  10906. AdviceDate: AdviceDate,
  10907. StartTime: StartTime,
  10908. AdviceName: advice_name,
  10909. AdviceDesc: advice_desc,
  10910. ReminderDate: 0,
  10911. SingleDose: single_dose,
  10912. SingleDoseUnit: single_dose_unit,
  10913. PrescribingNumber: prescribing_number,
  10914. PrescribingNumberUnit: prescribing_number_unit,
  10915. DeliveryWay: delivery_way,
  10916. ExecutionFrequency: execution_frequency,
  10917. AdviceDoctor: advice_doctor,
  10918. Status: 1,
  10919. CreatedTime: time.Now().Unix(),
  10920. UpdatedTime: time.Now().Unix(),
  10921. AdviceAffirm: "",
  10922. Remark: remark,
  10923. StopTime: 0,
  10924. StopReason: "",
  10925. StopDoctor: 0,
  10926. StopState: 2,
  10927. ParentId: parent_id,
  10928. ExecutionTime: 0,
  10929. ExecutionStaff: 0,
  10930. ExecutionState: 0,
  10931. Checker: 0,
  10932. RecordDate: RecordDate,
  10933. DialysisOrderId: 0,
  10934. CheckTime: 0,
  10935. CheckState: 0,
  10936. DrugSpec: 0,
  10937. DrugSpecUnit: "",
  10938. Groupno: groupNo,
  10939. RemindType: 0,
  10940. FrequencyType: 0,
  10941. DayCount: 0,
  10942. WeekDay: "",
  10943. TemplateId: "",
  10944. Modifier: 0,
  10945. }
  10946. service.CreateMobileAdivceOne(advice)
  10947. c.ServeSuccessJSON(map[string]interface{}{
  10948. "msg": "保存成功!",
  10949. })
  10950. }
  10951. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10952. id, _ := c.GetInt64("id")
  10953. service.DeleteSelfAdviceSubAdvice(id)
  10954. c.ServeSuccessJSON(map[string]interface{}{
  10955. "msg": "保存成功!",
  10956. })
  10957. }
  10958. func (c *DialysisAPIController) GetEditAdviceAction() {
  10959. id, _ := c.GetInt64("id")
  10960. org_id := c.GetMobileAdminUserInfo().Org.Id
  10961. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10962. drugList, _ := service.GetAllDrugList(org_id)
  10963. c.ServeSuccessJSON(map[string]interface{}{
  10964. "advice": advice,
  10965. "drugList": drugList,
  10966. })
  10967. }
  10968. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10969. dataBody := make(map[string]interface{}, 0)
  10970. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10971. if err != nil {
  10972. utils.ErrorLog(err.Error())
  10973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10974. return
  10975. }
  10976. timeLayout := "2006-01-02"
  10977. loc, _ := time.LoadLocation("Local")
  10978. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10979. utils.ErrorLog("start_time")
  10980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10981. return
  10982. }
  10983. startTime2, _ := dataBody["start_time"].(string)
  10984. time_arr := strings.Split(startTime2, " ")
  10985. if len(time_arr) > 0 {
  10986. startTime2 = time_arr[0]
  10987. }
  10988. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10989. utils.ErrorLog("advice_date")
  10990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10991. return
  10992. }
  10993. advice_date, _ := dataBody["advice_date"].(string)
  10994. var advicedateunix int64
  10995. if len(advice_date) > 0 {
  10996. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10997. if err != nil {
  10998. fmt.Println(err)
  10999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11000. return
  11001. }
  11002. advicedateunix = theTime.Unix()
  11003. }
  11004. adviceDate := startTime2
  11005. if len(adviceDate) == 0 {
  11006. utils.ErrorLog("len(adviceDate) == 0")
  11007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11008. return
  11009. }
  11010. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11011. if err != nil {
  11012. utils.ErrorLog(err.Error())
  11013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11014. return
  11015. }
  11016. AdviceDate := advicedateunix
  11017. RecordDate := advicedateunix
  11018. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11019. utils.ErrorLog("start_time")
  11020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11021. return
  11022. }
  11023. startTime, _ := dataBody["start_time"].(string)
  11024. if len(startTime) == 0 {
  11025. utils.ErrorLog("len(start_time) == 0")
  11026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11027. return
  11028. }
  11029. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11030. if err != nil {
  11031. utils.ErrorLog(err.Error())
  11032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11033. return
  11034. }
  11035. StartTime := theTime.Unix()
  11036. advice_name, _ := dataBody["advice_name"].(string)
  11037. advice_desc, _ := dataBody["advice_desc"].(string)
  11038. delivery_way, _ := dataBody["delivery_way"].(string)
  11039. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11040. prescribing_number := dataBody["prescribing_number"].(float64)
  11041. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11042. remark := dataBody["remark"].(string)
  11043. single_dose := dataBody["single_dose"].(float64)
  11044. single_dose_unit := dataBody["single_dose_unit"].(string)
  11045. id := int64(dataBody["id"].(float64))
  11046. frequency_type := int64(dataBody["frequency_type"].(float64))
  11047. frequency_week, _ := dataBody["frequency_week"].(string)
  11048. day_count := int64(dataBody["day_count"].(float64))
  11049. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11050. advice := models.XtDoctorAdviceOne{
  11051. AdviceDate: AdviceDate,
  11052. StartTime: StartTime,
  11053. AdviceName: advice_name,
  11054. AdviceDesc: advice_desc,
  11055. SingleDose: single_dose,
  11056. SingleDoseUnit: single_dose_unit,
  11057. PrescribingNumber: prescribing_number,
  11058. PrescribingNumberUnit: prescribing_number_unit,
  11059. DeliveryWay: delivery_way,
  11060. ExecutionFrequency: execution_frequency,
  11061. AdviceDoctor: advice_doctor,
  11062. Remark: remark,
  11063. RecordDate: RecordDate,
  11064. FrequencyType: frequency_type,
  11065. DayCount: day_count,
  11066. WeekDay: frequency_week,
  11067. }
  11068. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  11069. c.ServeSuccessJSON(map[string]interface{}{
  11070. "advice": advice,
  11071. })
  11072. }
  11073. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  11074. dataBody := make(map[string]interface{}, 0)
  11075. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11076. if err != nil {
  11077. utils.ErrorLog(err.Error())
  11078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11079. return
  11080. }
  11081. timeLayout := "2006-01-02"
  11082. loc, _ := time.LoadLocation("Local")
  11083. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11084. utils.ErrorLog("start_time")
  11085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11086. return
  11087. }
  11088. startTime2, _ := dataBody["start_time"].(string)
  11089. time_arr := strings.Split(startTime2, " ")
  11090. if len(time_arr) > 0 {
  11091. startTime2 = time_arr[0]
  11092. }
  11093. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11094. utils.ErrorLog("advice_date")
  11095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11096. return
  11097. }
  11098. advice_date, _ := dataBody["advice_date"].(string)
  11099. var advicedateunix int64
  11100. if len(advice_date) > 0 {
  11101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11102. if err != nil {
  11103. fmt.Println(err)
  11104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11105. return
  11106. }
  11107. advicedateunix = theTime.Unix()
  11108. }
  11109. adviceDate := startTime2
  11110. if len(adviceDate) == 0 {
  11111. utils.ErrorLog("len(adviceDate) == 0")
  11112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11113. return
  11114. }
  11115. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11116. if err != nil {
  11117. utils.ErrorLog(err.Error())
  11118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11119. return
  11120. }
  11121. AdviceDate := advicedateunix
  11122. RecordDate := advicedateunix
  11123. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11124. utils.ErrorLog("start_time")
  11125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11126. return
  11127. }
  11128. startTime, _ := dataBody["start_time"].(string)
  11129. if len(startTime) == 0 {
  11130. utils.ErrorLog("len(start_time) == 0")
  11131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11132. return
  11133. }
  11134. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11135. if err != nil {
  11136. utils.ErrorLog(err.Error())
  11137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11138. return
  11139. }
  11140. StartTime := theTime.Unix()
  11141. advice_name, _ := dataBody["advice_name"].(string)
  11142. advice_desc, _ := dataBody["advice_desc"].(string)
  11143. delivery_way, _ := dataBody["delivery_way"].(string)
  11144. execution_frequency, _ := dataBody["execution_frequency"].(string)
  11145. prescribing_number := dataBody["prescribing_number"].(float64)
  11146. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  11147. remark := dataBody["remark"].(string)
  11148. single_dose := dataBody["single_dose"].(float64)
  11149. single_dose_unit := dataBody["single_dose_unit"].(string)
  11150. id := int64(dataBody["id"].(float64))
  11151. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11152. advice := models.XtDoctorAdviceOne{
  11153. AdviceDate: AdviceDate,
  11154. StartTime: StartTime,
  11155. AdviceName: advice_name,
  11156. AdviceDesc: advice_desc,
  11157. SingleDose: single_dose,
  11158. SingleDoseUnit: single_dose_unit,
  11159. PrescribingNumber: prescribing_number,
  11160. PrescribingNumberUnit: prescribing_number_unit,
  11161. DeliveryWay: delivery_way,
  11162. ExecutionFrequency: execution_frequency,
  11163. AdviceDoctor: advice_doctor,
  11164. Remark: remark,
  11165. RecordDate: RecordDate,
  11166. }
  11167. service.UpdateMobileDoctorAdviceById(id, advice)
  11168. c.ServeSuccessJSON(map[string]interface{}{
  11169. "advice": advice,
  11170. })
  11171. }
  11172. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  11173. dataBody := make(map[string]interface{}, 0)
  11174. timeLayout := "2006-01-02"
  11175. loc, _ := time.LoadLocation("Local")
  11176. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11177. if err != nil {
  11178. utils.ErrorLog(err.Error())
  11179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11180. return
  11181. }
  11182. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11183. utils.ErrorLog("start_time")
  11184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11185. return
  11186. }
  11187. startTime2, _ := dataBody["start_time"].(string)
  11188. time_arr := strings.Split(startTime2, " ")
  11189. if len(time_arr) > 0 {
  11190. startTime2 = time_arr[0]
  11191. }
  11192. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  11193. utils.ErrorLog("advice_date")
  11194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11195. return
  11196. }
  11197. advice_date, _ := dataBody["advice_date"].(string)
  11198. var advicedateunix int64
  11199. if len(advice_date) > 0 {
  11200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  11201. if err != nil {
  11202. fmt.Println(err)
  11203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11204. return
  11205. }
  11206. advicedateunix = theTime.Unix()
  11207. }
  11208. adviceDate := startTime2
  11209. if len(adviceDate) == 0 {
  11210. utils.ErrorLog("len(adviceDate) == 0")
  11211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11212. return
  11213. }
  11214. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  11215. if err != nil {
  11216. utils.ErrorLog(err.Error())
  11217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11218. return
  11219. }
  11220. RecordDate := advicedateunix
  11221. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11222. utils.ErrorLog("start_time")
  11223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11224. return
  11225. }
  11226. startTime, _ := dataBody["start_time"].(string)
  11227. if len(startTime) == 0 {
  11228. utils.ErrorLog("len(start_time) == 0")
  11229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11230. return
  11231. }
  11232. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11233. if err != nil {
  11234. utils.ErrorLog(err.Error())
  11235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11236. return
  11237. }
  11238. StartTime := theTime.Unix()
  11239. patient_id := int64(dataBody["patient_id"].(float64))
  11240. group_no := int64(dataBody["group_no"].(float64))
  11241. org_id := c.GetMobileAdminUserInfo().Org.Id
  11242. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11243. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11244. utils.ErrorLog("advices")
  11245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11246. return
  11247. }
  11248. adviceNames := dataBody["advices"].([]interface{})
  11249. var advices []*models.GroupAdvice
  11250. for _, adviceNameMap := range adviceNames {
  11251. var advice models.GroupAdvice
  11252. adviceNameM := adviceNameMap.(map[string]interface{})
  11253. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11254. utils.ErrorLog("advice_name")
  11255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11256. return
  11257. }
  11258. adviceName, _ := adviceNameM["advice_name"].(string)
  11259. if len(adviceName) == 0 {
  11260. utils.ErrorLog("len(advice_name) == 0")
  11261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11262. return
  11263. }
  11264. advice.AdviceName = adviceName
  11265. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11266. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11267. advice.DrugSpec = drugSpec
  11268. }
  11269. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11270. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11271. advice.AdviceDesc = adviceDesc
  11272. }
  11273. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11274. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11275. advice.DrugSpecUnit = drugSpecUnit
  11276. }
  11277. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11278. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11279. advice.SingleDose = singleDose
  11280. }
  11281. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11282. singleDose := adviceNameM["single_dose"].(float64)
  11283. advice.SingleDose = singleDose
  11284. }
  11285. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11286. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11287. advice.SingleDoseUnit = singleDoseUnit
  11288. }
  11289. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11290. tmp := adviceNameM["single_dose_unit"].(float64)
  11291. singleDoseUnit := service.TypeConversion(tmp)
  11292. advice.SingleDoseUnit = singleDoseUnit
  11293. }
  11294. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11295. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11296. advice.PrescribingNumber = prescribingNumber
  11297. }
  11298. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11299. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11300. advice.PrescribingNumber = prescribingNumber
  11301. }
  11302. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11303. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11304. advice.PrescribingNumberUnit = prescribingNumberUnit
  11305. }
  11306. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11307. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11308. advice.DeliveryWay = deliveryWay
  11309. }
  11310. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11311. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11312. advice.ExecutionFrequency = executionFrequency
  11313. }
  11314. remark, _ := adviceNameM["remark"].(string)
  11315. advice.Remark = remark
  11316. advice.AdviceType = 1
  11317. advice.StartTime = StartTime
  11318. advice.RecordDate = RecordDate
  11319. advice.PatientId = patient_id
  11320. advice.UserOrgId = org_id
  11321. advice.AdviceDoctor = advice_doctor
  11322. advice.StopState = 2
  11323. advices = append(advices, &advice)
  11324. }
  11325. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11326. c.ServeSuccessJSON(map[string]interface{}{
  11327. "advice": newAdvices,
  11328. })
  11329. }
  11330. func (c *DialysisAPIController) StopLongAdvice() {
  11331. stop_time := c.GetString("execution_time")
  11332. id, _ := c.GetInt64("id")
  11333. if len(stop_time) <= 0 {
  11334. utils.ErrorLog("stop_time")
  11335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11336. return
  11337. }
  11338. timeLayout2 := "2006-01-02 15:04:05"
  11339. loc, _ := time.LoadLocation("Local")
  11340. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11341. if errs != nil {
  11342. utils.ErrorLog(errs.Error())
  11343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11344. return
  11345. }
  11346. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11347. c.ServeSuccessJSON(map[string]interface{}{
  11348. "advice": advice,
  11349. })
  11350. }
  11351. func (c *DialysisAPIController) BatchAdviceCheckList() {
  11352. dataBody := make(map[string]interface{}, 0)
  11353. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11354. if err != nil {
  11355. utils.ErrorLog(err.Error())
  11356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11357. return
  11358. }
  11359. orgId := c.GetMobileAdminUserInfo().Org.Id
  11360. patient_id := int64(dataBody["patient_id"].(float64))
  11361. record_date := int64(dataBody["record_date"].(float64))
  11362. checker := int64(dataBody["checker"].(float64))
  11363. check_time := dataBody["check_time"].(string)
  11364. checkTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", check_time)
  11365. if parseStartDateErr != nil {
  11366. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11368. return
  11369. }
  11370. var advice_id []int64
  11371. var his_advice_id []int64
  11372. var project_id []int64
  11373. var team_list []int64
  11374. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11375. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11376. if len(newAdviceList) > 0 {
  11377. for _, item := range newAdviceList {
  11378. items := item.(map[string]interface{})
  11379. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11380. utils.ErrorLog("id")
  11381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11382. return
  11383. }
  11384. id := int64(items["id"].(float64))
  11385. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11386. utils.ErrorLog("origin")
  11387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11388. return
  11389. }
  11390. origin := int64(items["origin"].(float64))
  11391. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11392. utils.ErrorLog("team_id")
  11393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11394. return
  11395. }
  11396. team_id := int64(items["team_id"].(float64))
  11397. if team_id == 0 {
  11398. //临时医嘱
  11399. if origin == 1 {
  11400. service.BatchAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11401. advice_id = append(advice_id, id)
  11402. }
  11403. //his医嘱
  11404. if origin == 2 {
  11405. service.BatchHisAdviceDoctorList(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11406. his_advice_id = append(his_advice_id, id)
  11407. }
  11408. //his医嘱
  11409. if origin == 3 {
  11410. service.BatchHisPrescriptionProject(patient_id, record_date, id, orgId, checker, checkTime.Unix())
  11411. project_id = append(project_id, id)
  11412. }
  11413. }
  11414. if team_id > 0 {
  11415. service.BatchCheckPrescriptionProject(patient_id, record_date, team_id, orgId, checker, checkTime.Unix())
  11416. team_list = append(team_list, team_id)
  11417. }
  11418. }
  11419. }
  11420. }
  11421. advice, _ := service.GetBatchAdviceList(advice_id)
  11422. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11423. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11424. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11425. c.ServeSuccessJSON(map[string]interface{}{
  11426. "advice": advice,
  11427. "hisadvice": hisadvice,
  11428. "hisproject": hisproject,
  11429. "teamlist": teamlist,
  11430. })
  11431. return
  11432. }
  11433. func (c *DialysisAPIController) BatchAdviceExeCutionList() {
  11434. dataBody := make(map[string]interface{}, 0)
  11435. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11436. if err != nil {
  11437. utils.ErrorLog(err.Error())
  11438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11439. return
  11440. }
  11441. orgId := c.GetMobileAdminUserInfo().Org.Id
  11442. patient_id := int64(dataBody["patient_id"].(float64))
  11443. record_date := int64(dataBody["record_date"].(float64))
  11444. execution_staff := int64(dataBody["execution_staff"].(float64))
  11445. execution_time := dataBody["execution_time"].(string)
  11446. executionTime, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  11447. if parseStartDateErr != nil {
  11448. c.ErrorLog("时间解析失败:%v", parseStartDateErr)
  11449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11450. return
  11451. }
  11452. var advice_id []int64
  11453. var his_advice_id []int64
  11454. var project_id []int64
  11455. var team_list []int64
  11456. if dataBody["new_advice_list"] != nil && reflect.TypeOf(dataBody["new_advice_list"]).String() == "[]interface {}" {
  11457. newAdviceList, _ := dataBody["new_advice_list"].([]interface{})
  11458. if len(newAdviceList) > 0 {
  11459. for _, item := range newAdviceList {
  11460. items := item.(map[string]interface{})
  11461. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11462. utils.ErrorLog("id")
  11463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11464. return
  11465. }
  11466. id := int64(items["id"].(float64))
  11467. if items["origin"] == nil || reflect.TypeOf(items["origin"]).String() != "float64" {
  11468. utils.ErrorLog("origin")
  11469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11470. return
  11471. }
  11472. origin := int64(items["origin"].(float64))
  11473. if items["team_id"] == nil || reflect.TypeOf(items["team_id"]).String() != "float64" {
  11474. utils.ErrorLog("team_id")
  11475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11476. return
  11477. }
  11478. team_id := int64(items["team_id"].(float64))
  11479. if team_id == 0 {
  11480. //临时医嘱
  11481. if origin == 1 {
  11482. service.BatchExecutionAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11483. advice_id = append(advice_id, id)
  11484. }
  11485. //his医嘱
  11486. if origin == 2 {
  11487. service.BatchExecutionHisAdviceDoctorList(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11488. his_advice_id = append(his_advice_id, id)
  11489. }
  11490. //his医嘱
  11491. if origin == 3 {
  11492. service.BatchExecutionHisPrescriptionProject(patient_id, record_date, id, orgId, execution_staff, executionTime.Unix())
  11493. project_id = append(project_id, id)
  11494. }
  11495. }
  11496. if team_id > 0 {
  11497. service.BatchExecutionPrescriptionProject(patient_id, record_date, team_id, orgId, execution_staff, executionTime.Unix())
  11498. team_list = append(team_list, team_id)
  11499. }
  11500. }
  11501. }
  11502. }
  11503. advice, _ := service.GetBatchAdviceList(advice_id)
  11504. hisadvice, _ := service.GetBatchHisAdviceList(his_advice_id)
  11505. hisproject, _ := service.GetBatchPrescriptionList(project_id)
  11506. teamlist, _ := service.GetBatchTeamList(team_list, patient_id, record_date, orgId)
  11507. c.ServeSuccessJSON(map[string]interface{}{
  11508. "advice": advice,
  11509. "hisadvice": hisadvice,
  11510. "hisproject": hisproject,
  11511. "teamlist": teamlist,
  11512. })
  11513. return
  11514. }