dialysis_api_controller.go 461KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993
  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. var first_sup int64
  1771. if first_super == "是" {
  1772. first_sup = 1
  1773. }
  1774. if first_super == "否" {
  1775. first_sup = 2
  1776. }
  1777. if first_super == "请选择" {
  1778. first_sup = 0
  1779. }
  1780. is_sequential := c.GetString("is_sequential")
  1781. var is_sequent int64
  1782. if is_sequential == "是" {
  1783. is_sequent = 1
  1784. }
  1785. if is_sequential == "否" {
  1786. is_sequent = 2
  1787. }
  1788. if is_sequential == "请选择" {
  1789. is_sequent = 0
  1790. }
  1791. conduct := c.GetString("conduct")
  1792. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1793. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1794. //
  1795. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1796. // if appRole.UserType == 3 {
  1797. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1798. // if getPermissionErr != nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. // return
  1801. // } else if headNursePermission == nil {
  1802. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1803. // return
  1804. // }
  1805. // }
  1806. //}
  1807. // 查询信息规挡的设置天数
  1808. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1809. if infor.ID > 0 && infor.WeekDay > 0 {
  1810. var cha_time int64
  1811. timeNowStr := time.Now().Format("2006-01-02")
  1812. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1813. //今日的日期减去设置的日期
  1814. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1815. if cha_time >= recordDate.Unix() {
  1816. //查询审核是否允许
  1817. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1818. //申请状态不允许的情况 拒绝修改
  1819. if infor.ApplicationStatus != 1 {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1821. return
  1822. }
  1823. }
  1824. }
  1825. if mode_id > 0 {
  1826. var str string
  1827. //查找该机构用的是什么透析器
  1828. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1829. if filedConfig.ID > 0 {
  1830. str = dialyzerPerfusionApparatus
  1831. } else {
  1832. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1833. }
  1834. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1835. }
  1836. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1837. var dialysis_dialyszers_id int64
  1838. var dialysis_strainer_id int64
  1839. var dialysis_irrigation_id int64
  1840. if len(goodList) > 0 {
  1841. for _, item := range goodList {
  1842. if item.SpecificationName == dialysis_dialyszers {
  1843. dialysis_dialyszers_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_irrigation {
  1846. dialysis_irrigation_id = item.ID
  1847. }
  1848. if item.SpecificationName == dialysis_strainer {
  1849. dialysis_strainer_id = item.ID
  1850. }
  1851. }
  1852. }
  1853. //TODO 需要根据角色去判断
  1854. prescription := models.DialysisPrescription{
  1855. UserOrgId: adminUserInfo.Org.Id,
  1856. PatientId: id,
  1857. RecordDate: recordDate.Unix(),
  1858. ModeId: mode_id,
  1859. DialysisDuration: dialysis_duration,
  1860. Dialyzer: dialyzer,
  1861. PerfusionApparatus: perfusion_apparatus,
  1862. BloodFlowVolume: blood_flow_volume,
  1863. DewaterAmount: dewater_amount,
  1864. DisplaceLiqui: displace_liqui,
  1865. ReplacementWay: replacement_way,
  1866. Anticoagulant: anticoagulant,
  1867. AnticoagulantShouji: anticoagulant_shouji,
  1868. AnticoagulantWeichi: anticoagulant_weichi,
  1869. AnticoagulantZongliang: anticoagulant_zongliang,
  1870. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1871. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1872. Kalium: kalium,
  1873. Sodium: sodium,
  1874. Calcium: calcium,
  1875. Bicarbonate: bicarbonate,
  1876. Glucose: glucose,
  1877. // DryWeight: dry_weight,
  1878. DialysateFlow: dialysate_flow,
  1879. DialysateTemperature: dialysate_temperature,
  1880. // PrescriptionDoctor: prescription_doctor,
  1881. ReplacementTotal: replacement_total,
  1882. Conductivity: conductivity,
  1883. Remark: remark,
  1884. Status: 1,
  1885. CreatedTime: time.Now().Unix(),
  1886. UpdatedTime: time.Now().Unix(),
  1887. DialysisDurationMinute: dialysisDurationMinute,
  1888. DialysisDurationHour: dialysisDurationHour,
  1889. TargetUltrafiltration: targetUltrafiltration,
  1890. DialysateFormulation: dialysateFormulation,
  1891. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1892. BodyFluid: body_fluid,
  1893. SpecialMedicine: special_medicine,
  1894. SpecialMedicineOther: special_medicine_other,
  1895. DisplaceLiquiPart: displace_liqui_part,
  1896. DisplaceLiquiValue: displace_liqui_value,
  1897. BloodAccess: blood_access,
  1898. Ultrafiltration: ultrafiltration,
  1899. BodyFluidOther: body_fluid_other,
  1900. Niprocart: niprocart,
  1901. Jms: jms,
  1902. FistulaNeedleSet: fistula_needle_set,
  1903. FistulaNeedleSet16: fistula_needle_set_16,
  1904. Hemoperfusion: hemoperfusion,
  1905. DialyserSterilised: dialyser_sterilised,
  1906. Filtryzer: filtryzer,
  1907. Dialyzers: dialyzers,
  1908. Injector: injector,
  1909. Bloodlines: bloodlines,
  1910. TubingHemodialysis: tubing_hemodialysis,
  1911. Package: safe_package,
  1912. ALiquid: a_liquid,
  1913. TargetKtv: target_ktv,
  1914. PreImpulse: pre_impulse,
  1915. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1916. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1917. Blood: blood,
  1918. DialysisDialyszers: dialysis_dialyszers,
  1919. DialysisIrrigation: dialysis_irrigation,
  1920. AntioxidantCommodityName: antioxidant_commodity_name,
  1921. DisplaceSpeed: displace_speed,
  1922. Illness: illness,
  1923. Amylaceum: amylaceum,
  1924. SingleTime: single_time,
  1925. SingleWater: single_water,
  1926. ReplacementFlow: replacement_flow,
  1927. PlasmaSeparator: plasma_separator,
  1928. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1929. OxygenUptake: oxygen_uptake,
  1930. OxygenFlow: oxygen_flow,
  1931. OxygenTime: oxygen_time,
  1932. HemodialysisPipelines: hemodialysis_pipelines,
  1933. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1934. PunctureNeedle: puncture_needle,
  1935. PunctureNeedleCount: puncture_needle_count,
  1936. Epo: epo,
  1937. EpoCount: epo_count,
  1938. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1939. AdminUserId: admin_user_id,
  1940. IsWater: is_war,
  1941. DrhyWater: drhy_water,
  1942. DryWaterHour: dry_water_hour,
  1943. WaterMachine: water_machine,
  1944. AddAmount: add_amount,
  1945. ReduceAmount: reduce_amount,
  1946. DialysisRemark: dialysis_remark,
  1947. PrescribingNumber: prescribing_number,
  1948. StartSodium: start_sodium,
  1949. SodiumCurve: sodium_curve,
  1950. TreatmentRemark: treatment_remark,
  1951. PrescriptionSodium: prescription_sodium,
  1952. DialysisFluidFlow: dialysis_fluid_flow,
  1953. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1954. PrescriptionWater: prescription_water,
  1955. DialysisStrainer: dialysis_strainer,
  1956. Chaptalization: chaptalization,
  1957. WashingTime: washing_time,
  1958. WarshCount: warsh_count,
  1959. BloodAccessPartId: blood_access_part_id,
  1960. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1961. Dialyzate: dialyzate,
  1962. DialysisDialyszersId: dialysis_dialyszers_id,
  1963. DialysisIrrigationId: dialysis_irrigation_id,
  1964. DialysisStrainerId: dialysis_strainer_id,
  1965. FirstSuper: first_sup,
  1966. IsSequential: is_sequent,
  1967. Conduct: conduct,
  1968. }
  1969. if adminUserInfo.Org.Id == 10721 {
  1970. if prescription.ModeId == 2 {
  1971. if prescription.ReplacementTotal == 0 {
  1972. prescription.ReplacementTotal = 15
  1973. }
  1974. }
  1975. }
  1976. //查询最近透析准备表里是否存在 透析器 灌流器
  1977. //
  1978. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1979. //
  1980. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1981. //
  1982. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1983. //if len(mation)>0{
  1984. // for _, item := range splitStr {
  1985. // for _,it := range mation{
  1986. // if(item == it.SpecificationName){
  1987. //
  1988. // //查询最近一次的透析器
  1989. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1990. //
  1991. // if errcode == gorm.ErrRecordNotFound{
  1992. // //插入数据
  1993. // prepare := models.DialysisBeforePrepare{
  1994. // UserOrgId: adminUserInfo.Org.Id,
  1995. // PatientId: id,
  1996. // RecordDate: recordDate.Unix(),
  1997. // GoodTypeId: it.GoodTypeId,
  1998. // GoodId: it.ID,
  1999. // Count: 1,
  2000. // Ctime: time.Now().Unix(),
  2001. // Creater: adminUserInfo.AdminUser.Id,
  2002. // Status:1,
  2003. //
  2004. // }
  2005. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2006. // fmt.Println("",errcode)
  2007. // }
  2008. // }
  2009. // }
  2010. //
  2011. // }
  2012. //
  2013. // for _, item := range splitIrrigation {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. // //查询最近一次的透析器
  2017. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2018. // if errcode == gorm.ErrRecordNotFound{
  2019. // //插入数据
  2020. // prepare := models.DialysisBeforePrepare{
  2021. // UserOrgId: adminUserInfo.Org.Id,
  2022. // PatientId: id,
  2023. // RecordDate: recordDate.Unix(),
  2024. // GoodTypeId: it.GoodTypeId,
  2025. // GoodId: it.ID,
  2026. // Count: 1,
  2027. // Ctime: time.Now().Unix(),
  2028. // Creater: adminUserInfo.AdminUser.Id,
  2029. // Status:1,
  2030. //
  2031. // }
  2032. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2033. // fmt.Println(errcode)
  2034. // }
  2035. // }
  2036. // }
  2037. // }
  2038. //}
  2039. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2040. if dialysisPrescription.ID == 0 { //新增
  2041. if appRole.UserType == 2 || appRole.UserType == 1 {
  2042. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2043. }
  2044. prescription.Creater = adminUserInfo.AdminUser.Id
  2045. //针对河间咸得
  2046. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2047. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2048. prescription.DisplaceLiquiPart = 0
  2049. prescription.DisplaceLiquiValue = 0
  2050. }
  2051. }
  2052. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2053. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2054. }
  2055. err := service.AddSigleRecord(&prescription)
  2056. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2057. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2058. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2059. if len(monitorList) > 0 {
  2060. var ultrafiltration_rate float64
  2061. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2062. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2063. var replacement_rate float64
  2064. //乘10 除10是为了保留一位小数
  2065. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2066. var firstOpeateTime = monitorList[0].OperateTime
  2067. for _, item := range monitorList {
  2068. //超滤率
  2069. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2070. //置换率
  2071. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2072. //超滤量
  2073. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2074. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2075. //置换量
  2076. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2077. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2078. }
  2079. }
  2080. }
  2081. //记录日志
  2082. byterequest, _ := json.Marshal(prescription)
  2083. prescriptionLog := models.XtDialysisPrescriptionLog{
  2084. UserOrgId: prescription.UserOrgId,
  2085. Ctime: time.Now().Unix(),
  2086. Mtime: 0,
  2087. ErrLog: string(byterequest),
  2088. AdminUserId: adminUserInfo.AdminUser.Id,
  2089. RecordDate: prescription.RecordDate,
  2090. PatientId: prescription.PatientId,
  2091. Source: "手机端新增保存处方",
  2092. Status: 1,
  2093. }
  2094. service.CreatePrescriptionLog(prescriptionLog)
  2095. finish := models.XtDialysisFinish{
  2096. IsFinish: 1,
  2097. UserOrgId: adminUserInfo.Org.Id,
  2098. Status: 1,
  2099. Ctime: time.Now().Unix(),
  2100. Mtime: 0,
  2101. Module: 1,
  2102. RecordDate: recordDate.Unix(),
  2103. Sourse: 1,
  2104. PatientId: id,
  2105. }
  2106. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2107. if dialysisFinish.ID == 0 {
  2108. service.CreateDialysisFinish(finish)
  2109. }
  2110. //长沙南雅医院,自动生成抗凝剂的临时处方
  2111. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2112. if prescribing_number == 0 {
  2113. prescribing_number = 1
  2114. }
  2115. if prescribing_number == 0 && id == 14682 {
  2116. prescribing_number = 2
  2117. }
  2118. if prescribing_number == 0 && id == 18560 {
  2119. prescribing_number = 2
  2120. }
  2121. advice := models.DoctorAdvice{
  2122. UserOrgId: adminUserInfo.Org.Id,
  2123. PatientId: id,
  2124. GroupNo: 0,
  2125. AdviceType: 2,
  2126. RecordDate: recordDate.Unix(),
  2127. AdviceDate: recordDate.Unix(),
  2128. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2129. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2130. AdviceDesc: "",
  2131. ReminderDate: 0,
  2132. SingleDose: anticoagulant_zongliang,
  2133. SingleDoseUnit: "iu",
  2134. DrugSpec: 0,
  2135. DrugSpecUnit: "",
  2136. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2137. PrescribingNumberUnit: "支",
  2138. DeliveryWay: "静脉注射",
  2139. ExecutionFrequency: "上机前",
  2140. AdviceDoctor: 0,
  2141. Status: 1,
  2142. CreatedTime: time.Now().Unix(),
  2143. UpdatedTime: time.Now().Unix(),
  2144. IsPrescription: 1,
  2145. ExecutionState: 2,
  2146. StopState: 2,
  2147. IsSettle: 2,
  2148. }
  2149. // 查询排班信息
  2150. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2151. if schedulePatient.ID > 0 {
  2152. if schedulePatient.ScheduleType == 1 {
  2153. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2154. }
  2155. if schedulePatient.ScheduleType == 2 {
  2156. advice.StartTime = recordDate.Unix() + 9*60*60
  2157. }
  2158. }
  2159. // 抗凝剂名称
  2160. switch anticoagulant {
  2161. case 1:
  2162. advice.AdviceName = "无肝素"
  2163. break
  2164. case 2:
  2165. advice.AdviceName = "普通肝素"
  2166. break
  2167. case 3:
  2168. advice.AdviceName = "低分子肝素"
  2169. break
  2170. case 4:
  2171. advice.AdviceName = "阿加曲班"
  2172. break
  2173. case 5:
  2174. advice.AdviceName = "枸橼酸钠"
  2175. break
  2176. case 6:
  2177. advice.AdviceName = "低分子肝素钙"
  2178. break
  2179. case 7:
  2180. advice.AdviceName = "低分子肝素钠"
  2181. break
  2182. case 8:
  2183. advice.AdviceName = "依诺肝素"
  2184. break
  2185. case 9:
  2186. advice.AdviceName = "达肝素"
  2187. break
  2188. case 10:
  2189. advice.AdviceName = "体外抗凝"
  2190. break
  2191. case 11:
  2192. advice.AdviceName = "那曲肝素"
  2193. break
  2194. case 12:
  2195. advice.AdviceName = "无抗凝剂"
  2196. break
  2197. }
  2198. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2199. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2200. advice.AdviceDoctor = appRole.AdminUserId
  2201. }
  2202. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2203. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2204. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2205. advice.AdviceName = "低分子肝素钠注射液"
  2206. // 修改患者临时医嘱里的抗凝剂医嘱
  2207. advice.ID = advicePrescription.ID
  2208. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2209. } else {
  2210. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2211. advice.AdviceName = "低分子肝素钠注射液"
  2212. // 新增患者临时医嘱里的抗凝剂医嘱
  2213. service.CreateDoctorAdvice(&advice)
  2214. }
  2215. }
  2216. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2217. redis := service.RedisClient()
  2218. defer redis.Close()
  2219. //清空key 值
  2220. redis.Set(key, "", time.Second)
  2221. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2222. redis.Set(keyOne, "", time.Second)
  2223. }
  2224. //获取key,清空redis
  2225. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2226. redis := service.RedisClient()
  2227. //清空key 值
  2228. redis.Set(key, "", time.Second)
  2229. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2230. //清空key 值
  2231. redis.Set(keyOne, "", time.Second)
  2232. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2233. //清空key 值
  2234. redis.Set(keyTwo, "", time.Second)
  2235. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2236. redis.Set(keySix, "", time.Second)
  2237. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2238. redis.Set(keySeven, "", time.Second)
  2239. if err == nil {
  2240. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2241. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2242. //清空key 值
  2243. redis.Set(keyThree, "", time.Second)
  2244. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2245. //清空key 值
  2246. redis.Set(keyFour, "", time.Second)
  2247. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2248. redis.Set(keyFive, "", time.Second)
  2249. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2250. redis.Set(keySix, "", time.Second)
  2251. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2252. redis.Set(keySeven, "", time.Second)
  2253. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2254. //清空key 值
  2255. redis.Set(keyOne, "", time.Second)
  2256. if updateErr != nil {
  2257. utils.ErrorLog("%v", updateErr)
  2258. }
  2259. defer redis.Close()
  2260. c.ServeSuccessJSON(map[string]interface{}{
  2261. "prescription": prescription,
  2262. })
  2263. }
  2264. } else { //修改
  2265. //if mode_id > 0 {
  2266. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2267. //}
  2268. //if template.TemplateId == 1 {
  2269. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2270. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2271. // if getPermissionErr != nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2273. // return
  2274. // } else if headNursePermission == nil {
  2275. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2276. // return
  2277. // }
  2278. // }
  2279. //}
  2280. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2281. prescription.Modifier = adminUserInfo.AdminUser.Id
  2282. if appRole.UserType == 2 || appRole.UserType == 1 {
  2283. prescription_doctor := adminUserInfo.AdminUser.Id
  2284. prescription.PrescriptionDoctor = prescription_doctor
  2285. } else {
  2286. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2287. }
  2288. if dialysisPrescription.Creater == 0 { //体重称
  2289. prescription.Creater = adminUserInfo.AdminUser.Id
  2290. } else {
  2291. prescription.Creater = dialysisPrescription.Creater
  2292. if adminUserInfo.Org.Id == 9882 {
  2293. if appRole.UserType == 2 || appRole.UserType == 1 {
  2294. prescription_doctor := adminUserInfo.AdminUser.Id
  2295. prescription.PrescriptionDoctor = prescription_doctor
  2296. prescription.Creater = prescription_doctor
  2297. }
  2298. }
  2299. }
  2300. prescription.ID = dialysisPrescription.ID
  2301. if adminUserInfo.Org.Id == 10721 {
  2302. if prescription.ModeId == 2 {
  2303. if prescription.ReplacementTotal == 0 {
  2304. prescription.ReplacementTotal = 15
  2305. }
  2306. }
  2307. }
  2308. service.UpDateDialysisPrescription(&prescription)
  2309. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2310. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2311. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2312. if len(monitorList) > 0 {
  2313. var ultrafiltration_rate float64
  2314. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2315. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2316. var replacement_rate float64
  2317. //乘10 除10是为了保留一位小数
  2318. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2319. var firstOpeateTime = monitorList[0].OperateTime
  2320. for _, item := range monitorList {
  2321. //超滤率
  2322. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2323. //置换率
  2324. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2325. //超滤量
  2326. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2327. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2328. //置换量
  2329. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2330. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2331. }
  2332. }
  2333. }
  2334. //记录日志
  2335. byterequest, _ := json.Marshal(prescription)
  2336. prescriptionLog := models.XtDialysisPrescriptionLog{
  2337. UserOrgId: prescription.UserOrgId,
  2338. Ctime: time.Now().Unix(),
  2339. Mtime: 0,
  2340. ErrLog: string(byterequest),
  2341. AdminUserId: adminUserInfo.AdminUser.Id,
  2342. RecordDate: prescription.RecordDate,
  2343. PatientId: prescription.PatientId,
  2344. Source: "手机端修改处方",
  2345. Status: 1,
  2346. }
  2347. service.CreatePrescriptionLog(prescriptionLog)
  2348. finish := models.XtDialysisFinish{
  2349. IsFinish: 1,
  2350. UserOrgId: adminUserInfo.Org.Id,
  2351. Status: 1,
  2352. Ctime: time.Now().Unix(),
  2353. Mtime: 0,
  2354. Module: 1,
  2355. RecordDate: recordDate.Unix(),
  2356. Sourse: 1,
  2357. PatientId: id,
  2358. }
  2359. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2360. if dialysisFinish.ID == 0 {
  2361. service.CreateDialysisFinish(finish)
  2362. }
  2363. //修改处方
  2364. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2365. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2366. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2367. if advicePrescription.ID > 0 {
  2368. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2369. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2370. redis := service.RedisClient()
  2371. defer redis.Close()
  2372. //清空key 值
  2373. redis.Set(key, "", time.Second)
  2374. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2375. redis.Set(keyOne, "", time.Second)
  2376. }
  2377. }
  2378. //获取key,清空redis
  2379. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2380. redis := service.RedisClient()
  2381. //清空key 值
  2382. redis.Set(key, "", time.Second)
  2383. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2384. //清空key 值
  2385. redis.Set(keyOne, "", time.Second)
  2386. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2387. redis.Set(keySix, "", time.Second)
  2388. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2389. redis.Set(keySeven, "", time.Second)
  2390. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2391. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2392. //清空key 值
  2393. redis.Set(keyTwoOne, "", time.Second)
  2394. defer redis.Close()
  2395. if updateErr != nil {
  2396. utils.ErrorLog("%v", updateErr)
  2397. }
  2398. c.ServeSuccessJSON(map[string]interface{}{
  2399. "prescription": prescription,
  2400. })
  2401. }
  2402. }
  2403. func (c *DialysisAPIController) Finish() {
  2404. id, _ := c.GetInt64("patient", 0)
  2405. recordDateStr := c.GetString("record_date")
  2406. nurseID, _ := c.GetInt64("nurse")
  2407. end_time := c.GetString("end_time")
  2408. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2409. internal_fistula := c.GetString("blood_access_internal_fistula")
  2410. catheter := c.GetString("catheter")
  2411. cruor := c.GetString("cruor")
  2412. mission := c.GetString("mission")
  2413. condenser := c.GetString("condenser")
  2414. if id <= 0 || nurseID <= 0 {
  2415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2416. return
  2417. }
  2418. adminUserInfo := c.GetMobileAdminUserInfo()
  2419. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2420. if patient.ID == 0 {
  2421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2422. return
  2423. }
  2424. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2425. if getNurseErr != nil {
  2426. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2428. return
  2429. } else if nurse == nil {
  2430. c.ErrorLog("护士不存在")
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2432. return
  2433. }
  2434. if len(recordDateStr) == 0 {
  2435. recordDateStr = time.Now().Format("2006-01-02")
  2436. }
  2437. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2438. if parseDateErr != nil {
  2439. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2441. return
  2442. }
  2443. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2444. if parseEndDateErr != nil {
  2445. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2447. return
  2448. }
  2449. // 查询信息规挡的设置天数
  2450. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2451. if infor.ID > 0 && infor.WeekDay > 0 {
  2452. var cha_time int64
  2453. timeNowStr := time.Now().Format("2006-01-02")
  2454. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2455. //今日的日期减去设置的日期
  2456. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2457. if cha_time >= recordDate.Unix() {
  2458. //查询审核是否允许
  2459. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2460. //申请状态不允许的情况 拒绝修改
  2461. if infor.ApplicationStatus != 1 {
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2463. return
  2464. }
  2465. }
  2466. }
  2467. //now := time.Now()
  2468. //year, month, day := now.Date()
  2469. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2470. //todayTimeStamp := today_time.Unix()
  2471. // 获取当天的第一条透析纪录
  2472. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2473. if getMonitorRecordsErr != nil {
  2474. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2476. return
  2477. }
  2478. // 获取当前的最后一条透析纪录
  2479. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2480. if getMonitorRecordsErr != nil {
  2481. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. return
  2484. }
  2485. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2486. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2487. if getAADErr != nil {
  2488. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2490. return
  2491. }
  2492. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2493. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2494. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2495. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2496. if assessmentAfterDislysis != nil {
  2497. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2498. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2499. } else {
  2500. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2501. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2502. tempassessmentAfterDislysis.Status = 1
  2503. tempassessmentAfterDislysis.PatientId = id
  2504. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2505. }
  2506. //长沙南雅
  2507. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2508. //获取最后一条透析处方数据
  2509. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2510. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2511. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2512. }
  2513. if dialysisOrder.Stage == 1 {
  2514. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2515. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2516. fmt.Println(value)
  2517. a, b := math.Modf(value)
  2518. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2519. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2520. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2521. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2522. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2523. }
  2524. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2525. //var num1 int64
  2526. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2527. //fmt.Println(num1)
  2528. //sub := float64(num1 / 3600)
  2529. //fmt.Println(sub)
  2530. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2531. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2532. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2533. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2534. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2535. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2536. if adminUserInfo.Org.Id != 10375 {
  2537. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2538. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2539. }
  2540. if adminUserInfo.Org.Id != 10445 {
  2541. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2542. }
  2543. //北方营口医院
  2544. if adminUserInfo.Org.Id == 10445 {
  2545. //获取最后一条透析处方数据
  2546. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2547. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2548. } else {
  2549. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2550. }
  2551. //新化博翔
  2552. if adminUserInfo.Org.Id == 10447 {
  2553. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2554. }
  2555. //阳春
  2556. if adminUserInfo.Org.Id == 10485 {
  2557. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2558. }
  2559. if adminUserInfo.Org.Id == 10551 {
  2560. //获取最后一条透析处方数据
  2561. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2563. }
  2564. if adminUserInfo.Org.Id == 10580 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2566. }
  2567. if adminUserInfo.Org.Id == 10612 {
  2568. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2569. }
  2570. //孝康
  2571. if adminUserInfo.Org.Id == 10693 {
  2572. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2573. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2574. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2576. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2577. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2578. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2579. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2580. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2581. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2582. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2583. }
  2584. if adminUserInfo.Org.Id == 10721 {
  2585. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2586. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2587. }
  2588. if adminUserInfo.Org.Id == 10697 {
  2589. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2590. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2591. lastWeightAfter.LastAfterWeight = floatAfeter
  2592. }
  2593. if adminUserInfo.Org.Id == 10624 {
  2594. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2595. }
  2596. }
  2597. 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 {
  2598. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2599. if adminUserInfo.Org.Id != 10702 {
  2600. if evaluation.SystolicBloodPressure == 0 {
  2601. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2602. if adminUserInfo.Org.Id == 10693 {
  2603. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2604. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2605. }
  2606. pre := models.PredialysisEvaluation{
  2607. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2608. }
  2609. fmt.Println("prew", pre)
  2610. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2612. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2613. redis := service.RedisClient()
  2614. redis.Set(key, "", time.Second)
  2615. redis.Set(keyOne, "", time.Second)
  2616. defer redis.Close()
  2617. fmt.Println(getNurseErr)
  2618. }
  2619. }
  2620. if adminUserInfo.Org.Id != 10702 {
  2621. if evaluation.DiastolicBloodPressure == 0 {
  2622. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2623. if adminUserInfo.Org.Id == 10693 {
  2624. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2625. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2626. }
  2627. pres := models.PredialysisEvaluation{
  2628. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2629. }
  2630. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2631. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2632. redis := service.RedisClient()
  2633. redis.Set(key, "", time.Second)
  2634. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2635. redis.Set(keyOne, "", time.Second)
  2636. defer redis.Close()
  2637. fmt.Println(getNurseErr)
  2638. }
  2639. }
  2640. if adminUserInfo.Org.Id != 10702 {
  2641. if evaluation.PulseFrequency == 0 {
  2642. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2643. if adminUserInfo.Org.Id == 10693 {
  2644. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2645. evaluation.PulseFrequency = pulseFrequency
  2646. }
  2647. press := models.PredialysisEvaluation{
  2648. PulseFrequency: evaluation.PulseFrequency,
  2649. }
  2650. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2651. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2652. redis := service.RedisClient()
  2653. redis.Set(key, "", time.Second)
  2654. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2655. redis.Set(keyOne, "", time.Second)
  2656. defer redis.Close()
  2657. fmt.Println(getNurseErr)
  2658. }
  2659. }
  2660. if evaluation.Temperature == 0 {
  2661. evaluation.Temperature = fmonitorRecords.Temperature
  2662. press := models.PredialysisEvaluation{
  2663. Temperature: evaluation.Temperature,
  2664. }
  2665. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2666. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2667. redis := service.RedisClient()
  2668. redis.Set(key, "", time.Second)
  2669. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2670. redis.Set(keyOne, "", time.Second)
  2671. defer redis.Close()
  2672. fmt.Println(getNurseErr)
  2673. }
  2674. }
  2675. if adminUserInfo.Org.Id == 9583 {
  2676. //获取透析处方的最后一条数据
  2677. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2678. if diaerr != nil {
  2679. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2681. return
  2682. }
  2683. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2684. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2685. }
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2694. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2695. }
  2696. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2697. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2698. }
  2699. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2700. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2701. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2702. }
  2703. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2704. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2705. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2706. }
  2707. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2708. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2709. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2710. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2711. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2712. }
  2713. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2714. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2715. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2716. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2717. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2718. }
  2719. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2720. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2721. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2722. }
  2723. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2724. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2725. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2726. }
  2727. if lastAssessmentAfterDislysis != nil {
  2728. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2729. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2730. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2731. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2732. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2733. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2734. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2735. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2736. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2737. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2738. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2739. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2740. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2741. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2742. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2743. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2744. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2745. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2746. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2747. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2748. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2749. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2750. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2751. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2752. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2753. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2754. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2755. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2756. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2757. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2758. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2759. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2760. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2761. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2762. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2763. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2764. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2765. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2766. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2767. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2768. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2769. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2770. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2771. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2772. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2773. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2774. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2775. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2776. if tempassessmentAfterDislysis.PatientId == 18695 {
  2777. tempassessmentAfterDislysis.ActualDisplacement = 0
  2778. }
  2779. if adminUserInfo.Org.Id != 10375 {
  2780. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2781. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2782. }
  2783. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2784. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2785. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2786. }
  2787. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2788. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2789. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2790. }
  2791. }
  2792. finish := models.XtDialysisFinish{
  2793. IsFinish: 1,
  2794. UserOrgId: adminUserInfo.Org.Id,
  2795. Status: 1,
  2796. Ctime: time.Now().Unix(),
  2797. Mtime: 0,
  2798. Module: 9,
  2799. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2800. Sourse: 1,
  2801. PatientId: tempassessmentAfterDislysis.PatientId,
  2802. }
  2803. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2804. if dialysisFinish.ID == 0 {
  2805. service.CreateDialysisFinish(finish)
  2806. }
  2807. //孝康
  2808. if adminUserInfo.Org.Id == 10693 {
  2809. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2810. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2811. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2812. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2813. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2814. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2815. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2816. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2817. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2818. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2819. }
  2820. if adminUserInfo.Org.Id == 10697 {
  2821. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2822. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2823. lastWeightAfter.LastAfterWeight = floatAfeter
  2824. }
  2825. if adminUserInfo.Org.Id == 10721 {
  2826. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2827. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2828. }
  2829. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2830. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2831. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2832. redis := service.RedisClient()
  2833. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2834. redis.Set(keyOne, "", time.Second)
  2835. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2836. redis.Set(keyTwo, "", time.Second)
  2837. defer redis.Close()
  2838. //清空key 值
  2839. redis.Set(key, "", time.Second)
  2840. if err != nil {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2842. return
  2843. }
  2844. if dialysisOrder == nil {
  2845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2846. return
  2847. }
  2848. if dialysisOrder.Stage == 2 {
  2849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2850. return
  2851. }
  2852. if dialysisOrder.Stage == 1 {
  2853. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2854. finish := models.XtDialysisFinish{
  2855. IsFinish: 1,
  2856. UserOrgId: adminUserInfo.Org.Id,
  2857. Status: 1,
  2858. Ctime: time.Now().Unix(),
  2859. Mtime: 0,
  2860. Module: 8,
  2861. RecordDate: recordDate.Unix(),
  2862. Sourse: 1,
  2863. PatientId: id,
  2864. }
  2865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2866. if dialysisFinish.ID == 0 {
  2867. service.CreateDialysisFinish(finish)
  2868. }
  2869. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2870. redis := service.RedisClient()
  2871. defer redis.Close()
  2872. //清空key 值
  2873. redis.Set(key, "", time.Second)
  2874. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2875. redis.Set(keyOne, "", time.Second)
  2876. //结束时候透析次数加1
  2877. service.UpdateSolutionByPatientId(id)
  2878. //下机完自动消毒,针对长沙南雅
  2879. if dialysisOrder.Stage == 1 {
  2880. 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 {
  2881. //根据床位号获取设备型号
  2882. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2883. //查询使用消毒最后一条消毒记录
  2884. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2885. fmt.Println("err", err)
  2886. if err == gorm.ErrRecordNotFound {
  2887. //查找排班
  2888. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2889. //查询改设备是否有消毒计划
  2890. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2891. //根据床位号获取设备id
  2892. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2893. //查询病人信息
  2894. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2895. var con = ""
  2896. if patients.IsInfectious == 0 {
  2897. con = ""
  2898. }
  2899. if patients.IsInfectious == 1 {
  2900. con = "无"
  2901. }
  2902. if patients.IsInfectious == 2 {
  2903. con = "有"
  2904. }
  2905. if errcode == nil {
  2906. var end_time int64
  2907. end_time = endDate.Unix() + plan.DisinfecTime*60
  2908. //新增消毒
  2909. information := models.DeviceInformation{
  2910. Date: dialysisOrder.DialysisDate,
  2911. Zone: dialysisOrder.ZoneId,
  2912. Class: dialysisOrder.SchedualType,
  2913. BedNumber: dialysisOrder.BedID,
  2914. PatientId: dialysisOrder.PatientId,
  2915. DialysisMode: scheduleByPatient.ModeId,
  2916. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2917. Disinfection: 1,
  2918. DialysisConcentration: 1,
  2919. DisinfectionStatus: 1,
  2920. Move: 1,
  2921. UserOrgId: dialysisOrder.UserOrgId,
  2922. DisinfectType: plan.Way,
  2923. DisinfectantType: plan.MachineDisinfectant,
  2924. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2925. Disinfectant: plan.Disinfectant,
  2926. Ctime: time.Now().Unix(),
  2927. Status: 1,
  2928. SignName: nurseID,
  2929. EquimentId: addmacher.ID,
  2930. DisinfectionResidue: 2,
  2931. Bed: addmacher.BedNumber,
  2932. StartTime: dialysisOrder.StartTime,
  2933. EndTime: dialysisOrder.EndTime,
  2934. Contagion: con,
  2935. WeightLoss: 0,
  2936. Hyperfiltratio: 0,
  2937. DialysisHour: "",
  2938. MachineRun: 1,
  2939. DisinfecStartime: endDate.Unix(),
  2940. DisinfecEndtime: end_time,
  2941. }
  2942. err := service.CreateInformationTwo(&information)
  2943. fmt.Println("报错", err)
  2944. }
  2945. }
  2946. }
  2947. }
  2948. dialysisOrder.Stage = 2
  2949. dialysisOrder.FinishNurse = nurseID
  2950. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2951. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2952. dialysisOrder.EndTime = endDate.Unix()
  2953. // 长沙南雅需求
  2954. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2955. //获取最后1条监测的数据
  2956. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2957. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2958. var accumulatedBloodVolume float64
  2959. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2960. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2961. fmt.Println(err)
  2962. // 查询未执行的医嘱
  2963. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2964. for _, item := range doctorAdvice {
  2965. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2966. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2967. redis := service.RedisClient()
  2968. //清空key 值
  2969. redis.Set(key, "", time.Second)
  2970. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2971. redis.Set(keyTwo, "", time.Second)
  2972. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2973. redis.Set(keyThree, "", time.Second)
  2974. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2975. theTime := toTime.Format("2006-01-02")
  2976. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2977. redis.Set(keyFour, "", time.Second)
  2978. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2979. redis.Set(keyFive, "", time.Second)
  2980. defer redis.Close()
  2981. }
  2982. }
  2983. go func() {
  2984. ssoDomain := beego.AppConfig.String("call_domain")
  2985. api := ssoDomain + "/index/downpatient"
  2986. values := make(url.Values)
  2987. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2988. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2989. values.Set("patient_id", strconv.FormatInt(id, 10))
  2990. http.PostForm(api, values)
  2991. }()
  2992. if err == nil {
  2993. c.ServeSuccessJSON(map[string]interface{}{
  2994. "dialysisOrder": dialysisOrder,
  2995. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2996. })
  2997. } else {
  2998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2999. }
  3000. }
  3001. //查找是否开启配置
  3002. //orderSetting, _ := service.GetDialysisOrderSetting(adminUserInfo.Org.Id)
  3003. ////开启下机扣减
  3004. //if orderSetting.IsOpen == 1 {
  3005. //
  3006. // //查询今日患者排班的模式
  3007. // db := service.XTWriteDB()
  3008. // // 开始外部循环的事务
  3009. // tx := db.Begin()
  3010. // // 在函数结束时处理事务回滚
  3011. // defer func() {
  3012. // if r := recover(); r != nil {
  3013. // tx.Rollback()
  3014. // }
  3015. // }()
  3016. //
  3017. // schedule, _ := service.GetDialysisOrderSchedule(id, recordDate.Unix(), adminUserInfo.Org.Id, tx)
  3018. //
  3019. // if schedule.ModeId == 1 {
  3020. // //扣减库存
  3021. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3022. //
  3023. // patient, _ := service.GetSfPatientById(tx, id)
  3024. // var over_count int64
  3025. // if schedule.ModeId == 1 {
  3026. // over_count = patient.HdCount
  3027. // }
  3028. // if schedule.ModeId == 2 {
  3029. // over_count = patient.HdfCount
  3030. // }
  3031. //
  3032. // if schedule.ModeId == 3 {
  3033. // over_count = patient.HdhpCount
  3034. // }
  3035. // if schedule.ModeId == 4 {
  3036. // over_count = patient.HpCount
  3037. // }
  3038. // if schedule.ModeId == 5 {
  3039. // over_count = patient.OtherCount
  3040. // }
  3041. // patientCountFlow := models.SfPatientCountFlow{
  3042. // PatientId: id,
  3043. // ModeId: schedule.ModeId,
  3044. // Count: 1,
  3045. // Status: 1,
  3046. // Ctime: time.Now().Unix(),
  3047. // Mtime: time.Now().Unix(),
  3048. // RecordDate: recordDate.Unix(),
  3049. // UserOrgId: adminUserInfo.Org.Id,
  3050. // Creater: adminUserInfo.AdminUser.Id,
  3051. // IsType: 1,
  3052. // OverCount: over_count,
  3053. // WarehouseOutId: 0,
  3054. // }
  3055. //
  3056. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3057. // }
  3058. //
  3059. // if schedule.ModeId == 2 {
  3060. //
  3061. // //扣减库存
  3062. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3063. //
  3064. // patient, _ := service.GetSfPatientById(tx, id)
  3065. // var over_count int64
  3066. // if schedule.ModeId == 1 {
  3067. // over_count = patient.HdCount
  3068. // }
  3069. // if schedule.ModeId == 2 {
  3070. // over_count = patient.HdfCount
  3071. // }
  3072. //
  3073. // if schedule.ModeId == 3 {
  3074. // over_count = patient.HdhpCount
  3075. // }
  3076. // if schedule.ModeId == 4 {
  3077. // over_count = patient.HpCount
  3078. // }
  3079. // if schedule.ModeId == 5 {
  3080. // over_count = patient.OtherCount
  3081. // }
  3082. // patientCountFlow := models.SfPatientCountFlow{
  3083. // PatientId: id,
  3084. // ModeId: schedule.ModeId,
  3085. // Count: 1,
  3086. // Status: 1,
  3087. // Ctime: time.Now().Unix(),
  3088. // Mtime: time.Now().Unix(),
  3089. // RecordDate: recordDate.Unix(),
  3090. // UserOrgId: adminUserInfo.Org.Id,
  3091. // Creater: adminUserInfo.AdminUser.Id,
  3092. // IsType: 2,
  3093. // OverCount: over_count,
  3094. // WarehouseOutId: 0,
  3095. // }
  3096. //
  3097. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3098. // }
  3099. //
  3100. // if schedule.ModeId == 3 {
  3101. //
  3102. // //扣减库存
  3103. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3104. //
  3105. // patient, _ := service.GetSfPatientById(tx, id)
  3106. // var over_count int64
  3107. // if schedule.ModeId == 1 {
  3108. // over_count = patient.HdCount
  3109. // }
  3110. // if schedule.ModeId == 2 {
  3111. // over_count = patient.HdfCount
  3112. // }
  3113. //
  3114. // if schedule.ModeId == 3 {
  3115. // over_count = patient.HdhpCount
  3116. // }
  3117. // if schedule.ModeId == 4 {
  3118. // over_count = patient.HpCount
  3119. // }
  3120. // if schedule.ModeId == 5 {
  3121. // over_count = patient.OtherCount
  3122. // }
  3123. // patientCountFlow := models.SfPatientCountFlow{
  3124. // PatientId: id,
  3125. // ModeId: schedule.ModeId,
  3126. // Count: 1,
  3127. // Status: 1,
  3128. // Ctime: time.Now().Unix(),
  3129. // Mtime: time.Now().Unix(),
  3130. // RecordDate: recordDate.Unix(),
  3131. // UserOrgId: adminUserInfo.Org.Id,
  3132. // Creater: adminUserInfo.AdminUser.Id,
  3133. // IsType: 3,
  3134. // OverCount: over_count,
  3135. // WarehouseOutId: 0,
  3136. // }
  3137. //
  3138. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3139. // }
  3140. // if schedule.ModeId == 4 {
  3141. //
  3142. // //扣减库存
  3143. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3144. //
  3145. // patient, _ := service.GetSfPatientById(tx, id)
  3146. // var over_count int64
  3147. // if schedule.ModeId == 1 {
  3148. // over_count = patient.HdCount
  3149. // }
  3150. // if schedule.ModeId == 2 {
  3151. // over_count = patient.HdfCount
  3152. // }
  3153. //
  3154. // if schedule.ModeId == 3 {
  3155. // over_count = patient.HdhpCount
  3156. // }
  3157. // if schedule.ModeId == 4 {
  3158. // over_count = patient.HpCount
  3159. // }
  3160. // if schedule.ModeId == 5 {
  3161. // over_count = patient.OtherCount
  3162. // }
  3163. // patientCountFlow := models.SfPatientCountFlow{
  3164. // PatientId: id,
  3165. // ModeId: schedule.ModeId,
  3166. // Count: 1,
  3167. // Status: 1,
  3168. // Ctime: time.Now().Unix(),
  3169. // Mtime: time.Now().Unix(),
  3170. // RecordDate: recordDate.Unix(),
  3171. // UserOrgId: adminUserInfo.Org.Id,
  3172. // Creater: adminUserInfo.AdminUser.Id,
  3173. // IsType: 4,
  3174. // OverCount: over_count,
  3175. // WarehouseOutId: 0,
  3176. // }
  3177. //
  3178. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3179. // }
  3180. // if schedule.ModeId != 1 && schedule.ModeId != 2 && schedule.ModeId != 3 && schedule.ModeId != 4 {
  3181. //
  3182. // //扣减库存
  3183. // service.ReducePatientCount(1, schedule.ModeId, id, tx)
  3184. //
  3185. // patient, _ := service.GetSfPatientById(tx, id)
  3186. // var over_count int64
  3187. // if schedule.ModeId == 1 {
  3188. // over_count = patient.HdCount
  3189. // }
  3190. // if schedule.ModeId == 2 {
  3191. // over_count = patient.HdfCount
  3192. // }
  3193. //
  3194. // if schedule.ModeId == 3 {
  3195. // over_count = patient.HdhpCount
  3196. // }
  3197. // if schedule.ModeId == 4 {
  3198. // over_count = patient.HpCount
  3199. // }
  3200. // if schedule.ModeId == 5 {
  3201. // over_count = patient.OtherCount
  3202. // }
  3203. // patientCountFlow := models.SfPatientCountFlow{
  3204. // PatientId: id,
  3205. // ModeId: schedule.ModeId,
  3206. // Count: 1,
  3207. // Status: 1,
  3208. // Ctime: time.Now().Unix(),
  3209. // Mtime: time.Now().Unix(),
  3210. // RecordDate: recordDate.Unix(),
  3211. // UserOrgId: adminUserInfo.Org.Id,
  3212. // Creater: adminUserInfo.AdminUser.Id,
  3213. // IsType: 5,
  3214. // OverCount: over_count,
  3215. // WarehouseOutId: 0,
  3216. // }
  3217. //
  3218. // service.CreatePatientCountFlow(patientCountFlow, tx)
  3219. // }
  3220. //
  3221. // tx.Commit()
  3222. // return
  3223. //}
  3224. }
  3225. func (c *DialysisAPIController) GetAllZone() {
  3226. adminUserInfo := c.GetMobileAdminUserInfo()
  3227. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3228. if err == nil {
  3229. c.ServeSuccessJSON(map[string]interface{}{
  3230. "zone": zone,
  3231. })
  3232. }
  3233. }
  3234. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3235. adminUserInfo := c.GetMobileAdminUserInfo()
  3236. page, _ := c.GetInt64("page", 1)
  3237. limit, _ := c.GetInt64("limit", 10)
  3238. schedulType, _ := c.GetInt64("schedul_type", 0)
  3239. startTime, _ := c.GetInt64("schedul_time", 0)
  3240. partitionType, _ := c.GetInt64("partition_type", 0)
  3241. keywords := c.GetString("keywords")
  3242. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3243. if err == nil {
  3244. c.ServeSuccessJSON(map[string]interface{}{
  3245. "schedule": dialysisSchedule,
  3246. })
  3247. }
  3248. return
  3249. }
  3250. // /m/api/dialysis/start [post]
  3251. // @param patient_id:int
  3252. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3253. // @param nurse:int 上机护士
  3254. // @param bed:int 床位号
  3255. func (this *DialysisAPIController) StartDialysis() {
  3256. patientID, _ := this.GetInt64("patient_id")
  3257. recordDateStr := this.GetString("record_date")
  3258. nurseID, _ := this.GetInt64("start_nurse")
  3259. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3260. blood_drawing, _ := this.GetInt64("blood_drawing")
  3261. schedual_type, _ := this.GetInt64("schedual_type")
  3262. bedID, _ := this.GetInt64("bed")
  3263. start_time := this.GetString("start_time")
  3264. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3265. change_nurse, _ := this.GetInt64("change_nurse")
  3266. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3267. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3268. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3269. puncture_needle := this.GetString("puncture_needle")
  3270. puncture_way := this.GetString("puncture_way")
  3271. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3272. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3273. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3274. zone_id, _ := this.GetInt64("zone_id")
  3275. elecsign := this.GetString("url")
  3276. nuclein_date_str := this.GetString("nuclein_date_str")
  3277. schedule_remark := this.GetString("schedule_remark")
  3278. order_remark := this.GetString("order_remark")
  3279. catheter_operation := this.GetString("catheter_operation")
  3280. blood_flow_volume := this.GetString("blood_flow_volume")
  3281. dialysis_strainer := this.GetString("dialysis_strainer")
  3282. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3284. return
  3285. }
  3286. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3287. if parseStartDateErr != nil {
  3288. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3290. return
  3291. }
  3292. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3293. if parseErr != nil {
  3294. this.ErrorLog("时间解析失败:%v", parseErr)
  3295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3296. return
  3297. }
  3298. adminUserInfo := this.GetMobileAdminUserInfo()
  3299. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3300. if getPatientErr != nil {
  3301. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3303. return
  3304. } else if patient == nil {
  3305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3306. return
  3307. }
  3308. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3309. if getNurseErr != nil {
  3310. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3312. return
  3313. } else if nurse == nil {
  3314. this.ErrorLog("护士不存在")
  3315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3316. return
  3317. }
  3318. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3319. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3320. if getDeviceNumberErr != nil {
  3321. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3323. return
  3324. } else if deviceNumber == nil {
  3325. this.ErrorLog("床位号不存在")
  3326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3327. return
  3328. }
  3329. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3330. if getRecordErr != nil {
  3331. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3333. return
  3334. } else if dialysisRecord != nil {
  3335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3336. return
  3337. }
  3338. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3339. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3340. timeLayout := "2006-01-02 15:04:05"
  3341. loc, _ := time.LoadLocation("Local")
  3342. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3343. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3344. schedulestartTime := theStartTime.Unix()
  3345. scheduleendTime := theEndTime.Unix()
  3346. var theNucleinDate int64
  3347. timeLayoutOne := "2006-01-02"
  3348. if len(nuclein_date_str) > 0 {
  3349. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3350. if err != nil {
  3351. utils.ErrorLog(err.Error())
  3352. }
  3353. theNucleinDate = theTime.Unix()
  3354. }
  3355. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3356. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3357. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3358. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3359. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3360. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3361. if record.ID == 0 {
  3362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3363. return
  3364. }
  3365. }
  3366. //查询该床位是否有人用了
  3367. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3368. if err == gorm.ErrRecordNotFound { //空床位
  3369. // 修改了床位逻辑
  3370. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3371. if daySchedule.ID > 0 {
  3372. daySchedule.PartitionId = deviceNumber.ZoneID
  3373. daySchedule.BedId = bedID
  3374. daySchedule.ScheduleType = schedual_type
  3375. daySchedule.UpdatedTime = time.Now().Unix()
  3376. xtSchedule := models.Schedule{
  3377. PartitionId: deviceNumber.ZoneID,
  3378. BedId: bedID,
  3379. ScheduleType: schedual_type,
  3380. UpdatedTime: time.Now().Unix(),
  3381. }
  3382. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3383. if err != nil {
  3384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3385. return
  3386. }
  3387. }
  3388. } else if err == nil {
  3389. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3390. if order.ID > 0 { //该机位被其他人占用了
  3391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3392. return
  3393. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3394. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3395. if daySchedule.ID > 0 {
  3396. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3397. if err != nil {
  3398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3399. return
  3400. }
  3401. }
  3402. }
  3403. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3404. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3405. return
  3406. }
  3407. //else if order.ID == 0 { //该床位没被占用
  3408. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3409. // if daySchedule.ID > 0 {
  3410. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3411. // //daySchedule.BedId = bedID
  3412. // //daySchedule.ScheduleType = schedual_type
  3413. // //daySchedule.UpdatedTime = time.Now().Unix()
  3414. // //err := service.UpdateSchedule(&daySchedule)
  3415. // xtSchedule := models.Schedule{
  3416. // PartitionId: deviceNumber.ZoneID,
  3417. // BedId: bedID,
  3418. // ScheduleType: schedual_type,
  3419. // UpdatedTime: time.Now().Unix(),
  3420. // }
  3421. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3422. // if err != nil {
  3423. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3424. // return
  3425. // }
  3426. // }
  3427. //}
  3428. //}
  3429. } else if err != nil {
  3430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3431. return
  3432. }
  3433. // 查询信息规挡的设置天数
  3434. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3435. if infor.ID > 0 && infor.WeekDay > 0 {
  3436. var cha_time int64
  3437. timeNowStr := time.Now().Format("2006-01-02")
  3438. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3439. //今日的日期减去设置的日期
  3440. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3441. if cha_time >= recordDate.Unix() {
  3442. //查询审核是否允许
  3443. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3444. //申请状态不允许的情况 拒绝修改
  3445. if infor.ApplicationStatus != 1 {
  3446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3447. return
  3448. }
  3449. }
  3450. }
  3451. dialysisRecord = &models.DialysisOrder{
  3452. DialysisDate: recordDate.Unix(),
  3453. UserOrgId: adminUserInfo.Org.Id,
  3454. PatientId: patientID,
  3455. Stage: 1,
  3456. BedID: bedID,
  3457. StartNurse: nurseID,
  3458. Status: 1,
  3459. StartTime: startDate.Unix(),
  3460. CreatedTime: time.Now().Unix(),
  3461. UpdatedTime: time.Now().Unix(),
  3462. PunctureNurse: puncture_nurse,
  3463. Creator: adminUserInfo.AdminUser.Id,
  3464. Modifier: adminUserInfo.AdminUser.Id,
  3465. SchedualType: schedual_type,
  3466. WashpipeNurse: washpipe_nurse,
  3467. ChangeNurse: change_nurse,
  3468. DifficultPunctureNurse: difficult_puncture_nurse,
  3469. NewFistulaNurse: new_fistula_nurse,
  3470. ZoneId: zone_id,
  3471. QualityNurseId: quality_nurse_id,
  3472. PunctureNeedle: puncture_needle,
  3473. PunctureWay: puncture_way,
  3474. DialysisIrrigation: dialysis_irrigation,
  3475. DialysisDialyszers: dialysis_dialyszers,
  3476. BloodAccessId: blood_access_id,
  3477. Url: elecsign,
  3478. NucleinDate: theNucleinDate,
  3479. ScheduleRemark: schedule_remark,
  3480. OrderRemark: order_remark,
  3481. CatheterOperation: catheter_operation,
  3482. BloodFlowVolume: blood_flow_volume,
  3483. BloodDrawing: blood_drawing,
  3484. DialysisStrainer: dialysis_strainer,
  3485. }
  3486. //查询该床位是否有人用了
  3487. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3488. if errorscode == gorm.ErrRecordNotFound {
  3489. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3490. finish := models.XtDialysisFinish{
  3491. IsFinish: 1,
  3492. UserOrgId: adminUserInfo.Org.Id,
  3493. Status: 1,
  3494. Ctime: time.Now().Unix(),
  3495. Mtime: 0,
  3496. Module: 6,
  3497. RecordDate: schedulestartTime,
  3498. Sourse: 1,
  3499. PatientId: patientID,
  3500. }
  3501. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3502. if dialysisFinish.ID == 0 {
  3503. service.CreateDialysisFinish(finish)
  3504. }
  3505. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3506. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3507. //统计该患者总次数
  3508. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3509. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3510. }
  3511. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3512. //统计该患者总次数
  3513. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3514. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3515. }
  3516. redis := service.RedisClient()
  3517. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3518. redis.Set(key, "", time.Second)
  3519. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3520. //清空key 值
  3521. redis.Set(keyOne, "", time.Second)
  3522. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3523. //清空key 值
  3524. redis.Set(keyTwo, "", time.Second)
  3525. if createErr != nil {
  3526. this.ErrorLog("上机失败:%v", createErr)
  3527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3528. return
  3529. }
  3530. }
  3531. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3532. var tempdispose string
  3533. // 只针对中能建
  3534. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3535. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3536. }
  3537. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3538. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3539. }
  3540. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3541. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3542. //}
  3543. var ultrafiltration_rate float64
  3544. var ultrafiltration_rate_one string
  3545. var replacement_rate float64
  3546. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3547. //后期预增脱水量
  3548. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3549. if prescription.ID > 0 {
  3550. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3551. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3552. 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
  3553. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3554. }
  3555. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 || adminUserInfo.Org.Id == 9478 {
  3556. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3557. }
  3558. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3559. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3560. }
  3561. //针对医师汇
  3562. if adminUserInfo.Org.Id == 10121 {
  3563. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3564. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3565. }
  3566. //针对通道
  3567. if adminUserInfo.Org.Id == 10234 {
  3568. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3569. }
  3570. //针对监利大垸医院
  3571. if template.TemplateId == 41 {
  3572. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3573. }
  3574. //针对肇庆三鹤血液透析中心
  3575. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3576. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3577. }
  3578. if adminUserInfo.Org.Id == 10469 {
  3579. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3580. }
  3581. if adminUserInfo.Org.Id == 10667 {
  3582. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3583. }
  3584. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3585. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3586. }
  3587. // 只针对方济医院
  3588. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3589. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3590. ultrafiltration_rate = value
  3591. }
  3592. //针对
  3593. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3594. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3595. ultrafiltration_rate = ultrafiltration_rate / 1000
  3596. }
  3597. if adminUserInfo.Org.Id == 10551 {
  3598. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3599. ultrafiltration_rate = ultrafiltration_rate / 1000
  3600. }
  3601. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3602. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3603. ultrafiltration_rate = ultrafiltration_rate / 1000
  3604. }
  3605. if adminUserInfo.Org.Id == 10580 {
  3606. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3607. ultrafiltration_rate = ultrafiltration_rate / 1000
  3608. }
  3609. if adminUserInfo.Org.Id == 10629 {
  3610. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3611. ultrafiltration_rate = ultrafiltration_rate / 1000
  3612. }
  3613. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3614. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3615. ultrafiltration_rate = ultrafiltration_rate / 1000
  3616. }
  3617. if adminUserInfo.Org.Id == 10751 {
  3618. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3619. ultrafiltration_rate = ultrafiltration_rate / 1000
  3620. }
  3621. if adminUserInfo.Org.Id == 10667 {
  3622. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3623. ultrafiltration_rate = ultrafiltration_rate / 1000
  3624. }
  3625. if adminUserInfo.Org.Id == 10693 {
  3626. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3627. ultrafiltration_rate = ultrafiltration_rate
  3628. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3629. }
  3630. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3631. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3632. ultrafiltration_rate = ultrafiltration_rate
  3633. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3634. }
  3635. if adminUserInfo.Org.Id == 10206 {
  3636. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3637. ultrafiltration_rate = ultrafiltration_rate
  3638. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3639. }
  3640. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3641. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3642. ultrafiltration_rate = ultrafiltration_rate
  3643. }
  3644. if adminUserInfo.Org.Id == 10702 {
  3645. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3646. ultrafiltration_rate = ultrafiltration_rate / 1000
  3647. }
  3648. if adminUserInfo.Org.Id == 10752 {
  3649. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3650. ultrafiltration_rate = ultrafiltration_rate / 1000
  3651. }
  3652. if adminUserInfo.Org.Id == 10723 {
  3653. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3654. ultrafiltration_rate = ultrafiltration_rate / 1000
  3655. }
  3656. if adminUserInfo.Org.Id == 10721 {
  3657. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3658. ultrafiltration_rate = ultrafiltration_rate / 1000
  3659. }
  3660. if adminUserInfo.Org.Id == 10757 {
  3661. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3662. ultrafiltration_rate = ultrafiltration_rate / 1000
  3663. }
  3664. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3665. if prescription.ModeId == 2 {
  3666. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3667. if totalMin == 0 {
  3668. totalMin = 240
  3669. }
  3670. if prescription.ReplacementTotal == 0 {
  3671. prescription.ReplacementTotal = 15
  3672. }
  3673. //乘10 除10是为了保留一位小数
  3674. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3675. }
  3676. }
  3677. if adminUserInfo.Org.Id == 10752 {
  3678. if prescription.ModeId == 2 {
  3679. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3680. if totalMin == 0 {
  3681. totalMin = 240
  3682. }
  3683. if prescription.ReplacementTotal == 0 {
  3684. prescription.ReplacementTotal = 15
  3685. }
  3686. //乘10 除10是为了保留一位小数
  3687. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3688. }
  3689. }
  3690. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10744 {
  3691. if prescription.ModeId == 2 {
  3692. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3693. if totalMin == 0 {
  3694. totalMin = 240
  3695. }
  3696. if prescription.DisplaceLiquiValue == 0 {
  3697. prescription.ReplacementTotal = 32
  3698. }
  3699. //乘10 除10是为了保留一位小数
  3700. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3701. }
  3702. }
  3703. }
  3704. }
  3705. if adminUserInfo.Org.Id == 10172 {
  3706. if prescription.ID == 0 {
  3707. if prescription.ModeId == 2 {
  3708. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3709. if totalMin == 0 {
  3710. totalMin = 240
  3711. }
  3712. if prescription.ReplacementTotal == 0 {
  3713. prescription.ReplacementTotal = 15
  3714. }
  3715. //乘10 除10是为了保留一位小数
  3716. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3717. }
  3718. }
  3719. }
  3720. record := models.MonitoringRecord{
  3721. UserOrgId: adminUserInfo.Org.Id,
  3722. PatientId: patientID,
  3723. DialysisOrderId: dialysisRecord.ID,
  3724. MonitoringDate: schedulestartTime,
  3725. OperateTime: startDate.Unix(),
  3726. // MonitoringTime: recordTime,
  3727. MonitoringNurse: nurseID,
  3728. Dispose: tempdispose,
  3729. UltrafiltrationRate: ultrafiltration_rate,
  3730. UltrafiltrationVolume: 0,
  3731. Status: 1,
  3732. CreatedTime: time.Now().Unix(),
  3733. UpdatedTime: time.Now().Unix(),
  3734. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3735. ReplacementRate: replacement_rate,
  3736. }
  3737. //只针对广慈医院
  3738. 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 {
  3739. // 查询病人是否有透前评估数据
  3740. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3741. //如果有数据就插入
  3742. if errcode == nil {
  3743. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3744. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3745. record.BreathingRate = befor.BreathingRate
  3746. record.PulseFrequency = befor.PulseFrequency
  3747. record.Temperature = befor.Temperature
  3748. }
  3749. }
  3750. //孝昌
  3751. if adminUserInfo.Org.Id == 10693 {
  3752. // 查询病人是否有透前评估数据
  3753. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3754. //如果有数据就插入
  3755. if errcode == nil {
  3756. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3757. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3758. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3759. record.BreathingRate = befor.BreathingRate
  3760. }
  3761. }
  3762. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3763. if newdialysisRecord.ID > 0 {
  3764. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3765. record.Temperature = 36.5
  3766. record.ArterialPressure = -100
  3767. record.DialysateTemperature = 36.5
  3768. record.Conductivity = 14
  3769. record.BreathingRate = "20"
  3770. record.VenousPressure = 80
  3771. record.TransmembranePressure = 60
  3772. record.Dispose = catheter_operation
  3773. }
  3774. //针对新化博翔
  3775. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3776. record.BloodOxygenSaturation = "99"
  3777. record.Conductivity = 14
  3778. record.DialysateTemperature = 36.5
  3779. record.BreathingRate = "20"
  3780. }
  3781. //针对兰溪人民医院的需求
  3782. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3783. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3784. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3785. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3786. record.Temperature = befor.Temperature
  3787. record.PulseFrequency = befor.PulseFrequency
  3788. record.BreathingRate = befor.BreathingRate
  3789. }
  3790. //针对乐山友谊医院的需求
  3791. if adminUserInfo.Org.Id == 10677 {
  3792. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3793. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3794. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3795. record.Temperature = befor.Temperature
  3796. record.PulseFrequency = befor.PulseFrequency
  3797. record.BreathingRate = befor.BreathingRate
  3798. }
  3799. //新化博翔
  3800. if adminUserInfo.Org.Id == 10447 {
  3801. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3802. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3803. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3804. record.BreathingRate = befor.BreathingRate
  3805. }
  3806. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3807. record.PulseFrequency = 80
  3808. record.Temperature = 36.5
  3809. }
  3810. //诊断灵山圣康
  3811. if adminUserInfo.Org.Id == 10375 {
  3812. record.Conductivity = 13.8
  3813. record.DialysateTemperature = 37
  3814. record.DialysateFlow = 500
  3815. record.BloodFlowVolume = 200
  3816. record.BreathingRate = "18"
  3817. record.SodiumConcentration = 140
  3818. }
  3819. //江成肾病医院
  3820. if adminUserInfo.Org.Id == 10517 {
  3821. record.SodiumConcentration = 138
  3822. record.DialysateTemperature = 36.5
  3823. }
  3824. //濉溪杏康血液透析中心
  3825. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3826. record.BloodFlowVolume = prescription.BloodFlowVolume
  3827. }
  3828. //胶州少海医院
  3829. if adminUserInfo.Org.Id == 10735 {
  3830. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3831. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3832. record.BreathingRate = befor.BreathingRate
  3833. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3834. record.Temperature = befor.Temperature
  3835. record.PulseFrequency = befor.PulseFrequency
  3836. }
  3837. if adminUserInfo.Org.Id != 10683 {
  3838. err = service.CreateMonitor(&record)
  3839. }
  3840. //记录日志
  3841. byterequest, _ := json.Marshal(record)
  3842. monitorRecordLog := models.XtMonitorRecordLog{
  3843. RecordDate: record.MonitoringDate,
  3844. PatientId: record.PatientId,
  3845. Module: 1,
  3846. AdminUserId: adminUserInfo.AdminUser.Id,
  3847. Ctime: time.Now().Unix(),
  3848. Mtime: 0,
  3849. Status: 1,
  3850. UserOrgId: record.UserOrgId,
  3851. ErrLog: string(byterequest),
  3852. Source: "执行上机时新增监测",
  3853. }
  3854. service.CreateMonitorRecordLog(monitorRecordLog)
  3855. finish := models.XtDialysisFinish{
  3856. IsFinish: 1,
  3857. UserOrgId: adminUserInfo.Org.Id,
  3858. Status: 1,
  3859. Ctime: time.Now().Unix(),
  3860. Mtime: 0,
  3861. Module: 7,
  3862. RecordDate: schedulestartTime,
  3863. Sourse: 1,
  3864. PatientId: patientID,
  3865. }
  3866. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3867. if dialysisFinish.ID == 0 {
  3868. service.CreateDialysisFinish(finish)
  3869. }
  3870. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3871. redis := service.RedisClient()
  3872. //清空key 值
  3873. redis.Set(key, "", time.Second)
  3874. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3875. redis.Set(keyOne, "", time.Second)
  3876. defer redis.Close()
  3877. if err != nil {
  3878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3879. return
  3880. }
  3881. }
  3882. go func() {
  3883. ssoDomain := beego.AppConfig.String("call_domain")
  3884. api := ssoDomain + "/index/uppatient"
  3885. values := make(url.Values)
  3886. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3887. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3888. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3889. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3890. http.PostForm(api, values)
  3891. }()
  3892. this.ServeSuccessJSON(map[string]interface{}{
  3893. "dialysis_order": newdialysisRecord,
  3894. "monitor": record,
  3895. })
  3896. return
  3897. }
  3898. func (c *DialysisAPIController) PostSolution() {
  3899. id, _ := c.GetInt64("patient", 0)
  3900. recordDateStr := c.GetString("record_date")
  3901. if id <= 0 {
  3902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3903. return
  3904. }
  3905. adminUserInfo := c.GetMobileAdminUserInfo()
  3906. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3907. if patient.ID == 0 {
  3908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3909. return
  3910. }
  3911. if len(recordDateStr) == 0 {
  3912. recordDateStr = time.Now().Format("2006-01-02")
  3913. }
  3914. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3915. if parseDateErr != nil {
  3916. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3918. return
  3919. }
  3920. mode_id, _ := c.GetInt64("mode_id", 0)
  3921. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3922. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3923. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3924. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3925. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3926. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3927. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3928. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3929. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3930. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3931. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3932. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3933. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3934. kalium, _ := c.GetFloat("kalium", 0)
  3935. sodium, _ := c.GetFloat("sodium", 0)
  3936. calcium, _ := c.GetFloat("calcium", 0)
  3937. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3938. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3939. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3940. glucose, _ := c.GetFloat("glucose", 0)
  3941. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3942. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3943. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3944. conductivity, _ := c.GetFloat("conductivity", 0)
  3945. remark := c.GetString("remark")
  3946. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3947. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3948. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3949. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3950. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3951. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3952. special_medicine_other := c.GetString("special_medicine_other")
  3953. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3954. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3955. blood_access, _ := c.GetInt64("blood_access", 0)
  3956. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3957. body_fluid_other := c.GetString("body_fluid_other")
  3958. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3959. niprocart, _ := c.GetInt64("niprocart", 0)
  3960. jms, _ := c.GetInt64("jms", 0)
  3961. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3962. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3963. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3964. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3965. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3966. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3967. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3968. injector, _ := c.GetInt64("injector", 0)
  3969. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3970. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3971. safe_package, _ := c.GetInt64("package", 0)
  3972. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3973. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3974. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3975. blood := c.GetString("blood")
  3976. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3977. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3978. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3979. displace_speed := c.GetString("displace_speed")
  3980. illness, _ := c.GetInt64("illness")
  3981. amylaceum := c.GetString("amylaceum")
  3982. single_time := c.GetString("single_time")
  3983. single_water := c.GetString("single_water")
  3984. replacement_flow := c.GetString("replacement_flow")
  3985. plasma_separator := c.GetString("plasma_separator")
  3986. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3987. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3988. oxygen_flow := c.GetString("oxygen_flow")
  3989. oxygen_time := c.GetString("oxygen_time")
  3990. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3991. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3992. puncture_needle := c.GetString("puncture_needle")
  3993. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3994. epo := c.GetString("epo")
  3995. epo_count, _ := c.GetFloat("epo_count", 0)
  3996. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3997. pre_impulse := c.GetString("pre_impulse")
  3998. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3999. admin_user_id, _ := c.GetInt64("admin_user_id")
  4000. is_water := c.GetString("is_water")
  4001. add_amount, _ := c.GetFloat("add_amount")
  4002. reduce_amount, _ := c.GetFloat("reduce_amount")
  4003. prescribing_number, _ := c.GetFloat("prescribing_number")
  4004. treatment_remark := c.GetString("treatment_remark")
  4005. prescription_sodium := c.GetString("prescription_sodium")
  4006. start_sodium := c.GetString("start_sodium")
  4007. sodium_curve := c.GetString("sodium_curve")
  4008. var is_war int64
  4009. if is_water == "是" {
  4010. is_war = 1
  4011. }
  4012. if is_water == "否" {
  4013. is_war = 2
  4014. }
  4015. if is_water == "请选择" {
  4016. is_war = 0
  4017. }
  4018. drhy_water := c.GetString("drhy_water")
  4019. dry_water_hour := c.GetString("dry_water_hour")
  4020. water_machine := c.GetString("water_machine")
  4021. dialysis_remark := c.GetString("dialysis_remark")
  4022. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  4023. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  4024. prescription_water, _ := c.GetFloat("prescription_water")
  4025. dialysis_strainer := c.GetString("dialysis_strainer")
  4026. chaptalization := c.GetString("chaptalization")
  4027. washing_time := c.GetString("washing_time")
  4028. warsh_count := c.GetString("warsh_count")
  4029. blood_access_part_id := c.GetString("blood_access_part_id")
  4030. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  4031. dialyzate := c.GetString("dialyzate")
  4032. first_super := c.GetString("first_super")
  4033. is_sequential := c.GetString("is_sequential")
  4034. var fisrt_sup int64
  4035. if first_super == "是" {
  4036. fisrt_sup = 1
  4037. }
  4038. if first_super == "否" {
  4039. fisrt_sup = 2
  4040. }
  4041. if first_super == "请选择" {
  4042. fisrt_sup = 0
  4043. }
  4044. var is_sequen int64
  4045. if is_sequential == "是" {
  4046. is_sequen = 1
  4047. }
  4048. if is_sequential == "否" {
  4049. is_sequen = 2
  4050. }
  4051. if is_sequential == "请选择" {
  4052. is_sequen = 0
  4053. }
  4054. conduct := c.GetString("conduct")
  4055. if mode_id > 0 {
  4056. var str string
  4057. //查找该机构用的是什么透析器
  4058. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  4059. if filedConfig.ID > 0 {
  4060. str = dialyzerPerfusionApparatus
  4061. } else {
  4062. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  4063. }
  4064. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  4065. }
  4066. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4067. //
  4068. //if template.TemplateId == 2 || template.TemplateId == 6 {
  4069. // if appRole.UserType == 3 {
  4070. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4071. // if getPermissionErr != nil {
  4072. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4073. // return
  4074. // } else if headNursePermission == nil {
  4075. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4076. // return
  4077. // }
  4078. // }
  4079. //}
  4080. // 查询信息规挡的设置天数
  4081. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4082. if infor.ID > 0 && infor.WeekDay > 0 {
  4083. var cha_time int64
  4084. timeNowStr := time.Now().Format("2006-01-02")
  4085. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4086. //今日的日期减去设置的日期
  4087. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4088. if cha_time >= recordDate.Unix() {
  4089. //查询审核是否允许
  4090. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  4091. //申请状态不允许的情况 拒绝修改
  4092. if infor.ApplicationStatus != 1 {
  4093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4094. return
  4095. }
  4096. }
  4097. }
  4098. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  4099. var dialysis_dialyszers_id int64
  4100. var dialysis_strainer_id int64
  4101. var dialysis_irrigation_id int64
  4102. if len(goodList) > 0 {
  4103. for _, item := range goodList {
  4104. if item.SpecificationName == dialysis_dialyszers {
  4105. dialysis_dialyszers_id = item.ID
  4106. }
  4107. if item.SpecificationName == dialysis_irrigation {
  4108. dialysis_irrigation_id = item.ID
  4109. }
  4110. if item.SpecificationName == dialysis_strainer {
  4111. dialysis_strainer_id = item.ID
  4112. }
  4113. }
  4114. }
  4115. prescription := models.DialysisPrescription{
  4116. UserOrgId: adminUserInfo.Org.Id,
  4117. PatientId: id,
  4118. RecordDate: recordDate.Unix(),
  4119. ModeId: mode_id,
  4120. DialysisDuration: dialysis_duration,
  4121. Dialyzer: dialyzer,
  4122. PerfusionApparatus: perfusion_apparatus,
  4123. BloodFlowVolume: blood_flow_volume,
  4124. DewaterAmount: dewater_amount,
  4125. DisplaceLiqui: displace_liqui,
  4126. ReplacementWay: replacement_way,
  4127. Anticoagulant: anticoagulant,
  4128. AnticoagulantShouji: anticoagulant_shouji,
  4129. AnticoagulantWeichi: anticoagulant_weichi,
  4130. AnticoagulantZongliang: anticoagulant_zongliang,
  4131. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4132. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4133. Kalium: kalium,
  4134. Sodium: sodium,
  4135. Calcium: calcium,
  4136. Bicarbonate: bicarbonate,
  4137. Glucose: glucose,
  4138. // DryWeight: dry_weight,
  4139. DialysateFlow: dialysate_flow,
  4140. DialysateTemperature: dialysate_temperature,
  4141. Conductivity: conductivity,
  4142. Remark: remark,
  4143. Status: 1,
  4144. CreatedTime: time.Now().Unix(),
  4145. UpdatedTime: time.Now().Unix(),
  4146. DialysisDurationMinute: dialysisDurationMinute,
  4147. DialysisDurationHour: dialysisDurationHour,
  4148. TargetUltrafiltration: targetUltrafiltration,
  4149. DialysateFormulation: dialysateFormulation,
  4150. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4151. BodyFluid: body_fluid,
  4152. SpecialMedicine: special_medicine,
  4153. SpecialMedicineOther: special_medicine_other,
  4154. DisplaceLiquiPart: displace_liqui_part,
  4155. DisplaceLiquiValue: displace_liqui_value,
  4156. BloodAccess: blood_access,
  4157. Ultrafiltration: ultrafiltration,
  4158. BodyFluidOther: body_fluid_other,
  4159. ReplacementTotal: replacement_total,
  4160. Niprocart: niprocart,
  4161. Jms: jms,
  4162. FistulaNeedleSet: fistula_needle_set,
  4163. FistulaNeedleSet16: fistula_needle_set_16,
  4164. Hemoperfusion: hemoperfusion,
  4165. DialyserSterilised: dialyser_sterilised,
  4166. Filtryzer: filtryzer,
  4167. TargetKtv: target_ktv,
  4168. Dialyzers: dialyzers,
  4169. Injector: injector,
  4170. Bloodlines: bloodlines,
  4171. TubingHemodialysis: tubing_hemodialysis,
  4172. Package: safe_package,
  4173. ALiquid: a_liquid,
  4174. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  4175. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  4176. Blood: blood,
  4177. DialysisDialyszers: dialysis_dialyszers,
  4178. DialysisIrrigation: dialysis_irrigation,
  4179. AntioxidantCommodityName: antioxidant_commodity_name,
  4180. DisplaceSpeed: displace_speed,
  4181. Illness: illness,
  4182. Amylaceum: amylaceum,
  4183. SingleWater: single_water,
  4184. SingleTime: single_time,
  4185. ReplacementFlow: replacement_flow,
  4186. PlasmaSeparator: plasma_separator,
  4187. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  4188. OxygenUptake: oxygen_uptake,
  4189. OxygenTime: oxygen_time,
  4190. OxygenFlow: oxygen_flow,
  4191. HemodialysisPipelines: hemodialysis_pipelines,
  4192. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4193. PunctureNeedle: puncture_needle,
  4194. PunctureNeedleCount: puncture_needle_count,
  4195. Epo: epo,
  4196. EpoCount: epo_count,
  4197. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4198. PreImpulse: impulse,
  4199. AdminUserId: admin_user_id,
  4200. IsWater: is_war,
  4201. DrhyWater: drhy_water,
  4202. DryWaterHour: dry_water_hour,
  4203. WaterMachine: water_machine,
  4204. AddAmount: add_amount,
  4205. ReduceAmount: reduce_amount,
  4206. DialysisRemark: dialysis_remark,
  4207. PrescribingNumber: prescribing_number,
  4208. PrescriptionSodium: prescription_sodium,
  4209. StartSodium: start_sodium,
  4210. SodiumCurve: sodium_curve,
  4211. TreatmentRemark: treatment_remark,
  4212. DialysisFluidFlow: dialysis_fluid_flow,
  4213. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4214. PrescriptionWater: prescription_water,
  4215. DialysisStrainer: dialysis_strainer,
  4216. Chaptalization: chaptalization,
  4217. WashingTime: washing_time,
  4218. WarshCount: warsh_count,
  4219. BloodAccessPartId: blood_access_part_id,
  4220. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4221. Dialyzate: dialyzate,
  4222. DialysisDialyszersId: dialysis_dialyszers_id,
  4223. DialysisIrrigationId: dialysis_irrigation_id,
  4224. DialysisStrainerId: dialysis_strainer_id,
  4225. FirstSuper: fisrt_sup,
  4226. IsSequential: is_sequen,
  4227. Conduct: conduct,
  4228. }
  4229. if adminUserInfo.Org.Id == 10721 {
  4230. if prescription.ModeId == 2 {
  4231. if prescription.ReplacementTotal == 0 {
  4232. prescription.ReplacementTotal = 15
  4233. }
  4234. }
  4235. }
  4236. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4237. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4238. //
  4239. if appRole.UserType == 2 || appRole.UserType == 1 {
  4240. prescription_doctor = adminUserInfo.AdminUser.Id
  4241. prescription.PrescriptionDoctor = prescription_doctor
  4242. }
  4243. if dialysisPrescription.ID == 0 { //新增
  4244. prescription.Creater = adminUserInfo.AdminUser.Id
  4245. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4246. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4247. }
  4248. } else { //修改
  4249. if dialysisPrescription.Creater == 0 {
  4250. prescription.Creater = adminUserInfo.AdminUser.Id
  4251. } else {
  4252. prescription.Creater = dialysisPrescription.Creater
  4253. if adminUserInfo.Org.Id == 9882 {
  4254. if appRole.UserType == 2 || appRole.UserType == 1 {
  4255. prescription.Creater = adminUserInfo.AdminUser.Id
  4256. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4257. }
  4258. }
  4259. }
  4260. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4261. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4262. }
  4263. //if/**/
  4264. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4265. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4266. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4267. // if getPermissionErr != nil {
  4268. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4269. // return
  4270. // } else if headNursePermission == nil {
  4271. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4272. // return
  4273. // }
  4274. //}
  4275. //prescription.Creater = dialysisPrescription.Creater
  4276. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4277. prescription.Modifier = adminUserInfo.AdminUser.Id
  4278. prescription.ID = dialysisPrescription.ID
  4279. }
  4280. solution := models.DialysisSolution{
  4281. RegistrarsId: adminUserInfo.AdminUser.Id,
  4282. UserOrgId: adminUserInfo.Org.Id,
  4283. Doctor: prescription_doctor,
  4284. PatientId: id,
  4285. ModeId: mode_id,
  4286. DialysisDuration: dialysis_duration,
  4287. PerfusionApparatus: perfusion_apparatus,
  4288. BloodFlowVolume: blood_flow_volume,
  4289. Dewater: dewater_amount,
  4290. DisplaceLiqui: displace_liqui,
  4291. ReplacementWay: replacement_way,
  4292. Anticoagulant: anticoagulant,
  4293. AnticoagulantShouji: anticoagulant_shouji,
  4294. AnticoagulantWeichi: anticoagulant_weichi,
  4295. AnticoagulantZongliang: anticoagulant_zongliang,
  4296. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4297. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4298. Kalium: kalium,
  4299. Sodium: sodium,
  4300. Calcium: calcium,
  4301. Bicarbonate: bicarbonate,
  4302. Glucose: glucose,
  4303. // DryWeight: dry_weight,
  4304. DialysateFlow: dialysate_flow,
  4305. DialysateTemperature: dialysate_temperature,
  4306. Conductivity: conductivity,
  4307. Remark: remark,
  4308. Status: 1,
  4309. CreatedTime: time.Now().Unix(),
  4310. UpdatedTime: time.Now().Unix(),
  4311. DialysisDurationMinute: dialysisDurationMinute,
  4312. DialysisDurationHour: dialysisDurationHour,
  4313. TargetUltrafiltration: targetUltrafiltration,
  4314. DialysateFormulation: dialysateFormulation,
  4315. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4316. BodyFluid: body_fluid,
  4317. SpecialMedicine: special_medicine,
  4318. SpecialMedicineOther: special_medicine_other,
  4319. DisplaceLiquiPart: displace_liqui_part,
  4320. DisplaceLiquiValue: displace_liqui_value,
  4321. BloodAccess: blood_access,
  4322. Ultrafiltration: ultrafiltration,
  4323. BodyFluidOther: body_fluid_other,
  4324. ReplacementTotal: replacement_total,
  4325. TargetKtv: target_ktv,
  4326. DialysisDialyszers: dialysis_dialyszers,
  4327. DialysisIrrigation: dialysis_irrigation,
  4328. HemodialysisPipelines: hemodialysis_pipelines,
  4329. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4330. PunctureNeedle: puncture_needle,
  4331. PunctureNeedleCount: puncture_needle_count,
  4332. Epo: epo,
  4333. EpoCount: epo_count,
  4334. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4335. PreImpulse: impulse,
  4336. SolutionStatus: 1,
  4337. DialysisRemark: dialysis_remark,
  4338. PrescribingNumber: prescribing_number,
  4339. PrescriptionSodium: prescription_sodium,
  4340. StartSodium: start_sodium,
  4341. SodiumCurve: sodium_curve,
  4342. TreatmentRemark: treatment_remark,
  4343. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4344. DialysisFluidFlow: dialysis_fluid_flow,
  4345. PrescriptionWater: prescription_water,
  4346. DialysisStrainer: dialysis_strainer,
  4347. Chaptalization: chaptalization,
  4348. WashingTime: washing_time,
  4349. WarshCount: warsh_count,
  4350. BloodAccessPartId: blood_access_part_id,
  4351. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4352. Dialyzate: dialyzate,
  4353. DialysisDialyszersId: dialysis_dialyszers_id,
  4354. DialysisIrrigationId: dialysis_irrigation_id,
  4355. DialysisStrainerId: dialysis_strainer_id,
  4356. FirstSuper: fisrt_sup,
  4357. IsSequential: is_sequen,
  4358. Conduct: conduct,
  4359. }
  4360. //针对河间咸的
  4361. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4362. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4363. solution.DisplaceLiquiPart = 0
  4364. solution.DisplaceLiquiValue = 0
  4365. }
  4366. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4367. prescription.DisplaceLiquiPart = 0
  4368. prescription.DisplaceLiquiValue = 0
  4369. }
  4370. }
  4371. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4372. if solution.PrescribingNumber == 0 {
  4373. solution.PrescribingNumber = 1
  4374. }
  4375. if prescription.PrescribingNumber == 0 {
  4376. prescription.PrescribingNumber = 1
  4377. }
  4378. if solution.PrescribingNumber == 0 && id == 14682 {
  4379. solution.PrescribingNumber = 2
  4380. }
  4381. if solution.PrescribingNumber == 0 && id == 18560 {
  4382. solution.PrescribingNumber = 2
  4383. }
  4384. if prescription.PrescribingNumber == 0 && id == 14682 {
  4385. prescription.PrescribingNumber = 2
  4386. }
  4387. if prescription.PrescribingNumber == 0 && id == 18560 {
  4388. prescription.PrescribingNumber = 2
  4389. }
  4390. }
  4391. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4392. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4393. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4394. if len(monitorList) > 0 {
  4395. var ultrafiltration_rate float64
  4396. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4397. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4398. var replacement_rate float64
  4399. //乘10 除10是为了保留一位小数
  4400. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4401. var firstOpeateTime = monitorList[0].OperateTime
  4402. for _, item := range monitorList {
  4403. //超滤率
  4404. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4405. //置换率
  4406. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4407. //超滤量
  4408. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4409. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4410. //置换量
  4411. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4412. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4413. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4414. }
  4415. }
  4416. }
  4417. //记录日志
  4418. byterequest, _ := json.Marshal(prescription)
  4419. prescriptionLog := models.XtDialysisPrescriptionLog{
  4420. UserOrgId: prescription.UserOrgId,
  4421. Ctime: time.Now().Unix(),
  4422. Mtime: 0,
  4423. ErrLog: string(byterequest),
  4424. AdminUserId: adminUserInfo.AdminUser.Id,
  4425. RecordDate: prescription.RecordDate,
  4426. PatientId: prescription.PatientId,
  4427. Source: "手机端新增长期处方",
  4428. Status: 1,
  4429. }
  4430. service.CreatePrescriptionLog(prescriptionLog)
  4431. finish := models.XtDialysisFinish{
  4432. IsFinish: 1,
  4433. UserOrgId: adminUserInfo.Org.Id,
  4434. Status: 1,
  4435. Ctime: time.Now().Unix(),
  4436. Mtime: 0,
  4437. Module: 1,
  4438. RecordDate: recordDate.Unix(),
  4439. Sourse: 1,
  4440. PatientId: id,
  4441. }
  4442. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4443. if dialysisFinish.ID == 0 {
  4444. service.CreateDialysisFinish(finish)
  4445. }
  4446. //获取最新1条
  4447. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4448. //更新状态
  4449. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4450. //长沙南雅医院,自动生成抗凝剂的临时处方
  4451. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4452. if prescribing_number == 0 {
  4453. prescribing_number = 1
  4454. }
  4455. advice := models.DoctorAdvice{
  4456. UserOrgId: adminUserInfo.Org.Id,
  4457. PatientId: id,
  4458. GroupNo: 0,
  4459. AdviceType: 2,
  4460. RecordDate: recordDate.Unix(),
  4461. AdviceDate: recordDate.Unix(),
  4462. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4463. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4464. AdviceDesc: "",
  4465. ReminderDate: 0,
  4466. SingleDose: prescription.AnticoagulantZongliang,
  4467. SingleDoseUnit: "iu",
  4468. DrugSpec: 0,
  4469. DrugSpecUnit: "",
  4470. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4471. PrescribingNumberUnit: "支",
  4472. DeliveryWay: "静脉注射",
  4473. ExecutionFrequency: "上机前",
  4474. AdviceDoctor: 0,
  4475. Status: 1,
  4476. CreatedTime: time.Now().Unix(),
  4477. UpdatedTime: time.Now().Unix(),
  4478. IsPrescription: 1,
  4479. ExecutionState: 2,
  4480. StopState: 2,
  4481. IsSettle: 2,
  4482. }
  4483. // 查询排班信息
  4484. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4485. if schedulePatient.ID > 0 {
  4486. if schedulePatient.ScheduleType == 1 {
  4487. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4488. }
  4489. if schedulePatient.ScheduleType == 2 {
  4490. advice.StartTime = recordDate.Unix() + 9*60*60
  4491. }
  4492. }
  4493. // 抗凝剂名称
  4494. switch anticoagulant {
  4495. case 1:
  4496. advice.AdviceName = "无肝素"
  4497. break
  4498. case 2:
  4499. advice.AdviceName = "普通肝素"
  4500. break
  4501. case 3:
  4502. advice.AdviceName = "低分子肝素"
  4503. break
  4504. case 4:
  4505. advice.AdviceName = "阿加曲班"
  4506. break
  4507. case 5:
  4508. advice.AdviceName = "枸橼酸钠"
  4509. break
  4510. case 6:
  4511. advice.AdviceName = "低分子肝素钙"
  4512. break
  4513. case 7:
  4514. advice.AdviceName = "低分子肝素钠"
  4515. break
  4516. case 8:
  4517. advice.AdviceName = "依诺肝素"
  4518. break
  4519. case 9:
  4520. advice.AdviceName = "达肝素"
  4521. break
  4522. case 10:
  4523. advice.AdviceName = "体外抗凝"
  4524. break
  4525. case 11:
  4526. advice.AdviceName = "那曲肝素"
  4527. break
  4528. case 12:
  4529. advice.AdviceName = "无抗凝剂"
  4530. break
  4531. }
  4532. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4533. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4534. advice.AdviceDoctor = appRole.AdminUserId
  4535. }
  4536. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4537. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4538. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4539. advice.AdviceName = "低分子肝素钠注射液"
  4540. // 修改患者临时医嘱里的抗凝剂医嘱
  4541. advice.ID = advicePrescription.ID
  4542. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4543. } else {
  4544. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4545. advice.AdviceName = "低分子肝素钠注射液"
  4546. service.CreateDoctorAdvice(&advice)
  4547. }
  4548. }
  4549. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4550. redis := service.RedisClient()
  4551. defer redis.Close()
  4552. //清空key 值
  4553. redis.Set(key, "", time.Second)
  4554. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4555. redis.Set(keyOne, "", time.Second)
  4556. }
  4557. //获取key,清空redis
  4558. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4559. redis := service.RedisClient()
  4560. defer redis.Close()
  4561. //清空key 值
  4562. redis.Set(key, "", time.Second)
  4563. //清空长期医嘱的key
  4564. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4565. redis.Set(soulution_key, "", time.Second)
  4566. //查询最近透析准备表里是否存在 透析器 灌流器
  4567. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4568. redis.Set(keyOne, "", time.Second)
  4569. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4570. redis.Set(keyTwo, "", time.Second)
  4571. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4572. redis.Set(keyThree, "", time.Second)
  4573. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4574. redis.Set(keyFour, "", time.Second)
  4575. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4576. //
  4577. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4578. //
  4579. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4580. //if len(mation)>0{
  4581. // for _, item := range splitStr {
  4582. // for _,it := range mation{
  4583. // if(item == it.SpecificationName){
  4584. //
  4585. // //查询最近一次的透析器
  4586. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4587. //
  4588. // if errcode == gorm.ErrRecordNotFound{
  4589. // //插入数据
  4590. // prepare := models.DialysisBeforePrepare{
  4591. // UserOrgId: adminUserInfo.Org.Id,
  4592. // PatientId: id,
  4593. // RecordDate: recordDate.Unix(),
  4594. // GoodTypeId: it.GoodTypeId,
  4595. // GoodId: it.ID,
  4596. // Count: 1,
  4597. // Ctime: time.Now().Unix(),
  4598. // Creater: adminUserInfo.AdminUser.Id,
  4599. // Status:1,
  4600. //
  4601. // }
  4602. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4603. // fmt.Println("",errcode)
  4604. // }
  4605. // }
  4606. // }
  4607. //
  4608. // }
  4609. //
  4610. // for _, item := range splitIrrigation {
  4611. // for _,it := range mation{
  4612. // if(item == it.SpecificationName){
  4613. // //查询最近一次的透析器
  4614. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4615. // if errcode == gorm.ErrRecordNotFound{
  4616. // //插入数据
  4617. // prepare := models.DialysisBeforePrepare{
  4618. // UserOrgId: adminUserInfo.Org.Id,
  4619. // PatientId: id,
  4620. // RecordDate: recordDate.Unix(),
  4621. // GoodTypeId: it.GoodTypeId,
  4622. // GoodId: it.ID,
  4623. // Count: 1,
  4624. // Ctime: time.Now().Unix(),
  4625. // Creater: adminUserInfo.AdminUser.Id,
  4626. // Status:1,
  4627. //
  4628. // }
  4629. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4630. // fmt.Println(errcode)
  4631. // }
  4632. // }
  4633. // }
  4634. // }
  4635. //}
  4636. c.ServeSuccessJSON(map[string]interface{}{
  4637. "solution": &solution,
  4638. "prescription": &prescription,
  4639. })
  4640. }
  4641. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4642. patient, _ := c.GetInt64("patient", 0)
  4643. adminUserInfo := c.GetMobileAdminUserInfo()
  4644. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4645. c.ServeSuccessJSON(map[string]interface{}{
  4646. "receiveTreatmentAsses": receiveTreatmentAsses,
  4647. })
  4648. }
  4649. func (this *DialysisAPIController) PostSignInfo() {
  4650. patientID, _ := this.GetInt64("patient_id")
  4651. recordDateStr := this.GetString("date")
  4652. if patientID <= 0 {
  4653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4654. return
  4655. }
  4656. if len(recordDateStr) == 0 {
  4657. recordDateStr = time.Now().Format("2006-01-02")
  4658. }
  4659. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4660. if parseDateErr != nil {
  4661. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4663. return
  4664. }
  4665. adminInfo := this.GetMobileAdminUserInfo()
  4666. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4667. if err != nil {
  4668. this.ErrorLog("签名失败:%v", err)
  4669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4670. return
  4671. }
  4672. this.ServeSuccessJSON(map[string]interface{}{
  4673. "doctor_id": adminInfo.AdminUser.Id,
  4674. })
  4675. }
  4676. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4677. patientID, _ := this.GetInt64("patient_id")
  4678. adminInfo := this.GetMobileAdminUserInfo()
  4679. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4680. this.ServeSuccessJSON(map[string]interface{}{
  4681. "monitor": record,
  4682. })
  4683. }
  4684. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4685. thisTime := time.Now()
  4686. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4687. timeLayout := "2006-01-02 15:04:05"
  4688. loc, _ := time.LoadLocation("Local")
  4689. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4690. theAssessmentDateTime := theStartTime.Unix()
  4691. patientID, _ := this.GetInt64("patient_id")
  4692. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4693. adminInfo := this.GetMobileAdminUserInfo()
  4694. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4695. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4696. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4697. var ultrafiltration_rate float64
  4698. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4699. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4700. fmt.Println(evaluation)
  4701. fmt.Println("prescription.ID", prescription.ID)
  4702. if prescription.ID > 0 {
  4703. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4704. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4705. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4706. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4707. record.UltrafiltrationRate = ultrafiltration_rate
  4708. }
  4709. //重庆塘坝卫生院
  4710. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4711. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4712. fmt.Println("ultrafiltration_rate--------------------", ultrafiltration_rate)
  4713. record.UltrafiltrationRate = ultrafiltration_rate
  4714. }
  4715. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4716. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4717. record.UltrafiltrationRate = ultrafiltration_rate
  4718. }
  4719. if adminInfo.Org.Id == 10510 {
  4720. record.UltrafiltrationRate = 0
  4721. }
  4722. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4723. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4724. record.UltrafiltrationRate = ultrafiltration_rate
  4725. }
  4726. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4727. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4728. record.UltrafiltrationRate = ultrafiltration_rate
  4729. }
  4730. // 只针对方济医院
  4731. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4732. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4733. ultrafiltration_rate = value
  4734. record.UltrafiltrationRate = ultrafiltration_rate
  4735. }
  4736. if template.TemplateId == 41 || template.TemplateId == 47 {
  4737. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4738. record.UltrafiltrationRate = ultrafiltration_rate
  4739. }
  4740. if template.TemplateId == 43 {
  4741. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4742. record.UltrafiltrationRate = ultrafiltration_rate
  4743. }
  4744. if template.TemplateId == 46 || template.TemplateId == 54 {
  4745. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4746. record.UltrafiltrationRate = ultrafiltration_rate
  4747. }
  4748. 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 {
  4749. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4750. record.UltrafiltrationRate = ultrafiltration_rate
  4751. }
  4752. if adminInfo.Org.Id == 10469 {
  4753. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4754. record.UltrafiltrationRate = ultrafiltration_rate
  4755. }
  4756. if adminInfo.Org.Id == 10667 {
  4757. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4758. record.UltrafiltrationRate = ultrafiltration_rate
  4759. }
  4760. if adminInfo.Org.Id == 10471 {
  4761. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4762. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4763. }
  4764. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4765. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4766. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4767. }
  4768. if adminInfo.Org.Id == 10751 {
  4769. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4770. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4771. }
  4772. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4773. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4774. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4775. }
  4776. if adminInfo.Org.Id == 10721 {
  4777. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4778. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4779. }
  4780. if adminInfo.Org.Id == 10757 {
  4781. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4782. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4783. }
  4784. if adminInfo.Org.Id == 10752 {
  4785. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4786. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4787. }
  4788. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4789. record.UltrafiltrationRate = 0
  4790. }
  4791. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4792. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4793. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4794. }
  4795. if adminInfo.Org.Id == 10206 {
  4796. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4797. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4798. }
  4799. //湘潭爱心美白石
  4800. if adminInfo.Org.Id == 9850 {
  4801. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4802. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4803. }
  4804. if adminInfo.Org.Id == 9919 {
  4805. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4806. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4807. }
  4808. //if template.TemplateId == 47 {
  4809. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4810. // record.UltrafiltrationRate = ultrafiltration_rate
  4811. //}
  4812. }
  4813. }
  4814. // record.UltrafiltrationRate = ultrafiltration_rate
  4815. record.UltrafiltrationVolume = 0
  4816. 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
  4817. if ultrafiltration_rate > 0 {
  4818. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4819. record.UltrafiltrationVolume = value
  4820. }
  4821. }
  4822. 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
  4823. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4824. if adminInfo.Org.Id != 10735 {
  4825. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4826. record.UltrafiltrationVolume = ultrafiltration_volume
  4827. }
  4828. //胶州少海医院
  4829. if adminInfo.Org.Id == 10735 {
  4830. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4831. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4832. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4833. if lastMonitorRecordList.ID > 0 {
  4834. record.UltrafiltrationRate = ultrafiltration_rate_one
  4835. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4836. record.UltrafiltrationVolume = ultrafiltration_volume
  4837. } else {
  4838. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4839. record.UltrafiltrationVolume = ultrafiltration_volume
  4840. }
  4841. }
  4842. }
  4843. }
  4844. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4845. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4846. record.UltrafiltrationVolume = ultrafiltration_volume
  4847. }
  4848. //长沙南雅
  4849. 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 {
  4850. if ultrafiltration_rate > 0 {
  4851. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4852. record.UltrafiltrationVolume = ultrafiltration_volume
  4853. }
  4854. }
  4855. if adminInfo.Org.Id == 10471 {
  4856. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4857. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4858. }
  4859. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4860. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4861. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4862. }
  4863. if adminInfo.Org.Id == 10751 {
  4864. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4865. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4866. }
  4867. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4868. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4869. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4870. }
  4871. //长沙南雅累计血容量自动计算
  4872. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4873. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4874. //}
  4875. if template.TemplateId == 47 || template.TemplateId == 54 {
  4876. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4877. }
  4878. if adminInfo.Org.Id == 10510 {
  4879. record.UltrafiltrationVolume = 0
  4880. }
  4881. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 || adminInfo.Org.Id == 10757 {
  4882. if ultrafiltration_rate > 0 {
  4883. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4884. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4885. }
  4886. }
  4887. //古镇乐生
  4888. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4889. if ultrafiltration_rate > 0 {
  4890. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4891. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4892. }
  4893. }
  4894. if adminInfo.Org.Id == 9919 {
  4895. if ultrafiltration_rate > 0 {
  4896. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4897. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  4898. }
  4899. }
  4900. if adminInfo.Org.Id == 10206 {
  4901. if ultrafiltration_rate > 0 {
  4902. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4903. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4904. }
  4905. }
  4906. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 || adminInfo.Org.Id == 9478 || adminInfo.Org.Id == 10290 {
  4907. var replacement_rate float64
  4908. var displacement_quantity float64
  4909. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4910. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4911. record.ReplacementRate = replacement_rate
  4912. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4913. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4914. record.DisplacementQuantity = displacement_quantity
  4915. }
  4916. if adminInfo.Org.Id == 10752 {
  4917. var replacement_rate float64
  4918. var displacement_quantity float64
  4919. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4920. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4921. record.ReplacementRate = replacement_rate
  4922. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4923. record.DisplacementQuantity = displacement_quantity
  4924. }
  4925. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 || adminInfo.Org.Id == 9478 {
  4926. var replacement_rate float64
  4927. var displacement_quantity float64
  4928. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4929. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4930. record.ReplacementRate = replacement_rate
  4931. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4932. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4933. record.DisplacementQuantity = displacement_quantity
  4934. }
  4935. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4936. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4937. record.UltrafiltrationVolume = ultrafiltration_volume
  4938. }
  4939. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10744 {
  4940. var replacement_rate float64
  4941. var displacement_quantity float64
  4942. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4943. if totalMin == 0 {
  4944. totalMin = 240
  4945. }
  4946. if prescription.DisplaceLiquiValue == 0 {
  4947. prescription.ReplacementTotal = 32
  4948. }
  4949. //乘10 除10是为了保留一位小数
  4950. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4951. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4952. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4953. record.DisplacementQuantity = displacement_quantity
  4954. }
  4955. if adminInfo.Org.Id == 9850 {
  4956. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4957. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4958. }
  4959. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4960. this.ServeSuccessJSON(map[string]interface{}{
  4961. "monitor": record,
  4962. "lastMonitorRecordList": lastMonitorRecordList,
  4963. })
  4964. }
  4965. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4966. record_id, _ := this.GetInt64("id")
  4967. nurseID, _ := this.GetInt64("start_nurse")
  4968. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4969. bedID, _ := this.GetInt64("bed")
  4970. start_time := this.GetString("start_time")
  4971. schedual_type, _ := this.GetInt64("schedual_type")
  4972. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4973. change_nurse, _ := this.GetInt64("change_nurse")
  4974. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4975. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4976. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4977. patient_id, _ := this.GetInt64("patient_id")
  4978. record_date, _ := this.GetInt64("record_date")
  4979. puncture_needle := this.GetString("puncture_needle")
  4980. puncture_way := this.GetString("puncture_way")
  4981. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4982. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4983. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4984. nuclein_date_str := this.GetString("nuclein_date_str")
  4985. order_remark := this.GetString("order_remark")
  4986. schedule_remark := this.GetString("schedule_remark")
  4987. catheter_operation := this.GetString("catheter_operation")
  4988. blood_flow_volume := this.GetString("blood_flow_volume")
  4989. blood_drawing, _ := this.GetInt64("blood_drawing")
  4990. dialysis_strainer := this.GetString("dialysis_strainer")
  4991. if record_id == 0 {
  4992. this.ErrorLog("id:%v", record_id)
  4993. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4994. return
  4995. }
  4996. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4997. if parseStartDateErr != nil {
  4998. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5000. return
  5001. }
  5002. adminUserInfo := this.GetMobileAdminUserInfo()
  5003. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5004. if getNurseErr != nil {
  5005. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5007. return
  5008. } else if nurse == nil {
  5009. this.ErrorLog("护士不存在")
  5010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5011. return
  5012. }
  5013. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5014. //if getNurseErr != nil {
  5015. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  5016. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5017. // return
  5018. //} else if nurse == nil {
  5019. // this.ErrorLog("护士不存在")
  5020. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5021. // return
  5022. //}
  5023. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5024. if getDeviceNumberErr != nil {
  5025. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5027. return
  5028. } else if deviceNumber == nil {
  5029. this.ErrorLog("床位号不存在")
  5030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5031. return
  5032. }
  5033. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5034. //
  5035. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5036. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5037. // if getPermissionErr != nil {
  5038. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5039. // return
  5040. // } else if headNursePermission == nil {
  5041. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5042. // return
  5043. // }
  5044. //}
  5045. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5046. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5047. timeLayout := "2006-01-02 15:04:05"
  5048. loc, _ := time.LoadLocation("Local")
  5049. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5050. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5051. schedulestartTime := theStartTime.Unix()
  5052. scheduleendTime := theEndTime.Unix()
  5053. var theNucleinDate int64
  5054. timeLayoutOne := "2006-01-02"
  5055. if len(nuclein_date_str) > 0 {
  5056. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  5057. if err != nil {
  5058. utils.ErrorLog(err.Error())
  5059. }
  5060. theNucleinDate = theTime.Unix()
  5061. }
  5062. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5063. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5064. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5065. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5066. if err == gorm.ErrRecordNotFound { //空床位
  5067. // 修改了床位逻辑
  5068. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5069. if daySchedule.ID > 0 {
  5070. //daySchedule.BedId = bedID
  5071. //daySchedule.PartitionId = deviceNumber.ZoneID
  5072. //daySchedule.ScheduleType = schedual_type
  5073. //daySchedule.UpdatedTime = time.Now().Unix()
  5074. //err := service.UpdateSchedule(&daySchedule)
  5075. xtSchedule := models.Schedule{
  5076. PartitionId: deviceNumber.ZoneID,
  5077. BedId: bedID,
  5078. ScheduleType: schedual_type,
  5079. UpdatedTime: time.Now().Unix(),
  5080. }
  5081. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5082. if err != nil {
  5083. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5084. return
  5085. }
  5086. }
  5087. } else if err == nil {
  5088. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5089. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5090. if daySchedule.ID > 0 {
  5091. //daySchedule.BedId = bedID
  5092. //daySchedule.PartitionId = deviceNumber.ZoneID
  5093. //
  5094. //daySchedule.ScheduleType = schedual_type
  5095. //daySchedule.UpdatedTime = time.Now().Unix()
  5096. //err := service.UpdateSchedule(&daySchedule)
  5097. xtSchedule := models.Schedule{
  5098. PartitionId: deviceNumber.ZoneID,
  5099. BedId: bedID,
  5100. ScheduleType: schedual_type,
  5101. UpdatedTime: time.Now().Unix(),
  5102. }
  5103. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  5104. if err != nil {
  5105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5106. return
  5107. }
  5108. }
  5109. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5111. return
  5112. }
  5113. } else if err != nil {
  5114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5115. return
  5116. }
  5117. }
  5118. dialysisRecord := &models.DialysisOrder{
  5119. ID: record_id,
  5120. UserOrgId: adminUserInfo.Org.Id,
  5121. BedID: bedID,
  5122. StartNurse: nurseID,
  5123. StartTime: startDate.Unix(),
  5124. PunctureNurse: puncture_nurse,
  5125. Creator: adminUserInfo.AdminUser.Id,
  5126. Modifier: adminUserInfo.AdminUser.Id,
  5127. WashpipeNurse: washpipe_nurse,
  5128. SchedualType: schedual_type,
  5129. ChangeNurse: change_nurse,
  5130. DifficultPunctureNurse: difficult_puncture_nurse,
  5131. NewFistulaNurse: new_fistula_nurse,
  5132. QualityNurseId: quality_nurse_id,
  5133. PunctureNeedle: puncture_needle,
  5134. PunctureWay: puncture_way,
  5135. DialysisDialyszers: dialysis_dialyszers,
  5136. DialysisIrrigation: dialysis_irrigation,
  5137. BloodAccessId: blood_access_id,
  5138. NucleinDate: theNucleinDate,
  5139. OrderRemark: order_remark,
  5140. ScheduleRemark: schedule_remark,
  5141. CatheterOperation: catheter_operation,
  5142. BloodFlowVolume: blood_flow_volume,
  5143. BloodDrawing: blood_drawing,
  5144. DialysisStrainer: dialysis_strainer,
  5145. }
  5146. //修改床位号需要重新消毒
  5147. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  5148. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5149. //查询第一条监测
  5150. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  5151. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  5152. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  5153. redis := service.RedisClient()
  5154. //清空key 值
  5155. redis.Set(key, "", time.Second)
  5156. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  5157. redis.Set(keyOne, "", time.Second)
  5158. defer redis.Close()
  5159. }
  5160. // 查询信息规挡的设置天数
  5161. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5162. if infor.ID > 0 && infor.WeekDay > 0 {
  5163. var cha_time int64
  5164. timeNowStr := time.Now().Format("2006-01-02")
  5165. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5166. //今日的日期减去设置的日期
  5167. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5168. if cha_time >= record_date {
  5169. //查询审核是否允许
  5170. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  5171. //申请状态不允许的情况 拒绝修改
  5172. if infor.ApplicationStatus != 1 {
  5173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5174. return
  5175. }
  5176. }
  5177. }
  5178. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5179. //修改床位后重新生成消毒计划
  5180. if adminUserInfo.Org.Id == 10340 {
  5181. //根据床位号获取设备型号
  5182. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5183. //查询使用消毒最后一条消毒记录
  5184. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  5185. fmt.Println("err", err)
  5186. if err == gorm.ErrRecordNotFound {
  5187. //查找排班
  5188. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  5189. //查询改设备是否有消毒计划
  5190. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  5191. //根据床位号获取设备id
  5192. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  5193. //查询病人信息
  5194. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  5195. var con = ""
  5196. if patients.IsInfectious == 0 {
  5197. con = ""
  5198. }
  5199. if patients.IsInfectious == 1 {
  5200. con = "无"
  5201. }
  5202. if patients.IsInfectious == 2 {
  5203. con = "有"
  5204. }
  5205. if errcode == nil {
  5206. var end_time int64
  5207. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  5208. //新增消毒
  5209. information := models.DeviceInformation{
  5210. Date: dialysisRecord.DialysisDate,
  5211. Zone: dialysisRecord.ZoneId,
  5212. Class: dialysisRecord.SchedualType,
  5213. BedNumber: dialysisRecord.BedID,
  5214. PatientId: dialysisRecord.PatientId,
  5215. DialysisMode: scheduleByPatient.ModeId,
  5216. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  5217. Disinfection: 1,
  5218. DialysisConcentration: 1,
  5219. DisinfectionStatus: 1,
  5220. Move: 1,
  5221. UserOrgId: dialysisRecord.UserOrgId,
  5222. DisinfectType: plan.Way,
  5223. DisinfectantType: plan.MachineDisinfectant,
  5224. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5225. Disinfectant: plan.Disinfectant,
  5226. Ctime: time.Now().Unix(),
  5227. Status: 1,
  5228. SignName: nurseID,
  5229. EquimentId: addmacher.ID,
  5230. DisinfectionResidue: 2,
  5231. Bed: addmacher.BedNumber,
  5232. StartTime: dialysisRecord.StartTime,
  5233. EndTime: dialysisRecord.EndTime,
  5234. Contagion: con,
  5235. WeightLoss: 0,
  5236. Hyperfiltratio: 0,
  5237. DialysisHour: "",
  5238. MachineRun: 1,
  5239. DisinfecStartime: dialysisRecord.EndTime,
  5240. DisinfecEndtime: end_time,
  5241. }
  5242. err := service.CreateInformationTwo(&information)
  5243. fmt.Println("报错", err)
  5244. }
  5245. }
  5246. }
  5247. order, _ := service.GetLastPatientOrder(record_id)
  5248. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5249. redis := service.RedisClient()
  5250. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5251. redis.Set(key, "", time.Second)
  5252. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5253. //清空key 值
  5254. redis.Set(keyOne, "", time.Second)
  5255. scheduleDateStartOne := startDate.Format("2006-01-02")
  5256. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5257. redis.Set(keyTwo, "", time.Second)
  5258. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5259. redis.Set(keyThree, "", time.Second)
  5260. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5261. redis.Set(keyFour, "", time.Second)
  5262. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5263. redis.Set(keyFive, "", time.Second)
  5264. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5265. redis.Set(keySix, "", time.Second)
  5266. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5267. redis.Set(keySeven, "", time.Second)
  5268. if updateErr != nil {
  5269. this.ErrorLog("修改上机失败:%v", updateErr)
  5270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5271. return
  5272. }
  5273. if updateErr == nil {
  5274. if tempDialysisRecord.Stage == 2 {
  5275. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5276. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5277. fmt.Println(value)
  5278. a, b := math.Modf(value)
  5279. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5280. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5281. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5282. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5283. redis := service.RedisClient()
  5284. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5285. redis.Set(key, "", time.Second)
  5286. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5287. redis.Set(keyOne, "", time.Second)
  5288. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5289. //清空key 值
  5290. redis.Set(keySix, "", time.Second)
  5291. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5292. redis.Set(keySeven, "", time.Second)
  5293. redis.Close()
  5294. if updateAssessmentErr != nil {
  5295. utils.ErrorLog("%v", updateAssessmentErr)
  5296. }
  5297. }
  5298. }
  5299. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5300. this.ServeSuccessJSON(map[string]interface{}{
  5301. "dialysis_order": dialysisRecords,
  5302. })
  5303. }
  5304. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5305. record_id, _ := c.GetInt64("id")
  5306. nurseID, _ := c.GetInt64("nurse")
  5307. end_time := c.GetString("end_time")
  5308. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5309. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5310. catheter := c.GetString("catheter")
  5311. cruor := c.GetString("cruor")
  5312. mission := c.GetString("mission")
  5313. condenser := c.GetString("condenser")
  5314. if record_id <= 0 || nurseID <= 0 {
  5315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5316. return
  5317. }
  5318. adminUserInfo := c.GetMobileAdminUserInfo()
  5319. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5320. if getNurseErr != nil {
  5321. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5323. return
  5324. } else if nurse == nil {
  5325. c.ErrorLog("护士不存在")
  5326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5327. return
  5328. }
  5329. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5330. if parseEndDateErr != nil {
  5331. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5333. return
  5334. }
  5335. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5336. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5337. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5338. // if getPermissionErr != nil {
  5339. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5340. // return
  5341. // } else if headNursePermission == nil {
  5342. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5343. // return
  5344. // }
  5345. //}
  5346. // 查询信息规挡的设置天数
  5347. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5348. if infor.ID > 0 {
  5349. var cha_time int64
  5350. timeNowStr := time.Now().Format("2006-01-02")
  5351. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5352. //今日的日期减去设置的日期
  5353. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5354. if cha_time >= tempDialysisRecords.DialysisDate {
  5355. //查询审核是否允许
  5356. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5357. //申请状态不允许的情况 拒绝修改
  5358. if infor.ApplicationStatus != 1 {
  5359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5360. return
  5361. }
  5362. }
  5363. }
  5364. dialysisRecord := &models.DialysisOrder{
  5365. ID: record_id,
  5366. UserOrgId: adminUserInfo.Org.Id,
  5367. EndTime: endDate.Unix(),
  5368. FinishNurse: nurseID,
  5369. FinishModifier: adminUserInfo.AdminUser.Id,
  5370. PuncturePointHaematoma: puncture_point_haematoma,
  5371. BloodAccessInternalFistula: blood_access_internal_fistula,
  5372. Catheter: catheter,
  5373. Cruor: cruor,
  5374. Mission: mission,
  5375. Condenser: condenser,
  5376. }
  5377. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5378. redis := service.RedisClient()
  5379. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5380. //清空key 值
  5381. redis.Set(key, "", time.Second)
  5382. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5383. //清空key 值
  5384. redis.Set(keyOne, "", time.Second)
  5385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5386. redis.Set(keySeven, "", time.Second)
  5387. redis.Close()
  5388. if updateErr != nil {
  5389. c.ErrorLog("修改下机失败:%v", updateErr)
  5390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5391. return
  5392. }
  5393. if updateErr == nil {
  5394. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5395. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5396. a, b := math.Modf(value)
  5397. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5398. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5399. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5400. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5401. redis := service.RedisClient()
  5402. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5403. redis.Set(keyTen, "", time.Second)
  5404. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5405. redis.Set(keyTwo, "", time.Second)
  5406. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5407. redis.Set(key, "", time.Second)
  5408. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5409. redis.Set(keyThree, "", time.Second)
  5410. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5411. redis.Set(keySeven, "", time.Second)
  5412. defer redis.Close()
  5413. if updateAssessmentErr != nil {
  5414. utils.ErrorLog("%v", updateAssessmentErr)
  5415. }
  5416. }
  5417. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5418. c.ServeSuccessJSON(map[string]interface{}{
  5419. "dialysis_order": dialysisRecords,
  5420. })
  5421. }
  5422. func (c *DialysisAPIController) GetLongAdvice() {
  5423. patient_id, _ := c.GetInt64("id")
  5424. adminUserInfo := c.GetMobileAdminUserInfo()
  5425. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5426. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5427. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5428. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5429. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5430. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5431. c.ServeSuccessJSON(map[string]interface{}{
  5432. "status": "1",
  5433. })
  5434. return
  5435. } else { //开启推送提醒
  5436. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5437. var advice_three []*models.DoctorAdvice
  5438. recordDateStr := time.Now().Format("2006-01-02")
  5439. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5440. nowtime := recordDate.Unix()
  5441. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5442. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5443. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5444. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5445. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5446. for _, advice := range advices {
  5447. if advice.FrequencyType == 3 {
  5448. t := time.Now()
  5449. week := int(t.Weekday())
  5450. fmt.Println(t.Weekday())
  5451. fmt.Println(week)
  5452. switch week {
  5453. case 1:
  5454. if strings.Index(advice.WeekDay, "周一") == -1 {
  5455. advice_three = append(advice_three, advice)
  5456. }
  5457. break
  5458. case 2:
  5459. if strings.Index(advice.WeekDay, "周二") == -1 {
  5460. advice_three = append(advice_three, advice)
  5461. }
  5462. break
  5463. case 3:
  5464. if strings.Index(advice.WeekDay, "周三") == -1 {
  5465. advice_three = append(advice_three, advice)
  5466. }
  5467. break
  5468. case 4:
  5469. if strings.Index(advice.WeekDay, "周四") == -1 {
  5470. advice_three = append(advice_three, advice)
  5471. }
  5472. break
  5473. case 5:
  5474. if strings.Index(advice.WeekDay, "周五") == -1 {
  5475. advice_three = append(advice_three, advice)
  5476. }
  5477. break
  5478. case 6:
  5479. if strings.Index(advice.WeekDay, "周六") == -1 {
  5480. advice_three = append(advice_three, advice)
  5481. }
  5482. break
  5483. case 0:
  5484. if strings.Index(advice.WeekDay, "周日") == -1 {
  5485. advice_three = append(advice_three, advice)
  5486. }
  5487. break
  5488. }
  5489. }
  5490. }
  5491. for _, advice := range advices_two {
  5492. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5493. now := p.Unix()
  5494. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5495. dayStr2 := "-" + dayStr
  5496. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5497. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5498. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5499. for _, ad := range advices {
  5500. advice_three = append(advice_three, ad)
  5501. }
  5502. }
  5503. if err == nil {
  5504. c.ServeSuccessJSON(map[string]interface{}{
  5505. "status": "2",
  5506. "advices": advices,
  5507. "advices_two": RemoveRepeatedElement(advice_three),
  5508. "is_open_remind": config.IsOpenRemind,
  5509. "his_config_open": hisConfig.IsOpen,
  5510. "is_advice_open": is_advice_open.IsAdviceOpen,
  5511. "prescription_open": prescription_open.IsOpen,
  5512. })
  5513. }
  5514. }
  5515. }
  5516. func (c *DialysisAPIController) GetLongAdviceOne() {
  5517. patient_id, _ := c.GetInt64("id")
  5518. startTime := c.GetString("schedule_date")
  5519. timeLayout := "2006-01-02"
  5520. loc, _ := time.LoadLocation("Local")
  5521. var theStartTime int64
  5522. if len(startTime) > 0 {
  5523. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5524. if err != nil {
  5525. utils.ErrorLog(err.Error())
  5526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5527. return
  5528. }
  5529. theStartTime = theTime.Unix()
  5530. }
  5531. adminUserInfo := c.GetMobileAdminUserInfo()
  5532. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5533. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5534. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5535. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5536. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5537. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5538. c.ServeSuccessJSON(map[string]interface{}{
  5539. "status": "1",
  5540. })
  5541. return
  5542. } else { //开启推送提醒
  5543. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5544. var advice_three []*models.DoctorAdvice
  5545. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5546. fmt.Println("theStartTime-----------------------", theStartTime)
  5547. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5548. for _, advice := range advices {
  5549. if advice.FrequencyType == 3 {
  5550. t := time.Now()
  5551. week := int(t.Weekday())
  5552. fmt.Println(t.Weekday())
  5553. fmt.Println(week)
  5554. switch week {
  5555. case 1:
  5556. if strings.Index(advice.WeekDay, "周一") == -1 {
  5557. advice_three = append(advice_three, advice)
  5558. }
  5559. break
  5560. case 2:
  5561. if strings.Index(advice.WeekDay, "周二") == -1 {
  5562. advice_three = append(advice_three, advice)
  5563. }
  5564. break
  5565. case 3:
  5566. if strings.Index(advice.WeekDay, "周三") == -1 {
  5567. advice_three = append(advice_three, advice)
  5568. }
  5569. break
  5570. case 4:
  5571. if strings.Index(advice.WeekDay, "周四") == -1 {
  5572. advice_three = append(advice_three, advice)
  5573. }
  5574. break
  5575. case 5:
  5576. if strings.Index(advice.WeekDay, "周五") == -1 {
  5577. advice_three = append(advice_three, advice)
  5578. }
  5579. break
  5580. case 6:
  5581. if strings.Index(advice.WeekDay, "周六") == -1 {
  5582. advice_three = append(advice_three, advice)
  5583. }
  5584. break
  5585. case 0:
  5586. if strings.Index(advice.WeekDay, "周日") == -1 {
  5587. advice_three = append(advice_three, advice)
  5588. }
  5589. break
  5590. }
  5591. }
  5592. }
  5593. for _, advice := range advices_two {
  5594. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5595. now := p.Unix()
  5596. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5597. dayStr2 := "-" + dayStr
  5598. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5599. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5600. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5601. fmt.Println("advices-==---------------", advices)
  5602. for _, ad := range advices {
  5603. advice_three = append(advice_three, ad)
  5604. }
  5605. }
  5606. if err == nil {
  5607. c.ServeSuccessJSON(map[string]interface{}{
  5608. "status": "2",
  5609. "advices": advices,
  5610. "advices_two": RemoveRepeatedElement(advice_three),
  5611. "is_open_remind": config.IsOpenRemind,
  5612. "his_config_open": hisConfig.IsOpen,
  5613. "is_advice_open": is_advice_open.IsAdviceOpen,
  5614. "prescription_open": prescription_open.IsOpen,
  5615. })
  5616. }
  5617. }
  5618. }
  5619. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5620. newArr = make([]*models.DoctorAdvice, 0)
  5621. for i := 0; i < len(arr); i++ {
  5622. repeat := false
  5623. for j := i + 1; j < len(arr); j++ {
  5624. if arr[i].ID == arr[j].ID {
  5625. repeat = true
  5626. break
  5627. }
  5628. }
  5629. if !repeat {
  5630. newArr = append(newArr, arr[i])
  5631. }
  5632. }
  5633. return
  5634. }
  5635. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5636. patient, _ := c.GetInt64("id", 0)
  5637. groupNo, _ := c.GetInt64("groupno", 0)
  5638. if patient <= 0 {
  5639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5640. return
  5641. }
  5642. adminUserInfo := c.GetMobileAdminUserInfo()
  5643. dataBody := make(map[string]interface{}, 0)
  5644. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5645. if err != nil {
  5646. utils.ErrorLog(err.Error())
  5647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5648. return
  5649. }
  5650. utils.ErrorLog("%v", dataBody)
  5651. timeLayout := "2006-01-02 15:04"
  5652. loc, _ := time.LoadLocation("Local")
  5653. timeLayout2 := "2006-01-02"
  5654. loc2, _ := time.LoadLocation("Local")
  5655. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5656. utils.ErrorLog("advice_type")
  5657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5658. return
  5659. }
  5660. adviceType := int64(2)
  5661. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5662. utils.ErrorLog("advice_date")
  5663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5664. return
  5665. }
  5666. adviceDate, _ := dataBody["advice_date"].(string)
  5667. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5668. AdviceDate := theTime.Unix()
  5669. RecordDate := theTime.Unix()
  5670. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5671. utils.ErrorLog("start_time")
  5672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5673. return
  5674. }
  5675. startTime, _ := dataBody["start_time"].(string)
  5676. if len(startTime) == 0 {
  5677. utils.ErrorLog("len(start_time) == 0")
  5678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5679. return
  5680. }
  5681. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5682. if err != nil {
  5683. utils.ErrorLog(err.Error())
  5684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5685. return
  5686. }
  5687. StartTime := theTime.Unix()
  5688. Remark := ""
  5689. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5690. remark, _ := dataBody["remark"].(string)
  5691. Remark = remark
  5692. }
  5693. var advices []*models.GroupAdvice
  5694. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5695. utils.ErrorLog("advices")
  5696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5697. return
  5698. }
  5699. adviceNames := dataBody["advices"].([]interface{})
  5700. for _, adviceNameMap := range adviceNames {
  5701. adviceNameM := adviceNameMap.(map[string]interface{})
  5702. var advice models.GroupAdvice
  5703. advice.Remark = Remark
  5704. advice.AdviceType = adviceType
  5705. advice.StartTime = StartTime
  5706. advice.AdviceDate = AdviceDate
  5707. advice.RecordDate = RecordDate
  5708. advice.Status = 1
  5709. advice.CreatedTime = time.Now().Unix()
  5710. advice.UpdatedTime = time.Now().Unix()
  5711. advice.StopState = 2
  5712. advice.ExecutionState = 2
  5713. advice.UserOrgId = adminUserInfo.Org.Id
  5714. advice.PatientId = patient
  5715. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5716. advice.IsSettle = 2
  5717. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5718. utils.ErrorLog("advice_name")
  5719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5720. return
  5721. }
  5722. adviceName, _ := adviceNameM["advice_name"].(string)
  5723. if len(adviceName) == 0 {
  5724. utils.ErrorLog("len(advice_name) == 0")
  5725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5726. return
  5727. }
  5728. advice.AdviceName = adviceName
  5729. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5730. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5731. advice.DrugSpec = drugSpec
  5732. }
  5733. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5734. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5735. advice.AdviceDesc = adviceDesc
  5736. }
  5737. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5738. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5739. advice.DrugSpecUnit = drugSpecUnit
  5740. }
  5741. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5742. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5743. // advice.SingleDose = singleDose
  5744. //}
  5745. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5746. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5747. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5748. }
  5749. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5750. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5751. advice.SingleDoseUnit = singleDoseUnit
  5752. }
  5753. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5754. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5755. // advice.PrescribingNumber = prescribingNumber
  5756. //}
  5757. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5758. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5759. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5760. }
  5761. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5762. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5763. advice.PrescribingNumberUnit = prescribingNumberUnit
  5764. }
  5765. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5766. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5767. advice.DeliveryWay = deliveryWay
  5768. }
  5769. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5770. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5771. advice.ExecutionFrequency = executionFrequency
  5772. }
  5773. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5774. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5775. advice.FrequencyType = frequency_type
  5776. }
  5777. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5778. day_count := int64(adviceNameM["day_count"].(float64))
  5779. advice.DayCount = day_count
  5780. }
  5781. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5782. week_day, _ := adviceNameM["week_day"].(string)
  5783. advice.WeekDay = week_day
  5784. }
  5785. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5786. way := int64(adviceNameM["way"].(float64))
  5787. advice.Way = way
  5788. }
  5789. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5790. drug_id := int64(adviceNameM["drug_id"].(float64))
  5791. advice.DrugId = drug_id
  5792. }
  5793. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5794. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5795. advice.DrugNameId = drug_name_id
  5796. }
  5797. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5798. remark, _ := adviceNameM["remark"].(string)
  5799. advice.Remark = remark
  5800. }
  5801. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5802. groupno := int64(adviceNameM["groupno"].(float64))
  5803. advice.GroupNo = groupno
  5804. }
  5805. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5806. template_id, _ := adviceNameM["template_id"].(string)
  5807. advice.TemplateId = template_id
  5808. }
  5809. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5810. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5811. advice.ExecutionFrequency = executionFrequency
  5812. }
  5813. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5814. children := adviceNameM["child"].([]interface{})
  5815. if len(children) > 0 {
  5816. for _, childrenMap := range children {
  5817. childMap := childrenMap.(map[string]interface{})
  5818. var child models.GroupAdvice
  5819. child.Remark = Remark
  5820. child.AdviceType = adviceType
  5821. child.StartTime = StartTime
  5822. child.AdviceDate = AdviceDate
  5823. child.RecordDate = RecordDate
  5824. child.Status = 1
  5825. child.CreatedTime = time.Now().Unix()
  5826. child.UpdatedTime = time.Now().Unix()
  5827. child.StopState = 2
  5828. child.ExecutionState = 2
  5829. child.UserOrgId = adminUserInfo.Org.Id
  5830. child.PatientId = patient
  5831. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5832. child.IsSettle = 1
  5833. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5834. utils.ErrorLog("child advice_name")
  5835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5836. return
  5837. }
  5838. childAdviceName, _ := childMap["advice_name"].(string)
  5839. if len(childAdviceName) == 0 {
  5840. utils.ErrorLog("len(child advice_name) == 0")
  5841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5842. return
  5843. }
  5844. child.AdviceName = childAdviceName
  5845. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5846. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5847. child.AdviceDesc = childAdviceDesc
  5848. }
  5849. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5850. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5851. child.DrugSpec = childDrugSpec
  5852. }
  5853. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5854. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5855. child.DrugSpecUnit = childDrugSpecUnit
  5856. }
  5857. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5858. child.SingleDose = childMap["single_dose"].(float64)
  5859. }
  5860. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5861. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5862. child.SingleDoseUnit = childSingleDoseUnit
  5863. }
  5864. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5865. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5866. }
  5867. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5868. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5869. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5870. }
  5871. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5872. groupno := int64(childMap["groupno"].(float64))
  5873. advice.GroupNo = groupno
  5874. }
  5875. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5876. remark, _ := childMap["remark"].(string)
  5877. child.Remark = remark
  5878. }
  5879. child.DeliveryWay = advice.DeliveryWay
  5880. child.ExecutionFrequency = advice.ExecutionFrequency
  5881. advice.Children = append(advice.Children, &child)
  5882. }
  5883. }
  5884. }
  5885. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5886. if temp_advice.ID == 0 {
  5887. advices = append(advices, &advice)
  5888. }
  5889. }
  5890. if len(advices) > 0 {
  5891. finish := models.XtDialysisFinish{
  5892. IsFinish: 1,
  5893. UserOrgId: adminUserInfo.Org.Id,
  5894. Status: 1,
  5895. Ctime: time.Now().Unix(),
  5896. Mtime: 0,
  5897. Module: 4,
  5898. RecordDate: AdviceDate,
  5899. Sourse: 1,
  5900. PatientId: patient,
  5901. }
  5902. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5903. if dialysisFinish.ID == 0 {
  5904. service.CreateDialysisFinish(finish)
  5905. }
  5906. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5907. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5908. for _, item := range advices {
  5909. byterequest, _ := json.Marshal(item)
  5910. adviceLog := models.XtDoctorAdviceLog{
  5911. UserOrgId: adminUserInfo.Org.Id,
  5912. PatientId: patient,
  5913. AdminUserId: adminUserInfo.AdminUser.Id,
  5914. Module: 1,
  5915. ErrLog: string(byterequest),
  5916. Status: 1,
  5917. Ctime: time.Now().Unix(),
  5918. Mtime: 0,
  5919. Source: "手机端医嘱推送",
  5920. RecordDate: item.AdviceDate,
  5921. }
  5922. service.CreateDoctorAdviceLog(adviceLog)
  5923. }
  5924. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5925. redis := service.RedisClient()
  5926. //清空key 值
  5927. redis.Set(key, "", time.Second)
  5928. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5929. redis.Set(keyOne, "", time.Second)
  5930. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5931. defer redis.Close()
  5932. redis.Set(keyThree, "", time.Second)
  5933. if err != nil {
  5934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5935. return
  5936. }
  5937. c.ServeSuccessJSON(map[string]interface{}{
  5938. "msg": "ok",
  5939. "advices": list,
  5940. })
  5941. } else {
  5942. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5943. for _, item := range advices {
  5944. byterequest, _ := json.Marshal(item)
  5945. adviceLog := models.XtDoctorAdviceLog{
  5946. UserOrgId: adminUserInfo.Org.Id,
  5947. PatientId: patient,
  5948. AdminUserId: adminUserInfo.AdminUser.Id,
  5949. Module: 1,
  5950. ErrLog: string(byterequest),
  5951. Status: 1,
  5952. Ctime: time.Now().Unix(),
  5953. Mtime: 0,
  5954. Source: "手机端医嘱推送",
  5955. RecordDate: item.AdviceDate,
  5956. }
  5957. service.CreateDoctorAdviceLog(adviceLog)
  5958. }
  5959. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5960. redis := service.RedisClient()
  5961. //清空key 值
  5962. redis.Set(key, "", time.Second)
  5963. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5964. redis.Set(keyOne, "", time.Second)
  5965. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5966. defer redis.Close()
  5967. redis.Set(keyThree, "", time.Second)
  5968. if err != nil {
  5969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5970. return
  5971. }
  5972. c.ServeSuccessJSON(map[string]interface{}{
  5973. "msg": "ok",
  5974. "advices": list,
  5975. })
  5976. }
  5977. } else {
  5978. c.ServeSuccessJSON(map[string]interface{}{
  5979. "msg": "ok",
  5980. })
  5981. }
  5982. return
  5983. }
  5984. func (c *DialysisAPIController) UploadDryWeight() {
  5985. patient_id, _ := c.GetInt64("id")
  5986. dry_weight, _ := c.GetFloat("dry_weight")
  5987. doctor_id, _ := c.GetInt64("doctor_id")
  5988. remark := c.GetString("remark")
  5989. adminUserInfo := c.GetMobileAdminUserInfo()
  5990. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5991. if err == gorm.ErrRecordNotFound {
  5992. dryWeight := &models.SgjPatientDryweight{
  5993. PatientId: patient_id,
  5994. DryWeight: dry_weight,
  5995. Remakes: remark,
  5996. Ctime: time.Now().Unix(),
  5997. Mtime: time.Now().Unix(),
  5998. Creator: doctor_id,
  5999. Status: 1,
  6000. UserOrgId: adminUserInfo.Org.Id,
  6001. AdjustedValue: "/",
  6002. UserId: adminUserInfo.AdminUser.Id,
  6003. }
  6004. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6005. redis := service.RedisClient()
  6006. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  6007. redis.Set(keyOne, "", time.Second)
  6008. loc, _ := time.LoadLocation("Local")
  6009. nowTime := time.Now()
  6010. nowDay := nowTime.Format("2006-01-02")
  6011. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6012. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6013. redis.Set(key, "", time.Second)
  6014. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6015. redis.Set(keyTwo, "", time.Second)
  6016. redis.Close()
  6017. if createErr == nil {
  6018. c.ServeSuccessJSON(map[string]interface{}{
  6019. "msg": "提交成功",
  6020. "weight": dryWeight,
  6021. })
  6022. }
  6023. } else {
  6024. dryWeight := &models.SgjPatientDryweight{
  6025. PatientId: patient_id,
  6026. DryWeight: dry_weight,
  6027. Remakes: remark,
  6028. Ctime: time.Now().Unix(),
  6029. Mtime: time.Now().Unix(),
  6030. Creator: doctor_id,
  6031. Status: 1,
  6032. UserOrgId: adminUserInfo.Org.Id,
  6033. AdjustedValue: "/",
  6034. UserId: adminUserInfo.AdminUser.Id,
  6035. }
  6036. var value float64
  6037. value = dry_weight - weightAdjust.DryWeight
  6038. if value < 0 {
  6039. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  6040. } else if value == 0 {
  6041. dryWeight.AdjustedValue = "/"
  6042. } else if value > 0 {
  6043. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  6044. }
  6045. createErr := service.CreatePatientWeightAdjust(dryWeight)
  6046. //康桥
  6047. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  6048. timeNowStr := time.Now().Format("2006-01-02")
  6049. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6050. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6051. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  6052. if beforAssesment.ID > 0 {
  6053. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  6054. var dewater_amount float64
  6055. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  6056. if adminUserInfo.Org.Id != 10702 {
  6057. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  6058. }
  6059. if adminUserInfo.Org.Id == 10702 {
  6060. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  6061. }
  6062. //获取key,清空redis
  6063. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  6064. redis := service.RedisClient()
  6065. //清空key 值
  6066. redis.Set(key, "", time.Second)
  6067. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  6068. //清空key 值
  6069. redis.Set(keyOne, "", time.Second)
  6070. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  6071. //清空key 值
  6072. redis.Set(keyTwo, "", time.Second)
  6073. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  6074. redis.Set(keySix, "", time.Second)
  6075. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  6076. redis.Set(keySeven, "", time.Second)
  6077. }
  6078. }
  6079. redis := service.RedisClient()
  6080. loc, _ := time.LoadLocation("Local")
  6081. nowTime := time.Now()
  6082. nowDay := nowTime.Format("2006-01-02")
  6083. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  6084. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  6085. redis.Set(keyOne, "", time.Second)
  6086. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  6087. redis.Set(key, "", time.Second)
  6088. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  6089. redis.Set(keyTwo, "", time.Second)
  6090. redis.Close()
  6091. if createErr == nil {
  6092. c.ServeSuccessJSON(map[string]interface{}{
  6093. "msg": "提交成功",
  6094. "weight": dryWeight,
  6095. })
  6096. }
  6097. }
  6098. }
  6099. func (c *DialysisAPIController) GetSolution() {
  6100. patient_id, _ := c.GetInt64("patient_id")
  6101. mode_id, _ := c.GetInt64("mode_id")
  6102. adminUserInfo := c.GetMobileAdminUserInfo()
  6103. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6104. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  6105. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  6106. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  6107. if err != nil {
  6108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6109. return
  6110. }
  6111. c.ServeSuccessJSON(map[string]interface{}{
  6112. "solution": solution,
  6113. "prescription": prescription,
  6114. "system_prescription": system_prescription,
  6115. "dialysisPrescription": dialysisPrescription,
  6116. })
  6117. }
  6118. func (c *DialysisAPIController) GetSchedule() {
  6119. schedual_type, _ := c.GetInt64("schedual_type")
  6120. adminUserInfo := c.GetMobileAdminUserInfo()
  6121. scheduleTime, _ := c.GetInt64("record_date")
  6122. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  6123. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  6124. c.ServeSuccessJSON(map[string]interface{}{
  6125. "number": deviceNumber,
  6126. "list": list,
  6127. })
  6128. }
  6129. func (c *DialysisAPIController) GetPatientId() {
  6130. id, _ := c.GetInt64("id")
  6131. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6132. patientId, _ := service.GetPatientId(id)
  6133. //获取该患者的所有传染病
  6134. list, _ := service.GetPatientInfectious(id)
  6135. c.ServeSuccessJSON(map[string]interface{}{
  6136. "patient": patientId,
  6137. "infectioulist": list,
  6138. })
  6139. }
  6140. func (this *DialysisAPIController) GetDialysisSchedule() {
  6141. schedualDate := this.GetString("date")
  6142. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6143. if parseDateErr != nil {
  6144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6145. return
  6146. }
  6147. adminInfo := this.GetMobileAdminUserInfo()
  6148. orgID := adminInfo.Org.Id
  6149. redis := service.RedisClient()
  6150. defer redis.Close()
  6151. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  6152. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  6153. if len(scheduals) > 0 {
  6154. //缓存数据
  6155. scheduals_json, err := json.Marshal(scheduals)
  6156. if err == nil {
  6157. redis.Set(key, scheduals_json, time.Second*30)
  6158. }
  6159. }
  6160. this.ServeSuccessJSON(map[string]interface{}{
  6161. "scheduals": scheduals,
  6162. })
  6163. }
  6164. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  6165. change_type, _ := this.GetInt64("type", 0)
  6166. record_date := this.GetString("record_time")
  6167. patient_id, _ := this.GetInt64("patient_id", 0)
  6168. timeLayout := "2006-01-02"
  6169. loc, _ := time.LoadLocation("Local")
  6170. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6171. record_time := theAdviceRecordTime.Unix()
  6172. adminUserInfo := this.GetMobileAdminUserInfo()
  6173. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  6174. if err == nil {
  6175. if len(advices) == 0 {
  6176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6177. return
  6178. } else {
  6179. this.ServeSuccessJSON(map[string]interface{}{
  6180. "advices": advices,
  6181. "schedule": sch,
  6182. })
  6183. return
  6184. }
  6185. } else {
  6186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6187. return
  6188. }
  6189. }
  6190. func (c *DialysisAPIController) CreateConsumables() {
  6191. record_date := c.GetString("record_time")
  6192. patient_id, _ := c.GetInt64("patient_id", 0)
  6193. active, _ := c.GetInt64("active")
  6194. adminUser := c.GetMobileAdminUserInfo()
  6195. timeLayout := "2006-01-02"
  6196. loc, _ := time.LoadLocation("Local")
  6197. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6198. record_time := theRecordTime.Unix()
  6199. // 查询信息规挡的设置天数
  6200. orgid := c.GetMobileAdminUserInfo().Org.Id
  6201. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  6202. if infor.ID > 0 {
  6203. var cha_time int64
  6204. timeNowStr := time.Now().Format("2006-01-02")
  6205. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6206. //今日的日期减去设置的日期
  6207. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6208. if cha_time >= record_time {
  6209. //查询审核是否允许
  6210. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  6211. //申请状态不允许的情况 拒绝修改
  6212. if infor.ApplicationStatus != 1 {
  6213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6214. return
  6215. }
  6216. }
  6217. }
  6218. dataBody := make(map[string]interface{}, 0)
  6219. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6220. if err != nil {
  6221. utils.ErrorLog(err.Error())
  6222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6223. return
  6224. }
  6225. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6226. var beforePrepares []*models.DialysisBeforePrepareGoods
  6227. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6228. var dialysisBefor []*models.DialysisBeforePrepare
  6229. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6230. goods, _ := dataBody["goods"].([]interface{})
  6231. if len(goods) > 0 {
  6232. for _, item := range goods {
  6233. items := item.(map[string]interface{})
  6234. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6235. utils.ErrorLog("good_id")
  6236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6237. return
  6238. }
  6239. good_id := int64(items["good_id"].(float64))
  6240. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6241. utils.ErrorLog("good_type_id")
  6242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6243. return
  6244. }
  6245. good_type_id := int64(items["good_type_id"].(float64))
  6246. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6247. utils.ErrorLog("count")
  6248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6249. return
  6250. }
  6251. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6252. commdity_code := items["commdity_code"].(string)
  6253. fmt.Println("commdity", commdity_code)
  6254. prepareGoods := &models.DialysisBeforePrepareGoods{
  6255. GoodTypeId: good_type_id,
  6256. GoodId: good_id,
  6257. Count: count,
  6258. StorehouseId: houseConfig.StorehouseOutInfo,
  6259. }
  6260. beforePrepares = append(beforePrepares, prepareGoods)
  6261. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6262. GoodTypeId: good_type_id,
  6263. GoodId: good_id,
  6264. Count: count,
  6265. StorehouseId: houseConfig.StorehouseOutInfo,
  6266. }
  6267. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6268. prepare := &models.DialysisBeforePrepare{
  6269. GoodTypeId: good_type_id,
  6270. GoodId: good_id,
  6271. Count: count,
  6272. PatientId: patient_id,
  6273. RecordDate: record_time,
  6274. UserOrgId: adminUser.Org.Id,
  6275. Status: 1,
  6276. Ctime: time.Now().Unix(),
  6277. Creater: adminUser.AdminUser.Id,
  6278. CommdityCode: commdity_code,
  6279. StorehouseId: houseConfig.StorehouseOutInfo,
  6280. }
  6281. dialysisBefor = append(dialysisBefor, prepare)
  6282. }
  6283. }
  6284. //查询是否有库存
  6285. for _, item := range dialysisBefor {
  6286. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6287. if err == gorm.ErrRecordNotFound {
  6288. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6289. c.ServeSuccessJSON(map[string]interface{}{
  6290. "message": "1",
  6291. "good_name": goodObj.GoodName,
  6292. "specification_name": goodObj.SpecificationName,
  6293. })
  6294. return
  6295. }
  6296. if err != nil {
  6297. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6298. c.ServeSuccessJSON(map[string]interface{}{
  6299. "message": "1",
  6300. "good_name": goodObj.GoodName,
  6301. "specification_name": goodObj.SpecificationName,
  6302. })
  6303. return
  6304. }
  6305. }
  6306. fmt.Println("active-----------------------", active)
  6307. fmt.Println("len(goods)-----------------------", len(goods))
  6308. //新增
  6309. if active == 1 && len(goods) > 0 {
  6310. for _, item := range dialysisBefor {
  6311. dialyPrepareOne := models.DialysisBeforePrepare{
  6312. GoodTypeId: item.GoodTypeId,
  6313. GoodId: item.GoodId,
  6314. PatientId: item.PatientId,
  6315. RecordDate: item.RecordDate,
  6316. UserOrgId: item.UserOrgId,
  6317. Count: item.Count,
  6318. Ctime: time.Now().Unix(),
  6319. Creater: item.Creater,
  6320. CommdityCode: item.CommdityCode,
  6321. Status: 1,
  6322. StorehouseId: houseConfig.StorehouseOutInfo,
  6323. }
  6324. //先清除再插入
  6325. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6326. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6327. //查询默认仓库
  6328. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6329. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6330. var total_count int64
  6331. for _, it := range stockList {
  6332. total_count += it.StockCount
  6333. }
  6334. //基础库插入数据
  6335. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6336. //更新库存
  6337. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6338. var flush_count int64
  6339. for _, it := range goodList {
  6340. flush_count += it.StockCount
  6341. }
  6342. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6343. }
  6344. if err == nil {
  6345. c.ServeSuccessJSON(map[string]interface{}{
  6346. "msg": "保存成功",
  6347. "message": "2",
  6348. })
  6349. return
  6350. } else {
  6351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6352. return
  6353. }
  6354. }
  6355. if len(beforePrepares) > 0 && active == 2 {
  6356. for _, item := range beforePrepares {
  6357. //1.查看该患者该耗材型号最后一次出库数量
  6358. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6359. //判断当前出库数量和最后一次出库数量的大小
  6360. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6361. if item.Count <= goodInfo.Count {
  6362. //退库
  6363. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6364. //查询今日出库数据
  6365. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6366. for _, it := range list {
  6367. prepare := models.DialysisBeforePrepare{
  6368. UserOrgId: it.OrgId,
  6369. PatientId: patient_id,
  6370. RecordDate: it.RecordTime,
  6371. GoodId: it.GoodId,
  6372. GoodTypeId: it.GoodTypeId,
  6373. Count: it.Count,
  6374. Ctime: time.Now().Unix(),
  6375. Creater: adminUser.AdminUser.Id,
  6376. Status: 1,
  6377. StorehouseId: houseConfig.StorehouseOutInfo,
  6378. }
  6379. //删除准备表数据
  6380. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6381. service.CreateDialysisBeforePrepareOne(&prepare)
  6382. }
  6383. }
  6384. var last_total int64
  6385. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6386. if item.Count >= goodInfo.Count {
  6387. //查询当前批次当前耗材最后一条出库数据
  6388. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6389. //计算当前出库和最后一次出库数据相差数据
  6390. last_total = item.Count - lastOutInfo.Count
  6391. //查询该批次剩余库存
  6392. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6393. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6394. if lastInfo.StockCount >= last_total {
  6395. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6396. //查询今日出库数据
  6397. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6398. for _, it := range list {
  6399. prepare := models.DialysisBeforePrepare{
  6400. UserOrgId: it.OrgId,
  6401. PatientId: patient_id,
  6402. RecordDate: it.RecordTime,
  6403. GoodId: it.GoodId,
  6404. GoodTypeId: it.GoodTypeId,
  6405. Count: it.Count,
  6406. Ctime: time.Now().Unix(),
  6407. Creater: adminUser.AdminUser.Id,
  6408. Status: 1,
  6409. StorehouseId: houseConfig.StorehouseOutInfo,
  6410. }
  6411. //删除准备表数据
  6412. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6413. service.CreateDialysisBeforePrepareOne(&prepare)
  6414. //查询默认仓库
  6415. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6416. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6417. var total_count int64
  6418. for _, it := range stockList {
  6419. total_count += it.StockCount
  6420. }
  6421. //基础库插入数据
  6422. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6423. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6424. var flush_count int64
  6425. for _, it := range goodList {
  6426. flush_count += it.StockCount
  6427. }
  6428. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6429. }
  6430. }
  6431. //如果库存不够,则出库到下一个批次
  6432. if lastInfo.StockCount < last_total {
  6433. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6434. //查询今日出库数据
  6435. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6436. for _, it := range list {
  6437. prepare := models.DialysisBeforePrepare{
  6438. UserOrgId: it.OrgId,
  6439. PatientId: patient_id,
  6440. RecordDate: it.RecordTime,
  6441. GoodId: it.GoodId,
  6442. GoodTypeId: it.GoodTypeId,
  6443. Count: it.Count,
  6444. Ctime: time.Now().Unix(),
  6445. Creater: adminUser.AdminUser.Id,
  6446. Status: 1,
  6447. StorehouseId: houseConfig.StorehouseOutInfo,
  6448. }
  6449. //删除准备表数据
  6450. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6451. service.CreateDialysisBeforePrepareOne(&prepare)
  6452. //查询默认仓库
  6453. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6454. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6455. var total_count int64
  6456. for _, it := range stockList {
  6457. total_count += it.StockCount
  6458. }
  6459. //基础库插入数据
  6460. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6461. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6462. var flush_count int64
  6463. for _, it := range goodList {
  6464. flush_count += it.StockCount
  6465. }
  6466. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6467. }
  6468. if err != nil {
  6469. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6470. c.ServeSuccessJSON(map[string]interface{}{
  6471. "message": "1",
  6472. "good_name": goodObj.GoodName,
  6473. "specification_name": goodObj.SpecificationName,
  6474. })
  6475. return
  6476. }
  6477. }
  6478. }
  6479. if err != nil {
  6480. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6481. c.ServeSuccessJSON(map[string]interface{}{
  6482. "message": "1",
  6483. "good_name": goodObj.GoodName,
  6484. "specification_name": goodObj.SpecificationName,
  6485. })
  6486. return
  6487. }
  6488. }
  6489. }
  6490. }
  6491. var errs error
  6492. if errs == nil {
  6493. c.ServeSuccessJSON(map[string]interface{}{
  6494. "msg": "提交成功",
  6495. "message": "2",
  6496. "good_name": "",
  6497. "specification_name": "",
  6498. })
  6499. return
  6500. } else {
  6501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6502. return
  6503. }
  6504. }
  6505. func (c *DialysisAPIController) CreateStockOutInfo() {
  6506. patient_id, _ := c.GetInt64("patient_id", 0)
  6507. record_date := c.GetString("record_time")
  6508. if patient_id <= 0 {
  6509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6510. return
  6511. }
  6512. adminInfo := c.GetMobileAdminUserInfo()
  6513. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6514. timeLayout := "2006-01-02"
  6515. loc, _ := time.LoadLocation("Local")
  6516. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6517. record_time := theRecordTime.Unix()
  6518. // 查询信息规挡的设置天数
  6519. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6520. if infor.ID > 0 && infor.WeekDay > 0 {
  6521. var cha_time int64
  6522. timeNowStr := time.Now().Format("2006-01-02")
  6523. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6524. //今日的日期减去设置的日期
  6525. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6526. if cha_time >= record_time {
  6527. //查询审核是否允许
  6528. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6529. //申请状态不允许的情况 拒绝修改
  6530. if infor.ApplicationStatus != 1 {
  6531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6532. return
  6533. }
  6534. }
  6535. }
  6536. //创建步骤表
  6537. finish := models.XtDialysisFinish{
  6538. IsFinish: 1,
  6539. UserOrgId: adminInfo.Org.Id,
  6540. Status: 1,
  6541. Ctime: time.Now().Unix(),
  6542. Mtime: 0,
  6543. Module: 11,
  6544. RecordDate: record_time,
  6545. Sourse: 1,
  6546. PatientId: patient_id,
  6547. }
  6548. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6549. if dialysisFinish.ID == 0 {
  6550. service.CreateDialysisFinish(finish)
  6551. }
  6552. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6553. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6554. //去重
  6555. consumables = RemoveRepeatedGood(consumables)
  6556. if adminInfo.Org.Id == 9919 {
  6557. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6558. //查询是否有库存
  6559. for _, item := range consumables {
  6560. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6561. if item.Count > warehouse.Count {
  6562. goodErrcode := models.XtGoodErrcode{
  6563. UserOrgId: item.UserOrgId,
  6564. Errcode: "自动出库库存不足",
  6565. GoodId: item.GoodId,
  6566. Status: 1,
  6567. Ctime: time.Now().Unix(),
  6568. Mtime: 0,
  6569. Count: 0,
  6570. StockCount: 0,
  6571. Creater: creator,
  6572. BatchNumberId: warehouse.ID,
  6573. WarehouseOutId: 0,
  6574. }
  6575. service.CreateGoodErrcode(goodErrcode)
  6576. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6577. c.ServeSuccessJSON(map[string]interface{}{
  6578. "message": "1",
  6579. "good_name": goodObj.GoodName,
  6580. "specification_name": goodObj.SpecificationName,
  6581. })
  6582. return
  6583. }
  6584. }
  6585. //查询是否有出库单
  6586. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6587. if err == gorm.ErrRecordNotFound {
  6588. //没有记录,则创建出库单
  6589. timeStr := time.Now().Format("2006-01-02")
  6590. timeArr := strings.Split(timeStr, "-")
  6591. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6592. total = total + 1
  6593. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6594. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6595. number = number + total
  6596. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6597. creater := adminInfo.AdminUser.Id
  6598. warehouseOut := models.WarehouseOut{
  6599. WarehouseOutOrderNumber: warehousing_out_order,
  6600. OperationTime: time.Now().Unix(),
  6601. OrgId: adminInfo.Org.Id,
  6602. Creater: creater,
  6603. Ctime: time.Now().Unix(),
  6604. Status: 1,
  6605. WarehouseOutTime: record_time,
  6606. Dealer: 0,
  6607. Manufacturer: 0,
  6608. Type: 1,
  6609. IsSys: 1,
  6610. StorehouseId: houseConfig.StorehouseOutInfo,
  6611. IsCheck: 1,
  6612. }
  6613. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6614. if err != nil {
  6615. goodErrcode := models.XtGoodErrcode{
  6616. UserOrgId: adminInfo.Org.Id,
  6617. Errcode: "创建出库单失败",
  6618. GoodId: 0,
  6619. Status: 1,
  6620. Ctime: time.Now().Unix(),
  6621. Mtime: 0,
  6622. Count: 0,
  6623. StockCount: 0,
  6624. Creater: creator,
  6625. BatchNumberId: 0,
  6626. WarehouseOutId: 0,
  6627. }
  6628. service.CreateGoodErrcode(goodErrcode)
  6629. utils.TraceLog("创建出库单失败 err = %v", err)
  6630. } else {
  6631. for _, item := range consumables {
  6632. //出库
  6633. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6634. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6635. if err == nil {
  6636. goodErrcode := models.XtGoodErrcode{
  6637. UserOrgId: adminInfo.Org.Id,
  6638. Errcode: "自动出库接口报错",
  6639. GoodId: 0,
  6640. Status: 1,
  6641. Ctime: time.Now().Unix(),
  6642. Mtime: 0,
  6643. Count: 0,
  6644. StockCount: 0,
  6645. Creater: creator,
  6646. BatchNumberId: 0,
  6647. WarehouseOutId: 0,
  6648. }
  6649. service.CreateGoodErrcode(goodErrcode)
  6650. utils.TraceLog("创建出库单失败 err = %v", err)
  6651. }
  6652. //查询
  6653. //出库数量相加
  6654. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6655. if errs != nil {
  6656. goodErrcode := models.XtGoodErrcode{
  6657. UserOrgId: item.UserOrgId,
  6658. Errcode: "创建剩余库存字段报错",
  6659. GoodId: item.GoodId,
  6660. Status: 1,
  6661. Ctime: time.Now().Unix(),
  6662. Mtime: 0,
  6663. Count: 0,
  6664. StockCount: 0,
  6665. Creater: creater,
  6666. BatchNumberId: 0,
  6667. WarehouseOutId: 0,
  6668. }
  6669. service.CreateGoodErrcode(goodErrcode)
  6670. }
  6671. }
  6672. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6673. if len(list) == 0 {
  6674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6675. return
  6676. }
  6677. for _, item := range list {
  6678. prepare := models.DialysisBeforePrepare{
  6679. UserOrgId: adminInfo.Org.Id,
  6680. PatientId: patient_id,
  6681. RecordDate: record_time,
  6682. GoodId: item.GoodId,
  6683. GoodTypeId: item.GoodTypeId,
  6684. Count: item.Count,
  6685. Creater: adminInfo.AdminUser.Id,
  6686. Status: 1,
  6687. Ctime: time.Now().Unix(),
  6688. StorehouseId: houseConfig.StorehouseOutInfo,
  6689. }
  6690. //清空准备表数据
  6691. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6692. if err != nil {
  6693. goodErrcode := models.XtGoodErrcode{
  6694. UserOrgId: item.OrgId,
  6695. Errcode: "自动出库清空准备表数据报错",
  6696. GoodId: item.GoodId,
  6697. Status: 1,
  6698. Ctime: time.Now().Unix(),
  6699. Mtime: 0,
  6700. Count: 0,
  6701. StockCount: 0,
  6702. Creater: creater,
  6703. BatchNumberId: 0,
  6704. WarehouseOutId: 0,
  6705. }
  6706. service.CreateGoodErrcode(goodErrcode)
  6707. }
  6708. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6709. if errs != nil {
  6710. goodErrcode := models.XtGoodErrcode{
  6711. UserOrgId: item.OrgId,
  6712. Errcode: "自动出库创建准备表数据报错",
  6713. GoodId: item.GoodId,
  6714. Status: 1,
  6715. Ctime: time.Now().Unix(),
  6716. Mtime: 0,
  6717. Count: 0,
  6718. StockCount: 0,
  6719. Creater: creater,
  6720. BatchNumberId: 0,
  6721. WarehouseOutId: 0,
  6722. }
  6723. service.CreateGoodErrcode(goodErrcode)
  6724. }
  6725. //查询默认仓库
  6726. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6727. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6728. var total_count int64
  6729. for _, it := range stockList {
  6730. total_count += it.StockCount
  6731. }
  6732. //基础库插入数据
  6733. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6734. if errcodes != nil {
  6735. goodErrcode := models.XtGoodErrcode{
  6736. UserOrgId: item.OrgId,
  6737. Errcode: "自动出库基础库插入数据",
  6738. GoodId: item.GoodId,
  6739. Status: 1,
  6740. Ctime: time.Now().Unix(),
  6741. Mtime: 0,
  6742. Count: 0,
  6743. StockCount: 0,
  6744. Creater: creater,
  6745. BatchNumberId: 0,
  6746. WarehouseOutId: 0,
  6747. }
  6748. service.CreateGoodErrcode(goodErrcode)
  6749. }
  6750. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6751. var flush_count int64
  6752. for _, it := range goodList {
  6753. flush_count += it.StockCount
  6754. }
  6755. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6756. if errsss != nil {
  6757. goodErrcode := models.XtGoodErrcode{
  6758. UserOrgId: item.OrgId,
  6759. Errcode: "自动出库剩余库存更新数据",
  6760. GoodId: item.GoodId,
  6761. Status: 1,
  6762. Ctime: time.Now().Unix(),
  6763. Mtime: 0,
  6764. Count: 0,
  6765. StockCount: 0,
  6766. Creater: creater,
  6767. BatchNumberId: 0,
  6768. WarehouseOutId: 0,
  6769. }
  6770. service.CreateGoodErrcode(goodErrcode)
  6771. }
  6772. }
  6773. }
  6774. //
  6775. } else if err == nil {
  6776. for _, item := range consumables {
  6777. //出库
  6778. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6779. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6780. if err != nil {
  6781. goodErrcode := models.XtGoodErrcode{
  6782. UserOrgId: adminInfo.Org.Id,
  6783. Errcode: "自动出库接口报错",
  6784. GoodId: 0,
  6785. Status: 1,
  6786. Ctime: time.Now().Unix(),
  6787. Mtime: 0,
  6788. Count: 0,
  6789. StockCount: 0,
  6790. Creater: creator,
  6791. BatchNumberId: 0,
  6792. WarehouseOutId: 0,
  6793. }
  6794. service.CreateGoodErrcode(goodErrcode)
  6795. }
  6796. //出库数量相加
  6797. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6798. if errss != nil {
  6799. goodErrcode := models.XtGoodErrcode{
  6800. UserOrgId: item.UserOrgId,
  6801. Errcode: "创建剩余库存字段报错",
  6802. GoodId: item.GoodId,
  6803. Status: 1,
  6804. Ctime: time.Now().Unix(),
  6805. Mtime: time.Now().Unix(),
  6806. Count: 0,
  6807. StockCount: 0,
  6808. Creater: item.Creater,
  6809. BatchNumberId: 0,
  6810. WarehouseOutId: 0,
  6811. }
  6812. service.CreateGoodErrcode(goodErrcode)
  6813. }
  6814. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6815. if len(list) == 0 {
  6816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6817. return
  6818. }
  6819. for _, item := range list {
  6820. prepare := models.DialysisBeforePrepare{
  6821. UserOrgId: adminInfo.Org.Id,
  6822. PatientId: patient_id,
  6823. RecordDate: record_time,
  6824. GoodId: item.GoodId,
  6825. GoodTypeId: item.GoodTypeId,
  6826. Count: item.Count,
  6827. Creater: adminInfo.AdminUser.Id,
  6828. Status: 1,
  6829. Ctime: time.Now().Unix(),
  6830. StorehouseId: houseConfig.StorehouseOutInfo,
  6831. }
  6832. //清空准备表数据
  6833. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6834. if errs != nil {
  6835. goodErrcode := models.XtGoodErrcode{
  6836. UserOrgId: adminInfo.Org.Id,
  6837. Errcode: "自动出库清空准备表数据报错",
  6838. GoodId: 0,
  6839. Status: 1,
  6840. Ctime: time.Now().Unix(),
  6841. Mtime: 0,
  6842. Count: 0,
  6843. StockCount: 0,
  6844. Creater: creator,
  6845. BatchNumberId: 0,
  6846. WarehouseOutId: 0,
  6847. }
  6848. service.CreateGoodErrcode(goodErrcode)
  6849. }
  6850. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6851. if errcodes != nil {
  6852. goodErrcode := models.XtGoodErrcode{
  6853. UserOrgId: adminInfo.Org.Id,
  6854. Errcode: "自动出库创建准备表数据报错",
  6855. GoodId: 0,
  6856. Status: 1,
  6857. Ctime: time.Now().Unix(),
  6858. Mtime: 0,
  6859. Count: 0,
  6860. StockCount: 0,
  6861. Creater: creator,
  6862. BatchNumberId: 0,
  6863. WarehouseOutId: 0,
  6864. }
  6865. service.CreateGoodErrcode(goodErrcode)
  6866. }
  6867. //查询默认仓库
  6868. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6869. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6870. var total_count int64
  6871. for _, it := range stockList {
  6872. total_count += it.StockCount
  6873. }
  6874. //基础库插入数据
  6875. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6876. if errcodes != nil {
  6877. goodErrcode := models.XtGoodErrcode{
  6878. UserOrgId: adminInfo.Org.Id,
  6879. Errcode: "自动出库基础库插入数据报错",
  6880. GoodId: 0,
  6881. Status: 1,
  6882. Ctime: time.Now().Unix(),
  6883. Mtime: 0,
  6884. Count: 0,
  6885. StockCount: 0,
  6886. Creater: creator,
  6887. BatchNumberId: 0,
  6888. WarehouseOutId: 0,
  6889. }
  6890. service.CreateGoodErrcode(goodErrcode)
  6891. }
  6892. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6893. var flush_count int64
  6894. for _, it := range goodList {
  6895. flush_count += it.StockCount
  6896. }
  6897. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6898. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6899. if errss != nil {
  6900. goodErrcode := models.XtGoodErrcode{
  6901. UserOrgId: item.OrgId,
  6902. Errcode: "自动出库剩余库存更新数据",
  6903. GoodId: item.GoodId,
  6904. Status: 1,
  6905. Ctime: time.Now().Unix(),
  6906. Mtime: 0,
  6907. Count: 0,
  6908. StockCount: 0,
  6909. Creater: creater,
  6910. BatchNumberId: 0,
  6911. WarehouseOutId: 0,
  6912. }
  6913. service.CreateGoodErrcode(goodErrcode)
  6914. }
  6915. }
  6916. }
  6917. }
  6918. c.ServeSuccessJSON(map[string]interface{}{
  6919. "msg": "提交成功",
  6920. "message": "2",
  6921. "good_name": "",
  6922. "specification_name": "",
  6923. })
  6924. return
  6925. }
  6926. if record.IsOpen == 1 {
  6927. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6928. //查询是否有库存
  6929. for _, item := range consumables {
  6930. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6931. if item.Count > warehouse.Count {
  6932. goodErrcode := models.XtGoodErrcode{
  6933. UserOrgId: item.UserOrgId,
  6934. Errcode: "自动出库库存不足",
  6935. GoodId: item.GoodId,
  6936. Status: 1,
  6937. Ctime: time.Now().Unix(),
  6938. Mtime: 0,
  6939. Count: 0,
  6940. StockCount: 0,
  6941. Creater: creator,
  6942. BatchNumberId: warehouse.ID,
  6943. WarehouseOutId: 0,
  6944. }
  6945. service.CreateGoodErrcode(goodErrcode)
  6946. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6947. c.ServeSuccessJSON(map[string]interface{}{
  6948. "message": "1",
  6949. "good_name": goodObj.GoodName,
  6950. "specification_name": goodObj.SpecificationName,
  6951. })
  6952. return
  6953. }
  6954. }
  6955. //查询是否有出库单
  6956. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6957. if err == gorm.ErrRecordNotFound {
  6958. //没有记录,则创建出库单
  6959. timeStr := time.Now().Format("2006-01-02")
  6960. timeArr := strings.Split(timeStr, "-")
  6961. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6962. total = total + 1
  6963. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6964. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6965. number = number + total
  6966. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6967. creater := adminInfo.AdminUser.Id
  6968. warehouseOut := models.WarehouseOut{
  6969. WarehouseOutOrderNumber: warehousing_out_order,
  6970. OperationTime: time.Now().Unix(),
  6971. OrgId: adminInfo.Org.Id,
  6972. Creater: creater,
  6973. Ctime: time.Now().Unix(),
  6974. Status: 1,
  6975. WarehouseOutTime: record_time,
  6976. Dealer: 0,
  6977. Manufacturer: 0,
  6978. Type: 1,
  6979. IsSys: 1,
  6980. StorehouseId: houseConfig.StorehouseOutInfo,
  6981. IsCheck: 1,
  6982. }
  6983. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  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. utils.TraceLog("创建出库单失败 err = %v", err)
  7000. } else {
  7001. for _, item := range consumables {
  7002. //出库
  7003. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  7004. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  7005. if err == nil {
  7006. goodErrcode := models.XtGoodErrcode{
  7007. UserOrgId: adminInfo.Org.Id,
  7008. Errcode: "自动出库接口报错",
  7009. GoodId: 0,
  7010. Status: 1,
  7011. Ctime: time.Now().Unix(),
  7012. Mtime: 0,
  7013. Count: 0,
  7014. StockCount: 0,
  7015. Creater: creator,
  7016. BatchNumberId: 0,
  7017. WarehouseOutId: 0,
  7018. }
  7019. service.CreateGoodErrcode(goodErrcode)
  7020. utils.TraceLog("创建出库单失败 err = %v", err)
  7021. }
  7022. //查询
  7023. //出库数量相加
  7024. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7025. if errs != nil {
  7026. goodErrcode := models.XtGoodErrcode{
  7027. UserOrgId: item.UserOrgId,
  7028. Errcode: "创建剩余库存字段报错",
  7029. GoodId: item.GoodId,
  7030. Status: 1,
  7031. Ctime: time.Now().Unix(),
  7032. Mtime: 0,
  7033. Count: 0,
  7034. StockCount: 0,
  7035. Creater: creater,
  7036. BatchNumberId: 0,
  7037. WarehouseOutId: 0,
  7038. }
  7039. service.CreateGoodErrcode(goodErrcode)
  7040. }
  7041. }
  7042. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7043. if len(list) == 0 {
  7044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7045. return
  7046. }
  7047. for _, item := range list {
  7048. prepare := models.DialysisBeforePrepare{
  7049. UserOrgId: adminInfo.Org.Id,
  7050. PatientId: patient_id,
  7051. RecordDate: record_time,
  7052. GoodId: item.GoodId,
  7053. GoodTypeId: item.GoodTypeId,
  7054. Count: item.Count,
  7055. Creater: adminInfo.AdminUser.Id,
  7056. Status: 1,
  7057. Ctime: time.Now().Unix(),
  7058. StorehouseId: houseConfig.StorehouseOutInfo,
  7059. }
  7060. //清空准备表数据
  7061. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7062. if err != nil {
  7063. goodErrcode := models.XtGoodErrcode{
  7064. UserOrgId: item.OrgId,
  7065. Errcode: "自动出库清空准备表数据报错",
  7066. GoodId: item.GoodId,
  7067. Status: 1,
  7068. Ctime: time.Now().Unix(),
  7069. Mtime: 0,
  7070. Count: 0,
  7071. StockCount: 0,
  7072. Creater: creater,
  7073. BatchNumberId: 0,
  7074. WarehouseOutId: 0,
  7075. }
  7076. service.CreateGoodErrcode(goodErrcode)
  7077. }
  7078. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  7079. if errs != nil {
  7080. goodErrcode := models.XtGoodErrcode{
  7081. UserOrgId: item.OrgId,
  7082. Errcode: "自动出库创建准备表数据报错",
  7083. GoodId: item.GoodId,
  7084. Status: 1,
  7085. Ctime: time.Now().Unix(),
  7086. Mtime: 0,
  7087. Count: 0,
  7088. StockCount: 0,
  7089. Creater: creater,
  7090. BatchNumberId: 0,
  7091. WarehouseOutId: 0,
  7092. }
  7093. service.CreateGoodErrcode(goodErrcode)
  7094. }
  7095. //查询默认仓库
  7096. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7097. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7098. var total_count int64
  7099. for _, it := range stockList {
  7100. total_count += it.StockCount
  7101. }
  7102. //基础库插入数据
  7103. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7104. if errcodes != nil {
  7105. goodErrcode := models.XtGoodErrcode{
  7106. UserOrgId: item.OrgId,
  7107. Errcode: "自动出库基础库插入数据",
  7108. GoodId: item.GoodId,
  7109. Status: 1,
  7110. Ctime: time.Now().Unix(),
  7111. Mtime: 0,
  7112. Count: 0,
  7113. StockCount: 0,
  7114. Creater: creater,
  7115. BatchNumberId: 0,
  7116. WarehouseOutId: 0,
  7117. }
  7118. service.CreateGoodErrcode(goodErrcode)
  7119. }
  7120. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7121. var flush_count int64
  7122. for _, it := range goodList {
  7123. flush_count += it.StockCount
  7124. }
  7125. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7126. if errsss != nil {
  7127. goodErrcode := models.XtGoodErrcode{
  7128. UserOrgId: item.OrgId,
  7129. Errcode: "自动出库剩余库存更新数据",
  7130. GoodId: item.GoodId,
  7131. Status: 1,
  7132. Ctime: time.Now().Unix(),
  7133. Mtime: 0,
  7134. Count: 0,
  7135. StockCount: 0,
  7136. Creater: creater,
  7137. BatchNumberId: 0,
  7138. WarehouseOutId: 0,
  7139. }
  7140. service.CreateGoodErrcode(goodErrcode)
  7141. }
  7142. }
  7143. }
  7144. //
  7145. } else if err == nil {
  7146. for _, item := range consumables {
  7147. //出库
  7148. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  7149. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  7150. if err != nil {
  7151. goodErrcode := models.XtGoodErrcode{
  7152. UserOrgId: adminInfo.Org.Id,
  7153. Errcode: "自动出库接口报错",
  7154. GoodId: 0,
  7155. Status: 1,
  7156. Ctime: time.Now().Unix(),
  7157. Mtime: 0,
  7158. Count: 0,
  7159. StockCount: 0,
  7160. Creater: creator,
  7161. BatchNumberId: 0,
  7162. WarehouseOutId: 0,
  7163. }
  7164. service.CreateGoodErrcode(goodErrcode)
  7165. }
  7166. //出库数量相加
  7167. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  7168. if errss != nil {
  7169. goodErrcode := models.XtGoodErrcode{
  7170. UserOrgId: item.UserOrgId,
  7171. Errcode: "创建剩余库存字段报错",
  7172. GoodId: item.GoodId,
  7173. Status: 1,
  7174. Ctime: time.Now().Unix(),
  7175. Mtime: time.Now().Unix(),
  7176. Count: 0,
  7177. StockCount: 0,
  7178. Creater: item.Creater,
  7179. BatchNumberId: 0,
  7180. WarehouseOutId: 0,
  7181. }
  7182. service.CreateGoodErrcode(goodErrcode)
  7183. }
  7184. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7185. if len(list) == 0 {
  7186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7187. return
  7188. }
  7189. for _, item := range list {
  7190. prepare := models.DialysisBeforePrepare{
  7191. UserOrgId: adminInfo.Org.Id,
  7192. PatientId: patient_id,
  7193. RecordDate: record_time,
  7194. GoodId: item.GoodId,
  7195. GoodTypeId: item.GoodTypeId,
  7196. Count: item.Count,
  7197. Creater: adminInfo.AdminUser.Id,
  7198. Status: 1,
  7199. Ctime: time.Now().Unix(),
  7200. StorehouseId: houseConfig.StorehouseOutInfo,
  7201. }
  7202. //清空准备表数据
  7203. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7204. if errs != nil {
  7205. goodErrcode := models.XtGoodErrcode{
  7206. UserOrgId: adminInfo.Org.Id,
  7207. Errcode: "自动出库清空准备表数据报错",
  7208. GoodId: 0,
  7209. Status: 1,
  7210. Ctime: time.Now().Unix(),
  7211. Mtime: 0,
  7212. Count: 0,
  7213. StockCount: 0,
  7214. Creater: creator,
  7215. BatchNumberId: 0,
  7216. WarehouseOutId: 0,
  7217. }
  7218. service.CreateGoodErrcode(goodErrcode)
  7219. }
  7220. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  7221. if errcodes != nil {
  7222. goodErrcode := models.XtGoodErrcode{
  7223. UserOrgId: adminInfo.Org.Id,
  7224. Errcode: "自动出库创建准备表数据报错",
  7225. GoodId: 0,
  7226. Status: 1,
  7227. Ctime: time.Now().Unix(),
  7228. Mtime: 0,
  7229. Count: 0,
  7230. StockCount: 0,
  7231. Creater: creator,
  7232. BatchNumberId: 0,
  7233. WarehouseOutId: 0,
  7234. }
  7235. service.CreateGoodErrcode(goodErrcode)
  7236. }
  7237. //查询默认仓库
  7238. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7239. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7240. var total_count int64
  7241. for _, it := range stockList {
  7242. total_count += it.StockCount
  7243. }
  7244. //基础库插入数据
  7245. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7246. if errcodes != nil {
  7247. goodErrcode := models.XtGoodErrcode{
  7248. UserOrgId: adminInfo.Org.Id,
  7249. Errcode: "自动出库基础库插入数据报错",
  7250. GoodId: 0,
  7251. Status: 1,
  7252. Ctime: time.Now().Unix(),
  7253. Mtime: 0,
  7254. Count: 0,
  7255. StockCount: 0,
  7256. Creater: creator,
  7257. BatchNumberId: 0,
  7258. WarehouseOutId: 0,
  7259. }
  7260. service.CreateGoodErrcode(goodErrcode)
  7261. }
  7262. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7263. var flush_count int64
  7264. for _, it := range goodList {
  7265. flush_count += it.StockCount
  7266. }
  7267. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7268. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7269. if errss != nil {
  7270. goodErrcode := models.XtGoodErrcode{
  7271. UserOrgId: item.OrgId,
  7272. Errcode: "自动出库剩余库存更新数据",
  7273. GoodId: item.GoodId,
  7274. Status: 1,
  7275. Ctime: time.Now().Unix(),
  7276. Mtime: 0,
  7277. Count: 0,
  7278. StockCount: 0,
  7279. Creater: creater,
  7280. BatchNumberId: 0,
  7281. WarehouseOutId: 0,
  7282. }
  7283. service.CreateGoodErrcode(goodErrcode)
  7284. }
  7285. }
  7286. }
  7287. }
  7288. c.ServeSuccessJSON(map[string]interface{}{
  7289. "msg": "提交成功",
  7290. "message": "2",
  7291. "good_name": "",
  7292. "specification_name": "",
  7293. })
  7294. return
  7295. } else {
  7296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7297. return
  7298. }
  7299. }
  7300. func (c *DialysisAPIController) EditConsumables() {
  7301. patient_id, _ := c.GetInt64("patient_id", 0)
  7302. record_date := c.GetString("record_time")
  7303. if patient_id <= 0 {
  7304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7305. return
  7306. }
  7307. adminInfo := c.GetMobileAdminUserInfo()
  7308. timeLayout := "2006-01-02"
  7309. loc, _ := time.LoadLocation("Local")
  7310. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7311. record_time := theRecordTime.Unix()
  7312. // 查询信息规挡的设置天数
  7313. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7314. if infor.ID > 0 && infor.WeekDay > 0 {
  7315. var cha_time int64
  7316. timeNowStr := time.Now().Format("2006-01-02")
  7317. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7318. //今日的日期减去设置的日期
  7319. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7320. if cha_time >= record_time {
  7321. //查询审核是否允许
  7322. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7323. //申请状态不允许的情况 拒绝修改
  7324. if infor.ApplicationStatus != 1 {
  7325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7326. return
  7327. }
  7328. }
  7329. }
  7330. dataBody := make(map[string]interface{}, 0)
  7331. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7332. if err != nil {
  7333. utils.ErrorLog(err.Error())
  7334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7335. return
  7336. }
  7337. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7338. var beforePrepares []*models.DialysisBeforePrepareGoods
  7339. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7340. var cancelbefor []*models.DialysisBeforePrepareGoods
  7341. var outbefor []*models.DialysisBeforePrepareGoods
  7342. //判断是否开启自动出库
  7343. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7344. if record.IsOpen == 1 {
  7345. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7346. goods, _ := dataBody["goods"].([]interface{})
  7347. if len(goods) > 0 {
  7348. for _, item := range goods {
  7349. items := item.(map[string]interface{})
  7350. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7351. utils.ErrorLog("good_id")
  7352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7353. return
  7354. }
  7355. good_id := int64(items["good_id"].(float64))
  7356. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7357. utils.ErrorLog("good_type_id")
  7358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7359. return
  7360. }
  7361. good_type_id := int64(items["good_type_id"].(float64))
  7362. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7363. utils.ErrorLog("count")
  7364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7365. return
  7366. }
  7367. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7368. commdity_code := items["commdity_code"].(string)
  7369. fmt.Println(commdity_code)
  7370. prepareGoods := &models.DialysisBeforePrepareGoods{
  7371. GoodTypeId: good_type_id,
  7372. GoodId: good_id,
  7373. Count: count,
  7374. StorehouseId: houseConfig.StorehouseOutInfo,
  7375. }
  7376. beforePrepares = append(beforePrepares, prepareGoods)
  7377. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7378. GoodTypeId: good_type_id,
  7379. GoodId: good_id,
  7380. Count: count,
  7381. StorehouseId: houseConfig.StorehouseOutInfo,
  7382. }
  7383. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7384. }
  7385. for _, item := range beforePrepares {
  7386. //1.查看该患者该耗材型号最后一次出库数量
  7387. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7388. //判断当前出库数量和最后一次出库数量的大小
  7389. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7390. if item.Count < goodInfo.Count {
  7391. cancelbefor = append(cancelbefor, item)
  7392. }
  7393. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7394. if item.Count > goodInfo.Count {
  7395. outbefor = append(outbefor, item)
  7396. }
  7397. //处理编辑耗材新增不了的问题
  7398. if goodInfo.Count == item.Count {
  7399. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7400. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7401. }
  7402. }
  7403. if len(cancelbefor) > 0 {
  7404. //退库
  7405. for _, item := range cancelbefor {
  7406. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7407. creater := adminInfo.AdminUser.Id
  7408. //查询该患者当天已经出库的耗材信息
  7409. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7410. var delete_count int64 = 0
  7411. delete_count = warehouseOutInfos.Count - item.Count
  7412. //增加库存数量
  7413. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7414. //减少实际出库库存数量
  7415. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7416. // 删除出库完成后,要增加对应批次的库存数量
  7417. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7418. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7419. //更新剩余库存
  7420. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7421. var flush_count int64
  7422. for _, it := range goodListOne {
  7423. flush_count += it.StockCount
  7424. }
  7425. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7426. //查询剩余库存
  7427. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7428. var sum_count int64
  7429. for _, item := range goodList {
  7430. sum_count += item.StockCount
  7431. }
  7432. // 在出库记录表里记录退库详情
  7433. warehouseOutInfo := &models.WarehouseOutInfo{
  7434. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7435. WarehouseOutId: warehouseOut.ID,
  7436. Status: 1,
  7437. Ctime: time.Now().Unix(),
  7438. OrgId: adminInfo.Org.Id,
  7439. Type: 1,
  7440. IsSys: 1,
  7441. SysRecordTime: record_time,
  7442. GoodTypeId: item.GoodTypeId,
  7443. GoodId: item.GoodId,
  7444. PatientId: patient_id,
  7445. ConsumableType: 2,
  7446. StorehouseId: houseConfig.StorehouseOutInfo,
  7447. IsCheck: 1,
  7448. OverCount: sum_count,
  7449. }
  7450. warehouseOutInfo.Count = item.Count
  7451. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7452. warehouseOutInfo.Price = stockInInfo.Price
  7453. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7454. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7455. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7456. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7457. warehouseOutInfo.Number = warehouseOutInfos.Number
  7458. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7459. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7460. //查找当天是否存在出库记录
  7461. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7462. if errcod == gorm.ErrRecordNotFound {
  7463. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7464. //插入详情明细表
  7465. stockFlow := models.VmStockFlow{
  7466. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7467. WarehouseOutId: warehouseOut.ID,
  7468. GoodId: item.GoodId,
  7469. Number: warehouseOutInfos.Number,
  7470. ProductDate: stockInInfo.ProductDate,
  7471. ExpireDate: stockInInfo.ExpiryDate,
  7472. Count: item.Count,
  7473. Price: stockInInfo.Price,
  7474. Status: 1,
  7475. Ctime: record_time,
  7476. UserOrgId: adminInfo.Org.Id,
  7477. Manufacturer: stockInInfo.Manufacturer,
  7478. Dealer: stockInInfo.Dealer,
  7479. LicenseNumber: stockInInfo.LicenseNumber,
  7480. IsEdit: 2,
  7481. Creator: creater,
  7482. SystemTime: record_time,
  7483. ConsumableType: 3,
  7484. WarehousingDetailId: 0,
  7485. IsSys: 1,
  7486. UpdateCreator: creater,
  7487. PatientId: patient_id,
  7488. StorehouseId: houseConfig.StorehouseOutInfo,
  7489. }
  7490. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7491. if errflow == gorm.ErrRecordNotFound {
  7492. //创建流水表
  7493. err := service.CreateStockFlowOne(stockFlow)
  7494. fmt.Println("err", err)
  7495. } else if errflow == nil {
  7496. //插入详情明细表
  7497. stockFlow := models.VmStockFlow{
  7498. ID: exsit.ID,
  7499. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7500. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7501. WarehouseOutId: warehouseOut.ID,
  7502. GoodId: item.GoodId,
  7503. Number: warehouseOutInfos.Number,
  7504. ProductDate: stockInInfo.ProductDate,
  7505. ExpireDate: stockInInfo.ExpiryDate,
  7506. Count: exsit.Count - delete_count,
  7507. Price: stockInInfo.Price,
  7508. Status: 1,
  7509. Ctime: record_time,
  7510. UserOrgId: adminInfo.Org.Id,
  7511. Manufacturer: stockInInfo.Manufacturer,
  7512. Dealer: stockInInfo.Dealer,
  7513. LicenseNumber: stockInInfo.LicenseNumber,
  7514. IsEdit: 2,
  7515. Creator: creater,
  7516. SystemTime: record_time,
  7517. ConsumableType: 3,
  7518. WarehousingDetailId: 0,
  7519. IsSys: 1,
  7520. UpdateCreator: creater,
  7521. PatientId: patient_id,
  7522. StorehouseId: houseConfig.StorehouseOutInfo,
  7523. }
  7524. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7525. }
  7526. } else if errcod == nil {
  7527. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7528. //查询剩余库存
  7529. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7530. var sum_count int64
  7531. for _, item := range goodList {
  7532. sum_count += item.StockCount
  7533. }
  7534. //创建退库单,生成退库数据
  7535. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7536. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7537. operation_time := time.Now().Unix()
  7538. creater := adminInfo.AdminUser.Id
  7539. //创建退库单
  7540. timeStr := time.Now().Format("2006-01-02")
  7541. timeArr := strings.Split(timeStr, "-")
  7542. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7543. total = total + 1
  7544. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7545. cancelStock := models.CancelStock{
  7546. OrderNumber: orderNumber,
  7547. OperaTime: operation_time,
  7548. OrgId: adminInfo.Org.Id,
  7549. Creater: creater,
  7550. Ctime: time.Now().Unix(),
  7551. Status: 1,
  7552. ReturnTime: record_time,
  7553. Type: 1,
  7554. StorehouseId: houseConfig.StorehouseOutInfo,
  7555. IsCheck: 1,
  7556. }
  7557. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7558. if msgerrkonde == gorm.ErrRecordNotFound {
  7559. service.AddSigleCancelStock(&cancelStock)
  7560. }
  7561. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7562. //查询是否有出库
  7563. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7564. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7565. deaerler, _ := service.GetDealerById(info.Dealer)
  7566. if info.ID > 0 {
  7567. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7568. cancelStockInfo := models.CancelStockInfo{
  7569. GoodId: item.GoodId,
  7570. CancelStockId: cancel.ID,
  7571. GoodTypeId: good.GoodTypeId,
  7572. Count: delete_count,
  7573. Price: info.Price,
  7574. Total: 0,
  7575. ProductDate: info.ProductDate,
  7576. ExpiryDate: info.ExpiryDate,
  7577. Ctime: time.Now().Unix(),
  7578. Status: 1,
  7579. OrgId: adminInfo.Org.Id,
  7580. OrderNumber: cancel.OrderNumber,
  7581. Type: 0,
  7582. Dealer: deaerler.DealerName,
  7583. Manufacturer: manufacturer.ManufacturerName,
  7584. Number: info.Number,
  7585. RegisterAccount: "",
  7586. Remark: "",
  7587. WarehouseInfoId: info.WarehouseInfotId,
  7588. PatientId: info.PatientId,
  7589. RecordDate: info.SysRecordTime,
  7590. StorehouseId: houseConfig.StorehouseOutInfo,
  7591. IsCheck: 1,
  7592. }
  7593. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7594. //退库数量增加
  7595. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7596. //查询剩余库存
  7597. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7598. var over_count int64
  7599. for _, it := range goodList {
  7600. over_count += it.StockCount
  7601. }
  7602. flow := models.VmStockFlow{
  7603. WarehousingId: info.WarehouseInfotId,
  7604. GoodId: item.GoodId,
  7605. Number: info.Number,
  7606. LicenseNumber: info.LicenseNumber,
  7607. Count: delete_count,
  7608. UserOrgId: adminInfo.Org.Id,
  7609. PatientId: patient_id,
  7610. SystemTime: info.SysRecordTime,
  7611. ConsumableType: 7,
  7612. IsSys: 0,
  7613. WarehousingOrder: "",
  7614. WarehouseOutId: info.WarehouseOutId,
  7615. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7616. IsEdit: 0,
  7617. CancelStockId: cancel.ID,
  7618. CancelOrderNumber: cancel.OrderNumber,
  7619. Manufacturer: manufacturer.ID,
  7620. Dealer: 0,
  7621. Creator: adminInfo.AdminUser.Id,
  7622. UpdateCreator: 0,
  7623. Status: 1,
  7624. Ctime: record_time,
  7625. Mtime: 0,
  7626. Price: info.Price,
  7627. WarehousingDetailId: info.WarehouseInfotId,
  7628. WarehouseOutDetailId: info.ID,
  7629. CancelOutDetailId: cancelInfo.ID,
  7630. ProductDate: info.ProductDate,
  7631. ExpireDate: info.ExpiryDate,
  7632. StorehouseId: houseConfig.StorehouseOutInfo,
  7633. OverCount: over_count,
  7634. }
  7635. service.CreateStockFlowOne(flow)
  7636. }
  7637. }
  7638. //更改自动出库的表格
  7639. details := models.BloodAutomaticReduceDetail{
  7640. WarehouseOutId: warehouseOutInfo.ID,
  7641. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7642. PatientId: patient_id,
  7643. Ctime: time.Now().Unix(),
  7644. Mtime: time.Now().Unix(),
  7645. Status: 1,
  7646. RecordTime: record_time,
  7647. OrgId: adminInfo.Org.Id,
  7648. GoodId: item.GoodId,
  7649. GoodTypeId: item.GoodTypeId,
  7650. Count: item.Count,
  7651. StorehouseId: houseConfig.StorehouseOutInfo,
  7652. }
  7653. //查询当天耗材是否已经存在数据
  7654. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7655. if errcode == gorm.ErrRecordNotFound {
  7656. service.CreateAutoReduceRecord(&details)
  7657. } else if errcode == nil {
  7658. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7659. service.CreateAutoReduceRecord(&details)
  7660. }
  7661. //查询默认仓库
  7662. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7663. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7664. var total_count int64
  7665. for _, it := range stockList {
  7666. total_count += it.StockCount
  7667. }
  7668. //基础库插入数据
  7669. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7670. }
  7671. }
  7672. if len(outbefor) > 0 {
  7673. //出库
  7674. for _, item := range outbefor {
  7675. var last_total int64
  7676. //1.查看该患者该耗材型号最后一次出库数量
  7677. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7678. //计算当前出库和最后一次出库数据相差数据
  7679. last_total = item.Count - goodInfoOne.Count
  7680. //查询该耗材的总库存
  7681. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7682. // 如果库存差大于剩余库存则提示库存不足
  7683. if last_total > wareinfo.StockCount {
  7684. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7685. c.ServeSuccessJSON(map[string]interface{}{
  7686. "message": "1",
  7687. "good_name": goodObj.GoodName,
  7688. "specification_name": goodObj.SpecificationName,
  7689. })
  7690. return
  7691. } else {
  7692. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7693. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7694. if err == gorm.ErrRecordNotFound {
  7695. //没有记录,则创建出库单
  7696. timeStr := time.Now().Format("2006-01-02")
  7697. timeArr := strings.Split(timeStr, "-")
  7698. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7699. total = total + 1
  7700. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7701. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7702. number = number + total
  7703. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7704. warehouseOut := models.WarehouseOut{
  7705. WarehouseOutOrderNumber: warehousing_out_order,
  7706. OperationTime: time.Now().Unix(),
  7707. OrgId: adminInfo.Org.Id,
  7708. Creater: adminInfo.AdminUser.Id,
  7709. Ctime: time.Now().Unix(),
  7710. Status: 1,
  7711. WarehouseOutTime: record_time,
  7712. Dealer: 0,
  7713. Manufacturer: 0,
  7714. Type: 1,
  7715. IsSys: 1,
  7716. StorehouseId: houseConfig.StorehouseOutInfo,
  7717. IsCheck: 1,
  7718. }
  7719. service.AddSigleWarehouseOutOne(&warehouseOut)
  7720. }
  7721. //出库
  7722. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7723. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7724. //1.查看该患者该耗材型号最后一次出库数量
  7725. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7726. prepare := models.DialysisBeforePrepare{
  7727. UserOrgId: adminInfo.Org.Id,
  7728. PatientId: patient_id,
  7729. RecordDate: record_time,
  7730. GoodId: item.GoodId,
  7731. GoodTypeId: item.GoodTypeId,
  7732. Count: item.Count - goodInfoTwo.Count,
  7733. Ctime: time.Now().Unix(),
  7734. Mtime: 0,
  7735. Creater: adminInfo.AdminUser.Id,
  7736. Modifier: adminInfo.AdminUser.Id,
  7737. Status: 1,
  7738. CommdityCode: "",
  7739. NewCount: 0,
  7740. ProjectId: 0,
  7741. StorehouseId: houseConfig.StorehouseOutInfo,
  7742. }
  7743. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7744. //增加出库数量
  7745. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7746. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7747. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7748. var total_count int64
  7749. for _, it := range stockList {
  7750. total_count += it.StockCount
  7751. }
  7752. //基础库插入数据
  7753. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7754. //剩余库存
  7755. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7756. var flush_count int64
  7757. for _, it := range goodList {
  7758. flush_count += it.StockCount
  7759. }
  7760. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7761. }
  7762. }
  7763. }
  7764. //查询今日出库数据
  7765. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7766. for _, it := range list {
  7767. prepare := models.DialysisBeforePrepare{
  7768. UserOrgId: it.OrgId,
  7769. PatientId: patient_id,
  7770. RecordDate: it.RecordTime,
  7771. GoodId: it.GoodId,
  7772. GoodTypeId: it.GoodTypeId,
  7773. Count: it.Count,
  7774. Ctime: time.Now().Unix(),
  7775. Creater: adminInfo.AdminUser.Id,
  7776. Status: 1,
  7777. StorehouseId: houseConfig.StorehouseOutInfo,
  7778. ProjectId: it.ProjectId,
  7779. }
  7780. //删除准备表数据
  7781. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7782. service.CreateDialysisBeforePrepareOne(&prepare)
  7783. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7784. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7785. var total_count int64
  7786. for _, it := range stockList {
  7787. total_count += it.StockCount
  7788. }
  7789. //基础库插入数据
  7790. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7791. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7792. var flush_count int64
  7793. for _, it := range goodList {
  7794. flush_count += it.StockCount
  7795. }
  7796. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7797. }
  7798. }
  7799. }
  7800. //更新自动出库的地方
  7801. var errs error
  7802. if errs == nil {
  7803. c.ServeSuccessJSON(map[string]interface{}{
  7804. "msg": "修改成功",
  7805. "message": "2",
  7806. "good_name": "",
  7807. "specification_name": "",
  7808. })
  7809. return
  7810. } else {
  7811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7812. return
  7813. }
  7814. }
  7815. }
  7816. func (c *DialysisAPIController) GetDialysisGoods() {
  7817. schedualDate := c.GetString("schedule_date")
  7818. schedule_type, _ := c.GetInt64("schedule_type")
  7819. partition_id, _ := c.GetInt64("partition_id")
  7820. page, _ := c.GetInt("page")
  7821. patient_id, _ := c.GetInt64("patient_id")
  7822. schedualEndDate := int64(0)
  7823. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7824. if parseDateErr != nil && len(schedualDate) != 0 {
  7825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7826. return
  7827. }
  7828. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7829. if parseDateErr != nil && len(schedualDate) != 0 {
  7830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7831. return
  7832. }
  7833. schedualEndDate = endDate.Unix()
  7834. adminUser := c.GetMobileAdminUserInfo()
  7835. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7836. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7837. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7838. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7839. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7840. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7841. //获取当天该病人的透析处方
  7842. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7843. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7844. if err == gorm.ErrRecordNotFound {
  7845. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7846. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7847. if patient_id != 0 {
  7848. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7849. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7850. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7851. //获取患者总的出库数据
  7852. item.LastAutomaticReduceDetail = goodUser
  7853. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7854. item.Project = project
  7855. for _, it := range item.AutomaticReduceDetail {
  7856. var total int64
  7857. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7858. for _, its := range auto {
  7859. total += its.Count
  7860. }
  7861. it.Count = total
  7862. }
  7863. }
  7864. }
  7865. c.ServeSuccessJSON(map[string]interface{}{
  7866. "dialysis_goods": dialysisGoods,
  7867. "good_type": goodTypes,
  7868. "total": total,
  7869. "prescribe": prescribe,
  7870. "good_info": good_info,
  7871. "warehouseOutList": warehouseOutList,
  7872. "config": config,
  7873. "outConfig": outConfig,
  7874. "settleConfig": settleConfig,
  7875. })
  7876. return
  7877. } else if err == nil {
  7878. //获取当天排班的每个患者的库存使用情况
  7879. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7880. //获取患者总的出库数据
  7881. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7882. if patient_id != 0 {
  7883. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7884. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7885. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7886. item.Project = project
  7887. item.LastAutomaticReduceDetail = goodUser
  7888. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7889. for _, it := range item.AutomaticReduceDetail {
  7890. var total int64
  7891. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7892. for _, its := range auto {
  7893. total += its.Count
  7894. }
  7895. it.Count = total
  7896. }
  7897. }
  7898. }
  7899. if err == nil {
  7900. c.ServeSuccessJSON(map[string]interface{}{
  7901. "dialysis_goods": dialysisGoods,
  7902. "good_type": goodTypes,
  7903. "total": total,
  7904. "prescribe": prescribe,
  7905. "good_info": good_info,
  7906. "project": project,
  7907. "warehouseOutList": warehouseOutList,
  7908. "config": config,
  7909. "outConfig": outConfig,
  7910. "settleConfig": settleConfig,
  7911. })
  7912. return
  7913. } else {
  7914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7915. return
  7916. }
  7917. } else if err != nil {
  7918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7919. return
  7920. }
  7921. }
  7922. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7923. start_time := c.GetString("start_time")
  7924. end_time := c.GetString("end_time")
  7925. timeLayout := "2006-01-02"
  7926. loc, _ := time.LoadLocation("Local")
  7927. var theStartTime int64
  7928. if len(start_time) > 0 {
  7929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7930. if err != nil {
  7931. utils.ErrorLog(err.Error())
  7932. }
  7933. theStartTime = theTime.Unix()
  7934. }
  7935. var theEndtTime int64
  7936. if len(end_time) > 0 {
  7937. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7938. if err != nil {
  7939. utils.ErrorLog(err.Error())
  7940. }
  7941. theEndtTime = theTime.Unix()
  7942. }
  7943. adminUser := c.GetMobileAdminUserInfo()
  7944. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7945. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7946. if err == nil {
  7947. c.ServeSuccessJSON(map[string]interface{}{
  7948. "stock_out": outInfo,
  7949. "stockCount": stockCount,
  7950. })
  7951. return
  7952. } else {
  7953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7954. return
  7955. }
  7956. }
  7957. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7958. patient_id, _ := c.GetInt64("patient_id", 0)
  7959. record_time := c.GetString("record_time")
  7960. adminUser := c.GetMobileAdminUserInfo()
  7961. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7962. if parseDateErr != nil && len(record_time) != 0 {
  7963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7964. return
  7965. }
  7966. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7967. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7968. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7969. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7970. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7971. //获取今日患者的透析处方参数
  7972. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7973. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7974. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7975. c.ServeSuccessJSON(map[string]interface{}{
  7976. "good_type": goodTypes,
  7977. "good_user": goodUser,
  7978. "good_info": good_info,
  7979. "last_good_user": lastGoodUserDetial,
  7980. "project": project,
  7981. "prescription": prescribe,
  7982. "outInfo": outInfo,
  7983. "configs": configs,
  7984. })
  7985. return
  7986. }
  7987. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7988. patient_id, _ := c.GetInt64("patient_id", 0)
  7989. record_date := c.GetString("record_time")
  7990. timeLayout := "2006-01-02"
  7991. loc, _ := time.LoadLocation("Local")
  7992. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7993. record_time := theRecordTime.Unix()
  7994. adminInfo := c.GetMobileAdminUserInfo()
  7995. dataBody := make(map[string]interface{}, 0)
  7996. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7997. if err != nil {
  7998. utils.ErrorLog(err.Error())
  7999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8000. return
  8001. }
  8002. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8003. var beforePrepares []*models.DialysisBeforePrepareGoods
  8004. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  8005. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  8006. goods, _ := dataBody["goods"].([]interface{})
  8007. if len(goods) > 0 {
  8008. for _, item := range goods {
  8009. items := item.(map[string]interface{})
  8010. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  8011. utils.ErrorLog("good_id")
  8012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8013. return
  8014. }
  8015. good_id := int64(items["good_id"].(float64))
  8016. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  8017. utils.ErrorLog("good_type_id")
  8018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8019. return
  8020. }
  8021. good_type_id := int64(items["good_type_id"].(float64))
  8022. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  8023. utils.ErrorLog("count")
  8024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8025. return
  8026. }
  8027. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  8028. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  8029. utils.ErrorLog("project_id")
  8030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8031. return
  8032. }
  8033. project_id := int64(items["project_id"].(float64))
  8034. new_count := int64(items["new_count"].(float64))
  8035. old_count := int64(items["old_count"].(float64))
  8036. prepare := &models.DialysisBeforePrepareGoods{
  8037. GoodId: good_id,
  8038. GoodTypeId: good_type_id,
  8039. Count: count,
  8040. ProjectId: project_id,
  8041. StorehouseId: houseConfig.StorehouseOutInfo,
  8042. NewCount: new_count,
  8043. OldCount: old_count,
  8044. }
  8045. beforePrepares = append(beforePrepares, prepare)
  8046. newPrepare := &models.NewDialysisBeforePrepareGoods{
  8047. GoodId: good_id,
  8048. GoodTypeId: good_type_id,
  8049. Count: count,
  8050. ProjectId: project_id,
  8051. StorehouseId: houseConfig.StorehouseOutInfo,
  8052. NewCount: new_count,
  8053. OldCount: old_count,
  8054. }
  8055. newBeforePrepares = append(newBeforePrepares, newPrepare)
  8056. }
  8057. }
  8058. }
  8059. //查询是否有库存
  8060. for _, item := range beforePrepares {
  8061. if item.NewCount > 0 {
  8062. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8063. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  8064. if item.Count > warehouse.Count {
  8065. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  8066. c.ServeSuccessJSON(map[string]interface{}{
  8067. "message": "1",
  8068. "good_name": goodObj.GoodName,
  8069. "specification_name": goodObj.SpecificationName,
  8070. })
  8071. return
  8072. }
  8073. }
  8074. }
  8075. // 查询信息规挡的设置天数
  8076. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  8077. if infor.ID > 0 && infor.WeekDay > 0 {
  8078. var cha_time int64
  8079. timeNowStr := time.Now().Format("2006-01-02")
  8080. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  8081. //今日的日期减去设置的日期
  8082. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  8083. if cha_time >= record_time {
  8084. //查询审核是否允许
  8085. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  8086. //申请状态不允许的情况 拒绝修改
  8087. if infor.ApplicationStatus != 1 {
  8088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  8089. return
  8090. }
  8091. }
  8092. }
  8093. //出库逻辑
  8094. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  8095. if err != nil {
  8096. utils.ErrorLog(err.Error())
  8097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8098. return
  8099. }
  8100. finish := models.XtDialysisFinish{
  8101. IsFinish: 1,
  8102. UserOrgId: adminInfo.Org.Id,
  8103. Status: 1,
  8104. Ctime: time.Now().Unix(),
  8105. Mtime: 0,
  8106. Module: 11,
  8107. RecordDate: record_time,
  8108. Sourse: 1,
  8109. PatientId: patient_id,
  8110. }
  8111. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  8112. if dialysisFinish.ID == 0 {
  8113. service.CreateDialysisFinish(finish)
  8114. }
  8115. //查询当天出库的数据
  8116. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  8117. for _, item := range list {
  8118. prepare := models.DialysisBeforePrepare{
  8119. UserOrgId: item.OrgId,
  8120. PatientId: item.PatientId,
  8121. RecordDate: item.RecordTime,
  8122. GoodId: item.GoodId,
  8123. GoodTypeId: item.GoodTypeId,
  8124. Count: item.Count,
  8125. Creater: adminInfo.AdminUser.Id,
  8126. Status: 1,
  8127. Ctime: time.Now().Unix(),
  8128. ProjectId: item.ProjectId,
  8129. StorehouseId: houseConfig.StorehouseOutInfo,
  8130. }
  8131. //清空准备表的数据
  8132. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  8133. //插入准备表数据
  8134. service.CreateDialysisBeforePrepareOne(&prepare)
  8135. //查询默认仓库
  8136. //查询默认仓库
  8137. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  8138. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  8139. var total_count int64
  8140. for _, it := range stockList {
  8141. total_count += it.StockCount
  8142. }
  8143. //基础库插入数据
  8144. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  8145. ////更新剩余库存
  8146. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  8147. var flush_count int64
  8148. for _, it := range goodList {
  8149. flush_count += it.StockCount
  8150. }
  8151. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  8152. if errs != nil {
  8153. goodErrcode := models.XtGoodErrcode{
  8154. UserOrgId: item.OrgId,
  8155. Errcode: "手动出库更新剩余出库失败",
  8156. GoodId: item.GoodId,
  8157. Status: 1,
  8158. Ctime: time.Now().Unix(),
  8159. Mtime: 0,
  8160. Count: 0,
  8161. StockCount: 0,
  8162. Creater: adminInfo.AdminUser.Id,
  8163. BatchNumberId: 0,
  8164. WarehouseOutId: 0,
  8165. }
  8166. service.CreateGoodErrcode(goodErrcode)
  8167. }
  8168. }
  8169. //更新自动出库的地方
  8170. var errs error
  8171. if errs == nil {
  8172. c.ServeSuccessJSON(map[string]interface{}{
  8173. "msg": "修改成功",
  8174. "message": "2",
  8175. "good_name": "",
  8176. "specification_name": "",
  8177. })
  8178. return
  8179. } else {
  8180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8181. return
  8182. }
  8183. }
  8184. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8185. newArr = make([]*models.DialysisBeforePrepare, 0)
  8186. for i := 0; i < len(arr); i++ {
  8187. repeat := false
  8188. for j := i + 1; j < len(arr); j++ {
  8189. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  8190. repeat = true
  8191. break
  8192. }
  8193. }
  8194. if !repeat {
  8195. newArr = append(newArr, arr[i])
  8196. }
  8197. }
  8198. return
  8199. }
  8200. func (c *DialysisAPIController) GetAllDrug() {
  8201. patient_id, _ := c.GetInt64("patient_id", 0)
  8202. adminInfo := c.GetMobileAdminUserInfo()
  8203. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  8204. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  8205. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  8206. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  8207. c.ServeSuccessJSON(map[string]interface{}{
  8208. "base_drug_config": drugStockConfig,
  8209. "private_drug_config": privateDrugConfig,
  8210. "base_drug_list": drugList,
  8211. "private_drug_list": privateDrugList,
  8212. })
  8213. }
  8214. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  8215. newArr = make([]*models.DialysisBeforePrepare, 0)
  8216. for i := 0; i < len(arr); i++ {
  8217. repeat := false
  8218. for j := i + 1; j < len(arr); j++ {
  8219. if arr[i].GoodId == arr[j].GoodId {
  8220. repeat = true
  8221. break
  8222. }
  8223. }
  8224. if !repeat {
  8225. newArr = append(newArr, arr[i])
  8226. }
  8227. }
  8228. return
  8229. }
  8230. func (c *DialysisAPIController) GetDepartment() {
  8231. adminInfo := c.GetMobileAdminUserInfo()
  8232. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8233. if err == nil {
  8234. c.ServeSuccessJSON(map[string]interface{}{
  8235. "departments": departments,
  8236. })
  8237. } else {
  8238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8239. return
  8240. }
  8241. }
  8242. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8243. types, _ := c.GetInt("type", 0)
  8244. start_time := c.GetString("start_time")
  8245. end_time := c.GetString("end_time")
  8246. orgId := c.GetMobileAdminUserInfo().Org.Id
  8247. timeLayout := "2006-01-02"
  8248. loc, _ := time.LoadLocation("Local")
  8249. var startTime int64
  8250. if len(start_time) > 0 {
  8251. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8252. if err != nil {
  8253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8254. return
  8255. }
  8256. startTime = theTime.Unix()
  8257. }
  8258. var endTime int64
  8259. if len(end_time) > 0 {
  8260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8261. if err != nil {
  8262. utils.ErrorLog(err.Error())
  8263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8264. return
  8265. }
  8266. endTime = theTime.Unix()
  8267. }
  8268. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8269. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8270. if err != nil {
  8271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8272. } else {
  8273. c.ServeSuccessJSON(map[string]interface{}{
  8274. "list": list,
  8275. "type": types,
  8276. "stockTotal": stockTotal,
  8277. })
  8278. }
  8279. }
  8280. func (c *DialysisAPIController) GetPrescriptionList() {
  8281. start_time := c.GetString("start_time")
  8282. end_time := c.GetString("end_time")
  8283. schedule_type, _ := c.GetInt64("schedule_type")
  8284. partion_id, _ := c.GetInt64("partion_id")
  8285. orgId := c.GetMobileAdminUserInfo().Org.Id
  8286. timeLayout := "2006-01-02"
  8287. loc, _ := time.LoadLocation("Local")
  8288. var startTime int64
  8289. if len(start_time) > 0 {
  8290. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8291. if err != nil {
  8292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8293. return
  8294. }
  8295. startTime = theTime.Unix()
  8296. }
  8297. var endTime int64
  8298. if len(end_time) > 0 {
  8299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8300. if err != nil {
  8301. utils.ErrorLog(err.Error())
  8302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8303. return
  8304. }
  8305. endTime = theTime.Unix()
  8306. }
  8307. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8308. fmt.Println("schedulelist22222222", schedulelist)
  8309. c.ServeSuccessJSON(map[string]interface{}{
  8310. "list": schedulelist,
  8311. })
  8312. return
  8313. }
  8314. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8315. ids := c.GetString("ids")
  8316. //patient_id, _ := c.GetInt64("patient_id")
  8317. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8318. idArray := strings.Split(ids, ",")
  8319. err := service.BatchDeleteMonitor(idArray)
  8320. fmt.Print("err", err)
  8321. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8322. //redis := service.RedisClient()
  8323. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8324. //redis.Set(key, "", time.Second)
  8325. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8326. //redis.Set(keyOne, "", time.Second)
  8327. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8328. //redis.Close()
  8329. c.ServeSuccessJSON(map[string]interface{}{
  8330. "msg": "批量删除成功",
  8331. })
  8332. return
  8333. }
  8334. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8335. id, _ := c.GetInt64("id")
  8336. timeLayout := "2006-01-02"
  8337. loc, _ := time.LoadLocation("Local")
  8338. //start_time := time.Now().Format("2006-01-02")
  8339. start_time := c.GetString("start_time")
  8340. end_time := c.GetString("end_time")
  8341. var startdateunix int64
  8342. if len(start_time) > 0 {
  8343. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8344. if err != nil {
  8345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8346. return
  8347. }
  8348. startdateunix = theTime.Unix()
  8349. }
  8350. var enddateunix int64
  8351. if len(end_time) > 0 {
  8352. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8353. if err != nil {
  8354. utils.ErrorLog(err.Error())
  8355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8356. return
  8357. }
  8358. enddateunix = theTime.Unix()
  8359. }
  8360. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8361. //nowTime := time.Now()
  8362. //endTime := nowTime.AddDate(-30, 0, 0)
  8363. //endTimes := endTime.Format("2006-01-02")
  8364. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8365. org_id := c.GetMobileAdminUserInfo().Org.Id
  8366. //if org_id == 10579 {
  8367. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8368. // c.ServeSuccessJSON(map[string]interface{}{
  8369. // "list": list,
  8370. // })
  8371. // return
  8372. //} else {
  8373. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8374. // c.ServeSuccessJSON(map[string]interface{}{
  8375. // "list": list,
  8376. // })
  8377. // return
  8378. //}
  8379. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8380. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8381. c.ServeSuccessJSON(map[string]interface{}{
  8382. "list": list,
  8383. })
  8384. return
  8385. } else {
  8386. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8387. c.ServeSuccessJSON(map[string]interface{}{
  8388. "list": list,
  8389. })
  8390. }
  8391. return
  8392. }
  8393. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8394. dataBody := make(map[string]interface{}, 0)
  8395. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8396. ids := c.GetString("ids")
  8397. idArray := strings.Split(ids, ",")
  8398. origin, _ := c.GetInt64("origin")
  8399. if origin == 1 {
  8400. err = service.BatchDeleteAdvice(idArray)
  8401. fmt.Print("err", err)
  8402. c.ServeSuccessJSON(map[string]interface{}{
  8403. "msg": "批量删除成功",
  8404. })
  8405. return
  8406. }
  8407. if origin == 2 {
  8408. service.BatchDeleteHisAdvice(idArray)
  8409. }
  8410. }
  8411. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8412. good_id, _ := c.GetInt64("good_id")
  8413. count, _ := c.GetInt64("count")
  8414. record_time, _ := c.GetInt64("record_time")
  8415. patient_id, _ := c.GetInt64("patient_id")
  8416. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8417. c.ServeSuccessJSON(map[string]interface{}{
  8418. "detail": detail,
  8419. })
  8420. return
  8421. }
  8422. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8423. good_id, _ := c.GetInt64("good_id")
  8424. record_time, _ := c.GetInt64("record_time")
  8425. patient_id, _ := c.GetInt64("patient_id")
  8426. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8427. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8428. fmt.Print("err", err)
  8429. c.ServeSuccessJSON(map[string]interface{}{
  8430. "msg": "批量删除成功",
  8431. })
  8432. return
  8433. }
  8434. func (c *DialysisAPIController) BatchAdviceCheck() {
  8435. ids := c.GetString("ids")
  8436. idArray := strings.Split(ids, ",")
  8437. creator, _ := c.GetInt64("creator")
  8438. origin, _ := c.GetInt64("origin")
  8439. if origin == 1 {
  8440. err := service.BatchAdviceCheck(idArray, creator)
  8441. fmt.Println(err)
  8442. list, _ := service.GetAdviceExecutionById(idArray)
  8443. c.ServeSuccessJSON(map[string]interface{}{
  8444. "list": list,
  8445. })
  8446. return
  8447. }
  8448. if origin == 2 {
  8449. service.BatchHisAdviceCheck(idArray, creator)
  8450. list, _ := service.GetHisAdviceExecutionById(idArray)
  8451. c.ServeSuccessJSON(map[string]interface{}{
  8452. "list": list,
  8453. })
  8454. return
  8455. }
  8456. }
  8457. func (c *DialysisAPIController) BatchAdviceExecution() {
  8458. ids := c.GetString("ids")
  8459. idArray := strings.Split(ids, ",")
  8460. executionTime := c.GetString("execution_time")
  8461. creator, _ := c.GetInt64("creator")
  8462. timeLayout := "2006-01-02 15:04:05"
  8463. loc, _ := time.LoadLocation("Local")
  8464. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8465. orgin, _ := c.GetInt64("origin")
  8466. if orgin == 1 {
  8467. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8468. list, _ := service.GetAdviceExecutionById(idArray)
  8469. fmt.Println(err)
  8470. c.ServeSuccessJSON(map[string]interface{}{
  8471. "list": list,
  8472. })
  8473. return
  8474. }
  8475. if orgin == 2 {
  8476. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8477. list, _ := service.GetHisAdviceExecutionById(idArray)
  8478. fmt.Println(err)
  8479. c.ServeSuccessJSON(map[string]interface{}{
  8480. "list": list,
  8481. })
  8482. return
  8483. }
  8484. }
  8485. func (c *DialysisAPIController) UpdateStockGoods() {
  8486. good_id, _ := c.GetInt64("good_id")
  8487. record_time, _ := c.GetInt64("record_time")
  8488. patient_id, _ := c.GetInt64("patient_id")
  8489. count, _ := c.GetInt64("count")
  8490. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8491. fmt.Print("err", err)
  8492. c.ServeSuccessJSON(map[string]interface{}{
  8493. "msg": "更新成功",
  8494. })
  8495. return
  8496. }
  8497. // 当前数据比上一次出库数据少
  8498. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8499. //查询该患者当天已经出库的耗材信息
  8500. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8501. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8502. for i := len(goods_yc) - 1; i >= 0; i-- {
  8503. goods_yc_temp := goods_yc[i]
  8504. for j := len(goods) - 1; j >= 0; j-- {
  8505. goods_temp := goods[j]
  8506. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8507. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8508. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8509. if goods_yc_temp.Count == goods_temp.Count {
  8510. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8511. goods = append(goods[:j], goods[j+1:]...)
  8512. break
  8513. }
  8514. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8515. if goods_yc_temp.Count > goods_temp.Count {
  8516. temp_count := goods_yc_temp.Count - goods_temp.Count
  8517. goods_yc[i].Count = temp_count
  8518. goods = append(goods[:j], goods[j+1:]...)
  8519. break
  8520. }
  8521. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8522. if goods_yc_temp.Count < goods_temp.Count {
  8523. temp_count := goods_temp.Count - goods_yc_temp.Count
  8524. goods[j].Count = temp_count
  8525. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8526. break
  8527. }
  8528. }
  8529. }
  8530. }
  8531. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8532. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8533. //退库
  8534. if len(goods_yc) > 0 {
  8535. for _, good_yc := range goods_yc {
  8536. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8537. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8538. }
  8539. }
  8540. return nil
  8541. }
  8542. // 耗材出库删除
  8543. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8544. // 先根据相关信息查询当天该耗材的出库信息
  8545. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8546. if err != nil {
  8547. return err
  8548. }
  8549. var delete_count int64 = 0
  8550. delete_count = warehouseOutInfos.Count - count
  8551. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8552. // 在出库记录表里记录退库详情
  8553. warehouseOutInfo := &models.WarehouseOutInfo{
  8554. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8555. WarehouseOutId: warehouseOut.ID,
  8556. Status: 1,
  8557. Ctime: time.Now().Unix(),
  8558. OrgId: orgID,
  8559. Type: 1,
  8560. IsSys: 1,
  8561. SysRecordTime: record_time,
  8562. GoodTypeId: good_yc.GoodTypeId,
  8563. GoodId: good_yc.GoodId,
  8564. PatientId: good_yc.PatientId,
  8565. ConsumableType: 2,
  8566. StorehouseId: houseConfig.StorehouseOutInfo,
  8567. IsCheck: 1,
  8568. }
  8569. warehouseOutInfo.Count = count
  8570. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8571. warehouseOutInfo.Price = stockInInfo.Price
  8572. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8573. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8574. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8575. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8576. warehouseOutInfo.Number = warehouseOutInfos.Number
  8577. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8578. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8579. //查找当天是否存在出库记录
  8580. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8581. if errcod == gorm.ErrRecordNotFound {
  8582. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8583. //插入详情明细表
  8584. stockFlow := models.VmStockFlow{
  8585. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8586. WarehouseOutId: warehouseOut.ID,
  8587. GoodId: good_yc.GoodId,
  8588. Number: warehouseOutInfos.Number,
  8589. ProductDate: stockInInfo.ProductDate,
  8590. ExpireDate: stockInInfo.ExpiryDate,
  8591. Count: count,
  8592. Price: stockInInfo.Price,
  8593. Status: 1,
  8594. Ctime: time.Now().Unix(),
  8595. UserOrgId: good_yc.OrgId,
  8596. Manufacturer: stockInInfo.Manufacturer,
  8597. Dealer: stockInInfo.Dealer,
  8598. LicenseNumber: stockInInfo.LicenseNumber,
  8599. IsEdit: 2,
  8600. Creator: creater,
  8601. SystemTime: record_time,
  8602. ConsumableType: 3,
  8603. WarehousingDetailId: 0,
  8604. IsSys: 1,
  8605. UpdateCreator: creater,
  8606. PatientId: patient_id,
  8607. StorehouseId: houseConfig.StorehouseOutInfo,
  8608. }
  8609. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8610. if errflow == gorm.ErrRecordNotFound {
  8611. //创建流水表
  8612. err := service.CreateStockFlowOne(stockFlow)
  8613. fmt.Println("err", err)
  8614. } else if errflow == nil {
  8615. //插入详情明细表
  8616. stockFlow := models.VmStockFlow{
  8617. ID: exsit.ID,
  8618. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8619. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8620. WarehouseOutId: warehouseOut.ID,
  8621. GoodId: good_yc.GoodId,
  8622. Number: warehouseOutInfos.Number,
  8623. ProductDate: stockInInfo.ProductDate,
  8624. ExpireDate: stockInInfo.ExpiryDate,
  8625. Count: exsit.Count - delete_count,
  8626. Price: stockInInfo.Price,
  8627. Status: 1,
  8628. Ctime: time.Now().Unix(),
  8629. UserOrgId: good_yc.OrgId,
  8630. Manufacturer: stockInInfo.Manufacturer,
  8631. Dealer: stockInInfo.Dealer,
  8632. LicenseNumber: stockInInfo.LicenseNumber,
  8633. IsEdit: 2,
  8634. Creator: creater,
  8635. SystemTime: record_time,
  8636. ConsumableType: 3,
  8637. WarehousingDetailId: 0,
  8638. IsSys: 1,
  8639. UpdateCreator: creater,
  8640. PatientId: patient_id,
  8641. StorehouseId: houseConfig.StorehouseOutInfo,
  8642. }
  8643. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8644. }
  8645. if errOne != nil {
  8646. return errOne
  8647. }
  8648. } else if errcod == nil {
  8649. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8650. //插入详情明细表
  8651. stockFlow := models.VmStockFlow{
  8652. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8653. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8654. WarehouseOutId: warehouseOut.ID,
  8655. GoodId: good_yc.GoodId,
  8656. Number: warehouseOutInfos.Number,
  8657. ProductDate: stockInInfo.ProductDate,
  8658. ExpireDate: stockInInfo.ExpiryDate,
  8659. Count: count,
  8660. Price: stockInInfo.Price,
  8661. Status: 1,
  8662. Ctime: time.Now().Unix(),
  8663. UserOrgId: good_yc.OrgId,
  8664. Manufacturer: stockInInfo.Manufacturer,
  8665. Dealer: stockInInfo.Dealer,
  8666. LicenseNumber: stockInInfo.LicenseNumber,
  8667. IsEdit: 2,
  8668. Creator: creater,
  8669. SystemTime: record_time,
  8670. ConsumableType: 3,
  8671. WarehousingDetailId: 0,
  8672. IsSys: 1,
  8673. UpdateCreator: creater,
  8674. PatientId: patient_id,
  8675. ReturnCount: delete_count,
  8676. StorehouseId: houseConfig.StorehouseOutInfo,
  8677. }
  8678. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8679. if errflows == gorm.ErrRecordNotFound {
  8680. //创建流水表
  8681. service.CreateStockFlowOne(stockFlow)
  8682. } else if errflows == nil {
  8683. stockFlow := models.VmStockFlow{
  8684. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8685. ID: exsit.ID,
  8686. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8687. WarehouseOutId: warehouseOut.ID,
  8688. GoodId: good_yc.GoodId,
  8689. Number: warehouseOutInfos.Number,
  8690. ProductDate: stockInInfo.ProductDate,
  8691. ExpireDate: stockInInfo.ExpiryDate,
  8692. Count: exsit.Count - delete_count,
  8693. Price: stockInInfo.Price,
  8694. Status: 1,
  8695. Ctime: time.Now().Unix(),
  8696. UserOrgId: good_yc.OrgId,
  8697. Manufacturer: stockInInfo.Manufacturer,
  8698. Dealer: stockInInfo.Dealer,
  8699. LicenseNumber: stockInInfo.LicenseNumber,
  8700. IsEdit: 2,
  8701. Creator: creater,
  8702. SystemTime: record_time,
  8703. ConsumableType: 3,
  8704. WarehousingDetailId: 0,
  8705. IsSys: 1,
  8706. UpdateCreator: creater,
  8707. PatientId: patient_id,
  8708. ReturnCount: delete_count,
  8709. StorehouseId: houseConfig.StorehouseOutInfo,
  8710. }
  8711. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8712. }
  8713. }
  8714. //更改自动出库的表格
  8715. details := models.BloodAutomaticReduceDetail{
  8716. WarehouseOutId: warehouseOutInfo.ID,
  8717. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8718. PatientId: patient_id,
  8719. Ctime: time.Now().Unix(),
  8720. Mtime: time.Now().Unix(),
  8721. Status: 1,
  8722. RecordTime: record_time,
  8723. OrgId: orgID,
  8724. GoodId: good_yc.GoodId,
  8725. GoodTypeId: good_yc.GoodTypeId,
  8726. Count: count,
  8727. StorehouseId: houseConfig.StorehouseOutInfo,
  8728. }
  8729. //查询当天耗材是否已经存在数据
  8730. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8731. if errcode == gorm.ErrRecordNotFound {
  8732. errTwo := service.CreateAutoReduceRecord(&details)
  8733. if errTwo != nil {
  8734. return errTwo
  8735. }
  8736. } else if errcode == nil {
  8737. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8738. service.CreateAutoReduceRecord(&details)
  8739. }
  8740. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8741. //增加出库库存数量
  8742. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8743. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8744. fmt.Println("errOne", errOne)
  8745. // 删除出库完成后,要增加对应批次的库存数量
  8746. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8747. if errThree != nil {
  8748. return errThree
  8749. }
  8750. if good_yc.Count == 0 {
  8751. return nil
  8752. } else {
  8753. return errors.New("退库和出库数据不匹配")
  8754. }
  8755. }
  8756. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8757. //查询该患者当天已经出库的耗材信息
  8758. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8759. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8760. for i := len(goods_yc) - 1; i >= 0; i-- {
  8761. goods_yc_temp := goods_yc[i]
  8762. for j := len(goods) - 1; j >= 0; j-- {
  8763. goods_temp := goods[j]
  8764. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8765. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8766. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8767. if goods_yc_temp.Count == goods_temp.Count {
  8768. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8769. goods = append(goods[:j], goods[j+1:]...)
  8770. break
  8771. }
  8772. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8773. if goods_yc_temp.Count > goods_temp.Count {
  8774. temp_count := goods_yc_temp.Count - goods_temp.Count
  8775. goods_yc[i].Count = temp_count
  8776. goods = append(goods[:j], goods[j+1:]...)
  8777. break
  8778. }
  8779. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8780. if goods_yc_temp.Count < goods_temp.Count {
  8781. temp_count := goods_temp.Count - goods_yc_temp.Count
  8782. goods[j].Count = temp_count
  8783. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8784. break
  8785. }
  8786. }
  8787. }
  8788. }
  8789. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8790. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8791. fmt.Println("剩余需要出库的", len(goods))
  8792. if len(goods) > 0 {
  8793. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8794. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8795. if err == gorm.ErrRecordNotFound {
  8796. //没有记录,则创建出库单
  8797. timeStr := time.Now().Format("2006-01-02")
  8798. timeArr := strings.Split(timeStr, "-")
  8799. total, _ := service.FindAllWarehouseOut(orgID)
  8800. total = total + 1
  8801. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8802. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8803. number = number + total
  8804. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8805. warehouseOut := models.WarehouseOut{
  8806. WarehouseOutOrderNumber: warehousing_out_order,
  8807. OperationTime: time.Now().Unix(),
  8808. OrgId: orgID,
  8809. Creater: creater,
  8810. Ctime: time.Now().Unix(),
  8811. Status: 1,
  8812. WarehouseOutTime: record_time,
  8813. Dealer: 0,
  8814. Manufacturer: 0,
  8815. Type: 1,
  8816. IsSys: 1,
  8817. StorehouseId: houseConfig.StorehouseOutInfo,
  8818. IsCheck: 1,
  8819. }
  8820. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8821. if err != nil {
  8822. utils.TraceLog("创建出库单失败 err = %v", err)
  8823. return err
  8824. } else {
  8825. out = warehouseOut
  8826. }
  8827. }
  8828. for _, item := range goods {
  8829. var newCount int64 = 0
  8830. for _, it := range goodOne {
  8831. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8832. newCount = it.Count
  8833. }
  8834. }
  8835. prepare := models.DialysisBeforePrepare{
  8836. GoodTypeId: item.GoodTypeId,
  8837. GoodId: item.GoodId,
  8838. Count: item.Count,
  8839. StorehouseId: houseConfig.StorehouseOutInfo,
  8840. }
  8841. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8842. //增加出库数量
  8843. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8844. }
  8845. }
  8846. if len(goods_yc) > 0 {
  8847. for _, good_yc := range goods_yc {
  8848. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8849. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8850. }
  8851. }
  8852. return nil
  8853. }
  8854. // 耗材出库删除
  8855. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8856. // 先根据相关信息查询当天该耗材的出库信息
  8857. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8858. if err != nil {
  8859. return err
  8860. }
  8861. var delete_count int64 = 0
  8862. for _, ware := range warehouseOutInfos {
  8863. // 判断当前出库的数据和删除出库数量
  8864. if good_yc.Count <= ware.Count {
  8865. delete_count = good_yc.Count
  8866. } else {
  8867. delete_count = ware.Count
  8868. }
  8869. warehouseOutInfo := &models.WarehouseOutInfo{
  8870. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8871. WarehouseOutId: warehouseOut.ID,
  8872. Status: 1,
  8873. Ctime: time.Now().Unix(),
  8874. Remark: "",
  8875. OrgId: orgID,
  8876. Type: 1,
  8877. Manufacturer: 0,
  8878. Dealer: 0,
  8879. IsSys: 0,
  8880. SysRecordTime: record_time,
  8881. GoodTypeId: good_yc.GoodTypeId,
  8882. GoodId: good_yc.GoodId,
  8883. StorehouseId: warehouseOut.StorehouseId,
  8884. IsCheck: 1,
  8885. }
  8886. warehouseOutInfo.Count = delete_count
  8887. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8888. warehouseOutInfo.Price = stockInInfo.Price
  8889. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8890. if errOne != nil {
  8891. return errOne
  8892. }
  8893. // 删除出库完成后,要改变流水库存(有疑问)
  8894. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8895. fmt.Println("errOne", errOne)
  8896. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8897. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8898. //扣减出库数量
  8899. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8900. if errThree != nil {
  8901. return errThree
  8902. }
  8903. }
  8904. if good_yc.Count == 0 {
  8905. return nil
  8906. } else {
  8907. return errors.New("退库和出库数据不匹配")
  8908. }
  8909. }
  8910. func (this *DialysisAPIController) GetMobileScheduleList() {
  8911. limit, _ := this.GetInt64("limit")
  8912. page, _ := this.GetInt64("page")
  8913. type_options_visible, _ := this.GetInt64("type_options_visible")
  8914. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8915. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8916. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8917. }
  8918. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8919. newArr = make([]*models.HisPrescriptionProject, 0)
  8920. for i := 0; i < len(arr); i++ {
  8921. repeat := false
  8922. for j := i + 1; j < len(arr); j++ {
  8923. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8924. repeat = true
  8925. break
  8926. }
  8927. }
  8928. if !repeat {
  8929. newArr = append(newArr, arr[i])
  8930. }
  8931. }
  8932. return
  8933. }
  8934. func (this *DialysisAPIController) GetRoleList() {
  8935. admin_user_id, _ := this.GetInt64("admin_user_id")
  8936. orgid := this.GetMobileAdminUserInfo().Org.Id
  8937. list, err := service.GetRoleList(orgid, admin_user_id)
  8938. fmt.Println(err)
  8939. this.ServeSuccessJSON(map[string]interface{}{
  8940. "list": list,
  8941. })
  8942. return
  8943. }
  8944. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8945. // 先根据相关信息查询当天该耗材的出库信息
  8946. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8947. if err != nil {
  8948. return err
  8949. }
  8950. var delete_count int64 = 0
  8951. delete_count = warehouseOutInfos.Count - count
  8952. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8953. // 删除出库完成后,要增加对应批次的库存数量
  8954. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8955. if errThree != nil {
  8956. return errThree
  8957. }
  8958. //增加退库数量
  8959. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8960. //扣减出库数量
  8961. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8962. //查询剩余库存
  8963. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8964. var sum_count int64
  8965. for _, item := range goodList {
  8966. sum_count += item.StockCount
  8967. }
  8968. // 在出库记录表里记录退库详情
  8969. warehouseOutInfo := &models.WarehouseOutInfo{
  8970. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8971. WarehouseOutId: warehouseOut.ID,
  8972. Status: 1,
  8973. Ctime: time.Now().Unix(),
  8974. OrgId: orgID,
  8975. Type: 1,
  8976. IsSys: 1,
  8977. SysRecordTime: record_time,
  8978. GoodTypeId: good_yc.GoodTypeId,
  8979. GoodId: good_yc.GoodId,
  8980. PatientId: good_yc.PatientId,
  8981. ConsumableType: 2,
  8982. StorehouseId: houseConfig.StorehouseOutInfo,
  8983. IsCheck: 1,
  8984. OverCount: sum_count,
  8985. }
  8986. warehouseOutInfo.Count = count
  8987. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8988. warehouseOutInfo.Price = stockInInfo.Price
  8989. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8990. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8991. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8992. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8993. warehouseOutInfo.Number = warehouseOutInfos.Number
  8994. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8995. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8996. //查找当天是否存在出库记录
  8997. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8998. if errcod == gorm.ErrRecordNotFound {
  8999. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  9000. //插入详情明细表
  9001. if errOne != nil {
  9002. return errOne
  9003. }
  9004. //插入详情明细表
  9005. stockFlow := models.VmStockFlow{
  9006. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  9007. WarehouseOutId: warehouseOut.ID,
  9008. GoodId: good_yc.GoodId,
  9009. Number: warehouseOutInfos.Number,
  9010. ProductDate: stockInInfo.ProductDate,
  9011. ExpireDate: stockInInfo.ExpiryDate,
  9012. Count: count,
  9013. Price: stockInInfo.Price,
  9014. Status: 1,
  9015. Ctime: record_time,
  9016. UserOrgId: good_yc.OrgId,
  9017. Manufacturer: stockInInfo.Manufacturer,
  9018. Dealer: stockInInfo.Dealer,
  9019. LicenseNumber: stockInInfo.LicenseNumber,
  9020. IsEdit: 2,
  9021. Creator: creater,
  9022. SystemTime: record_time,
  9023. ConsumableType: 3,
  9024. WarehousingDetailId: 0,
  9025. IsSys: 1,
  9026. UpdateCreator: creater,
  9027. PatientId: patient_id,
  9028. StorehouseId: houseConfig.StorehouseOutInfo,
  9029. OverCount: sum_count,
  9030. ProjectId: good_yc.ProjectId,
  9031. }
  9032. err := service.CreateStockFlowOne(stockFlow)
  9033. fmt.Println("err", err)
  9034. } else if errcod == nil {
  9035. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  9036. }
  9037. //创建退库单
  9038. operation_time := time.Now().Unix()
  9039. //创建退库单
  9040. timeStr := time.Now().Format("2006-01-02")
  9041. timeArr := strings.Split(timeStr, "-")
  9042. total, _ := service.FindAllCancelStockTotal(orgID)
  9043. total = total + 1
  9044. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9045. cancelStock := models.CancelStock{
  9046. OrderNumber: orderNumber,
  9047. OperaTime: operation_time,
  9048. OrgId: orgID,
  9049. Creater: warehouseOut.Creater,
  9050. Ctime: time.Now().Unix(),
  9051. Status: 1,
  9052. ReturnTime: record_time,
  9053. Type: 1,
  9054. StorehouseId: stockInInfo.StorehouseId,
  9055. IsCheck: 1,
  9056. }
  9057. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  9058. if msgerrkonde == gorm.ErrRecordNotFound {
  9059. service.AddSigleCancelStock(&cancelStock)
  9060. }
  9061. cancel, _ := service.GetLastCancelStockById(orgID)
  9062. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  9063. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  9064. cancelStockInfo := models.CancelStockInfo{
  9065. GoodId: stockInInfo.GoodId,
  9066. CancelStockId: cancel.ID,
  9067. GoodTypeId: stockInInfo.GoodTypeId,
  9068. Count: delete_count,
  9069. Price: stockInInfo.PackingPrice,
  9070. Total: 0,
  9071. ProductDate: stockInInfo.ProductDate,
  9072. ExpiryDate: stockInInfo.ExpiryDate,
  9073. Ctime: record_time,
  9074. Status: 1,
  9075. OrgId: orgID,
  9076. OrderNumber: cancel.OrderNumber,
  9077. Type: 0,
  9078. Dealer: deaerler.DealerName,
  9079. Manufacturer: manufacturer.ManufacturerName,
  9080. Number: stockInInfo.Number,
  9081. RegisterAccount: "",
  9082. Remark: "",
  9083. WarehouseInfoId: stockInInfo.ID,
  9084. PatientId: patient_id,
  9085. RecordDate: record_time,
  9086. StorehouseId: stockInInfo.StorehouseId,
  9087. IsCheck: 1,
  9088. }
  9089. service.CreateCancelStockInfoOne(&cancelStockInfo)
  9090. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  9091. flow := models.VmStockFlow{
  9092. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  9093. GoodId: good_yc.GoodId,
  9094. Number: warehouseOutInfos.Number,
  9095. LicenseNumber: stockInInfo.LicenseNumber,
  9096. Count: delete_count,
  9097. UserOrgId: orgID,
  9098. PatientId: patient_id,
  9099. SystemTime: record_time,
  9100. ConsumableType: 7,
  9101. IsSys: 0,
  9102. WarehousingOrder: "",
  9103. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  9104. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9105. IsEdit: 0,
  9106. CancelStockId: cancel.ID,
  9107. CancelOrderNumber: cancel.OrderNumber,
  9108. Manufacturer: manufacturer.ID,
  9109. Dealer: 0,
  9110. Creator: warehouseOut.Creater,
  9111. UpdateCreator: 0,
  9112. Status: 1,
  9113. Ctime: record_time,
  9114. Mtime: 0,
  9115. Price: stockInInfo.Price,
  9116. WarehousingDetailId: stockInInfo.ID,
  9117. WarehouseOutDetailId: warehouseOutInfos.ID,
  9118. CancelOutDetailId: cancelInfo.ID,
  9119. ProductDate: stockInInfo.ProductDate,
  9120. ExpireDate: stockInInfo.ExpiryDate,
  9121. StorehouseId: houseConfig.StorehouseOutInfo,
  9122. OverCount: sum_count,
  9123. }
  9124. service.CreateStockFlowOne(flow)
  9125. //更改自动出库的表格
  9126. details := models.BloodAutomaticReduceDetail{
  9127. WarehouseOutId: warehouseOutInfo.ID,
  9128. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  9129. PatientId: patient_id,
  9130. Ctime: time.Now().Unix(),
  9131. Mtime: time.Now().Unix(),
  9132. Status: 1,
  9133. RecordTime: record_time,
  9134. OrgId: orgID,
  9135. GoodId: good_yc.GoodId,
  9136. GoodTypeId: good_yc.GoodTypeId,
  9137. Count: count,
  9138. StorehouseId: houseConfig.StorehouseOutInfo,
  9139. }
  9140. //查询当天耗材是否已经存在数据
  9141. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9142. if errcode == gorm.ErrRecordNotFound {
  9143. errTwo := service.CreateAutoReduceRecord(&details)
  9144. if errTwo != nil {
  9145. return errTwo
  9146. }
  9147. } else if errcode == nil {
  9148. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  9149. service.CreateAutoReduceRecord(&details)
  9150. }
  9151. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  9152. //增加出库库存数量
  9153. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  9154. if good_yc.Count == 0 {
  9155. return nil
  9156. } else {
  9157. return errors.New("退库和出库数据不匹配")
  9158. }
  9159. }
  9160. func (this *DialysisAPIController) SavePatientSign() {
  9161. adminUserInfo := this.GetMobileAdminUserInfo()
  9162. patient_id, _ := this.GetInt64("patient_id")
  9163. dialysis_date, _ := this.GetInt64("dialysis_date")
  9164. orgid := adminUserInfo.Org.Id
  9165. var esdata models.DialysisOrder
  9166. var err error
  9167. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  9168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9169. return
  9170. }
  9171. esdata.Hash = esdata.Hash
  9172. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  9173. order := models.DialysisOrder{
  9174. Hash: esdata.Hash,
  9175. Url: esdata.Url,
  9176. }
  9177. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  9178. redis := service.RedisClient()
  9179. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9180. redis.Set(key, "", time.Second)
  9181. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9182. //清空key 值
  9183. redis.Set(keyOne, "", time.Second)
  9184. //scheduleDateStartOne := startDate.Format("2006-01-02")
  9185. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  9186. //redis.Set(keyTwo, "", time.Second)
  9187. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9188. redis.Set(keyThree, "", time.Second)
  9189. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9190. redis.Set(keyFour, "", time.Second)
  9191. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9192. redis.Set(keyFive, "", time.Second)
  9193. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9194. redis.Set(keySix, "", time.Second)
  9195. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  9196. redis.Set(keySeven, "", time.Second)
  9197. if err != nil {
  9198. fmt.Println(err)
  9199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9200. return
  9201. }
  9202. this.ServeSuccessJSON(map[string]interface{}{
  9203. "electronic_signature": esdata,
  9204. })
  9205. }
  9206. func (this *DialysisAPIController) GetPatientSign() {
  9207. patient_id, _ := this.GetInt64("patient_id")
  9208. dialysis_date, _ := this.GetInt64("dialysis_date")
  9209. adminUserInfo := this.GetMobileAdminUserInfo()
  9210. orgId := adminUserInfo.Org.Id
  9211. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  9212. if err != nil {
  9213. fmt.Println(err)
  9214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9215. return
  9216. }
  9217. this.ServeSuccessJSON(map[string]interface{}{
  9218. "dialysisOrder": dialysisOrder,
  9219. })
  9220. }
  9221. func (this *DialysisAPIController) GetScheduleByPatient() {
  9222. patient_id, _ := this.GetInt64("patient_id")
  9223. schedule_date, _ := this.GetInt64("schedule_date")
  9224. orgid := this.GetMobileAdminUserInfo().Org.Id
  9225. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9226. this.ServeSuccessJSON(map[string]interface{}{
  9227. "schedule": schedule,
  9228. })
  9229. }
  9230. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9231. org_id := this.GetMobileAdminUserInfo().Org.Id
  9232. patient_id, _ := this.GetInt64("patient_id")
  9233. schedule_date, _ := this.GetInt64("schedule_date")
  9234. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9235. this.ServeSuccessJSON(map[string]interface{}{
  9236. "order": order,
  9237. })
  9238. }
  9239. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9240. org_id := this.GetMobileAdminUserInfo().Org.Id
  9241. schedule_date := this.GetString("schedule_date")
  9242. schedule_type, _ := this.GetInt64("schedule_type")
  9243. timeLayout := "2006-01-02"
  9244. loc, _ := time.LoadLocation("Local")
  9245. var startdateunix int64
  9246. if len(schedule_date) > 0 {
  9247. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9248. if err != nil {
  9249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9250. return
  9251. }
  9252. startdateunix = theTime.Unix()
  9253. }
  9254. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9255. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9256. devices, _ := service.GetAllDevicetByListSix(org_id)
  9257. for key, item := range scheduals {
  9258. // 床位信息
  9259. for _, device := range devices {
  9260. if item.BedId == device.ID {
  9261. scheduals[key].DeviceNumber = device
  9262. break
  9263. }
  9264. }
  9265. }
  9266. this.ServeSuccessJSON(map[string]interface{}{
  9267. "list": list,
  9268. "scheduals": scheduals,
  9269. })
  9270. }
  9271. func (this *DialysisAPIController) SavePatientPicture() {
  9272. patient_id, _ := this.GetInt64("patient_id")
  9273. dialysis_date, _ := this.GetInt64("schedule_date")
  9274. avatar := this.GetString("avatar")
  9275. fmt.Println("patient_id", patient_id)
  9276. orgId := this.GetMobileAdminUserInfo().Org.Id
  9277. order := models.DialysisOrder{
  9278. Url: avatar,
  9279. }
  9280. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9281. redis := service.RedisClient()
  9282. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9283. redis.Set(key, "", time.Second)
  9284. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9285. //清空key 值
  9286. redis.Set(keyOne, "", time.Second)
  9287. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9288. redis.Set(keyThree, "", time.Second)
  9289. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9290. redis.Set(keyFour, "", time.Second)
  9291. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9292. redis.Set(keyFive, "", time.Second)
  9293. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9294. redis.Set(keySix, "", time.Second)
  9295. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9296. redis.Set(keySeven, "", time.Second)
  9297. if err != nil {
  9298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9299. return
  9300. }
  9301. this.ServeSuccessJSON(map[string]interface{}{
  9302. "order": order,
  9303. })
  9304. }
  9305. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9306. ids := this.GetString("ids")
  9307. idSplit := strings.Split(ids, ",")
  9308. orgId := this.GetMobileAdminUserInfo().Org.Id
  9309. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9310. execution_time := this.GetString("exce_time")
  9311. timeLayout2 := "2006-01-02 15:04:05"
  9312. loc, _ := time.LoadLocation("Local")
  9313. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9314. if errs != nil {
  9315. utils.ErrorLog(errs.Error())
  9316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9317. return
  9318. }
  9319. //his客户
  9320. if config.IsOpen == 1 {
  9321. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9322. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9323. for _, item := range list {
  9324. for _, it := range adviceList {
  9325. if item.DrugId == it.DrugId {
  9326. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9327. }
  9328. }
  9329. }
  9330. for _, item := range list {
  9331. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9332. var sum_out_count int64
  9333. for _, itemThree := range item.ChildDoctorAdvice {
  9334. var prescribing_number int64
  9335. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9336. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9337. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9338. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9339. }
  9340. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9341. prescribing_number = parseIntPrescribingNumber
  9342. }
  9343. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9344. prescribing_number = parseIntPrescribingNumber
  9345. }
  9346. sum_out_count += prescribing_number
  9347. }
  9348. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9349. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9350. //库存不足
  9351. if sum_out_count > drugStockOut.FlushCount {
  9352. this.ServeSuccessJSON(map[string]interface{}{
  9353. "msg": "2",
  9354. "drug": medical,
  9355. "ids": ids,
  9356. })
  9357. return
  9358. }
  9359. }
  9360. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9361. //执行医嘱
  9362. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9363. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9364. for _, item := range advices {
  9365. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9366. redis := service.RedisClient()
  9367. //清空key 值
  9368. redis.Set(key, "", time.Second)
  9369. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9370. redis.Set(keyTwo, "", time.Second)
  9371. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9372. redis.Set(keyThree, "", time.Second)
  9373. recordDate := theTime.Format("2006-01-02")
  9374. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9375. redis.Set(keyFour, "", time.Second)
  9376. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9377. redis.Set(keyFive, "", time.Second)
  9378. defer redis.Close()
  9379. }
  9380. if errs == nil {
  9381. //药品管理信息
  9382. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9383. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9384. if drugStockConfig.IsOpen == 1 {
  9385. for _, item := range advices {
  9386. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9387. config, _ := service.GetDrugOpenConfigOne(orgId)
  9388. if config.IsOpen != 1 {
  9389. //查询该药品是否有库存
  9390. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9391. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9392. if medical.IsUse == 2 {
  9393. if config.IsOpen != 1 {
  9394. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9395. service.HisDrugsDelivery(orgId, creater, &advice)
  9396. if orgId == 3877 || orgId == 10265 {
  9397. //查询该药品是否有出库记录
  9398. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9399. if len(flowMap) == 0 {
  9400. errs := service.UpdateHisAdviceById(advice.ID)
  9401. if errs != nil {
  9402. drugError := models.XtDrugError{
  9403. UserOrgId: orgId,
  9404. DrugId: item.DrugId,
  9405. RecordDate: item.AdviceDate,
  9406. PatientId: item.PatientId,
  9407. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9408. Status: 1,
  9409. Ctime: time.Now().Unix(),
  9410. Mtime: 0,
  9411. SumCount: 0,
  9412. Prescribingnumber: advice.PrescribingNumber,
  9413. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9414. }
  9415. service.CreateDrugError(drugError)
  9416. }
  9417. this.ServeSuccessJSON(map[string]interface{}{
  9418. "msg": "2",
  9419. "drug": medical,
  9420. "ids": ids,
  9421. })
  9422. return
  9423. }
  9424. }
  9425. }
  9426. if pharmacyConfig.IsOpen != 1 {
  9427. service.HisDrugsDelivery(orgId, creater, &advice)
  9428. if orgId == 3877 || orgId == 10265 {
  9429. //查询该药品是否有出库记录
  9430. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9431. if len(flowMap) == 0 {
  9432. errs := service.UpdateHisAdviceById(advice.ID)
  9433. if errs != nil {
  9434. drugError := models.XtDrugError{
  9435. UserOrgId: orgId,
  9436. DrugId: item.DrugId,
  9437. RecordDate: item.AdviceDate,
  9438. PatientId: item.PatientId,
  9439. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9440. Status: 1,
  9441. Ctime: time.Now().Unix(),
  9442. Mtime: 0,
  9443. SumCount: 0,
  9444. Prescribingnumber: advice.PrescribingNumber,
  9445. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9446. }
  9447. service.CreateDrugError(drugError)
  9448. }
  9449. this.ServeSuccessJSON(map[string]interface{}{
  9450. "msg": "2",
  9451. "drug": medical,
  9452. "ids": ids,
  9453. })
  9454. return
  9455. }
  9456. }
  9457. }
  9458. //更新字典里面的库存
  9459. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9460. var sum_count int64
  9461. for _, its := range stockInfo {
  9462. if its.MaxUnit == medical.MaxUnit {
  9463. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9464. }
  9465. sum_count += its.StockMaxNumber + its.StockMinNumber
  9466. }
  9467. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9468. //剩余库存
  9469. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9470. }
  9471. }
  9472. }
  9473. }
  9474. }
  9475. this.ServeSuccessJSON(map[string]interface{}{
  9476. "msg": "1",
  9477. "ids": ids,
  9478. })
  9479. return
  9480. } else {
  9481. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9482. }
  9483. }
  9484. //血透客户
  9485. if config.IsOpen == 2 || config.IsOpen == 0 {
  9486. //药品管理信息
  9487. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9488. if drugStockConfig.IsOpen == 1 {
  9489. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9490. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9491. for _, item := range list {
  9492. for _, it := range adviceList {
  9493. if item.DrugId == it.DrugId {
  9494. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9495. }
  9496. }
  9497. }
  9498. for _, item := range list {
  9499. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9500. var sum_out_count int64
  9501. for _, itemThree := range item.ChildDoctorAdvice {
  9502. var prescribing_number int64
  9503. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9504. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9505. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9506. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9507. }
  9508. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9509. prescribing_number = parseIntPrescribingNumber
  9510. }
  9511. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9512. prescribing_number = parseIntPrescribingNumber
  9513. }
  9514. sum_out_count += prescribing_number
  9515. }
  9516. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9517. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9518. //库存不足
  9519. if sum_out_count > drugStockOut.FlushCount {
  9520. this.ServeSuccessJSON(map[string]interface{}{
  9521. "msg": "2",
  9522. "drug": medical,
  9523. "ids": ids,
  9524. })
  9525. return
  9526. }
  9527. }
  9528. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9529. //执行医嘱
  9530. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9531. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9532. for _, item := range advices {
  9533. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9534. redis := service.RedisClient()
  9535. //清空key 值
  9536. redis.Set(key, "", time.Second)
  9537. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9538. redis.Set(keyTwo, "", time.Second)
  9539. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9540. redis.Set(keyThree, "", time.Second)
  9541. recordDate := theTime.Format("2006-01-02")
  9542. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9543. redis.Set(keyFour, "", time.Second)
  9544. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9545. redis.Set(keyFive, "", time.Second)
  9546. defer redis.Close()
  9547. }
  9548. if errs == nil {
  9549. for _, item := range advices {
  9550. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9551. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9552. //查询是否出库按钮开启
  9553. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9554. if adviceSetting.IsAdviceOpen == 1 {
  9555. //查询是否出库按钮开启
  9556. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9557. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9558. if prescriptionConfig.IsOpen == 1 {
  9559. if medical.IsUse == 2 {
  9560. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9561. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9562. }
  9563. if pharmacyConfig.IsOpen != 1 {
  9564. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9565. }
  9566. //更新字典里面的库存
  9567. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9568. var sum_count int64
  9569. for _, its := range stockInfo {
  9570. if its.MaxUnit == medical.MaxUnit {
  9571. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9572. }
  9573. sum_count += its.StockMaxNumber + its.StockMinNumber
  9574. }
  9575. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9576. //剩余库存
  9577. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9578. }
  9579. }
  9580. } else {
  9581. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9582. if medical.IsUse == 2 {
  9583. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9584. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9585. }
  9586. if pharmacyConfig.IsOpen != 1 {
  9587. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9588. }
  9589. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9590. var sum_count int64
  9591. for _, its := range stockInfo {
  9592. if its.MaxUnit == medical.MaxUnit {
  9593. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9594. }
  9595. sum_count += its.StockMaxNumber + its.StockMinNumber
  9596. }
  9597. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9598. //剩余库存
  9599. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9600. }
  9601. }
  9602. }
  9603. }
  9604. this.ServeSuccessJSON(map[string]interface{}{
  9605. "msg": "1",
  9606. "ids": ids,
  9607. })
  9608. return
  9609. } else {
  9610. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9611. //执行医嘱
  9612. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9613. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9614. for _, item := range advices {
  9615. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9616. redis := service.RedisClient()
  9617. //清空key 值
  9618. redis.Set(key, "", time.Second)
  9619. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9620. redis.Set(keyTwo, "", time.Second)
  9621. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9622. redis.Set(keyThree, "", time.Second)
  9623. recordDate := theTime.Format("2006-01-02")
  9624. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9625. redis.Set(keyFour, "", time.Second)
  9626. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9627. redis.Set(keyFive, "", time.Second)
  9628. defer redis.Close()
  9629. }
  9630. this.ServeSuccessJSON(map[string]interface{}{
  9631. "msg": "1",
  9632. "ids": ids,
  9633. })
  9634. return
  9635. }
  9636. }
  9637. }
  9638. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9639. ids := this.GetString("ids")
  9640. idSplit := strings.Split(ids, ",")
  9641. orgId := this.GetMobileAdminUserInfo().Org.Id
  9642. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9643. if config.IsOpen == 1 {
  9644. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9645. this.ServeSuccessJSON(map[string]interface{}{
  9646. "msg": "1",
  9647. "ids": ids,
  9648. })
  9649. return
  9650. }
  9651. if config.IsOpen == 0 || config.IsOpen == 2 {
  9652. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9653. this.ServeSuccessJSON(map[string]interface{}{
  9654. "msg": "1",
  9655. "ids": ids,
  9656. })
  9657. return
  9658. }
  9659. }
  9660. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9661. ids := this.GetString("ids")
  9662. idSplit := strings.Split(ids, ",")
  9663. orgId := this.GetMobileAdminUserInfo().Org.Id
  9664. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9665. //his
  9666. if config.IsOpen == 1 {
  9667. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9668. theTime := time.Now()
  9669. advices := models.HisDoctorAdviceThirty{
  9670. CheckTime: theTime.Unix(),
  9671. Checker: checker,
  9672. UpdatedTime: time.Now().Unix(),
  9673. }
  9674. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9675. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9676. for _, item := range list {
  9677. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9678. redis := service.RedisClient()
  9679. //清空key 值
  9680. redis.Set(key, "", time.Second)
  9681. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9682. redis.Set(keyTwo, "", time.Second)
  9683. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9684. redis.Set(keyThree, "", time.Second)
  9685. recordDate := theTime.Format("2006-01-02")
  9686. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9687. redis.Set(keyFour, "", time.Second)
  9688. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9689. redis.Set(keyFive, "", time.Second)
  9690. defer redis.Close()
  9691. }
  9692. this.ServeSuccessJSON(map[string]interface{}{
  9693. "msg": "1",
  9694. "ids": ids,
  9695. })
  9696. return
  9697. }
  9698. //血透
  9699. if config.IsOpen == 0 || config.IsOpen == 2 {
  9700. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9701. theTime := time.Now()
  9702. advices := models.DoctorAdvice{
  9703. CheckTime: theTime.Unix(),
  9704. Checker: checker,
  9705. UpdatedTime: time.Now().Unix(),
  9706. }
  9707. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9708. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9709. for _, item := range list {
  9710. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9711. redis := service.RedisClient()
  9712. //清空key 值
  9713. redis.Set(key, "", time.Second)
  9714. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9715. redis.Set(keyTwo, "", time.Second)
  9716. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9717. redis.Set(keyThree, "", time.Second)
  9718. recordDate := theTime.Format("2006-01-02")
  9719. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9720. redis.Set(keyFour, "", time.Second)
  9721. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9722. redis.Set(keyFive, "", time.Second)
  9723. defer redis.Close()
  9724. }
  9725. this.ServeSuccessJSON(map[string]interface{}{
  9726. "msg": "1",
  9727. "ids": ids,
  9728. })
  9729. return
  9730. }
  9731. }
  9732. func (this *DialysisAPIController) CheckSchedule() {
  9733. patientID, _ := this.GetInt64("patient_id")
  9734. recordDateStr := this.GetString("record_date")
  9735. nurseID, _ := this.GetInt64("start_nurse")
  9736. schedual_type, _ := this.GetInt64("schedual_type")
  9737. bedID, _ := this.GetInt64("bed")
  9738. start_time := this.GetString("start_time")
  9739. fmt.Println("patientID", patientID)
  9740. fmt.Println("recordDateStr", recordDateStr)
  9741. fmt.Println("nurseID", nurseID)
  9742. fmt.Println("schedual_type------", schedual_type)
  9743. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9745. return
  9746. }
  9747. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9748. if parseStartDateErr != nil {
  9749. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9751. return
  9752. }
  9753. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9754. if parseErr != nil {
  9755. this.ErrorLog("时间解析失败:%v", parseErr)
  9756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9757. return
  9758. }
  9759. adminUserInfo := this.GetMobileAdminUserInfo()
  9760. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9761. if getPatientErr != nil {
  9762. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9764. return
  9765. } else if patient == nil {
  9766. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9767. return
  9768. }
  9769. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9770. if getNurseErr != nil {
  9771. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9773. return
  9774. } else if nurse == nil {
  9775. this.ErrorLog("护士不存在")
  9776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9777. return
  9778. }
  9779. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9780. if getDeviceNumberErr != nil {
  9781. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9783. return
  9784. } else if deviceNumber == nil {
  9785. this.ErrorLog("床位号不存在")
  9786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9787. return
  9788. }
  9789. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9790. if getRecordErr != nil {
  9791. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9792. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9793. return
  9794. } else if dialysisRecord != nil {
  9795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9796. return
  9797. }
  9798. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9799. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9800. timeLayout := "2006-01-02 15:04:05"
  9801. loc, _ := time.LoadLocation("Local")
  9802. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9803. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9804. schedulestartTime := theStartTime.Unix()
  9805. scheduleendTime := theEndTime.Unix()
  9806. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9807. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9808. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9809. //查询该床位是否有人用了
  9810. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9811. if err == nil {
  9812. if schedule.ID == 0 {
  9813. this.ServeSuccessJSON(map[string]interface{}{
  9814. "status": 0,
  9815. "msg": "请求失败",
  9816. })
  9817. } else {
  9818. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9819. if order.ID > 0 { //该机位被其他人占用了
  9820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9821. return
  9822. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9823. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9824. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9825. this.ServeSuccessJSON(map[string]interface{}{
  9826. "status": 1,
  9827. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9828. })
  9829. return
  9830. } else {
  9831. this.ServeSuccessJSON(map[string]interface{}{
  9832. "status": 0,
  9833. "msg": "",
  9834. })
  9835. }
  9836. }
  9837. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9838. this.ServeSuccessJSON(map[string]interface{}{
  9839. "status": 2,
  9840. "msg": "当前机位已有患者在使用,请重新选择!",
  9841. })
  9842. }
  9843. }
  9844. } else {
  9845. this.ServeSuccessJSON(map[string]interface{}{
  9846. "status": 0,
  9847. "msg": "",
  9848. })
  9849. }
  9850. }
  9851. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9852. orgId := this.GetMobileAdminUserInfo().Org.Id
  9853. schedule_type, _ := this.GetInt64("schedule_type")
  9854. partion_type, _ := this.GetInt64("partion_type")
  9855. start_time := this.GetString("start_time")
  9856. timeLayout := "2006-01-02"
  9857. loc, _ := time.LoadLocation("Local")
  9858. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9859. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9860. _, config := service.FindXTHisRecordByOrgId(orgId)
  9861. appId := this.GetMobileAdminUserInfo().App.Id
  9862. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9863. if err == nil {
  9864. this.ServeSuccessJSON(map[string]interface{}{
  9865. "list": list,
  9866. "config": config,
  9867. "doctorList": doctorList,
  9868. })
  9869. return
  9870. } else {
  9871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9872. return
  9873. }
  9874. }
  9875. func (this *DialysisAPIController) SaveMobileInformation() {
  9876. patient_id, _ := this.GetInt64("patient_id")
  9877. record_date, _ := this.GetInt64("record_date")
  9878. startTime := this.GetString("start_time")
  9879. module, _ := this.GetInt64("module")
  9880. remark := this.GetString("remark")
  9881. timeLayout := "2006-01-02 15:04"
  9882. loc, _ := time.LoadLocation("Local")
  9883. if len(startTime) == 0 {
  9884. utils.ErrorLog("len(start_time) == 0")
  9885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9886. return
  9887. }
  9888. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9889. if err != nil {
  9890. utils.ErrorLog(err.Error())
  9891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9892. return
  9893. }
  9894. StartTime := theTime.Unix()
  9895. fmt.Println("startime-------------", StartTime)
  9896. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9897. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9898. information := models.XtDialysisInformation{
  9899. Module: module,
  9900. PatientId: patient_id,
  9901. RecordDate: record_date,
  9902. ApplicationDate: StartTime,
  9903. Creater: creater,
  9904. ApplicationStatus: 2,
  9905. Checker: 0,
  9906. CheckTime: 0,
  9907. Remark: remark,
  9908. UserOrgId: user_org_id,
  9909. Ctime: time.Now().Unix(),
  9910. Status: 1,
  9911. Mtime: 0,
  9912. }
  9913. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9914. if infor.ID == 0 {
  9915. service.SaveDialysisInformation(information)
  9916. }
  9917. if infor.ID > 0 {
  9918. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9919. }
  9920. this.ServeSuccessJSON(map[string]interface{}{
  9921. "information": information,
  9922. })
  9923. return
  9924. }
  9925. func (this *DialysisAPIController) GetMobileInformation() {
  9926. limit, _ := this.GetInt64("limit")
  9927. page, _ := this.GetInt64("page")
  9928. orgid := this.GetMobileAdminUserInfo().Org.Id
  9929. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9930. appid := this.GetMobileAdminUserInfo().App.Id
  9931. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9932. patients, _ := service.GetAllpatientThirty(orgid)
  9933. this.ServeSuccessJSON(map[string]interface{}{
  9934. "information": information,
  9935. "total": total,
  9936. "doclist": doclist,
  9937. "patients": patients,
  9938. })
  9939. return
  9940. }
  9941. func (this *DialysisAPIController) GetMobileInformationOne() {
  9942. limit, _ := this.GetInt64("limit")
  9943. page, _ := this.GetInt64("page")
  9944. orgid := this.GetMobileAdminUserInfo().Org.Id
  9945. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9946. appid := this.GetMobileAdminUserInfo().App.Id
  9947. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9948. patients, _ := service.GetAllpatientThirty(orgid)
  9949. this.ServeSuccessJSON(map[string]interface{}{
  9950. "information": information,
  9951. "total": total,
  9952. "doclist": doclist,
  9953. "patients": patients,
  9954. })
  9955. return
  9956. }
  9957. func (this *DialysisAPIController) CheckMobileInformation() {
  9958. id, _ := this.GetInt64("id")
  9959. application_status, _ := this.GetInt64("application_status")
  9960. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9961. checktime := time.Now().Unix()
  9962. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9963. if err == nil {
  9964. this.ServeSuccessJSON(map[string]interface{}{
  9965. "msg": "ok",
  9966. })
  9967. return
  9968. }
  9969. }
  9970. func (c *DialysisAPIController) GetControlMonitorList() {
  9971. partition, _ := c.GetInt64("partition")
  9972. monitorDate := c.GetString("date")
  9973. patient_id, _ := c.GetInt64("patient_id")
  9974. pat_type, _ := c.GetInt64("pat_type")
  9975. timeLayout := "2006-01-02"
  9976. loc, _ := time.LoadLocation("Local")
  9977. var theStartTime int64
  9978. if len(monitorDate) > 0 {
  9979. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9980. if err != nil {
  9981. theStartTime = 0
  9982. }
  9983. theStartTime = theTime.Unix()
  9984. }
  9985. adminInfo := c.GetMobileAdminUserInfo()
  9986. orgID := adminInfo.Org.Id
  9987. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9988. if err != nil {
  9989. c.ErrorLog("获取排班信息失败:%v", err)
  9990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9991. } else {
  9992. if len(monitor) > 0 {
  9993. //获取所有床位
  9994. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9995. //获取所有分区
  9996. zoneList, _ := service.GetAllZoneByList(orgID)
  9997. //获取透析处方
  9998. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9999. //获取透前评估
  10000. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  10001. //获取上机
  10002. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  10003. //获取透后
  10004. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  10005. //获取透后监测
  10006. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  10007. //获取所有的患者
  10008. patients, _ := service.GetAllPatientListByListOne(orgID)
  10009. //获取所有透析模式
  10010. treatments, _ := service.GetAllTreatModeByList(orgID)
  10011. //获取所有医嘱
  10012. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  10013. //获取双人核对
  10014. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  10015. //治疗小结
  10016. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  10017. //待消毒
  10018. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  10019. for key, item := range monitor {
  10020. // 获取床位信息
  10021. for _, it := range numberList {
  10022. if item.BedId == it.ID {
  10023. monitor[key].DeviceNumber = it
  10024. break
  10025. }
  10026. }
  10027. //获取分区信息
  10028. for _, it := range zoneList {
  10029. if item.PartitionId == it.ID {
  10030. monitor[key].DeviceZone = it
  10031. }
  10032. }
  10033. for _, prescription := range prescriptions {
  10034. if item.PatientId == prescription.PatientId {
  10035. monitor[key].Prescription = prescription
  10036. break
  10037. }
  10038. }
  10039. for _, it := range checkList {
  10040. if item.PatientId == it.PatientId {
  10041. monitor[key].DoubleCheck = it
  10042. break
  10043. }
  10044. }
  10045. for _, it := range summaryList {
  10046. if item.PatientId == it.PatientId {
  10047. monitor[key].TreatmentSummaryForList = it
  10048. break
  10049. }
  10050. }
  10051. // 透前评估
  10052. for _, assessmentBefore := range assessmentBefores {
  10053. if item.PatientId == assessmentBefore.PatientId {
  10054. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  10055. break
  10056. }
  10057. }
  10058. // 透析上下机
  10059. for _, dialysisOrder := range dialysisOrders {
  10060. if item.PatientId == dialysisOrder.PatientId {
  10061. monitor[key].DialysisOrder = dialysisOrder
  10062. break
  10063. }
  10064. }
  10065. // 治疗小节
  10066. for _, afterDislysis := range AssessmentAfterDislysis {
  10067. if item.PatientId == afterDislysis.PatientId {
  10068. monitor[key].AssessmentAfterDislysis = afterDislysis
  10069. break
  10070. }
  10071. }
  10072. for _, it := range monitorlist {
  10073. if item.PatientId == it.PatientId {
  10074. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  10075. }
  10076. }
  10077. for _, it := range adviceList {
  10078. if item.PatientId == it.PatientId {
  10079. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  10080. }
  10081. }
  10082. for _, patient := range patients {
  10083. if item.PatientId == patient.ID {
  10084. monitor[key].MonitorPatients = patient
  10085. break
  10086. }
  10087. }
  10088. for _, treatment := range treatments {
  10089. if item.ModeId == treatment.ID {
  10090. monitor[key].TreatmentMode = treatment
  10091. break
  10092. }
  10093. }
  10094. for _, infor := range informationList {
  10095. if item.PatientId == infor.PatientId {
  10096. monitor[key].NewDeviceInformation = infor
  10097. break
  10098. }
  10099. }
  10100. }
  10101. }
  10102. }
  10103. patients, err := service.GetAllpatientFourty(orgID)
  10104. var mds []*models.NewMonitorDialysisScheduleList
  10105. if pat_type == 0 {
  10106. for _, item := range monitor {
  10107. mds = append(mds, item)
  10108. }
  10109. }
  10110. //待医嘱核对
  10111. if pat_type == 1 {
  10112. for _, item := range monitor {
  10113. if len(item.AdviceList) > 0 {
  10114. mds = append(mds, item)
  10115. }
  10116. }
  10117. }
  10118. //待开小结
  10119. if pat_type == 2 {
  10120. for _, item := range monitor {
  10121. if item.TreatmentSummaryForList == nil {
  10122. mds = append(mds, item)
  10123. }
  10124. }
  10125. }
  10126. //待下机
  10127. if pat_type == 3 {
  10128. for _, item := range monitor {
  10129. if item.DialysisOrder != nil {
  10130. if item.DialysisOrder.ID > 0 {
  10131. mds = append(mds, item)
  10132. }
  10133. }
  10134. }
  10135. }
  10136. //待消毒
  10137. if pat_type == 4 {
  10138. for _, item := range monitor {
  10139. if item.NewDeviceInformation == nil {
  10140. mds = append(mds, item)
  10141. }
  10142. }
  10143. }
  10144. //待双人核对
  10145. if pat_type == 5 {
  10146. for _, item := range monitor {
  10147. if item.DoubleCheck == nil {
  10148. mds = append(mds, item)
  10149. }
  10150. }
  10151. }
  10152. //医嘱未执行
  10153. if pat_type == 6 {
  10154. for _, item := range monitor {
  10155. if len(item.AdviceList) > 0 {
  10156. mds = append(mds, item)
  10157. }
  10158. }
  10159. }
  10160. //患者未签名
  10161. if pat_type == 7 {
  10162. for _, item := range monitor {
  10163. if item.DialysisOrder != nil {
  10164. if item.DialysisOrder.ID > 0 {
  10165. mds = append(mds, item)
  10166. }
  10167. }
  10168. }
  10169. }
  10170. //目标超滤于实际超滤不同
  10171. if pat_type == 8 {
  10172. for _, item := range monitor {
  10173. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  10174. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  10175. mds = append(mds, item)
  10176. }
  10177. }
  10178. }
  10179. }
  10180. //血压少于5次
  10181. if pat_type == 9 {
  10182. for _, item := range monitor {
  10183. if len(item.MonitoringRecord) < 5 {
  10184. mds = append(mds, item)
  10185. }
  10186. }
  10187. }
  10188. if pat_type == 13 {
  10189. for _, item := range monitor {
  10190. if len(item.MonitoringRecord) < 3 {
  10191. mds = append(mds, item)
  10192. }
  10193. }
  10194. }
  10195. if pat_type == 10 {
  10196. for _, item := range monitor {
  10197. if len(item.MonitoringRecord) == 0 {
  10198. mds = append(mds, item)
  10199. }
  10200. }
  10201. }
  10202. if pat_type == 11 {
  10203. for _, item := range monitor {
  10204. if len(item.MonitoringRecord) > 0 {
  10205. mds = append(mds, item)
  10206. }
  10207. }
  10208. }
  10209. if pat_type == 12 {
  10210. for _, item := range monitor {
  10211. if len(item.MonitoringRecord) > 0 {
  10212. mds = append(mds, item)
  10213. }
  10214. }
  10215. }
  10216. if err == nil {
  10217. c.ServeSuccessJSON(map[string]interface{}{
  10218. "monitor": mds,
  10219. "patients": patients,
  10220. })
  10221. } else {
  10222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10223. }
  10224. }
  10225. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10226. admin_user_id, _ := c.GetInt64("admin_user_id")
  10227. timeStr := time.Now().Format("2006-01-02")
  10228. timeLayout := "2006-01-02 15:04:05"
  10229. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10230. timenow := timeStringToTime.Unix()
  10231. orgId := c.GetMobileAdminUserInfo().Org.Id
  10232. //查询当前护士的患者
  10233. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10234. var patientIds []int64
  10235. for _, item := range orderList {
  10236. patientIds = append(patientIds, item.PatientId)
  10237. }
  10238. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10239. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10240. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10241. //药品管理信息
  10242. _, drugStockConfig := service.FindHisConfig(orgId)
  10243. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10244. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10245. c.ServeSuccessJSON(map[string]interface{}{
  10246. "adviceList": adviceList,
  10247. "hisAdviceList": hisAdviceList,
  10248. "projectList": projectList,
  10249. "drugStockConfig": drugStockConfig,
  10250. "patientList": patientList,
  10251. "projectConfig": projectConfig,
  10252. })
  10253. }
  10254. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10255. patient_id, _ := c.GetInt64("patient_id")
  10256. org_id := c.GetMobileAdminUserInfo().Org.Id
  10257. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10258. c.ServeSuccessJSON(map[string]interface{}{
  10259. "recrods": recrods,
  10260. })
  10261. }
  10262. func (c *DialysisAPIController) ExMobileChangeSch() {
  10263. id_one, _ := c.GetInt64("id_one")
  10264. id_two, _ := c.GetInt64("id_two")
  10265. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10266. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10267. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10268. //if order2.ID > 0 {
  10269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10270. // return
  10271. //}
  10272. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10273. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10274. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10275. if count > 0 {
  10276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10277. return
  10278. }
  10279. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10280. if count1 > 0 {
  10281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10282. return
  10283. }
  10284. }
  10285. err := service.UpdateScheduleThree(sch, sch_two)
  10286. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10287. if order.ID > 0 {
  10288. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10289. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10290. redis := service.RedisClient()
  10291. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10292. redis.Set(key, "", time.Second)
  10293. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10294. //清空key 值
  10295. redis.Set(keyOne, "", time.Second)
  10296. }
  10297. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10298. if orderOne.ID > 0 {
  10299. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10300. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10301. redis := service.RedisClient()
  10302. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10303. redis.Set(key, "", time.Second)
  10304. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10305. //清空key 值
  10306. redis.Set(keyOne, "", time.Second)
  10307. }
  10308. if err == nil {
  10309. //去除当天患者排班中重复数据,保留最后一条数据
  10310. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10311. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10312. c.ServeSuccessJSON(map[string]interface{}{
  10313. "msg": "交换成功",
  10314. })
  10315. } else {
  10316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10317. return
  10318. }
  10319. }
  10320. func (c *DialysisAPIController) MobileCoverSch() {
  10321. id_one, _ := c.GetInt64("id_one")
  10322. id_two, _ := c.GetInt64("id_two")
  10323. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10324. //针对凤凰医院
  10325. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10326. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10327. if len(advice) > 0 {
  10328. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10329. }
  10330. }
  10331. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10332. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10333. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10334. if len(hisAdvice) > 0 {
  10335. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10336. }
  10337. if len(project) > 0 {
  10338. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10339. }
  10340. }
  10341. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10342. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10343. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10344. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10345. if count > 0 {
  10346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10347. return
  10348. }
  10349. }
  10350. var new_sch models.Schedule
  10351. new_sch = sch
  10352. new_sch.BedId = sch_two.BedId
  10353. new_sch.ScheduleDate = sch_two.ScheduleDate
  10354. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10355. new_sch.PartitionId = sch_two.PartitionId
  10356. new_sch.ScheduleType = sch_two.ScheduleType
  10357. new_sch.ID = 0
  10358. //删除原来的排班
  10359. err := service.SaveSchTwo(sch, sch_two)
  10360. //生成新的排班
  10361. if err == nil {
  10362. err2 := service.SaveSch(&new_sch)
  10363. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10364. if order.ID > 0 {
  10365. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10366. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10367. redis := service.RedisClient()
  10368. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10369. redis.Set(key, "", time.Second)
  10370. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10371. //清空key 值
  10372. redis.Set(keyOne, "", time.Second)
  10373. }
  10374. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10375. if orderOne.ID > 0 {
  10376. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10377. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10378. redis := service.RedisClient()
  10379. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10380. redis.Set(key, "", time.Second)
  10381. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10382. //清空key 值
  10383. redis.Set(keyOne, "", time.Second)
  10384. }
  10385. if err2 == nil {
  10386. //去除当天患者排班中重复数据,保留最后一条数据
  10387. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10388. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10389. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10390. c.ServeSuccessJSON(map[string]interface{}{
  10391. "msg": "覆盖成功",
  10392. "new_sch": new_sch,
  10393. })
  10394. } else {
  10395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10396. return
  10397. }
  10398. } else {
  10399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10400. return
  10401. }
  10402. }
  10403. func (c *DialysisAPIController) BatchCheckAdvice() {
  10404. patient_id, _ := c.GetInt64("patient_id")
  10405. advice_date, _ := c.GetInt64("advice_date")
  10406. org_id := c.GetMobileAdminUserInfo().Org.Id
  10407. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10408. //查询是his系统还是血透系统
  10409. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10410. //his客户
  10411. if configs.IsOpen == 1 {
  10412. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10413. for _, item := range adviceList {
  10414. service.BatchCheckHisAdvice(item.ID, creater)
  10415. }
  10416. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10417. for _, item := range projectList {
  10418. service.BatchCheckProject(item.ID, creater)
  10419. }
  10420. c.ServeSuccessJSON(map[string]interface{}{
  10421. "adviceList": adviceList,
  10422. "projectList": projectList,
  10423. })
  10424. }
  10425. if configs.IsOpen != 1 {
  10426. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10427. for _, item := range adviceList {
  10428. service.BatchAdviceList(item.ID, creater)
  10429. }
  10430. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10431. for _, item := range projectList {
  10432. service.BatchCheckProject(item.ID, creater)
  10433. }
  10434. c.ServeSuccessJSON(map[string]interface{}{
  10435. "adviceList": adviceList,
  10436. "projectList": projectList,
  10437. })
  10438. }
  10439. return
  10440. }
  10441. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10442. org_id := c.GetMobileAdminUserInfo().Org.Id
  10443. drugList, _ := service.GetAllDrugList(org_id)
  10444. c.ServeSuccessJSON(map[string]interface{}{
  10445. "drugList": drugList,
  10446. })
  10447. }
  10448. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10449. org_id := c.GetMobileAdminUserInfo().Org.Id
  10450. dataBody := make(map[string]interface{}, 0)
  10451. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10452. if err != nil {
  10453. utils.ErrorLog(err.Error())
  10454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10455. return
  10456. }
  10457. timeLayout := "2006-01-02"
  10458. loc, _ := time.LoadLocation("Local")
  10459. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10460. utils.ErrorLog("advice_type")
  10461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10462. return
  10463. }
  10464. adviceType := int64(dataBody["advice_type"].(float64))
  10465. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10466. utils.ErrorLog("start_time")
  10467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10468. return
  10469. }
  10470. startTime2, _ := dataBody["start_time"].(string)
  10471. time_arr := strings.Split(startTime2, " ")
  10472. if len(time_arr) > 0 {
  10473. startTime2 = time_arr[0]
  10474. }
  10475. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10476. utils.ErrorLog("advice_date")
  10477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10478. return
  10479. }
  10480. advice_date, _ := dataBody["advice_date"].(string)
  10481. var advicedateunix int64
  10482. if len(advice_date) > 0 {
  10483. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10484. if err != nil {
  10485. fmt.Println(err)
  10486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10487. return
  10488. }
  10489. advicedateunix = theTime.Unix()
  10490. }
  10491. adviceDate := startTime2
  10492. if len(adviceDate) == 0 {
  10493. utils.ErrorLog("len(adviceDate) == 0")
  10494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10495. return
  10496. }
  10497. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10498. if err != nil {
  10499. utils.ErrorLog(err.Error())
  10500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10501. return
  10502. }
  10503. AdviceDate := advicedateunix
  10504. RecordDate := advicedateunix
  10505. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10506. utils.ErrorLog("start_time")
  10507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10508. return
  10509. }
  10510. startTime, _ := dataBody["start_time"].(string)
  10511. if len(startTime) == 0 {
  10512. utils.ErrorLog("len(start_time) == 0")
  10513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10514. return
  10515. }
  10516. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10517. if err != nil {
  10518. utils.ErrorLog(err.Error())
  10519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10520. return
  10521. }
  10522. StartTime := theTime.Unix()
  10523. advice_name, _ := dataBody["advice_name"].(string)
  10524. advice_desc, _ := dataBody["advice_desc"].(string)
  10525. delivery_way, _ := dataBody["delivery_way"].(string)
  10526. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10527. frequency_type := int64(dataBody["frequency_type"].(float64))
  10528. frequency_week, _ := dataBody["frequency_week"].(string)
  10529. prescribing_number := dataBody["prescribing_number"].(float64)
  10530. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10531. remark := dataBody["remark"].(string)
  10532. single_dose := dataBody["single_dose"].(float64)
  10533. single_dose_unit := dataBody["single_dose_unit"].(string)
  10534. patient_id := int64(dataBody["patient_id"].(float64))
  10535. day_count := int64(dataBody["day_count"].(float64))
  10536. groupNo := int64(dataBody["group_no"].(float64))
  10537. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10538. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10539. if groupNo <= 0 {
  10540. group := service.GetMaxAdviceGroupID(org_id)
  10541. groupNo = group + 1
  10542. }
  10543. var template_id = ""
  10544. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10545. template_id = "M" + adviceLastId
  10546. advice := models.DoctorAdvice{
  10547. UserOrgId: org_id,
  10548. PatientId: patient_id,
  10549. AdviceType: adviceType,
  10550. AdviceDate: AdviceDate,
  10551. StartTime: StartTime,
  10552. AdviceName: advice_name,
  10553. AdviceDesc: advice_desc,
  10554. ReminderDate: 0,
  10555. SingleDose: single_dose,
  10556. SingleDoseUnit: single_dose_unit,
  10557. DrugSpec: 0,
  10558. DrugSpecUnit: "",
  10559. PrescribingNumber: prescribing_number,
  10560. PrescribingNumberUnit: prescribing_number_unit,
  10561. DeliveryWay: delivery_way,
  10562. ExecutionFrequency: execution_frequency,
  10563. AdviceDoctor: advice_doctor,
  10564. Status: 1,
  10565. CreatedTime: time.Now().Unix(),
  10566. UpdatedTime: 0,
  10567. AdviceAffirm: "",
  10568. Remark: remark,
  10569. StopTime: 0,
  10570. StopReason: "",
  10571. StopDoctor: 0,
  10572. StopState: 2,
  10573. ParentId: 0,
  10574. ExecutionTime: 0,
  10575. ExecutionStaff: 0,
  10576. ExecutionState: 0,
  10577. Checker: 0,
  10578. RecordDate: RecordDate,
  10579. DialysisOrderId: 0,
  10580. CheckTime: 0,
  10581. CheckState: 0,
  10582. AdviceId: 0,
  10583. RemindType: 0,
  10584. FrequencyType: frequency_type,
  10585. DayCount: day_count,
  10586. WeekDay: frequency_week,
  10587. ChildDoctorAdvice: nil,
  10588. TemplateId: template_id,
  10589. Modifier: 0,
  10590. IsCheck: 0,
  10591. Way: 0,
  10592. DrugId: 0,
  10593. DrugNameId: 0,
  10594. IsMedicine: 0,
  10595. PushStartTime: 0,
  10596. IsSettle: 0,
  10597. IsPrescription: 0,
  10598. GroupNo: groupNo,
  10599. }
  10600. service.CreateMobileAdivce(advice)
  10601. c.ServeSuccessJSON(map[string]interface{}{
  10602. "msg": "保存成功!",
  10603. })
  10604. }
  10605. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10606. patient_id, _ := c.GetInt64("patient_id")
  10607. org_id := c.GetMobileAdminUserInfo().Org.Id
  10608. app_id := c.GetMobileAdminUserInfo().App.Id
  10609. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10610. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10611. c.ServeSuccessJSON(map[string]interface{}{
  10612. "adviceList": adviceList,
  10613. "adminRoles": adminRoles,
  10614. })
  10615. }
  10616. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10617. org_id := c.GetMobileAdminUserInfo().Org.Id
  10618. dataBody := make(map[string]interface{}, 0)
  10619. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10620. if err != nil {
  10621. utils.ErrorLog(err.Error())
  10622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10623. return
  10624. }
  10625. timeLayout := "2006-01-02"
  10626. loc, _ := time.LoadLocation("Local")
  10627. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10628. utils.ErrorLog("start_time")
  10629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10630. return
  10631. }
  10632. startTime2, _ := dataBody["start_time"].(string)
  10633. time_arr := strings.Split(startTime2, " ")
  10634. if len(time_arr) > 0 {
  10635. startTime2 = time_arr[0]
  10636. }
  10637. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10638. utils.ErrorLog("advice_date")
  10639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10640. return
  10641. }
  10642. advice_date, _ := dataBody["advice_date"].(string)
  10643. var advicedateunix int64
  10644. if len(advice_date) > 0 {
  10645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10646. if err != nil {
  10647. fmt.Println(err)
  10648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10649. return
  10650. }
  10651. advicedateunix = theTime.Unix()
  10652. }
  10653. adviceDate := startTime2
  10654. if len(adviceDate) == 0 {
  10655. utils.ErrorLog("len(adviceDate) == 0")
  10656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10657. return
  10658. }
  10659. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10660. if err != nil {
  10661. utils.ErrorLog(err.Error())
  10662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10663. return
  10664. }
  10665. AdviceDate := advicedateunix
  10666. RecordDate := advicedateunix
  10667. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10668. utils.ErrorLog("start_time")
  10669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10670. return
  10671. }
  10672. startTime, _ := dataBody["start_time"].(string)
  10673. if len(startTime) == 0 {
  10674. utils.ErrorLog("len(start_time) == 0")
  10675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10676. return
  10677. }
  10678. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10679. if err != nil {
  10680. utils.ErrorLog(err.Error())
  10681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10682. return
  10683. }
  10684. StartTime := theTime.Unix()
  10685. advice_name, _ := dataBody["advice_name"].(string)
  10686. advice_desc, _ := dataBody["advice_desc"].(string)
  10687. delivery_way, _ := dataBody["delivery_way"].(string)
  10688. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10689. prescribing_number := dataBody["prescribing_number"].(float64)
  10690. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10691. remark := dataBody["remark"].(string)
  10692. single_dose := dataBody["single_dose"].(float64)
  10693. single_dose_unit := dataBody["single_dose_unit"].(string)
  10694. patient_id := int64(dataBody["patient_id"].(float64))
  10695. groupNo := int64(dataBody["group_no"].(float64))
  10696. parent_id := int64(dataBody["parent_id"].(float64))
  10697. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10698. advice := models.XtDoctorAdviceOne{
  10699. UserOrgId: org_id,
  10700. PatientId: patient_id,
  10701. AdviceType: 1,
  10702. AdviceDate: AdviceDate,
  10703. StartTime: StartTime,
  10704. AdviceName: advice_name,
  10705. AdviceDesc: advice_desc,
  10706. ReminderDate: 0,
  10707. SingleDose: single_dose,
  10708. SingleDoseUnit: single_dose_unit,
  10709. PrescribingNumber: prescribing_number,
  10710. PrescribingNumberUnit: prescribing_number_unit,
  10711. DeliveryWay: delivery_way,
  10712. ExecutionFrequency: execution_frequency,
  10713. AdviceDoctor: advice_doctor,
  10714. Status: 1,
  10715. CreatedTime: time.Now().Unix(),
  10716. UpdatedTime: time.Now().Unix(),
  10717. AdviceAffirm: "",
  10718. Remark: remark,
  10719. StopTime: 0,
  10720. StopReason: "",
  10721. StopDoctor: 0,
  10722. StopState: 2,
  10723. ParentId: parent_id,
  10724. ExecutionTime: 0,
  10725. ExecutionStaff: 0,
  10726. ExecutionState: 0,
  10727. Checker: 0,
  10728. RecordDate: RecordDate,
  10729. DialysisOrderId: 0,
  10730. CheckTime: 0,
  10731. CheckState: 0,
  10732. DrugSpec: 0,
  10733. DrugSpecUnit: "",
  10734. Groupno: groupNo,
  10735. RemindType: 0,
  10736. FrequencyType: 0,
  10737. DayCount: 0,
  10738. WeekDay: "",
  10739. TemplateId: "",
  10740. Modifier: 0,
  10741. }
  10742. service.CreateMobileAdivceOne(advice)
  10743. c.ServeSuccessJSON(map[string]interface{}{
  10744. "msg": "保存成功!",
  10745. })
  10746. }
  10747. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10748. id, _ := c.GetInt64("id")
  10749. service.DeleteSelfAdviceSubAdvice(id)
  10750. c.ServeSuccessJSON(map[string]interface{}{
  10751. "msg": "保存成功!",
  10752. })
  10753. }
  10754. func (c *DialysisAPIController) GetEditAdviceAction() {
  10755. id, _ := c.GetInt64("id")
  10756. org_id := c.GetMobileAdminUserInfo().Org.Id
  10757. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10758. drugList, _ := service.GetAllDrugList(org_id)
  10759. c.ServeSuccessJSON(map[string]interface{}{
  10760. "advice": advice,
  10761. "drugList": drugList,
  10762. })
  10763. }
  10764. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10765. dataBody := make(map[string]interface{}, 0)
  10766. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10767. if err != nil {
  10768. utils.ErrorLog(err.Error())
  10769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10770. return
  10771. }
  10772. timeLayout := "2006-01-02"
  10773. loc, _ := time.LoadLocation("Local")
  10774. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10775. utils.ErrorLog("start_time")
  10776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10777. return
  10778. }
  10779. startTime2, _ := dataBody["start_time"].(string)
  10780. time_arr := strings.Split(startTime2, " ")
  10781. if len(time_arr) > 0 {
  10782. startTime2 = time_arr[0]
  10783. }
  10784. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10785. utils.ErrorLog("advice_date")
  10786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10787. return
  10788. }
  10789. advice_date, _ := dataBody["advice_date"].(string)
  10790. var advicedateunix int64
  10791. if len(advice_date) > 0 {
  10792. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10793. if err != nil {
  10794. fmt.Println(err)
  10795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10796. return
  10797. }
  10798. advicedateunix = theTime.Unix()
  10799. }
  10800. adviceDate := startTime2
  10801. if len(adviceDate) == 0 {
  10802. utils.ErrorLog("len(adviceDate) == 0")
  10803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10804. return
  10805. }
  10806. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10807. if err != nil {
  10808. utils.ErrorLog(err.Error())
  10809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10810. return
  10811. }
  10812. AdviceDate := advicedateunix
  10813. RecordDate := advicedateunix
  10814. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10815. utils.ErrorLog("start_time")
  10816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10817. return
  10818. }
  10819. startTime, _ := dataBody["start_time"].(string)
  10820. if len(startTime) == 0 {
  10821. utils.ErrorLog("len(start_time) == 0")
  10822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10823. return
  10824. }
  10825. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10826. if err != nil {
  10827. utils.ErrorLog(err.Error())
  10828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10829. return
  10830. }
  10831. StartTime := theTime.Unix()
  10832. advice_name, _ := dataBody["advice_name"].(string)
  10833. advice_desc, _ := dataBody["advice_desc"].(string)
  10834. delivery_way, _ := dataBody["delivery_way"].(string)
  10835. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10836. prescribing_number := dataBody["prescribing_number"].(float64)
  10837. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10838. remark := dataBody["remark"].(string)
  10839. single_dose := dataBody["single_dose"].(float64)
  10840. single_dose_unit := dataBody["single_dose_unit"].(string)
  10841. id := int64(dataBody["id"].(float64))
  10842. frequency_type := int64(dataBody["frequency_type"].(float64))
  10843. frequency_week, _ := dataBody["frequency_week"].(string)
  10844. day_count := int64(dataBody["day_count"].(float64))
  10845. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10846. advice := models.XtDoctorAdviceOne{
  10847. AdviceDate: AdviceDate,
  10848. StartTime: StartTime,
  10849. AdviceName: advice_name,
  10850. AdviceDesc: advice_desc,
  10851. SingleDose: single_dose,
  10852. SingleDoseUnit: single_dose_unit,
  10853. PrescribingNumber: prescribing_number,
  10854. PrescribingNumberUnit: prescribing_number_unit,
  10855. DeliveryWay: delivery_way,
  10856. ExecutionFrequency: execution_frequency,
  10857. AdviceDoctor: advice_doctor,
  10858. Remark: remark,
  10859. RecordDate: RecordDate,
  10860. FrequencyType: frequency_type,
  10861. DayCount: day_count,
  10862. WeekDay: frequency_week,
  10863. }
  10864. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10865. c.ServeSuccessJSON(map[string]interface{}{
  10866. "advice": advice,
  10867. })
  10868. }
  10869. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10870. dataBody := make(map[string]interface{}, 0)
  10871. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10872. if err != nil {
  10873. utils.ErrorLog(err.Error())
  10874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10875. return
  10876. }
  10877. timeLayout := "2006-01-02"
  10878. loc, _ := time.LoadLocation("Local")
  10879. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10880. utils.ErrorLog("start_time")
  10881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10882. return
  10883. }
  10884. startTime2, _ := dataBody["start_time"].(string)
  10885. time_arr := strings.Split(startTime2, " ")
  10886. if len(time_arr) > 0 {
  10887. startTime2 = time_arr[0]
  10888. }
  10889. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10890. utils.ErrorLog("advice_date")
  10891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10892. return
  10893. }
  10894. advice_date, _ := dataBody["advice_date"].(string)
  10895. var advicedateunix int64
  10896. if len(advice_date) > 0 {
  10897. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10898. if err != nil {
  10899. fmt.Println(err)
  10900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10901. return
  10902. }
  10903. advicedateunix = theTime.Unix()
  10904. }
  10905. adviceDate := startTime2
  10906. if len(adviceDate) == 0 {
  10907. utils.ErrorLog("len(adviceDate) == 0")
  10908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10909. return
  10910. }
  10911. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10912. if err != nil {
  10913. utils.ErrorLog(err.Error())
  10914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10915. return
  10916. }
  10917. AdviceDate := advicedateunix
  10918. RecordDate := advicedateunix
  10919. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10920. utils.ErrorLog("start_time")
  10921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10922. return
  10923. }
  10924. startTime, _ := dataBody["start_time"].(string)
  10925. if len(startTime) == 0 {
  10926. utils.ErrorLog("len(start_time) == 0")
  10927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10928. return
  10929. }
  10930. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10931. if err != nil {
  10932. utils.ErrorLog(err.Error())
  10933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10934. return
  10935. }
  10936. StartTime := theTime.Unix()
  10937. advice_name, _ := dataBody["advice_name"].(string)
  10938. advice_desc, _ := dataBody["advice_desc"].(string)
  10939. delivery_way, _ := dataBody["delivery_way"].(string)
  10940. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10941. prescribing_number := dataBody["prescribing_number"].(float64)
  10942. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10943. remark := dataBody["remark"].(string)
  10944. single_dose := dataBody["single_dose"].(float64)
  10945. single_dose_unit := dataBody["single_dose_unit"].(string)
  10946. id := int64(dataBody["id"].(float64))
  10947. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10948. advice := models.XtDoctorAdviceOne{
  10949. AdviceDate: AdviceDate,
  10950. StartTime: StartTime,
  10951. AdviceName: advice_name,
  10952. AdviceDesc: advice_desc,
  10953. SingleDose: single_dose,
  10954. SingleDoseUnit: single_dose_unit,
  10955. PrescribingNumber: prescribing_number,
  10956. PrescribingNumberUnit: prescribing_number_unit,
  10957. DeliveryWay: delivery_way,
  10958. ExecutionFrequency: execution_frequency,
  10959. AdviceDoctor: advice_doctor,
  10960. Remark: remark,
  10961. RecordDate: RecordDate,
  10962. }
  10963. service.UpdateMobileDoctorAdviceById(id, advice)
  10964. c.ServeSuccessJSON(map[string]interface{}{
  10965. "advice": advice,
  10966. })
  10967. }
  10968. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10969. dataBody := make(map[string]interface{}, 0)
  10970. timeLayout := "2006-01-02"
  10971. loc, _ := time.LoadLocation("Local")
  10972. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10973. if err != nil {
  10974. utils.ErrorLog(err.Error())
  10975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10976. return
  10977. }
  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. RecordDate := advicedateunix
  11017. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  11018. utils.ErrorLog("start_time")
  11019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11020. return
  11021. }
  11022. startTime, _ := dataBody["start_time"].(string)
  11023. if len(startTime) == 0 {
  11024. utils.ErrorLog("len(start_time) == 0")
  11025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11026. return
  11027. }
  11028. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  11029. if err != nil {
  11030. utils.ErrorLog(err.Error())
  11031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11032. return
  11033. }
  11034. StartTime := theTime.Unix()
  11035. patient_id := int64(dataBody["patient_id"].(float64))
  11036. group_no := int64(dataBody["group_no"].(float64))
  11037. org_id := c.GetMobileAdminUserInfo().Org.Id
  11038. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  11039. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  11040. utils.ErrorLog("advices")
  11041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11042. return
  11043. }
  11044. adviceNames := dataBody["advices"].([]interface{})
  11045. var advices []*models.GroupAdvice
  11046. for _, adviceNameMap := range adviceNames {
  11047. var advice models.GroupAdvice
  11048. adviceNameM := adviceNameMap.(map[string]interface{})
  11049. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  11050. utils.ErrorLog("advice_name")
  11051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11052. return
  11053. }
  11054. adviceName, _ := adviceNameM["advice_name"].(string)
  11055. if len(adviceName) == 0 {
  11056. utils.ErrorLog("len(advice_name) == 0")
  11057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11058. return
  11059. }
  11060. advice.AdviceName = adviceName
  11061. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  11062. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  11063. advice.DrugSpec = drugSpec
  11064. }
  11065. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  11066. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  11067. advice.AdviceDesc = adviceDesc
  11068. }
  11069. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  11070. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  11071. advice.DrugSpecUnit = drugSpecUnit
  11072. }
  11073. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  11074. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  11075. advice.SingleDose = singleDose
  11076. }
  11077. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  11078. singleDose := adviceNameM["single_dose"].(float64)
  11079. advice.SingleDose = singleDose
  11080. }
  11081. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  11082. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  11083. advice.SingleDoseUnit = singleDoseUnit
  11084. }
  11085. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  11086. tmp := adviceNameM["single_dose_unit"].(float64)
  11087. singleDoseUnit := service.TypeConversion(tmp)
  11088. advice.SingleDoseUnit = singleDoseUnit
  11089. }
  11090. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  11091. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  11092. advice.PrescribingNumber = prescribingNumber
  11093. }
  11094. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  11095. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  11096. advice.PrescribingNumber = prescribingNumber
  11097. }
  11098. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  11099. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  11100. advice.PrescribingNumberUnit = prescribingNumberUnit
  11101. }
  11102. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  11103. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  11104. advice.DeliveryWay = deliveryWay
  11105. }
  11106. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  11107. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  11108. advice.ExecutionFrequency = executionFrequency
  11109. }
  11110. remark, _ := adviceNameM["remark"].(string)
  11111. advice.Remark = remark
  11112. advice.AdviceType = 1
  11113. advice.StartTime = StartTime
  11114. advice.RecordDate = RecordDate
  11115. advice.PatientId = patient_id
  11116. advice.UserOrgId = org_id
  11117. advice.AdviceDoctor = advice_doctor
  11118. advice.StopState = 2
  11119. advices = append(advices, &advice)
  11120. }
  11121. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  11122. c.ServeSuccessJSON(map[string]interface{}{
  11123. "advice": newAdvices,
  11124. })
  11125. }
  11126. func (c *DialysisAPIController) StopLongAdvice() {
  11127. stop_time := c.GetString("execution_time")
  11128. id, _ := c.GetInt64("id")
  11129. if len(stop_time) <= 0 {
  11130. utils.ErrorLog("stop_time")
  11131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11132. return
  11133. }
  11134. timeLayout2 := "2006-01-02 15:04:05"
  11135. loc, _ := time.LoadLocation("Local")
  11136. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  11137. if errs != nil {
  11138. utils.ErrorLog(errs.Error())
  11139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11140. return
  11141. }
  11142. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  11143. c.ServeSuccessJSON(map[string]interface{}{
  11144. "advice": advice,
  11145. })
  11146. }