dialysis_api_controller.go 449KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612
  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 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  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. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. start_time := c.GetString("start_time")
  1323. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1324. if id <= 0 {
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. adminUserInfo := c.GetMobileAdminUserInfo()
  1329. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1330. if patient.ID == 0 {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1332. return
  1333. }
  1334. if len(recordDateStr) == 0 {
  1335. recordDateStr = time.Now().Format("2006-01-02")
  1336. }
  1337. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1338. fmt.Println("parseDateErr", parseDateErr)
  1339. if parseDateErr != nil {
  1340. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1345. //now := time.Now()
  1346. //year, month, day := now.Date()
  1347. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1348. //todayTimeStamp := today_time.Unix()
  1349. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1350. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1351. UserOrgId: adminUserInfo.Org.Id,
  1352. PatientId: id,
  1353. AssessmentDate: recordDate.Unix(),
  1354. Temperature: temperature,
  1355. PulseFrequency: pulse_frequency,
  1356. BreathingRate: breathing_rate,
  1357. SystolicBloodPressure: systolic_blood_pressure,
  1358. DiastolicBloodPressure: diastolic_blood_pressure,
  1359. ActualUltrafiltration: actual_ultrafiltration,
  1360. ActualDisplacement: actual_displacement,
  1361. ActualTreatmentHour: actualtreatHour,
  1362. ActualTreatmentMinute: actualtreatmin,
  1363. WeightAfter: weightAfter,
  1364. AdditionalWeight: additionalWeight,
  1365. WeightLoss: weightReduce,
  1366. Cruor: cruor,
  1367. SymptomAfterDialysis: symptomsAfterDialysi,
  1368. InternalFistula: internalFistula,
  1369. Catheter: catheter,
  1370. Complication: complications,
  1371. DialysisIntakes: dialysateVolume,
  1372. CreatedTime: time.Now().Unix(),
  1373. UpdatedTime: time.Now().Unix(),
  1374. Status: 1,
  1375. Remark: remark,
  1376. BloodAccessPartId: blood_access_part_id,
  1377. BloodAccessPartOperaId: blood_access_part_opera_id,
  1378. DialysisIntakesUnit: dialysis_intakes_unit,
  1379. PuncturePointOozingBlood: puncturePointOozingBlood,
  1380. PuncturePointHaematoma: puncturePointHaematoma,
  1381. InternalFistulaTremorAc: internalFistulaTremorAc,
  1382. PatientGose: patientGose,
  1383. InpatientDepartment: inpatientDepartment,
  1384. ObservationContent: observationContent,
  1385. ObservationContentOther: observationContentOther,
  1386. DialysisProcess: dialysis_process,
  1387. InAdvanceMinute: in_advance_minute,
  1388. InAdvanceReason: in_advance_reason,
  1389. HemostasisMinute: hemostasis_minute,
  1390. HemostasisOpera: hemostasis_opera,
  1391. TremorNoise: tremor_noise,
  1392. DisequilibriumSyndrome: disequilibrium_syndrome,
  1393. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1394. ArterialTube: arterial_tube,
  1395. IntravenousTube: intravenous_tube,
  1396. Dialyzer: dialyzer,
  1397. InAdvanceReasonOther: in_advance_reason_other,
  1398. IsEat: is_eat,
  1399. CvcA: cvc_a,
  1400. CvcV: cvc_v,
  1401. Channel: channels,
  1402. ReturnBlood: return_blood,
  1403. RehydrationVolume: rehydration_volume,
  1404. DialysisDuring: dialysis_during,
  1405. StrokeVolume: stroke_volume,
  1406. BloodFlow: blood_flow,
  1407. SealingFluidDispose: sealing_fluid_dispose,
  1408. SealingFluidSpecial: sealing_fluid_special,
  1409. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1410. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1411. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1412. SettingPressure: setting_pressure,
  1413. DiastolicPressure: diastolic_pressure,
  1414. OtherComplication: other_complication,
  1415. Ktv: ktv,
  1416. Urr: urr,
  1417. Hypopiesia: hypopiesia,
  1418. Hypertenison: hypertenison,
  1419. Lapse: lapse,
  1420. LeaveOfficeMethod: leave_office_method,
  1421. Consciousness: consciousness,
  1422. Fallrisk: fallrisk,
  1423. MachineRun: machine_run,
  1424. AfterUrea: after_urea,
  1425. PipCoagulation: pip_coagulation,
  1426. AccumulatedBloodVolume: accumulated_blood_volume,
  1427. TransfusionVolume: transfusion_volume,
  1428. LastAfterWeight: last_after_weight,
  1429. DisplaceLiquiValue: displace_liqui_value,
  1430. RecordTime: startDate.Unix(),
  1431. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1432. }
  1433. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1434. // 查询信息规挡的设置天数
  1435. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1436. if infor.ID > 0 && infor.WeekDay > 0 {
  1437. var cha_time int64
  1438. timeNowStr := time.Now().Format("2006-01-02")
  1439. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1440. //今日的日期减去设置的日期
  1441. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1442. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1443. if cha_time >= recordDate.Unix() {
  1444. //查询审核是否允许
  1445. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1446. //申请状态不允许的情况 拒绝修改
  1447. if infor.ApplicationStatus != 1 {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1449. return
  1450. }
  1451. }
  1452. }
  1453. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1454. if assessmentAfter.ID == 0 { //新增
  1455. if appRole.UserType == 2 || appRole.UserType == 1 {
  1456. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1457. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1458. } else {
  1459. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1460. }
  1461. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1462. if assessmentAfterDislysis.UserOrgId != 10340 {
  1463. if assessmentAfterDislysis.WeightAfter == 0 {
  1464. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1465. }
  1466. }
  1467. if adminUserInfo.Org.Id == 10693 {
  1468. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1471. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1472. }
  1473. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1481. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1482. }
  1483. if assessmentAfterDislysis.PulseFrequency == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1486. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1487. }
  1488. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1489. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1490. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1491. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1492. }
  1493. }
  1494. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1495. //记录日志
  1496. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1497. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1498. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1499. PatientId: assessmentAfterDislysis.PatientId,
  1500. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1501. Status: 1,
  1502. ErrLog: string(byterequest),
  1503. AdminUserId: adminUserInfo.AdminUser.Id,
  1504. Ctime: 0,
  1505. Mtime: 0,
  1506. Source: "手机端保存透后评估",
  1507. }
  1508. service.CreateAfterDialysisLog(afterDialysisLog)
  1509. finish := models.XtDialysisFinish{
  1510. IsFinish: 1,
  1511. UserOrgId: adminUserInfo.Org.Id,
  1512. Status: 1,
  1513. Ctime: time.Now().Unix(),
  1514. Mtime: 0,
  1515. Module: 9,
  1516. RecordDate: recordDate.Unix(),
  1517. Sourse: 1,
  1518. PatientId: id,
  1519. }
  1520. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1521. if dialysisFinish.ID == 0 {
  1522. service.CreateDialysisFinish(finish)
  1523. }
  1524. redis := service.RedisClient()
  1525. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1526. redis.Set(keyTwo, "", time.Second)
  1527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1528. //清空key 值
  1529. redis.Set(key, "", time.Second)
  1530. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1531. redis.Set(keyOne, "", time.Second)
  1532. defer redis.Close()
  1533. if err == nil {
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "assessmentAfterDislysis": assessmentAfterDislysis,
  1536. })
  1537. }
  1538. return
  1539. } else { //修改
  1540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1541. if infor.ID > 0 && infor.WeekDay > 0 {
  1542. var cha_time int64
  1543. timeNowStr := time.Now().Format("2006-01-02")
  1544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1545. //今日的日期减去设置的日期
  1546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1547. if cha_time >= recordDate.Unix() {
  1548. //查询审核是否允许
  1549. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1550. //申请状态不允许的情况 拒绝修改
  1551. if infor.ApplicationStatus != 1 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. if appRole.UserType == 2 || appRole.UserType == 1 {
  1558. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1559. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1560. } else {
  1561. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1562. if assessmentAfterDislysis.Creater == 0 {
  1563. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1564. }
  1565. }
  1566. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1567. assessmentAfterDislysis.ID = assessmentAfter.ID
  1568. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1569. if assessmentAfterDislysis.UserOrgId != 10340 {
  1570. if assessmentAfterDislysis.WeightAfter == 0 {
  1571. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1572. }
  1573. }
  1574. if adminUserInfo.Org.Id == 10693 {
  1575. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1578. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1579. }
  1580. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1588. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1589. }
  1590. if assessmentAfterDislysis.PulseFrequency == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1593. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1594. }
  1595. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1596. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1597. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1598. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1599. }
  1600. }
  1601. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1602. //记录日志
  1603. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1604. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1605. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1606. PatientId: assessmentAfterDislysis.PatientId,
  1607. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1608. Status: 1,
  1609. ErrLog: string(byterequest),
  1610. AdminUserId: adminUserInfo.AdminUser.Id,
  1611. Ctime: time.Now().Unix(),
  1612. Mtime: 0,
  1613. Source: "手机端修改保存透后评估",
  1614. }
  1615. service.CreateAfterDialysisLog(afterDialysisLog)
  1616. redis := service.RedisClient()
  1617. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1618. redis.Set(keyTwo, "", time.Second)
  1619. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1620. //清空key 值
  1621. redis.Set(key, "", time.Second)
  1622. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1623. redis.Set(keyOne, "", time.Second)
  1624. if err == nil {
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "assessmentAfterDislysis": assessmentAfterDislysis,
  1627. })
  1628. return
  1629. }
  1630. }
  1631. return
  1632. }
  1633. func (c *DialysisAPIController) PostDialysisPrescription() {
  1634. id, _ := c.GetInt64("patient", 0)
  1635. recordDateStr := c.GetString("record_date")
  1636. if id <= 0 {
  1637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. adminUserInfo := c.GetMobileAdminUserInfo()
  1641. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1642. if patient.ID == 0 {
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1644. return
  1645. }
  1646. if len(recordDateStr) == 0 {
  1647. recordDateStr = time.Now().Format("2006-01-02")
  1648. }
  1649. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1650. if parseDateErr != nil {
  1651. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. mode_id, _ := c.GetInt64("mode_id", 0)
  1656. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1657. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1658. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1659. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1660. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1661. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1662. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1663. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1664. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1665. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1666. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1667. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1668. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1669. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1670. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1671. kalium, _ := c.GetFloat("kalium", 0)
  1672. sodium, _ := c.GetFloat("sodium", 0)
  1673. calcium, _ := c.GetFloat("calcium", 0)
  1674. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1675. glucose, _ := c.GetFloat("glucose", 0)
  1676. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1677. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1678. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1679. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1680. conductivity, _ := c.GetFloat("conductivity", 0)
  1681. remark := c.GetString("remark")
  1682. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1683. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1684. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1685. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1686. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1687. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1688. special_medicine_other := c.GetString("special_medicine_other")
  1689. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1690. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1691. blood_access, _ := c.GetInt64("blood_access", 0)
  1692. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1693. body_fluid_other := c.GetString("body_fluid_other")
  1694. niprocart, _ := c.GetInt64("niprocart", 0)
  1695. jms, _ := c.GetInt64("jms", 0)
  1696. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1697. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1698. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1699. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1700. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1701. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1702. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1703. injector, _ := c.GetInt64("injector", 0)
  1704. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1705. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1706. safe_package, _ := c.GetInt64("package", 0)
  1707. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1708. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1709. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1710. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1711. blood := c.GetString("blood")
  1712. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1713. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1714. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1715. displace_speed := c.GetString("displace_speed")
  1716. illness, _ := c.GetInt64("illness")
  1717. amylaceum := c.GetString("amylaceum")
  1718. single_time := c.GetString("single_time")
  1719. single_water := c.GetString("single_water")
  1720. replacement_flow := c.GetString("replacement_flow")
  1721. plasma_separator := c.GetString("plasma_separator")
  1722. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1723. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1724. oxygen_flow := c.GetString("oxygen_flow")
  1725. oxygen_time := c.GetString("oxygen_time")
  1726. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1727. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1728. puncture_needle := c.GetString("puncture_needle")
  1729. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1730. epo := c.GetString("epo")
  1731. epo_count, _ := c.GetFloat("epo_count", 0)
  1732. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1733. admin_user_id, _ := c.GetInt64("admin_user_id")
  1734. is_water := c.GetString("is_water")
  1735. var is_war int64
  1736. if is_water == "是" {
  1737. is_war = 1
  1738. }
  1739. if is_water == "否" {
  1740. is_war = 2
  1741. }
  1742. if is_water == "请选择" {
  1743. is_war = 0
  1744. }
  1745. drhy_water := c.GetString("drhy_water")
  1746. dry_water_hour := c.GetString("dry_water_hour")
  1747. water_machine := c.GetString("water_machine")
  1748. add_amount, _ := c.GetFloat("add_amount")
  1749. reduce_amount, _ := c.GetFloat("reduce_amount")
  1750. dialysis_remark := c.GetString("dialysis_remark")
  1751. prescribing_number, _ := c.GetFloat("prescribing_number")
  1752. prescription_sodium := c.GetString("prescription_sodium")
  1753. start_sodium := c.GetString("start_sodium")
  1754. sodium_curve := c.GetString("sodium_curve")
  1755. treatment_remark := c.GetString("treatment_remark")
  1756. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1757. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1758. prescription_water, _ := c.GetFloat("prescription_water")
  1759. dialysis_strainer := c.GetString("dialysis_strainer")
  1760. chaptalization := c.GetString("chaptalization")
  1761. washing_time := c.GetString("washing_time")
  1762. warsh_count := c.GetString("warsh_count")
  1763. blood_access_part_id := c.GetString("blood_access_part_id")
  1764. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1765. dialyzate := c.GetString("dialyzate")
  1766. first_super := c.GetString("first_super")
  1767. var first_sup int64
  1768. if first_super == "是" {
  1769. first_sup = 1
  1770. }
  1771. if first_super == "否" {
  1772. first_sup = 2
  1773. }
  1774. if first_super == "请选择" {
  1775. first_sup = 0
  1776. }
  1777. is_sequential := c.GetString("is_sequential")
  1778. var is_sequent int64
  1779. if is_sequential == "是" {
  1780. is_sequent = 1
  1781. }
  1782. if is_sequential == "否" {
  1783. is_sequent = 2
  1784. }
  1785. if is_sequential == "请选择" {
  1786. is_sequent = 0
  1787. }
  1788. conduct := c.GetString("conduct")
  1789. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1790. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1791. //
  1792. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1793. // if appRole.UserType == 3 {
  1794. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1795. // if getPermissionErr != nil {
  1796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. // return
  1798. // } else if headNursePermission == nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1800. // return
  1801. // }
  1802. // }
  1803. //}
  1804. // 查询信息规挡的设置天数
  1805. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1806. if infor.ID > 0 && infor.WeekDay > 0 {
  1807. var cha_time int64
  1808. timeNowStr := time.Now().Format("2006-01-02")
  1809. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1810. //今日的日期减去设置的日期
  1811. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1812. if cha_time >= recordDate.Unix() {
  1813. //查询审核是否允许
  1814. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1815. //申请状态不允许的情况 拒绝修改
  1816. if infor.ApplicationStatus != 1 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. if mode_id > 0 {
  1823. var str string
  1824. //查找该机构用的是什么透析器
  1825. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1826. if filedConfig.ID > 0 {
  1827. str = dialyzerPerfusionApparatus
  1828. } else {
  1829. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1830. }
  1831. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1832. }
  1833. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1834. var dialysis_dialyszers_id int64
  1835. var dialysis_strainer_id int64
  1836. var dialysis_irrigation_id int64
  1837. if len(goodList) > 0 {
  1838. for _, item := range goodList {
  1839. if item.SpecificationName == dialysis_dialyszers {
  1840. dialysis_dialyszers_id = item.ID
  1841. }
  1842. if item.SpecificationName == dialysis_irrigation {
  1843. dialysis_irrigation_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_strainer {
  1846. dialysis_strainer_id = item.ID
  1847. }
  1848. }
  1849. }
  1850. //TODO 需要根据角色去判断
  1851. prescription := models.DialysisPrescription{
  1852. UserOrgId: adminUserInfo.Org.Id,
  1853. PatientId: id,
  1854. RecordDate: recordDate.Unix(),
  1855. ModeId: mode_id,
  1856. DialysisDuration: dialysis_duration,
  1857. Dialyzer: dialyzer,
  1858. PerfusionApparatus: perfusion_apparatus,
  1859. BloodFlowVolume: blood_flow_volume,
  1860. DewaterAmount: dewater_amount,
  1861. DisplaceLiqui: displace_liqui,
  1862. ReplacementWay: replacement_way,
  1863. Anticoagulant: anticoagulant,
  1864. AnticoagulantShouji: anticoagulant_shouji,
  1865. AnticoagulantWeichi: anticoagulant_weichi,
  1866. AnticoagulantZongliang: anticoagulant_zongliang,
  1867. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1868. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1869. Kalium: kalium,
  1870. Sodium: sodium,
  1871. Calcium: calcium,
  1872. Bicarbonate: bicarbonate,
  1873. Glucose: glucose,
  1874. // DryWeight: dry_weight,
  1875. DialysateFlow: dialysate_flow,
  1876. DialysateTemperature: dialysate_temperature,
  1877. // PrescriptionDoctor: prescription_doctor,
  1878. ReplacementTotal: replacement_total,
  1879. Conductivity: conductivity,
  1880. Remark: remark,
  1881. Status: 1,
  1882. CreatedTime: time.Now().Unix(),
  1883. UpdatedTime: time.Now().Unix(),
  1884. DialysisDurationMinute: dialysisDurationMinute,
  1885. DialysisDurationHour: dialysisDurationHour,
  1886. TargetUltrafiltration: targetUltrafiltration,
  1887. DialysateFormulation: dialysateFormulation,
  1888. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1889. BodyFluid: body_fluid,
  1890. SpecialMedicine: special_medicine,
  1891. SpecialMedicineOther: special_medicine_other,
  1892. DisplaceLiquiPart: displace_liqui_part,
  1893. DisplaceLiquiValue: displace_liqui_value,
  1894. BloodAccess: blood_access,
  1895. Ultrafiltration: ultrafiltration,
  1896. BodyFluidOther: body_fluid_other,
  1897. Niprocart: niprocart,
  1898. Jms: jms,
  1899. FistulaNeedleSet: fistula_needle_set,
  1900. FistulaNeedleSet16: fistula_needle_set_16,
  1901. Hemoperfusion: hemoperfusion,
  1902. DialyserSterilised: dialyser_sterilised,
  1903. Filtryzer: filtryzer,
  1904. Dialyzers: dialyzers,
  1905. Injector: injector,
  1906. Bloodlines: bloodlines,
  1907. TubingHemodialysis: tubing_hemodialysis,
  1908. Package: safe_package,
  1909. ALiquid: a_liquid,
  1910. TargetKtv: target_ktv,
  1911. PreImpulse: pre_impulse,
  1912. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1914. Blood: blood,
  1915. DialysisDialyszers: dialysis_dialyszers,
  1916. DialysisIrrigation: dialysis_irrigation,
  1917. AntioxidantCommodityName: antioxidant_commodity_name,
  1918. DisplaceSpeed: displace_speed,
  1919. Illness: illness,
  1920. Amylaceum: amylaceum,
  1921. SingleTime: single_time,
  1922. SingleWater: single_water,
  1923. ReplacementFlow: replacement_flow,
  1924. PlasmaSeparator: plasma_separator,
  1925. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1926. OxygenUptake: oxygen_uptake,
  1927. OxygenFlow: oxygen_flow,
  1928. OxygenTime: oxygen_time,
  1929. HemodialysisPipelines: hemodialysis_pipelines,
  1930. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1931. PunctureNeedle: puncture_needle,
  1932. PunctureNeedleCount: puncture_needle_count,
  1933. Epo: epo,
  1934. EpoCount: epo_count,
  1935. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1936. AdminUserId: admin_user_id,
  1937. IsWater: is_war,
  1938. DrhyWater: drhy_water,
  1939. DryWaterHour: dry_water_hour,
  1940. WaterMachine: water_machine,
  1941. AddAmount: add_amount,
  1942. ReduceAmount: reduce_amount,
  1943. DialysisRemark: dialysis_remark,
  1944. PrescribingNumber: prescribing_number,
  1945. StartSodium: start_sodium,
  1946. SodiumCurve: sodium_curve,
  1947. TreatmentRemark: treatment_remark,
  1948. PrescriptionSodium: prescription_sodium,
  1949. DialysisFluidFlow: dialysis_fluid_flow,
  1950. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1951. PrescriptionWater: prescription_water,
  1952. DialysisStrainer: dialysis_strainer,
  1953. Chaptalization: chaptalization,
  1954. WashingTime: washing_time,
  1955. WarshCount: warsh_count,
  1956. BloodAccessPartId: blood_access_part_id,
  1957. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1958. Dialyzate: dialyzate,
  1959. DialysisDialyszersId: dialysis_dialyszers_id,
  1960. DialysisIrrigationId: dialysis_irrigation_id,
  1961. DialysisStrainerId: dialysis_strainer_id,
  1962. FirstSuper: first_sup,
  1963. IsSequential: is_sequent,
  1964. Conduct: conduct,
  1965. }
  1966. if adminUserInfo.Org.Id == 10721 {
  1967. if prescription.ModeId == 2 {
  1968. if prescription.ReplacementTotal == 0 {
  1969. prescription.ReplacementTotal = 15
  1970. }
  1971. }
  1972. }
  1973. //查询最近透析准备表里是否存在 透析器 灌流器
  1974. //
  1975. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1976. //
  1977. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1978. //
  1979. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1980. //if len(mation)>0{
  1981. // for _, item := range splitStr {
  1982. // for _,it := range mation{
  1983. // if(item == it.SpecificationName){
  1984. //
  1985. // //查询最近一次的透析器
  1986. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1987. //
  1988. // if errcode == gorm.ErrRecordNotFound{
  1989. // //插入数据
  1990. // prepare := models.DialysisBeforePrepare{
  1991. // UserOrgId: adminUserInfo.Org.Id,
  1992. // PatientId: id,
  1993. // RecordDate: recordDate.Unix(),
  1994. // GoodTypeId: it.GoodTypeId,
  1995. // GoodId: it.ID,
  1996. // Count: 1,
  1997. // Ctime: time.Now().Unix(),
  1998. // Creater: adminUserInfo.AdminUser.Id,
  1999. // Status:1,
  2000. //
  2001. // }
  2002. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2003. // fmt.Println("",errcode)
  2004. // }
  2005. // }
  2006. // }
  2007. //
  2008. // }
  2009. //
  2010. // for _, item := range splitIrrigation {
  2011. // for _,it := range mation{
  2012. // if(item == it.SpecificationName){
  2013. // //查询最近一次的透析器
  2014. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2015. // if errcode == gorm.ErrRecordNotFound{
  2016. // //插入数据
  2017. // prepare := models.DialysisBeforePrepare{
  2018. // UserOrgId: adminUserInfo.Org.Id,
  2019. // PatientId: id,
  2020. // RecordDate: recordDate.Unix(),
  2021. // GoodTypeId: it.GoodTypeId,
  2022. // GoodId: it.ID,
  2023. // Count: 1,
  2024. // Ctime: time.Now().Unix(),
  2025. // Creater: adminUserInfo.AdminUser.Id,
  2026. // Status:1,
  2027. //
  2028. // }
  2029. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2030. // fmt.Println(errcode)
  2031. // }
  2032. // }
  2033. // }
  2034. // }
  2035. //}
  2036. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2037. if dialysisPrescription.ID == 0 { //新增
  2038. if appRole.UserType == 2 || appRole.UserType == 1 {
  2039. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2040. }
  2041. prescription.Creater = adminUserInfo.AdminUser.Id
  2042. //针对河间咸得
  2043. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2044. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2045. prescription.DisplaceLiquiPart = 0
  2046. prescription.DisplaceLiquiValue = 0
  2047. }
  2048. }
  2049. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2050. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2051. }
  2052. err := service.AddSigleRecord(&prescription)
  2053. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2054. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2055. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2056. if len(monitorList) > 0 {
  2057. var ultrafiltration_rate float64
  2058. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2059. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2060. var replacement_rate float64
  2061. //乘10 除10是为了保留一位小数
  2062. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2063. var firstOpeateTime = monitorList[0].OperateTime
  2064. for _, item := range monitorList {
  2065. //超滤率
  2066. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2067. //置换率
  2068. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2069. //超滤量
  2070. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2071. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2072. //置换量
  2073. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2074. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2075. }
  2076. }
  2077. }
  2078. //记录日志
  2079. byterequest, _ := json.Marshal(prescription)
  2080. prescriptionLog := models.XtDialysisPrescriptionLog{
  2081. UserOrgId: prescription.UserOrgId,
  2082. Ctime: time.Now().Unix(),
  2083. Mtime: 0,
  2084. ErrLog: string(byterequest),
  2085. AdminUserId: adminUserInfo.AdminUser.Id,
  2086. RecordDate: prescription.RecordDate,
  2087. PatientId: prescription.PatientId,
  2088. Source: "手机端新增保存处方",
  2089. Status: 1,
  2090. }
  2091. service.CreatePrescriptionLog(prescriptionLog)
  2092. finish := models.XtDialysisFinish{
  2093. IsFinish: 1,
  2094. UserOrgId: adminUserInfo.Org.Id,
  2095. Status: 1,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. Module: 1,
  2099. RecordDate: recordDate.Unix(),
  2100. Sourse: 1,
  2101. PatientId: id,
  2102. }
  2103. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2104. if dialysisFinish.ID == 0 {
  2105. service.CreateDialysisFinish(finish)
  2106. }
  2107. //长沙南雅医院,自动生成抗凝剂的临时处方
  2108. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2109. if prescribing_number == 0 {
  2110. prescribing_number = 1
  2111. }
  2112. if prescribing_number == 0 && id == 14682 {
  2113. prescribing_number = 2
  2114. }
  2115. if prescribing_number == 0 && id == 18560 {
  2116. prescribing_number = 2
  2117. }
  2118. advice := models.DoctorAdvice{
  2119. UserOrgId: adminUserInfo.Org.Id,
  2120. PatientId: id,
  2121. GroupNo: 0,
  2122. AdviceType: 2,
  2123. RecordDate: recordDate.Unix(),
  2124. AdviceDate: recordDate.Unix(),
  2125. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2126. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2127. AdviceDesc: "",
  2128. ReminderDate: 0,
  2129. SingleDose: anticoagulant_zongliang,
  2130. SingleDoseUnit: "iu",
  2131. DrugSpec: 0,
  2132. DrugSpecUnit: "",
  2133. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2134. PrescribingNumberUnit: "支",
  2135. DeliveryWay: "静脉注射",
  2136. ExecutionFrequency: "上机前",
  2137. AdviceDoctor: 0,
  2138. Status: 1,
  2139. CreatedTime: time.Now().Unix(),
  2140. UpdatedTime: time.Now().Unix(),
  2141. IsPrescription: 1,
  2142. ExecutionState: 2,
  2143. StopState: 2,
  2144. IsSettle: 2,
  2145. }
  2146. // 查询排班信息
  2147. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2148. if schedulePatient.ID > 0 {
  2149. if schedulePatient.ScheduleType == 1 {
  2150. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2151. }
  2152. if schedulePatient.ScheduleType == 2 {
  2153. advice.StartTime = recordDate.Unix() + 9*60*60
  2154. }
  2155. }
  2156. // 抗凝剂名称
  2157. switch anticoagulant {
  2158. case 1:
  2159. advice.AdviceName = "无肝素"
  2160. break
  2161. case 2:
  2162. advice.AdviceName = "普通肝素"
  2163. break
  2164. case 3:
  2165. advice.AdviceName = "低分子肝素"
  2166. break
  2167. case 4:
  2168. advice.AdviceName = "阿加曲班"
  2169. break
  2170. case 5:
  2171. advice.AdviceName = "枸橼酸钠"
  2172. break
  2173. case 6:
  2174. advice.AdviceName = "低分子肝素钙"
  2175. break
  2176. case 7:
  2177. advice.AdviceName = "低分子肝素钠"
  2178. break
  2179. case 8:
  2180. advice.AdviceName = "依诺肝素"
  2181. break
  2182. case 9:
  2183. advice.AdviceName = "达肝素"
  2184. break
  2185. case 10:
  2186. advice.AdviceName = "体外抗凝"
  2187. break
  2188. case 11:
  2189. advice.AdviceName = "那曲肝素"
  2190. break
  2191. case 12:
  2192. advice.AdviceName = "无抗凝剂"
  2193. break
  2194. }
  2195. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2196. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2197. advice.AdviceDoctor = appRole.AdminUserId
  2198. }
  2199. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2200. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2201. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2202. advice.AdviceName = "低分子肝素钠注射液"
  2203. // 修改患者临时医嘱里的抗凝剂医嘱
  2204. advice.ID = advicePrescription.ID
  2205. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2206. } else {
  2207. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2208. advice.AdviceName = "低分子肝素钠注射液"
  2209. // 新增患者临时医嘱里的抗凝剂医嘱
  2210. service.CreateDoctorAdvice(&advice)
  2211. }
  2212. }
  2213. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2214. redis := service.RedisClient()
  2215. defer redis.Close()
  2216. //清空key 值
  2217. redis.Set(key, "", time.Second)
  2218. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2219. redis.Set(keyOne, "", time.Second)
  2220. }
  2221. //获取key,清空redis
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2223. redis := service.RedisClient()
  2224. //清空key 值
  2225. redis.Set(key, "", time.Second)
  2226. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2227. //清空key 值
  2228. redis.Set(keyOne, "", time.Second)
  2229. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2230. //清空key 值
  2231. redis.Set(keyTwo, "", time.Second)
  2232. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2233. redis.Set(keySix, "", time.Second)
  2234. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2235. redis.Set(keySeven, "", time.Second)
  2236. if err == nil {
  2237. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2238. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2239. //清空key 值
  2240. redis.Set(keyThree, "", time.Second)
  2241. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2242. //清空key 值
  2243. redis.Set(keyFour, "", time.Second)
  2244. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2245. redis.Set(keyFive, "", time.Second)
  2246. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2247. redis.Set(keySix, "", time.Second)
  2248. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2249. redis.Set(keySeven, "", time.Second)
  2250. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2251. //清空key 值
  2252. redis.Set(keyOne, "", time.Second)
  2253. if updateErr != nil {
  2254. utils.ErrorLog("%v", updateErr)
  2255. }
  2256. defer redis.Close()
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "prescription": prescription,
  2259. })
  2260. }
  2261. } else { //修改
  2262. //if mode_id > 0 {
  2263. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2264. //}
  2265. //if template.TemplateId == 1 {
  2266. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2267. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2268. // if getPermissionErr != nil {
  2269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2270. // return
  2271. // } else if headNursePermission == nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2273. // return
  2274. // }
  2275. // }
  2276. //}
  2277. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2278. prescription.Modifier = adminUserInfo.AdminUser.Id
  2279. if appRole.UserType == 2 || appRole.UserType == 1 {
  2280. prescription_doctor := adminUserInfo.AdminUser.Id
  2281. prescription.PrescriptionDoctor = prescription_doctor
  2282. } else {
  2283. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2284. }
  2285. if dialysisPrescription.Creater == 0 { //体重称
  2286. prescription.Creater = adminUserInfo.AdminUser.Id
  2287. } else {
  2288. prescription.Creater = dialysisPrescription.Creater
  2289. if adminUserInfo.Org.Id == 9882 {
  2290. if appRole.UserType == 2 || appRole.UserType == 1 {
  2291. prescription_doctor := adminUserInfo.AdminUser.Id
  2292. prescription.PrescriptionDoctor = prescription_doctor
  2293. prescription.Creater = prescription_doctor
  2294. }
  2295. }
  2296. }
  2297. prescription.ID = dialysisPrescription.ID
  2298. if adminUserInfo.Org.Id == 10721 {
  2299. if prescription.ModeId == 2 {
  2300. if prescription.ReplacementTotal == 0 {
  2301. prescription.ReplacementTotal = 15
  2302. }
  2303. }
  2304. }
  2305. service.UpDateDialysisPrescription(&prescription)
  2306. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2307. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2308. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2309. if len(monitorList) > 0 {
  2310. var ultrafiltration_rate float64
  2311. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2312. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2313. var replacement_rate float64
  2314. //乘10 除10是为了保留一位小数
  2315. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2316. var firstOpeateTime = monitorList[0].OperateTime
  2317. for _, item := range monitorList {
  2318. //超滤率
  2319. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2320. //置换率
  2321. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2322. //超滤量
  2323. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2324. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2325. //置换量
  2326. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2327. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2328. }
  2329. }
  2330. }
  2331. //记录日志
  2332. byterequest, _ := json.Marshal(prescription)
  2333. prescriptionLog := models.XtDialysisPrescriptionLog{
  2334. UserOrgId: prescription.UserOrgId,
  2335. Ctime: time.Now().Unix(),
  2336. Mtime: 0,
  2337. ErrLog: string(byterequest),
  2338. AdminUserId: adminUserInfo.AdminUser.Id,
  2339. RecordDate: prescription.RecordDate,
  2340. PatientId: prescription.PatientId,
  2341. Source: "手机端修改处方",
  2342. Status: 1,
  2343. }
  2344. service.CreatePrescriptionLog(prescriptionLog)
  2345. finish := models.XtDialysisFinish{
  2346. IsFinish: 1,
  2347. UserOrgId: adminUserInfo.Org.Id,
  2348. Status: 1,
  2349. Ctime: time.Now().Unix(),
  2350. Mtime: 0,
  2351. Module: 1,
  2352. RecordDate: recordDate.Unix(),
  2353. Sourse: 1,
  2354. PatientId: id,
  2355. }
  2356. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2357. if dialysisFinish.ID == 0 {
  2358. service.CreateDialysisFinish(finish)
  2359. }
  2360. //修改处方
  2361. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2362. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2363. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2364. if advicePrescription.ID > 0 {
  2365. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. }
  2374. }
  2375. //获取key,清空redis
  2376. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2377. redis := service.RedisClient()
  2378. //清空key 值
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2381. //清空key 值
  2382. redis.Set(keyOne, "", time.Second)
  2383. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2384. redis.Set(keySix, "", time.Second)
  2385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2386. redis.Set(keySeven, "", time.Second)
  2387. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2388. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2389. //清空key 值
  2390. redis.Set(keyTwoOne, "", time.Second)
  2391. defer redis.Close()
  2392. if updateErr != nil {
  2393. utils.ErrorLog("%v", updateErr)
  2394. }
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "prescription": prescription,
  2397. })
  2398. }
  2399. }
  2400. func (c *DialysisAPIController) Finish() {
  2401. id, _ := c.GetInt64("patient", 0)
  2402. recordDateStr := c.GetString("record_date")
  2403. nurseID, _ := c.GetInt64("nurse")
  2404. end_time := c.GetString("end_time")
  2405. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2406. internal_fistula := c.GetString("blood_access_internal_fistula")
  2407. catheter := c.GetString("catheter")
  2408. cruor := c.GetString("cruor")
  2409. mission := c.GetString("mission")
  2410. condenser := c.GetString("condenser")
  2411. if id <= 0 || nurseID <= 0 {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. adminUserInfo := c.GetMobileAdminUserInfo()
  2416. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2417. if patient.ID == 0 {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2419. return
  2420. }
  2421. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2422. if getNurseErr != nil {
  2423. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. } else if nurse == nil {
  2427. c.ErrorLog("护士不存在")
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2429. return
  2430. }
  2431. if len(recordDateStr) == 0 {
  2432. recordDateStr = time.Now().Format("2006-01-02")
  2433. }
  2434. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2435. if parseDateErr != nil {
  2436. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2438. return
  2439. }
  2440. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2441. if parseEndDateErr != nil {
  2442. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. // 查询信息规挡的设置天数
  2447. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2448. if infor.ID > 0 && infor.WeekDay > 0 {
  2449. var cha_time int64
  2450. timeNowStr := time.Now().Format("2006-01-02")
  2451. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2452. //今日的日期减去设置的日期
  2453. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2454. if cha_time >= recordDate.Unix() {
  2455. //查询审核是否允许
  2456. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2457. //申请状态不允许的情况 拒绝修改
  2458. if infor.ApplicationStatus != 1 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. //now := time.Now()
  2465. //year, month, day := now.Date()
  2466. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2467. //todayTimeStamp := today_time.Unix()
  2468. // 获取当天的第一条透析纪录
  2469. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2470. if getMonitorRecordsErr != nil {
  2471. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. }
  2475. // 获取当前的最后一条透析纪录
  2476. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if getMonitorRecordsErr != nil {
  2478. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2483. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2484. if getAADErr != nil {
  2485. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2487. return
  2488. }
  2489. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2490. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2491. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2492. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2493. if assessmentAfterDislysis != nil {
  2494. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2495. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2496. } else {
  2497. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2498. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2499. tempassessmentAfterDislysis.Status = 1
  2500. tempassessmentAfterDislysis.PatientId = id
  2501. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2502. }
  2503. //长沙南雅
  2504. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2505. //获取最后一条透析处方数据
  2506. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2507. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2508. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2509. }
  2510. if dialysisOrder.Stage == 1 {
  2511. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2513. fmt.Println(value)
  2514. a, b := math.Modf(value)
  2515. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2516. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2517. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2518. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2519. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2520. }
  2521. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2522. //var num1 int64
  2523. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2524. //fmt.Println(num1)
  2525. //sub := float64(num1 / 3600)
  2526. //fmt.Println(sub)
  2527. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2528. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2529. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2530. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2531. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2532. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2533. if adminUserInfo.Org.Id != 10375 {
  2534. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2535. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2536. }
  2537. if adminUserInfo.Org.Id != 10445 {
  2538. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2539. }
  2540. //北方营口医院
  2541. if adminUserInfo.Org.Id == 10445 {
  2542. //获取最后一条透析处方数据
  2543. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2544. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2545. } else {
  2546. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2547. }
  2548. //新化博翔
  2549. if adminUserInfo.Org.Id == 10447 {
  2550. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2551. }
  2552. //阳春
  2553. if adminUserInfo.Org.Id == 10485 {
  2554. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2555. }
  2556. if adminUserInfo.Org.Id == 10551 {
  2557. //获取最后一条透析处方数据
  2558. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2559. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2560. }
  2561. if adminUserInfo.Org.Id == 10580 {
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2563. }
  2564. if adminUserInfo.Org.Id == 10612 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2566. }
  2567. //孝康
  2568. if adminUserInfo.Org.Id == 10693 {
  2569. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2571. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2572. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2573. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2574. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2575. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2576. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2577. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2578. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2579. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2580. }
  2581. if adminUserInfo.Org.Id == 10721 {
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2584. }
  2585. if adminUserInfo.Org.Id == 10697 {
  2586. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2587. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2588. lastWeightAfter.LastAfterWeight = floatAfeter
  2589. }
  2590. }
  2591. 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 {
  2592. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2593. if adminUserInfo.Org.Id != 10702 {
  2594. if evaluation.SystolicBloodPressure == 0 {
  2595. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2596. if adminUserInfo.Org.Id == 10693 {
  2597. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2598. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2599. }
  2600. pre := models.PredialysisEvaluation{
  2601. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2602. }
  2603. fmt.Println("prew", pre)
  2604. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2605. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2606. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2607. redis := service.RedisClient()
  2608. redis.Set(key, "", time.Second)
  2609. redis.Set(keyOne, "", time.Second)
  2610. defer redis.Close()
  2611. fmt.Println(getNurseErr)
  2612. }
  2613. }
  2614. if adminUserInfo.Org.Id != 10702 {
  2615. if evaluation.DiastolicBloodPressure == 0 {
  2616. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2617. if adminUserInfo.Org.Id == 10693 {
  2618. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2619. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2620. }
  2621. pres := models.PredialysisEvaluation{
  2622. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2623. }
  2624. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2625. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2626. redis := service.RedisClient()
  2627. redis.Set(key, "", time.Second)
  2628. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2629. redis.Set(keyOne, "", time.Second)
  2630. defer redis.Close()
  2631. fmt.Println(getNurseErr)
  2632. }
  2633. }
  2634. if adminUserInfo.Org.Id != 10702 {
  2635. if evaluation.PulseFrequency == 0 {
  2636. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2637. if adminUserInfo.Org.Id == 10693 {
  2638. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2639. evaluation.PulseFrequency = pulseFrequency
  2640. }
  2641. press := models.PredialysisEvaluation{
  2642. PulseFrequency: evaluation.PulseFrequency,
  2643. }
  2644. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2645. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2646. redis := service.RedisClient()
  2647. redis.Set(key, "", time.Second)
  2648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2649. redis.Set(keyOne, "", time.Second)
  2650. defer redis.Close()
  2651. fmt.Println(getNurseErr)
  2652. }
  2653. }
  2654. if evaluation.Temperature == 0 {
  2655. evaluation.Temperature = fmonitorRecords.Temperature
  2656. press := models.PredialysisEvaluation{
  2657. Temperature: evaluation.Temperature,
  2658. }
  2659. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2661. redis := service.RedisClient()
  2662. redis.Set(key, "", time.Second)
  2663. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2664. redis.Set(keyOne, "", time.Second)
  2665. defer redis.Close()
  2666. fmt.Println(getNurseErr)
  2667. }
  2668. }
  2669. if adminUserInfo.Org.Id == 9583 {
  2670. //获取透析处方的最后一条数据
  2671. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2672. if diaerr != nil {
  2673. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2675. return
  2676. }
  2677. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2678. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2679. }
  2680. }
  2681. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2682. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2683. }
  2684. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2685. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2694. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2695. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2696. }
  2697. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2698. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2699. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2700. }
  2701. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2702. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2703. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2704. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2705. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2706. }
  2707. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  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 == 10598 {
  2714. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2715. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2716. }
  2717. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2718. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2719. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2720. }
  2721. if lastAssessmentAfterDislysis != nil {
  2722. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2723. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2724. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2725. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2726. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2727. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2728. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2729. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2730. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2731. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2732. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2733. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2734. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2735. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2736. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2737. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2738. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2739. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2740. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2741. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2742. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2743. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2744. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2745. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2746. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2747. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2748. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2749. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2750. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2751. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2752. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2753. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2754. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2755. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2756. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2757. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2758. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2759. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2760. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2761. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2762. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2763. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2764. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2765. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2766. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2767. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2768. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2769. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2770. if tempassessmentAfterDislysis.PatientId == 18695 {
  2771. tempassessmentAfterDislysis.ActualDisplacement = 0
  2772. }
  2773. if adminUserInfo.Org.Id != 10375 {
  2774. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2775. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2776. }
  2777. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2778. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2779. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2780. }
  2781. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2782. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2783. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2784. }
  2785. }
  2786. finish := models.XtDialysisFinish{
  2787. IsFinish: 1,
  2788. UserOrgId: adminUserInfo.Org.Id,
  2789. Status: 1,
  2790. Ctime: time.Now().Unix(),
  2791. Mtime: 0,
  2792. Module: 9,
  2793. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2794. Sourse: 1,
  2795. PatientId: tempassessmentAfterDislysis.PatientId,
  2796. }
  2797. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2798. if dialysisFinish.ID == 0 {
  2799. service.CreateDialysisFinish(finish)
  2800. }
  2801. //孝康
  2802. if adminUserInfo.Org.Id == 10693 {
  2803. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2804. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2805. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2806. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2807. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2808. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2809. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2810. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2811. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2812. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2813. }
  2814. if adminUserInfo.Org.Id == 10697 {
  2815. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2816. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2817. lastWeightAfter.LastAfterWeight = floatAfeter
  2818. }
  2819. if adminUserInfo.Org.Id == 10721 {
  2820. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2821. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2822. }
  2823. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2824. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2825. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2826. redis := service.RedisClient()
  2827. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2828. redis.Set(keyOne, "", time.Second)
  2829. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2830. redis.Set(keyTwo, "", time.Second)
  2831. defer redis.Close()
  2832. //清空key 值
  2833. redis.Set(key, "", time.Second)
  2834. if err != nil {
  2835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2836. return
  2837. }
  2838. if dialysisOrder == nil {
  2839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2840. return
  2841. }
  2842. if dialysisOrder.Stage == 2 {
  2843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2844. return
  2845. }
  2846. if dialysisOrder.Stage == 1 {
  2847. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2848. finish := models.XtDialysisFinish{
  2849. IsFinish: 1,
  2850. UserOrgId: adminUserInfo.Org.Id,
  2851. Status: 1,
  2852. Ctime: time.Now().Unix(),
  2853. Mtime: 0,
  2854. Module: 8,
  2855. RecordDate: recordDate.Unix(),
  2856. Sourse: 1,
  2857. PatientId: id,
  2858. }
  2859. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2860. if dialysisFinish.ID == 0 {
  2861. service.CreateDialysisFinish(finish)
  2862. }
  2863. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2864. redis := service.RedisClient()
  2865. defer redis.Close()
  2866. //清空key 值
  2867. redis.Set(key, "", time.Second)
  2868. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2869. redis.Set(keyOne, "", time.Second)
  2870. //结束时候透析次数加1
  2871. service.UpdateSolutionByPatientId(id)
  2872. //下机完自动消毒,针对长沙南雅
  2873. if dialysisOrder.Stage == 1 {
  2874. 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 {
  2875. //根据床位号获取设备型号
  2876. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2877. //查询使用消毒最后一条消毒记录
  2878. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2879. fmt.Println("err", err)
  2880. if err == gorm.ErrRecordNotFound {
  2881. //查找排班
  2882. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2883. //查询改设备是否有消毒计划
  2884. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2885. //根据床位号获取设备id
  2886. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2887. //查询病人信息
  2888. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2889. var con = ""
  2890. if patients.IsInfectious == 0 {
  2891. con = ""
  2892. }
  2893. if patients.IsInfectious == 1 {
  2894. con = "无"
  2895. }
  2896. if patients.IsInfectious == 2 {
  2897. con = "有"
  2898. }
  2899. if errcode == nil {
  2900. var end_time int64
  2901. end_time = endDate.Unix() + plan.DisinfecTime*60
  2902. //新增消毒
  2903. information := models.DeviceInformation{
  2904. Date: dialysisOrder.DialysisDate,
  2905. Zone: dialysisOrder.ZoneId,
  2906. Class: dialysisOrder.SchedualType,
  2907. BedNumber: dialysisOrder.BedID,
  2908. PatientId: dialysisOrder.PatientId,
  2909. DialysisMode: scheduleByPatient.ModeId,
  2910. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2911. Disinfection: 1,
  2912. DialysisConcentration: 1,
  2913. DisinfectionStatus: 1,
  2914. Move: 1,
  2915. UserOrgId: dialysisOrder.UserOrgId,
  2916. DisinfectType: plan.Way,
  2917. DisinfectantType: plan.MachineDisinfectant,
  2918. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2919. Disinfectant: plan.Disinfectant,
  2920. Ctime: time.Now().Unix(),
  2921. Status: 1,
  2922. SignName: nurseID,
  2923. EquimentId: addmacher.ID,
  2924. DisinfectionResidue: 2,
  2925. Bed: addmacher.BedNumber,
  2926. StartTime: dialysisOrder.StartTime,
  2927. EndTime: dialysisOrder.EndTime,
  2928. Contagion: con,
  2929. WeightLoss: 0,
  2930. Hyperfiltratio: 0,
  2931. DialysisHour: "",
  2932. MachineRun: 1,
  2933. DisinfecStartime: endDate.Unix(),
  2934. DisinfecEndtime: end_time,
  2935. }
  2936. err := service.CreateInformationTwo(&information)
  2937. fmt.Println("报错", err)
  2938. }
  2939. }
  2940. }
  2941. }
  2942. dialysisOrder.Stage = 2
  2943. dialysisOrder.FinishNurse = nurseID
  2944. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2945. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2946. dialysisOrder.EndTime = endDate.Unix()
  2947. // 长沙南雅需求
  2948. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2949. //获取最后1条监测的数据
  2950. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2951. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2952. var accumulatedBloodVolume float64
  2953. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2954. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2955. fmt.Println(err)
  2956. // 查询未执行的医嘱
  2957. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2958. for _, item := range doctorAdvice {
  2959. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2960. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2961. redis := service.RedisClient()
  2962. //清空key 值
  2963. redis.Set(key, "", time.Second)
  2964. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2965. redis.Set(keyTwo, "", time.Second)
  2966. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2967. redis.Set(keyThree, "", time.Second)
  2968. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2969. theTime := toTime.Format("2006-01-02")
  2970. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2971. redis.Set(keyFour, "", time.Second)
  2972. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2973. redis.Set(keyFive, "", time.Second)
  2974. defer redis.Close()
  2975. }
  2976. }
  2977. go func() {
  2978. ssoDomain := beego.AppConfig.String("call_domain")
  2979. api := ssoDomain + "/index/downpatient"
  2980. values := make(url.Values)
  2981. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2982. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2983. values.Set("patient_id", strconv.FormatInt(id, 10))
  2984. http.PostForm(api, values)
  2985. }()
  2986. if err == nil {
  2987. c.ServeSuccessJSON(map[string]interface{}{
  2988. "dialysisOrder": dialysisOrder,
  2989. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2990. })
  2991. } else {
  2992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2993. }
  2994. }
  2995. }
  2996. func (c *DialysisAPIController) GetAllZone() {
  2997. adminUserInfo := c.GetMobileAdminUserInfo()
  2998. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2999. if err == nil {
  3000. c.ServeSuccessJSON(map[string]interface{}{
  3001. "zone": zone,
  3002. })
  3003. }
  3004. }
  3005. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3006. adminUserInfo := c.GetMobileAdminUserInfo()
  3007. page, _ := c.GetInt64("page", 1)
  3008. limit, _ := c.GetInt64("limit", 10)
  3009. schedulType, _ := c.GetInt64("schedul_type", 0)
  3010. startTime, _ := c.GetInt64("schedul_time", 0)
  3011. partitionType, _ := c.GetInt64("partition_type", 0)
  3012. keywords := c.GetString("keywords")
  3013. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3014. if err == nil {
  3015. c.ServeSuccessJSON(map[string]interface{}{
  3016. "schedule": dialysisSchedule,
  3017. })
  3018. }
  3019. return
  3020. }
  3021. // /m/api/dialysis/start [post]
  3022. // @param patient_id:int
  3023. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3024. // @param nurse:int 上机护士
  3025. // @param bed:int 床位号
  3026. func (this *DialysisAPIController) StartDialysis() {
  3027. patientID, _ := this.GetInt64("patient_id")
  3028. recordDateStr := this.GetString("record_date")
  3029. nurseID, _ := this.GetInt64("start_nurse")
  3030. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3031. blood_drawing, _ := this.GetInt64("blood_drawing")
  3032. schedual_type, _ := this.GetInt64("schedual_type")
  3033. bedID, _ := this.GetInt64("bed")
  3034. start_time := this.GetString("start_time")
  3035. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3036. change_nurse, _ := this.GetInt64("change_nurse")
  3037. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3038. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3039. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3040. puncture_needle := this.GetString("puncture_needle")
  3041. puncture_way := this.GetString("puncture_way")
  3042. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3043. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3044. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3045. zone_id, _ := this.GetInt64("zone_id")
  3046. elecsign := this.GetString("url")
  3047. nuclein_date_str := this.GetString("nuclein_date_str")
  3048. schedule_remark := this.GetString("schedule_remark")
  3049. order_remark := this.GetString("order_remark")
  3050. catheter_operation := this.GetString("catheter_operation")
  3051. blood_flow_volume := this.GetString("blood_flow_volume")
  3052. dialysis_strainer := this.GetString("dialysis_strainer")
  3053. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3055. return
  3056. }
  3057. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3058. if parseStartDateErr != nil {
  3059. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3061. return
  3062. }
  3063. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3064. if parseErr != nil {
  3065. this.ErrorLog("时间解析失败:%v", parseErr)
  3066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. return
  3068. }
  3069. adminUserInfo := this.GetMobileAdminUserInfo()
  3070. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3071. if getPatientErr != nil {
  3072. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3074. return
  3075. } else if patient == nil {
  3076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3077. return
  3078. }
  3079. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3080. if getNurseErr != nil {
  3081. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. return
  3084. } else if nurse == nil {
  3085. this.ErrorLog("护士不存在")
  3086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3087. return
  3088. }
  3089. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3090. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3091. if getDeviceNumberErr != nil {
  3092. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3094. return
  3095. } else if deviceNumber == nil {
  3096. this.ErrorLog("床位号不存在")
  3097. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3098. return
  3099. }
  3100. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3101. if getRecordErr != nil {
  3102. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3104. return
  3105. } else if dialysisRecord != nil {
  3106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3107. return
  3108. }
  3109. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3110. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3111. timeLayout := "2006-01-02 15:04:05"
  3112. loc, _ := time.LoadLocation("Local")
  3113. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3114. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3115. schedulestartTime := theStartTime.Unix()
  3116. scheduleendTime := theEndTime.Unix()
  3117. var theNucleinDate int64
  3118. timeLayoutOne := "2006-01-02"
  3119. if len(nuclein_date_str) > 0 {
  3120. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3121. if err != nil {
  3122. utils.ErrorLog(err.Error())
  3123. }
  3124. theNucleinDate = theTime.Unix()
  3125. }
  3126. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3127. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3128. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3129. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3130. //查询该床位是否有人用了
  3131. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3132. if err == gorm.ErrRecordNotFound { //空床位
  3133. // 修改了床位逻辑
  3134. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3135. if daySchedule.ID > 0 {
  3136. daySchedule.PartitionId = deviceNumber.ZoneID
  3137. daySchedule.BedId = bedID
  3138. daySchedule.ScheduleType = schedual_type
  3139. daySchedule.UpdatedTime = time.Now().Unix()
  3140. xtSchedule := models.Schedule{
  3141. PartitionId: deviceNumber.ZoneID,
  3142. BedId: bedID,
  3143. ScheduleType: schedual_type,
  3144. UpdatedTime: time.Now().Unix(),
  3145. }
  3146. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3147. if err != nil {
  3148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3149. return
  3150. }
  3151. }
  3152. } else if err == nil {
  3153. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3154. if order.ID > 0 { //该机位被其他人占用了
  3155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3156. return
  3157. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3158. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3159. if daySchedule.ID > 0 {
  3160. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3161. if err != nil {
  3162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3163. return
  3164. }
  3165. }
  3166. }
  3167. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3169. return
  3170. }
  3171. //else if order.ID == 0 { //该床位没被占用
  3172. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3173. // if daySchedule.ID > 0 {
  3174. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3175. // //daySchedule.BedId = bedID
  3176. // //daySchedule.ScheduleType = schedual_type
  3177. // //daySchedule.UpdatedTime = time.Now().Unix()
  3178. // //err := service.UpdateSchedule(&daySchedule)
  3179. // xtSchedule := models.Schedule{
  3180. // PartitionId: deviceNumber.ZoneID,
  3181. // BedId: bedID,
  3182. // ScheduleType: schedual_type,
  3183. // UpdatedTime: time.Now().Unix(),
  3184. // }
  3185. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3186. // if err != nil {
  3187. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3188. // return
  3189. // }
  3190. // }
  3191. //}
  3192. //}
  3193. } else if err != nil {
  3194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3195. return
  3196. }
  3197. // 查询信息规挡的设置天数
  3198. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3199. if infor.ID > 0 && infor.WeekDay > 0 {
  3200. var cha_time int64
  3201. timeNowStr := time.Now().Format("2006-01-02")
  3202. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3203. //今日的日期减去设置的日期
  3204. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3205. if cha_time >= recordDate.Unix() {
  3206. //查询审核是否允许
  3207. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3208. //申请状态不允许的情况 拒绝修改
  3209. if infor.ApplicationStatus != 1 {
  3210. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3211. return
  3212. }
  3213. }
  3214. }
  3215. dialysisRecord = &models.DialysisOrder{
  3216. DialysisDate: recordDate.Unix(),
  3217. UserOrgId: adminUserInfo.Org.Id,
  3218. PatientId: patientID,
  3219. Stage: 1,
  3220. BedID: bedID,
  3221. StartNurse: nurseID,
  3222. Status: 1,
  3223. StartTime: startDate.Unix(),
  3224. CreatedTime: time.Now().Unix(),
  3225. UpdatedTime: time.Now().Unix(),
  3226. PunctureNurse: puncture_nurse,
  3227. Creator: adminUserInfo.AdminUser.Id,
  3228. Modifier: adminUserInfo.AdminUser.Id,
  3229. SchedualType: schedual_type,
  3230. WashpipeNurse: washpipe_nurse,
  3231. ChangeNurse: change_nurse,
  3232. DifficultPunctureNurse: difficult_puncture_nurse,
  3233. NewFistulaNurse: new_fistula_nurse,
  3234. ZoneId: zone_id,
  3235. QualityNurseId: quality_nurse_id,
  3236. PunctureNeedle: puncture_needle,
  3237. PunctureWay: puncture_way,
  3238. DialysisIrrigation: dialysis_irrigation,
  3239. DialysisDialyszers: dialysis_dialyszers,
  3240. BloodAccessId: blood_access_id,
  3241. Url: elecsign,
  3242. NucleinDate: theNucleinDate,
  3243. ScheduleRemark: schedule_remark,
  3244. OrderRemark: order_remark,
  3245. CatheterOperation: catheter_operation,
  3246. BloodFlowVolume: blood_flow_volume,
  3247. BloodDrawing: blood_drawing,
  3248. DialysisStrainer: dialysis_strainer,
  3249. }
  3250. //查询该床位是否有人用了
  3251. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3252. if errorscode == gorm.ErrRecordNotFound {
  3253. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3254. finish := models.XtDialysisFinish{
  3255. IsFinish: 1,
  3256. UserOrgId: adminUserInfo.Org.Id,
  3257. Status: 1,
  3258. Ctime: time.Now().Unix(),
  3259. Mtime: 0,
  3260. Module: 6,
  3261. RecordDate: schedulestartTime,
  3262. Sourse: 1,
  3263. PatientId: patientID,
  3264. }
  3265. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3266. if dialysisFinish.ID == 0 {
  3267. service.CreateDialysisFinish(finish)
  3268. }
  3269. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3270. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3271. //统计该患者总次数
  3272. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3273. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3274. }
  3275. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3276. //统计该患者总次数
  3277. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3278. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3279. }
  3280. redis := service.RedisClient()
  3281. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3282. redis.Set(key, "", time.Second)
  3283. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3284. //清空key 值
  3285. redis.Set(keyOne, "", time.Second)
  3286. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3287. //清空key 值
  3288. redis.Set(keyTwo, "", time.Second)
  3289. if createErr != nil {
  3290. this.ErrorLog("上机失败:%v", createErr)
  3291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3292. return
  3293. }
  3294. }
  3295. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3296. var tempdispose string
  3297. // 只针对中能建
  3298. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3299. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3300. }
  3301. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3302. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3303. }
  3304. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3305. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3306. //}
  3307. var ultrafiltration_rate float64
  3308. var ultrafiltration_rate_one string
  3309. var replacement_rate float64
  3310. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3311. //后期预增脱水量
  3312. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3313. if prescription.ID > 0 {
  3314. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3315. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3316. 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
  3317. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3318. }
  3319. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3320. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3321. }
  3322. //针对医师汇
  3323. if adminUserInfo.Org.Id == 10121 {
  3324. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3325. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3326. }
  3327. //针对通道
  3328. if adminUserInfo.Org.Id == 10234 {
  3329. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3330. }
  3331. //针对监利大垸医院
  3332. if template.TemplateId == 41 {
  3333. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3334. }
  3335. //针对肇庆三鹤血液透析中心
  3336. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3337. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3338. }
  3339. if adminUserInfo.Org.Id == 10469 {
  3340. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3341. }
  3342. if adminUserInfo.Org.Id == 10667 {
  3343. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3344. }
  3345. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3346. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3347. }
  3348. // 只针对方济医院
  3349. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3350. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3351. ultrafiltration_rate = value
  3352. }
  3353. //针对
  3354. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3355. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3356. ultrafiltration_rate = ultrafiltration_rate / 1000
  3357. }
  3358. if adminUserInfo.Org.Id == 10551 {
  3359. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3360. ultrafiltration_rate = ultrafiltration_rate / 1000
  3361. }
  3362. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3363. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3364. ultrafiltration_rate = ultrafiltration_rate / 1000
  3365. }
  3366. if adminUserInfo.Org.Id == 10580 {
  3367. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3368. ultrafiltration_rate = ultrafiltration_rate / 1000
  3369. }
  3370. if adminUserInfo.Org.Id == 10629 {
  3371. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3372. ultrafiltration_rate = ultrafiltration_rate / 1000
  3373. }
  3374. if adminUserInfo.Org.Id == 10644 {
  3375. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3376. ultrafiltration_rate = ultrafiltration_rate / 1000
  3377. }
  3378. if adminUserInfo.Org.Id == 10667 {
  3379. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3380. ultrafiltration_rate = ultrafiltration_rate / 1000
  3381. }
  3382. if adminUserInfo.Org.Id == 10693 {
  3383. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3384. ultrafiltration_rate = ultrafiltration_rate
  3385. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3386. }
  3387. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3388. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3389. ultrafiltration_rate = ultrafiltration_rate
  3390. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3391. }
  3392. if adminUserInfo.Org.Id == 10206 {
  3393. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3394. ultrafiltration_rate = ultrafiltration_rate
  3395. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3396. }
  3397. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3398. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3399. ultrafiltration_rate = ultrafiltration_rate
  3400. }
  3401. if adminUserInfo.Org.Id == 10702 {
  3402. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3403. ultrafiltration_rate = ultrafiltration_rate / 1000
  3404. }
  3405. if adminUserInfo.Org.Id == 10723 {
  3406. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3407. ultrafiltration_rate = ultrafiltration_rate / 1000
  3408. }
  3409. if adminUserInfo.Org.Id == 10721 {
  3410. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3411. ultrafiltration_rate = ultrafiltration_rate / 1000
  3412. }
  3413. if adminUserInfo.Org.Id == 10721 {
  3414. if prescription.ModeId == 2 {
  3415. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3416. if totalMin == 0 {
  3417. totalMin = 240
  3418. }
  3419. if prescription.ReplacementTotal == 0 {
  3420. prescription.ReplacementTotal = 15
  3421. }
  3422. //乘10 除10是为了保留一位小数
  3423. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3424. }
  3425. }
  3426. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3427. if prescription.ModeId == 2 {
  3428. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3429. if totalMin == 0 {
  3430. totalMin = 240
  3431. }
  3432. if prescription.DisplaceLiquiValue == 0 {
  3433. prescription.ReplacementTotal = 32
  3434. }
  3435. //乘10 除10是为了保留一位小数
  3436. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3437. }
  3438. }
  3439. }
  3440. }
  3441. if adminUserInfo.Org.Id == 10172 {
  3442. if prescription.ID == 0 {
  3443. if prescription.ModeId == 2 {
  3444. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3445. if totalMin == 0 {
  3446. totalMin = 240
  3447. }
  3448. if prescription.ReplacementTotal == 0 {
  3449. prescription.ReplacementTotal = 15
  3450. }
  3451. //乘10 除10是为了保留一位小数
  3452. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3453. }
  3454. }
  3455. }
  3456. record := models.MonitoringRecord{
  3457. UserOrgId: adminUserInfo.Org.Id,
  3458. PatientId: patientID,
  3459. DialysisOrderId: dialysisRecord.ID,
  3460. MonitoringDate: schedulestartTime,
  3461. OperateTime: startDate.Unix(),
  3462. // MonitoringTime: recordTime,
  3463. MonitoringNurse: nurseID,
  3464. Dispose: tempdispose,
  3465. UltrafiltrationRate: ultrafiltration_rate,
  3466. UltrafiltrationVolume: 0,
  3467. Status: 1,
  3468. CreatedTime: time.Now().Unix(),
  3469. UpdatedTime: time.Now().Unix(),
  3470. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3471. ReplacementRate: replacement_rate,
  3472. }
  3473. //只针对广慈医院
  3474. 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 {
  3475. // 查询病人是否有透前评估数据
  3476. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3477. //如果有数据就插入
  3478. if errcode == nil {
  3479. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3480. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3481. record.BreathingRate = befor.BreathingRate
  3482. record.PulseFrequency = befor.PulseFrequency
  3483. record.Temperature = befor.Temperature
  3484. }
  3485. }
  3486. //孝昌
  3487. if adminUserInfo.Org.Id == 10693 {
  3488. // 查询病人是否有透前评估数据
  3489. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3490. //如果有数据就插入
  3491. if errcode == nil {
  3492. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3493. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3494. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3495. record.BreathingRate = befor.BreathingRate
  3496. }
  3497. }
  3498. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3499. if newdialysisRecord.ID > 0 {
  3500. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3501. record.Temperature = 36.5
  3502. record.ArterialPressure = -100
  3503. record.DialysateTemperature = 36.5
  3504. record.Conductivity = 14
  3505. record.BreathingRate = "20"
  3506. record.VenousPressure = 80
  3507. record.TransmembranePressure = 60
  3508. record.Dispose = catheter_operation
  3509. }
  3510. //针对新化博翔
  3511. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3512. record.BloodOxygenSaturation = "99"
  3513. record.Conductivity = 14
  3514. record.DialysateTemperature = 36.5
  3515. record.BreathingRate = "20"
  3516. }
  3517. //针对兰溪人民医院的需求
  3518. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3519. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3520. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3521. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3522. record.Temperature = befor.Temperature
  3523. record.PulseFrequency = befor.PulseFrequency
  3524. record.BreathingRate = befor.BreathingRate
  3525. }
  3526. //针对乐山友谊医院的需求
  3527. if adminUserInfo.Org.Id == 10677 {
  3528. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3529. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3530. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3531. record.Temperature = befor.Temperature
  3532. record.PulseFrequency = befor.PulseFrequency
  3533. record.BreathingRate = befor.BreathingRate
  3534. }
  3535. //新化博翔
  3536. if adminUserInfo.Org.Id == 10447 {
  3537. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3538. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3539. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3540. record.BreathingRate = befor.BreathingRate
  3541. }
  3542. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3543. record.PulseFrequency = 80
  3544. record.Temperature = 36.5
  3545. }
  3546. //诊断灵山圣康
  3547. if adminUserInfo.Org.Id == 10375 {
  3548. record.Conductivity = 13.8
  3549. record.DialysateTemperature = 37
  3550. record.DialysateFlow = 500
  3551. record.BloodFlowVolume = 200
  3552. record.BreathingRate = "18"
  3553. record.SodiumConcentration = 140
  3554. }
  3555. //江成肾病医院
  3556. if adminUserInfo.Org.Id == 10517 {
  3557. record.SodiumConcentration = 138
  3558. record.DialysateTemperature = 36.5
  3559. }
  3560. //濉溪杏康血液透析中心
  3561. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3562. record.BloodFlowVolume = prescription.BloodFlowVolume
  3563. }
  3564. //胶州少海医院
  3565. if adminUserInfo.Org.Id == 10735 {
  3566. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3567. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3568. record.BreathingRate = befor.BreathingRate
  3569. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3570. record.Temperature = befor.Temperature
  3571. record.PulseFrequency = befor.PulseFrequency
  3572. }
  3573. if adminUserInfo.Org.Id != 10683 {
  3574. err = service.CreateMonitor(&record)
  3575. }
  3576. //记录日志
  3577. byterequest, _ := json.Marshal(record)
  3578. monitorRecordLog := models.XtMonitorRecordLog{
  3579. RecordDate: record.MonitoringDate,
  3580. PatientId: record.PatientId,
  3581. Module: 1,
  3582. AdminUserId: adminUserInfo.AdminUser.Id,
  3583. Ctime: time.Now().Unix(),
  3584. Mtime: 0,
  3585. Status: 1,
  3586. UserOrgId: record.UserOrgId,
  3587. ErrLog: string(byterequest),
  3588. Source: "执行上机时新增监测",
  3589. }
  3590. service.CreateMonitorRecordLog(monitorRecordLog)
  3591. finish := models.XtDialysisFinish{
  3592. IsFinish: 1,
  3593. UserOrgId: adminUserInfo.Org.Id,
  3594. Status: 1,
  3595. Ctime: time.Now().Unix(),
  3596. Mtime: 0,
  3597. Module: 7,
  3598. RecordDate: schedulestartTime,
  3599. Sourse: 1,
  3600. PatientId: patientID,
  3601. }
  3602. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3603. if dialysisFinish.ID == 0 {
  3604. service.CreateDialysisFinish(finish)
  3605. }
  3606. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3607. redis := service.RedisClient()
  3608. //清空key 值
  3609. redis.Set(key, "", time.Second)
  3610. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3611. redis.Set(keyOne, "", time.Second)
  3612. defer redis.Close()
  3613. if err != nil {
  3614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3615. return
  3616. }
  3617. }
  3618. go func() {
  3619. ssoDomain := beego.AppConfig.String("call_domain")
  3620. api := ssoDomain + "/index/uppatient"
  3621. values := make(url.Values)
  3622. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3623. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3624. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3625. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3626. http.PostForm(api, values)
  3627. }()
  3628. this.ServeSuccessJSON(map[string]interface{}{
  3629. "dialysis_order": newdialysisRecord,
  3630. "monitor": record,
  3631. })
  3632. return
  3633. }
  3634. func (c *DialysisAPIController) PostSolution() {
  3635. id, _ := c.GetInt64("patient", 0)
  3636. recordDateStr := c.GetString("record_date")
  3637. if id <= 0 {
  3638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3639. return
  3640. }
  3641. adminUserInfo := c.GetMobileAdminUserInfo()
  3642. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3643. if patient.ID == 0 {
  3644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3645. return
  3646. }
  3647. if len(recordDateStr) == 0 {
  3648. recordDateStr = time.Now().Format("2006-01-02")
  3649. }
  3650. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3651. if parseDateErr != nil {
  3652. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3654. return
  3655. }
  3656. mode_id, _ := c.GetInt64("mode_id", 0)
  3657. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3658. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3659. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3660. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3661. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3662. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3663. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3664. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3665. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3666. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3667. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3668. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3669. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3670. kalium, _ := c.GetFloat("kalium", 0)
  3671. sodium, _ := c.GetFloat("sodium", 0)
  3672. calcium, _ := c.GetFloat("calcium", 0)
  3673. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3674. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3675. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3676. glucose, _ := c.GetFloat("glucose", 0)
  3677. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3678. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3679. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3680. conductivity, _ := c.GetFloat("conductivity", 0)
  3681. remark := c.GetString("remark")
  3682. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3683. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3684. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3685. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3686. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3687. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3688. special_medicine_other := c.GetString("special_medicine_other")
  3689. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3690. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3691. blood_access, _ := c.GetInt64("blood_access", 0)
  3692. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3693. body_fluid_other := c.GetString("body_fluid_other")
  3694. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3695. niprocart, _ := c.GetInt64("niprocart", 0)
  3696. jms, _ := c.GetInt64("jms", 0)
  3697. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3698. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3699. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3700. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3701. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3702. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3703. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3704. injector, _ := c.GetInt64("injector", 0)
  3705. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3706. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3707. safe_package, _ := c.GetInt64("package", 0)
  3708. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3709. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3710. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3711. blood := c.GetString("blood")
  3712. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3713. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3714. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3715. displace_speed := c.GetString("displace_speed")
  3716. illness, _ := c.GetInt64("illness")
  3717. amylaceum := c.GetString("amylaceum")
  3718. single_time := c.GetString("single_time")
  3719. single_water := c.GetString("single_water")
  3720. replacement_flow := c.GetString("replacement_flow")
  3721. plasma_separator := c.GetString("plasma_separator")
  3722. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3723. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3724. oxygen_flow := c.GetString("oxygen_flow")
  3725. oxygen_time := c.GetString("oxygen_time")
  3726. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3727. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3728. puncture_needle := c.GetString("puncture_needle")
  3729. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3730. epo := c.GetString("epo")
  3731. epo_count, _ := c.GetFloat("epo_count", 0)
  3732. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3733. pre_impulse := c.GetString("pre_impulse")
  3734. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3735. admin_user_id, _ := c.GetInt64("admin_user_id")
  3736. is_water := c.GetString("is_water")
  3737. add_amount, _ := c.GetFloat("add_amount")
  3738. reduce_amount, _ := c.GetFloat("reduce_amount")
  3739. prescribing_number, _ := c.GetFloat("prescribing_number")
  3740. treatment_remark := c.GetString("treatment_remark")
  3741. prescription_sodium := c.GetString("prescription_sodium")
  3742. start_sodium := c.GetString("start_sodium")
  3743. sodium_curve := c.GetString("sodium_curve")
  3744. var is_war int64
  3745. if is_water == "是" {
  3746. is_war = 1
  3747. }
  3748. if is_water == "否" {
  3749. is_war = 2
  3750. }
  3751. if is_water == "请选择" {
  3752. is_war = 0
  3753. }
  3754. drhy_water := c.GetString("drhy_water")
  3755. dry_water_hour := c.GetString("dry_water_hour")
  3756. water_machine := c.GetString("water_machine")
  3757. dialysis_remark := c.GetString("dialysis_remark")
  3758. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3759. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3760. prescription_water, _ := c.GetFloat("prescription_water")
  3761. dialysis_strainer := c.GetString("dialysis_strainer")
  3762. chaptalization := c.GetString("chaptalization")
  3763. washing_time := c.GetString("washing_time")
  3764. warsh_count := c.GetString("warsh_count")
  3765. blood_access_part_id := c.GetString("blood_access_part_id")
  3766. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3767. dialyzate := c.GetString("dialyzate")
  3768. first_super := c.GetString("first_super")
  3769. is_sequential := c.GetString("is_sequential")
  3770. var fisrt_sup int64
  3771. if first_super == "是" {
  3772. fisrt_sup = 1
  3773. }
  3774. if first_super == "否" {
  3775. fisrt_sup = 2
  3776. }
  3777. if first_super == "请选择" {
  3778. fisrt_sup = 0
  3779. }
  3780. var is_sequen int64
  3781. if is_sequential == "是" {
  3782. is_sequen = 1
  3783. }
  3784. if is_sequential == "否" {
  3785. is_sequen = 2
  3786. }
  3787. if is_sequential == "请选择" {
  3788. is_sequen = 0
  3789. }
  3790. conduct := c.GetString("conduct")
  3791. if mode_id > 0 {
  3792. var str string
  3793. //查找该机构用的是什么透析器
  3794. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3795. if filedConfig.ID > 0 {
  3796. str = dialyzerPerfusionApparatus
  3797. } else {
  3798. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3799. }
  3800. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3801. }
  3802. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3803. //
  3804. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3805. // if appRole.UserType == 3 {
  3806. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3807. // if getPermissionErr != nil {
  3808. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3809. // return
  3810. // } else if headNursePermission == nil {
  3811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3812. // return
  3813. // }
  3814. // }
  3815. //}
  3816. // 查询信息规挡的设置天数
  3817. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3818. if infor.ID > 0 && infor.WeekDay > 0 {
  3819. var cha_time int64
  3820. timeNowStr := time.Now().Format("2006-01-02")
  3821. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3822. //今日的日期减去设置的日期
  3823. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3824. if cha_time >= recordDate.Unix() {
  3825. //查询审核是否允许
  3826. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3827. //申请状态不允许的情况 拒绝修改
  3828. if infor.ApplicationStatus != 1 {
  3829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3830. return
  3831. }
  3832. }
  3833. }
  3834. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3835. var dialysis_dialyszers_id int64
  3836. var dialysis_strainer_id int64
  3837. var dialysis_irrigation_id int64
  3838. if len(goodList) > 0 {
  3839. for _, item := range goodList {
  3840. if item.SpecificationName == dialysis_dialyszers {
  3841. dialysis_dialyszers_id = item.ID
  3842. }
  3843. if item.SpecificationName == dialysis_irrigation {
  3844. dialysis_irrigation_id = item.ID
  3845. }
  3846. if item.SpecificationName == dialysis_strainer {
  3847. dialysis_strainer_id = item.ID
  3848. }
  3849. }
  3850. }
  3851. prescription := models.DialysisPrescription{
  3852. UserOrgId: adminUserInfo.Org.Id,
  3853. PatientId: id,
  3854. RecordDate: recordDate.Unix(),
  3855. ModeId: mode_id,
  3856. DialysisDuration: dialysis_duration,
  3857. Dialyzer: dialyzer,
  3858. PerfusionApparatus: perfusion_apparatus,
  3859. BloodFlowVolume: blood_flow_volume,
  3860. DewaterAmount: dewater_amount,
  3861. DisplaceLiqui: displace_liqui,
  3862. ReplacementWay: replacement_way,
  3863. Anticoagulant: anticoagulant,
  3864. AnticoagulantShouji: anticoagulant_shouji,
  3865. AnticoagulantWeichi: anticoagulant_weichi,
  3866. AnticoagulantZongliang: anticoagulant_zongliang,
  3867. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3868. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3869. Kalium: kalium,
  3870. Sodium: sodium,
  3871. Calcium: calcium,
  3872. Bicarbonate: bicarbonate,
  3873. Glucose: glucose,
  3874. // DryWeight: dry_weight,
  3875. DialysateFlow: dialysate_flow,
  3876. DialysateTemperature: dialysate_temperature,
  3877. Conductivity: conductivity,
  3878. Remark: remark,
  3879. Status: 1,
  3880. CreatedTime: time.Now().Unix(),
  3881. UpdatedTime: time.Now().Unix(),
  3882. DialysisDurationMinute: dialysisDurationMinute,
  3883. DialysisDurationHour: dialysisDurationHour,
  3884. TargetUltrafiltration: targetUltrafiltration,
  3885. DialysateFormulation: dialysateFormulation,
  3886. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3887. BodyFluid: body_fluid,
  3888. SpecialMedicine: special_medicine,
  3889. SpecialMedicineOther: special_medicine_other,
  3890. DisplaceLiquiPart: displace_liqui_part,
  3891. DisplaceLiquiValue: displace_liqui_value,
  3892. BloodAccess: blood_access,
  3893. Ultrafiltration: ultrafiltration,
  3894. BodyFluidOther: body_fluid_other,
  3895. ReplacementTotal: replacement_total,
  3896. Niprocart: niprocart,
  3897. Jms: jms,
  3898. FistulaNeedleSet: fistula_needle_set,
  3899. FistulaNeedleSet16: fistula_needle_set_16,
  3900. Hemoperfusion: hemoperfusion,
  3901. DialyserSterilised: dialyser_sterilised,
  3902. Filtryzer: filtryzer,
  3903. TargetKtv: target_ktv,
  3904. Dialyzers: dialyzers,
  3905. Injector: injector,
  3906. Bloodlines: bloodlines,
  3907. TubingHemodialysis: tubing_hemodialysis,
  3908. Package: safe_package,
  3909. ALiquid: a_liquid,
  3910. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3911. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3912. Blood: blood,
  3913. DialysisDialyszers: dialysis_dialyszers,
  3914. DialysisIrrigation: dialysis_irrigation,
  3915. AntioxidantCommodityName: antioxidant_commodity_name,
  3916. DisplaceSpeed: displace_speed,
  3917. Illness: illness,
  3918. Amylaceum: amylaceum,
  3919. SingleWater: single_water,
  3920. SingleTime: single_time,
  3921. ReplacementFlow: replacement_flow,
  3922. PlasmaSeparator: plasma_separator,
  3923. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3924. OxygenUptake: oxygen_uptake,
  3925. OxygenTime: oxygen_time,
  3926. OxygenFlow: oxygen_flow,
  3927. HemodialysisPipelines: hemodialysis_pipelines,
  3928. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3929. PunctureNeedle: puncture_needle,
  3930. PunctureNeedleCount: puncture_needle_count,
  3931. Epo: epo,
  3932. EpoCount: epo_count,
  3933. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3934. PreImpulse: impulse,
  3935. AdminUserId: admin_user_id,
  3936. IsWater: is_war,
  3937. DrhyWater: drhy_water,
  3938. DryWaterHour: dry_water_hour,
  3939. WaterMachine: water_machine,
  3940. AddAmount: add_amount,
  3941. ReduceAmount: reduce_amount,
  3942. DialysisRemark: dialysis_remark,
  3943. PrescribingNumber: prescribing_number,
  3944. PrescriptionSodium: prescription_sodium,
  3945. StartSodium: start_sodium,
  3946. SodiumCurve: sodium_curve,
  3947. TreatmentRemark: treatment_remark,
  3948. DialysisFluidFlow: dialysis_fluid_flow,
  3949. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3950. PrescriptionWater: prescription_water,
  3951. DialysisStrainer: dialysis_strainer,
  3952. Chaptalization: chaptalization,
  3953. WashingTime: washing_time,
  3954. WarshCount: warsh_count,
  3955. BloodAccessPartId: blood_access_part_id,
  3956. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3957. Dialyzate: dialyzate,
  3958. DialysisDialyszersId: dialysis_dialyszers_id,
  3959. DialysisIrrigationId: dialysis_irrigation_id,
  3960. DialysisStrainerId: dialysis_strainer_id,
  3961. FirstSuper: fisrt_sup,
  3962. IsSequential: is_sequen,
  3963. Conduct: conduct,
  3964. }
  3965. if adminUserInfo.Org.Id == 10721 {
  3966. if prescription.ModeId == 2 {
  3967. if prescription.ReplacementTotal == 0 {
  3968. prescription.ReplacementTotal = 15
  3969. }
  3970. }
  3971. }
  3972. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3973. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3974. //
  3975. if appRole.UserType == 2 || appRole.UserType == 1 {
  3976. prescription_doctor = adminUserInfo.AdminUser.Id
  3977. prescription.PrescriptionDoctor = prescription_doctor
  3978. }
  3979. if dialysisPrescription.ID == 0 { //新增
  3980. prescription.Creater = adminUserInfo.AdminUser.Id
  3981. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3982. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3983. }
  3984. } else { //修改
  3985. if dialysisPrescription.Creater == 0 {
  3986. prescription.Creater = adminUserInfo.AdminUser.Id
  3987. } else {
  3988. prescription.Creater = dialysisPrescription.Creater
  3989. if adminUserInfo.Org.Id == 9882 {
  3990. if appRole.UserType == 2 || appRole.UserType == 1 {
  3991. prescription.Creater = adminUserInfo.AdminUser.Id
  3992. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3993. }
  3994. }
  3995. }
  3996. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3997. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3998. }
  3999. //if/**/
  4000. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4001. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4002. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4003. // if getPermissionErr != nil {
  4004. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4005. // return
  4006. // } else if headNursePermission == nil {
  4007. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4008. // return
  4009. // }
  4010. //}
  4011. //prescription.Creater = dialysisPrescription.Creater
  4012. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4013. prescription.Modifier = adminUserInfo.AdminUser.Id
  4014. prescription.ID = dialysisPrescription.ID
  4015. }
  4016. solution := models.DialysisSolution{
  4017. RegistrarsId: adminUserInfo.AdminUser.Id,
  4018. UserOrgId: adminUserInfo.Org.Id,
  4019. Doctor: prescription_doctor,
  4020. PatientId: id,
  4021. ModeId: mode_id,
  4022. DialysisDuration: dialysis_duration,
  4023. PerfusionApparatus: perfusion_apparatus,
  4024. BloodFlowVolume: blood_flow_volume,
  4025. Dewater: dewater_amount,
  4026. DisplaceLiqui: displace_liqui,
  4027. ReplacementWay: replacement_way,
  4028. Anticoagulant: anticoagulant,
  4029. AnticoagulantShouji: anticoagulant_shouji,
  4030. AnticoagulantWeichi: anticoagulant_weichi,
  4031. AnticoagulantZongliang: anticoagulant_zongliang,
  4032. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4033. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4034. Kalium: kalium,
  4035. Sodium: sodium,
  4036. Calcium: calcium,
  4037. Bicarbonate: bicarbonate,
  4038. Glucose: glucose,
  4039. // DryWeight: dry_weight,
  4040. DialysateFlow: dialysate_flow,
  4041. DialysateTemperature: dialysate_temperature,
  4042. Conductivity: conductivity,
  4043. Remark: remark,
  4044. Status: 1,
  4045. CreatedTime: time.Now().Unix(),
  4046. UpdatedTime: time.Now().Unix(),
  4047. DialysisDurationMinute: dialysisDurationMinute,
  4048. DialysisDurationHour: dialysisDurationHour,
  4049. TargetUltrafiltration: targetUltrafiltration,
  4050. DialysateFormulation: dialysateFormulation,
  4051. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4052. BodyFluid: body_fluid,
  4053. SpecialMedicine: special_medicine,
  4054. SpecialMedicineOther: special_medicine_other,
  4055. DisplaceLiquiPart: displace_liqui_part,
  4056. DisplaceLiquiValue: displace_liqui_value,
  4057. BloodAccess: blood_access,
  4058. Ultrafiltration: ultrafiltration,
  4059. BodyFluidOther: body_fluid_other,
  4060. ReplacementTotal: replacement_total,
  4061. TargetKtv: target_ktv,
  4062. DialysisDialyszers: dialysis_dialyszers,
  4063. DialysisIrrigation: dialysis_irrigation,
  4064. HemodialysisPipelines: hemodialysis_pipelines,
  4065. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4066. PunctureNeedle: puncture_needle,
  4067. PunctureNeedleCount: puncture_needle_count,
  4068. Epo: epo,
  4069. EpoCount: epo_count,
  4070. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4071. PreImpulse: impulse,
  4072. SolutionStatus: 1,
  4073. DialysisRemark: dialysis_remark,
  4074. PrescribingNumber: prescribing_number,
  4075. PrescriptionSodium: prescription_sodium,
  4076. StartSodium: start_sodium,
  4077. SodiumCurve: sodium_curve,
  4078. TreatmentRemark: treatment_remark,
  4079. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4080. DialysisFluidFlow: dialysis_fluid_flow,
  4081. PrescriptionWater: prescription_water,
  4082. DialysisStrainer: dialysis_strainer,
  4083. Chaptalization: chaptalization,
  4084. WashingTime: washing_time,
  4085. WarshCount: warsh_count,
  4086. BloodAccessPartId: blood_access_part_id,
  4087. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4088. Dialyzate: dialyzate,
  4089. DialysisDialyszersId: dialysis_dialyszers_id,
  4090. DialysisIrrigationId: dialysis_irrigation_id,
  4091. DialysisStrainerId: dialysis_strainer_id,
  4092. FirstSuper: fisrt_sup,
  4093. IsSequential: is_sequen,
  4094. Conduct: conduct,
  4095. }
  4096. //针对河间咸的
  4097. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4098. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4099. solution.DisplaceLiquiPart = 0
  4100. solution.DisplaceLiquiValue = 0
  4101. }
  4102. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4103. prescription.DisplaceLiquiPart = 0
  4104. prescription.DisplaceLiquiValue = 0
  4105. }
  4106. }
  4107. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4108. if solution.PrescribingNumber == 0 {
  4109. solution.PrescribingNumber = 1
  4110. }
  4111. if prescription.PrescribingNumber == 0 {
  4112. prescription.PrescribingNumber = 1
  4113. }
  4114. if solution.PrescribingNumber == 0 && id == 14682 {
  4115. solution.PrescribingNumber = 2
  4116. }
  4117. if solution.PrescribingNumber == 0 && id == 18560 {
  4118. solution.PrescribingNumber = 2
  4119. }
  4120. if prescription.PrescribingNumber == 0 && id == 14682 {
  4121. prescription.PrescribingNumber = 2
  4122. }
  4123. if prescription.PrescribingNumber == 0 && id == 18560 {
  4124. prescription.PrescribingNumber = 2
  4125. }
  4126. }
  4127. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4128. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4129. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4130. if len(monitorList) > 0 {
  4131. var ultrafiltration_rate float64
  4132. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4133. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4134. var replacement_rate float64
  4135. //乘10 除10是为了保留一位小数
  4136. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4137. var firstOpeateTime = monitorList[0].OperateTime
  4138. for _, item := range monitorList {
  4139. //超滤率
  4140. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4141. //置换率
  4142. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4143. //超滤量
  4144. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4145. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4146. //置换量
  4147. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4148. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4149. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4150. }
  4151. }
  4152. }
  4153. //记录日志
  4154. byterequest, _ := json.Marshal(prescription)
  4155. prescriptionLog := models.XtDialysisPrescriptionLog{
  4156. UserOrgId: prescription.UserOrgId,
  4157. Ctime: time.Now().Unix(),
  4158. Mtime: 0,
  4159. ErrLog: string(byterequest),
  4160. AdminUserId: adminUserInfo.AdminUser.Id,
  4161. RecordDate: prescription.RecordDate,
  4162. PatientId: prescription.PatientId,
  4163. Source: "手机端新增长期处方",
  4164. Status: 1,
  4165. }
  4166. service.CreatePrescriptionLog(prescriptionLog)
  4167. finish := models.XtDialysisFinish{
  4168. IsFinish: 1,
  4169. UserOrgId: adminUserInfo.Org.Id,
  4170. Status: 1,
  4171. Ctime: time.Now().Unix(),
  4172. Mtime: 0,
  4173. Module: 1,
  4174. RecordDate: recordDate.Unix(),
  4175. Sourse: 1,
  4176. PatientId: id,
  4177. }
  4178. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4179. if dialysisFinish.ID == 0 {
  4180. service.CreateDialysisFinish(finish)
  4181. }
  4182. //获取最新1条
  4183. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4184. //更新状态
  4185. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4186. //长沙南雅医院,自动生成抗凝剂的临时处方
  4187. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4188. if prescribing_number == 0 {
  4189. prescribing_number = 1
  4190. }
  4191. advice := models.DoctorAdvice{
  4192. UserOrgId: adminUserInfo.Org.Id,
  4193. PatientId: id,
  4194. GroupNo: 0,
  4195. AdviceType: 2,
  4196. RecordDate: recordDate.Unix(),
  4197. AdviceDate: recordDate.Unix(),
  4198. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4199. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4200. AdviceDesc: "",
  4201. ReminderDate: 0,
  4202. SingleDose: prescription.AnticoagulantZongliang,
  4203. SingleDoseUnit: "iu",
  4204. DrugSpec: 0,
  4205. DrugSpecUnit: "",
  4206. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4207. PrescribingNumberUnit: "支",
  4208. DeliveryWay: "静脉注射",
  4209. ExecutionFrequency: "上机前",
  4210. AdviceDoctor: 0,
  4211. Status: 1,
  4212. CreatedTime: time.Now().Unix(),
  4213. UpdatedTime: time.Now().Unix(),
  4214. IsPrescription: 1,
  4215. ExecutionState: 2,
  4216. StopState: 2,
  4217. IsSettle: 2,
  4218. }
  4219. // 查询排班信息
  4220. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4221. if schedulePatient.ID > 0 {
  4222. if schedulePatient.ScheduleType == 1 {
  4223. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4224. }
  4225. if schedulePatient.ScheduleType == 2 {
  4226. advice.StartTime = recordDate.Unix() + 9*60*60
  4227. }
  4228. }
  4229. // 抗凝剂名称
  4230. switch anticoagulant {
  4231. case 1:
  4232. advice.AdviceName = "无肝素"
  4233. break
  4234. case 2:
  4235. advice.AdviceName = "普通肝素"
  4236. break
  4237. case 3:
  4238. advice.AdviceName = "低分子肝素"
  4239. break
  4240. case 4:
  4241. advice.AdviceName = "阿加曲班"
  4242. break
  4243. case 5:
  4244. advice.AdviceName = "枸橼酸钠"
  4245. break
  4246. case 6:
  4247. advice.AdviceName = "低分子肝素钙"
  4248. break
  4249. case 7:
  4250. advice.AdviceName = "低分子肝素钠"
  4251. break
  4252. case 8:
  4253. advice.AdviceName = "依诺肝素"
  4254. break
  4255. case 9:
  4256. advice.AdviceName = "达肝素"
  4257. break
  4258. case 10:
  4259. advice.AdviceName = "体外抗凝"
  4260. break
  4261. case 11:
  4262. advice.AdviceName = "那曲肝素"
  4263. break
  4264. case 12:
  4265. advice.AdviceName = "无抗凝剂"
  4266. break
  4267. }
  4268. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4269. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4270. advice.AdviceDoctor = appRole.AdminUserId
  4271. }
  4272. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4273. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4274. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4275. advice.AdviceName = "低分子肝素钠注射液"
  4276. // 修改患者临时医嘱里的抗凝剂医嘱
  4277. advice.ID = advicePrescription.ID
  4278. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4279. } else {
  4280. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4281. advice.AdviceName = "低分子肝素钠注射液"
  4282. service.CreateDoctorAdvice(&advice)
  4283. }
  4284. }
  4285. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4286. redis := service.RedisClient()
  4287. defer redis.Close()
  4288. //清空key 值
  4289. redis.Set(key, "", time.Second)
  4290. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4291. redis.Set(keyOne, "", time.Second)
  4292. }
  4293. //获取key,清空redis
  4294. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4295. redis := service.RedisClient()
  4296. defer redis.Close()
  4297. //清空key 值
  4298. redis.Set(key, "", time.Second)
  4299. //清空长期医嘱的key
  4300. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4301. redis.Set(soulution_key, "", time.Second)
  4302. //查询最近透析准备表里是否存在 透析器 灌流器
  4303. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4304. redis.Set(keyOne, "", time.Second)
  4305. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4306. redis.Set(keyTwo, "", time.Second)
  4307. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4308. redis.Set(keyThree, "", time.Second)
  4309. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4310. redis.Set(keyFour, "", time.Second)
  4311. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4312. //
  4313. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4314. //
  4315. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4316. //if len(mation)>0{
  4317. // for _, item := range splitStr {
  4318. // for _,it := range mation{
  4319. // if(item == it.SpecificationName){
  4320. //
  4321. // //查询最近一次的透析器
  4322. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4323. //
  4324. // if errcode == gorm.ErrRecordNotFound{
  4325. // //插入数据
  4326. // prepare := models.DialysisBeforePrepare{
  4327. // UserOrgId: adminUserInfo.Org.Id,
  4328. // PatientId: id,
  4329. // RecordDate: recordDate.Unix(),
  4330. // GoodTypeId: it.GoodTypeId,
  4331. // GoodId: it.ID,
  4332. // Count: 1,
  4333. // Ctime: time.Now().Unix(),
  4334. // Creater: adminUserInfo.AdminUser.Id,
  4335. // Status:1,
  4336. //
  4337. // }
  4338. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4339. // fmt.Println("",errcode)
  4340. // }
  4341. // }
  4342. // }
  4343. //
  4344. // }
  4345. //
  4346. // for _, item := range splitIrrigation {
  4347. // for _,it := range mation{
  4348. // if(item == it.SpecificationName){
  4349. // //查询最近一次的透析器
  4350. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4351. // if errcode == gorm.ErrRecordNotFound{
  4352. // //插入数据
  4353. // prepare := models.DialysisBeforePrepare{
  4354. // UserOrgId: adminUserInfo.Org.Id,
  4355. // PatientId: id,
  4356. // RecordDate: recordDate.Unix(),
  4357. // GoodTypeId: it.GoodTypeId,
  4358. // GoodId: it.ID,
  4359. // Count: 1,
  4360. // Ctime: time.Now().Unix(),
  4361. // Creater: adminUserInfo.AdminUser.Id,
  4362. // Status:1,
  4363. //
  4364. // }
  4365. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4366. // fmt.Println(errcode)
  4367. // }
  4368. // }
  4369. // }
  4370. // }
  4371. //}
  4372. c.ServeSuccessJSON(map[string]interface{}{
  4373. "solution": &solution,
  4374. "prescription": &prescription,
  4375. })
  4376. }
  4377. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4378. patient, _ := c.GetInt64("patient", 0)
  4379. adminUserInfo := c.GetMobileAdminUserInfo()
  4380. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4381. c.ServeSuccessJSON(map[string]interface{}{
  4382. "receiveTreatmentAsses": receiveTreatmentAsses,
  4383. })
  4384. }
  4385. func (this *DialysisAPIController) PostSignInfo() {
  4386. patientID, _ := this.GetInt64("patient_id")
  4387. recordDateStr := this.GetString("date")
  4388. if patientID <= 0 {
  4389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4390. return
  4391. }
  4392. if len(recordDateStr) == 0 {
  4393. recordDateStr = time.Now().Format("2006-01-02")
  4394. }
  4395. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4396. if parseDateErr != nil {
  4397. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4399. return
  4400. }
  4401. adminInfo := this.GetMobileAdminUserInfo()
  4402. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4403. if err != nil {
  4404. this.ErrorLog("签名失败:%v", err)
  4405. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4406. return
  4407. }
  4408. this.ServeSuccessJSON(map[string]interface{}{
  4409. "doctor_id": adminInfo.AdminUser.Id,
  4410. })
  4411. }
  4412. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4413. patientID, _ := this.GetInt64("patient_id")
  4414. adminInfo := this.GetMobileAdminUserInfo()
  4415. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4416. this.ServeSuccessJSON(map[string]interface{}{
  4417. "monitor": record,
  4418. })
  4419. }
  4420. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4421. thisTime := time.Now()
  4422. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4423. timeLayout := "2006-01-02 15:04:05"
  4424. loc, _ := time.LoadLocation("Local")
  4425. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4426. theAssessmentDateTime := theStartTime.Unix()
  4427. patientID, _ := this.GetInt64("patient_id")
  4428. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4429. adminInfo := this.GetMobileAdminUserInfo()
  4430. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4431. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4432. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4433. var ultrafiltration_rate float64
  4434. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4435. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4436. fmt.Println(evaluation)
  4437. fmt.Println("prescription.ID", prescription.ID)
  4438. if prescription.ID > 0 {
  4439. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4440. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4441. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4442. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4443. record.UltrafiltrationRate = ultrafiltration_rate
  4444. }
  4445. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4446. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4447. record.UltrafiltrationRate = ultrafiltration_rate
  4448. }
  4449. if adminInfo.Org.Id == 10510 {
  4450. record.UltrafiltrationRate = 0
  4451. }
  4452. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4453. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4454. record.UltrafiltrationRate = ultrafiltration_rate
  4455. }
  4456. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4457. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4458. record.UltrafiltrationRate = ultrafiltration_rate
  4459. }
  4460. // 只针对方济医院
  4461. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4462. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4463. ultrafiltration_rate = value
  4464. record.UltrafiltrationRate = ultrafiltration_rate
  4465. }
  4466. if template.TemplateId == 41 || template.TemplateId == 47 {
  4467. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4468. record.UltrafiltrationRate = ultrafiltration_rate
  4469. }
  4470. if template.TemplateId == 43 {
  4471. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4472. record.UltrafiltrationRate = ultrafiltration_rate
  4473. }
  4474. if template.TemplateId == 46 || template.TemplateId == 54 {
  4475. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4476. record.UltrafiltrationRate = ultrafiltration_rate
  4477. }
  4478. 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 {
  4479. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4480. record.UltrafiltrationRate = ultrafiltration_rate
  4481. }
  4482. if adminInfo.Org.Id == 10469 {
  4483. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4484. record.UltrafiltrationRate = ultrafiltration_rate
  4485. }
  4486. if adminInfo.Org.Id == 10667 {
  4487. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4488. record.UltrafiltrationRate = ultrafiltration_rate
  4489. }
  4490. if adminInfo.Org.Id == 10471 {
  4491. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4492. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4493. }
  4494. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4495. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4496. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4497. }
  4498. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4499. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4500. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4501. }
  4502. if adminInfo.Org.Id == 10721 {
  4503. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4504. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4505. }
  4506. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4507. record.UltrafiltrationRate = 0
  4508. }
  4509. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4510. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4511. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4512. }
  4513. if adminInfo.Org.Id == 10206 {
  4514. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4515. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4516. }
  4517. //if template.TemplateId == 47 {
  4518. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4519. // record.UltrafiltrationRate = ultrafiltration_rate
  4520. //}
  4521. }
  4522. }
  4523. // record.UltrafiltrationRate = ultrafiltration_rate
  4524. record.UltrafiltrationVolume = 0
  4525. 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
  4526. if ultrafiltration_rate > 0 {
  4527. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4528. record.UltrafiltrationVolume = value
  4529. }
  4530. }
  4531. 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
  4532. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4533. if adminInfo.Org.Id != 10735 {
  4534. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4535. record.UltrafiltrationVolume = ultrafiltration_volume
  4536. }
  4537. //胶州少海医院
  4538. if adminInfo.Org.Id == 10735 {
  4539. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4540. if lastMonitorRecordList.ID > 0 {
  4541. record.UltrafiltrationRate = lastMonitorRecordList.UltrafiltrationRate
  4542. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * lastMonitorRecordList.UltrafiltrationRate)
  4543. record.UltrafiltrationVolume = ultrafiltration_volume
  4544. } else {
  4545. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4546. record.UltrafiltrationVolume = ultrafiltration_volume
  4547. }
  4548. }
  4549. }
  4550. }
  4551. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4552. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4553. record.UltrafiltrationVolume = ultrafiltration_volume
  4554. }
  4555. //长沙南雅
  4556. 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 {
  4557. if ultrafiltration_rate > 0 {
  4558. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4559. record.UltrafiltrationVolume = ultrafiltration_volume
  4560. }
  4561. }
  4562. if adminInfo.Org.Id == 10471 {
  4563. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4564. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4565. }
  4566. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4567. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4568. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4569. }
  4570. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4571. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4572. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4573. }
  4574. //长沙南雅累计血容量自动计算
  4575. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4576. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4577. //}
  4578. if template.TemplateId == 47 || template.TemplateId == 54 {
  4579. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4580. }
  4581. if adminInfo.Org.Id == 10510 {
  4582. record.UltrafiltrationVolume = 0
  4583. }
  4584. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4585. if ultrafiltration_rate > 0 {
  4586. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4587. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4588. }
  4589. }
  4590. //古镇乐生
  4591. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4592. if ultrafiltration_rate > 0 {
  4593. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4594. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4595. }
  4596. }
  4597. if adminInfo.Org.Id == 10206 {
  4598. if ultrafiltration_rate > 0 {
  4599. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4600. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4601. }
  4602. }
  4603. if adminInfo.Org.Id == 10721 {
  4604. var replacement_rate float64
  4605. var displacement_quantity float64
  4606. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4607. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4608. record.ReplacementRate = replacement_rate
  4609. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4610. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4611. record.DisplacementQuantity = displacement_quantity
  4612. }
  4613. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4614. var replacement_rate float64
  4615. var displacement_quantity float64
  4616. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4617. if totalMin == 0 {
  4618. totalMin = 240
  4619. }
  4620. if prescription.DisplaceLiquiValue == 0 {
  4621. prescription.ReplacementTotal = 32
  4622. }
  4623. //乘10 除10是为了保留一位小数
  4624. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4625. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4626. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4627. record.DisplacementQuantity = displacement_quantity
  4628. }
  4629. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4630. this.ServeSuccessJSON(map[string]interface{}{
  4631. "monitor": record,
  4632. "lastMonitorRecordList": lastMonitorRecordList,
  4633. })
  4634. }
  4635. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4636. record_id, _ := this.GetInt64("id")
  4637. nurseID, _ := this.GetInt64("start_nurse")
  4638. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4639. bedID, _ := this.GetInt64("bed")
  4640. start_time := this.GetString("start_time")
  4641. schedual_type, _ := this.GetInt64("schedual_type")
  4642. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4643. change_nurse, _ := this.GetInt64("change_nurse")
  4644. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4645. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4646. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4647. patient_id, _ := this.GetInt64("patient_id")
  4648. record_date, _ := this.GetInt64("record_date")
  4649. puncture_needle := this.GetString("puncture_needle")
  4650. puncture_way := this.GetString("puncture_way")
  4651. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4652. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4653. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4654. nuclein_date_str := this.GetString("nuclein_date_str")
  4655. order_remark := this.GetString("order_remark")
  4656. schedule_remark := this.GetString("schedule_remark")
  4657. catheter_operation := this.GetString("catheter_operation")
  4658. blood_flow_volume := this.GetString("blood_flow_volume")
  4659. blood_drawing, _ := this.GetInt64("blood_drawing")
  4660. dialysis_strainer := this.GetString("dialysis_strainer")
  4661. if record_id == 0 {
  4662. this.ErrorLog("id:%v", record_id)
  4663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4664. return
  4665. }
  4666. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4667. if parseStartDateErr != nil {
  4668. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4670. return
  4671. }
  4672. adminUserInfo := this.GetMobileAdminUserInfo()
  4673. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4674. if getNurseErr != nil {
  4675. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4676. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4677. return
  4678. } else if nurse == nil {
  4679. this.ErrorLog("护士不存在")
  4680. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4681. return
  4682. }
  4683. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4684. //if getNurseErr != nil {
  4685. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4686. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4687. // return
  4688. //} else if nurse == nil {
  4689. // this.ErrorLog("护士不存在")
  4690. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4691. // return
  4692. //}
  4693. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4694. if getDeviceNumberErr != nil {
  4695. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4697. return
  4698. } else if deviceNumber == nil {
  4699. this.ErrorLog("床位号不存在")
  4700. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4701. return
  4702. }
  4703. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4704. //
  4705. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4706. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4707. // if getPermissionErr != nil {
  4708. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4709. // return
  4710. // } else if headNursePermission == nil {
  4711. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4712. // return
  4713. // }
  4714. //}
  4715. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4716. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4717. timeLayout := "2006-01-02 15:04:05"
  4718. loc, _ := time.LoadLocation("Local")
  4719. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4720. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4721. schedulestartTime := theStartTime.Unix()
  4722. scheduleendTime := theEndTime.Unix()
  4723. var theNucleinDate int64
  4724. timeLayoutOne := "2006-01-02"
  4725. if len(nuclein_date_str) > 0 {
  4726. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4727. if err != nil {
  4728. utils.ErrorLog(err.Error())
  4729. }
  4730. theNucleinDate = theTime.Unix()
  4731. }
  4732. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4733. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4734. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4735. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4736. if err == gorm.ErrRecordNotFound { //空床位
  4737. // 修改了床位逻辑
  4738. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4739. if daySchedule.ID > 0 {
  4740. //daySchedule.BedId = bedID
  4741. //daySchedule.PartitionId = deviceNumber.ZoneID
  4742. //daySchedule.ScheduleType = schedual_type
  4743. //daySchedule.UpdatedTime = time.Now().Unix()
  4744. //err := service.UpdateSchedule(&daySchedule)
  4745. xtSchedule := models.Schedule{
  4746. PartitionId: deviceNumber.ZoneID,
  4747. BedId: bedID,
  4748. ScheduleType: schedual_type,
  4749. UpdatedTime: time.Now().Unix(),
  4750. }
  4751. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4752. if err != nil {
  4753. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4754. return
  4755. }
  4756. }
  4757. } else if err == nil {
  4758. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4759. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4760. if daySchedule.ID > 0 {
  4761. //daySchedule.BedId = bedID
  4762. //daySchedule.PartitionId = deviceNumber.ZoneID
  4763. //
  4764. //daySchedule.ScheduleType = schedual_type
  4765. //daySchedule.UpdatedTime = time.Now().Unix()
  4766. //err := service.UpdateSchedule(&daySchedule)
  4767. xtSchedule := models.Schedule{
  4768. PartitionId: deviceNumber.ZoneID,
  4769. BedId: bedID,
  4770. ScheduleType: schedual_type,
  4771. UpdatedTime: time.Now().Unix(),
  4772. }
  4773. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4774. if err != nil {
  4775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4776. return
  4777. }
  4778. }
  4779. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4781. return
  4782. }
  4783. } else if err != nil {
  4784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4785. return
  4786. }
  4787. }
  4788. dialysisRecord := &models.DialysisOrder{
  4789. ID: record_id,
  4790. UserOrgId: adminUserInfo.Org.Id,
  4791. BedID: bedID,
  4792. StartNurse: nurseID,
  4793. StartTime: startDate.Unix(),
  4794. PunctureNurse: puncture_nurse,
  4795. Creator: adminUserInfo.AdminUser.Id,
  4796. Modifier: adminUserInfo.AdminUser.Id,
  4797. WashpipeNurse: washpipe_nurse,
  4798. SchedualType: schedual_type,
  4799. ChangeNurse: change_nurse,
  4800. DifficultPunctureNurse: difficult_puncture_nurse,
  4801. NewFistulaNurse: new_fistula_nurse,
  4802. QualityNurseId: quality_nurse_id,
  4803. PunctureNeedle: puncture_needle,
  4804. PunctureWay: puncture_way,
  4805. DialysisDialyszers: dialysis_dialyszers,
  4806. DialysisIrrigation: dialysis_irrigation,
  4807. BloodAccessId: blood_access_id,
  4808. NucleinDate: theNucleinDate,
  4809. OrderRemark: order_remark,
  4810. ScheduleRemark: schedule_remark,
  4811. CatheterOperation: catheter_operation,
  4812. BloodFlowVolume: blood_flow_volume,
  4813. BloodDrawing: blood_drawing,
  4814. DialysisStrainer: dialysis_strainer,
  4815. }
  4816. //修改床位号需要重新消毒
  4817. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4818. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4819. //查询第一条监测
  4820. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4821. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4822. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4823. redis := service.RedisClient()
  4824. //清空key 值
  4825. redis.Set(key, "", time.Second)
  4826. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4827. redis.Set(keyOne, "", time.Second)
  4828. defer redis.Close()
  4829. }
  4830. // 查询信息规挡的设置天数
  4831. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4832. if infor.ID > 0 && infor.WeekDay > 0 {
  4833. var cha_time int64
  4834. timeNowStr := time.Now().Format("2006-01-02")
  4835. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4836. //今日的日期减去设置的日期
  4837. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4838. if cha_time >= record_date {
  4839. //查询审核是否允许
  4840. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4841. //申请状态不允许的情况 拒绝修改
  4842. if infor.ApplicationStatus != 1 {
  4843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4844. return
  4845. }
  4846. }
  4847. }
  4848. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4849. //修改床位后重新生成消毒计划
  4850. if adminUserInfo.Org.Id == 10340 {
  4851. //根据床位号获取设备型号
  4852. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4853. //查询使用消毒最后一条消毒记录
  4854. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4855. fmt.Println("err", err)
  4856. if err == gorm.ErrRecordNotFound {
  4857. //查找排班
  4858. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4859. //查询改设备是否有消毒计划
  4860. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4861. //根据床位号获取设备id
  4862. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4863. //查询病人信息
  4864. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4865. var con = ""
  4866. if patients.IsInfectious == 0 {
  4867. con = ""
  4868. }
  4869. if patients.IsInfectious == 1 {
  4870. con = "无"
  4871. }
  4872. if patients.IsInfectious == 2 {
  4873. con = "有"
  4874. }
  4875. if errcode == nil {
  4876. var end_time int64
  4877. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4878. //新增消毒
  4879. information := models.DeviceInformation{
  4880. Date: dialysisRecord.DialysisDate,
  4881. Zone: dialysisRecord.ZoneId,
  4882. Class: dialysisRecord.SchedualType,
  4883. BedNumber: dialysisRecord.BedID,
  4884. PatientId: dialysisRecord.PatientId,
  4885. DialysisMode: scheduleByPatient.ModeId,
  4886. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4887. Disinfection: 1,
  4888. DialysisConcentration: 1,
  4889. DisinfectionStatus: 1,
  4890. Move: 1,
  4891. UserOrgId: dialysisRecord.UserOrgId,
  4892. DisinfectType: plan.Way,
  4893. DisinfectantType: plan.MachineDisinfectant,
  4894. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4895. Disinfectant: plan.Disinfectant,
  4896. Ctime: time.Now().Unix(),
  4897. Status: 1,
  4898. SignName: nurseID,
  4899. EquimentId: addmacher.ID,
  4900. DisinfectionResidue: 2,
  4901. Bed: addmacher.BedNumber,
  4902. StartTime: dialysisRecord.StartTime,
  4903. EndTime: dialysisRecord.EndTime,
  4904. Contagion: con,
  4905. WeightLoss: 0,
  4906. Hyperfiltratio: 0,
  4907. DialysisHour: "",
  4908. MachineRun: 1,
  4909. DisinfecStartime: dialysisRecord.EndTime,
  4910. DisinfecEndtime: end_time,
  4911. }
  4912. err := service.CreateInformationTwo(&information)
  4913. fmt.Println("报错", err)
  4914. }
  4915. }
  4916. }
  4917. order, _ := service.GetLastPatientOrder(record_id)
  4918. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4919. redis := service.RedisClient()
  4920. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4921. redis.Set(key, "", time.Second)
  4922. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4923. //清空key 值
  4924. redis.Set(keyOne, "", time.Second)
  4925. scheduleDateStartOne := startDate.Format("2006-01-02")
  4926. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4927. redis.Set(keyTwo, "", time.Second)
  4928. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4929. redis.Set(keyThree, "", time.Second)
  4930. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4931. redis.Set(keyFour, "", time.Second)
  4932. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4933. redis.Set(keyFive, "", time.Second)
  4934. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4935. redis.Set(keySix, "", time.Second)
  4936. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4937. redis.Set(keySeven, "", time.Second)
  4938. if updateErr != nil {
  4939. this.ErrorLog("修改上机失败:%v", updateErr)
  4940. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4941. return
  4942. }
  4943. if updateErr == nil {
  4944. if tempDialysisRecord.Stage == 2 {
  4945. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4946. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4947. fmt.Println(value)
  4948. a, b := math.Modf(value)
  4949. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4950. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4951. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4952. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4953. redis := service.RedisClient()
  4954. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4955. redis.Set(key, "", time.Second)
  4956. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4957. redis.Set(keyOne, "", time.Second)
  4958. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4959. //清空key 值
  4960. redis.Set(keySix, "", time.Second)
  4961. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4962. redis.Set(keySeven, "", time.Second)
  4963. redis.Close()
  4964. if updateAssessmentErr != nil {
  4965. utils.ErrorLog("%v", updateAssessmentErr)
  4966. }
  4967. }
  4968. }
  4969. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4970. this.ServeSuccessJSON(map[string]interface{}{
  4971. "dialysis_order": dialysisRecords,
  4972. })
  4973. }
  4974. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4975. record_id, _ := c.GetInt64("id")
  4976. nurseID, _ := c.GetInt64("nurse")
  4977. end_time := c.GetString("end_time")
  4978. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4979. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4980. catheter := c.GetString("catheter")
  4981. cruor := c.GetString("cruor")
  4982. mission := c.GetString("mission")
  4983. condenser := c.GetString("condenser")
  4984. if record_id <= 0 || nurseID <= 0 {
  4985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4986. return
  4987. }
  4988. adminUserInfo := c.GetMobileAdminUserInfo()
  4989. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4990. if getNurseErr != nil {
  4991. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4993. return
  4994. } else if nurse == nil {
  4995. c.ErrorLog("护士不存在")
  4996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4997. return
  4998. }
  4999. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5000. if parseEndDateErr != nil {
  5001. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5003. return
  5004. }
  5005. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5006. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5007. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5008. // if getPermissionErr != nil {
  5009. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5010. // return
  5011. // } else if headNursePermission == nil {
  5012. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5013. // return
  5014. // }
  5015. //}
  5016. // 查询信息规挡的设置天数
  5017. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5018. if infor.ID > 0 {
  5019. var cha_time int64
  5020. timeNowStr := time.Now().Format("2006-01-02")
  5021. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5022. //今日的日期减去设置的日期
  5023. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5024. if cha_time >= tempDialysisRecords.DialysisDate {
  5025. //查询审核是否允许
  5026. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5027. //申请状态不允许的情况 拒绝修改
  5028. if infor.ApplicationStatus != 1 {
  5029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5030. return
  5031. }
  5032. }
  5033. }
  5034. dialysisRecord := &models.DialysisOrder{
  5035. ID: record_id,
  5036. UserOrgId: adminUserInfo.Org.Id,
  5037. EndTime: endDate.Unix(),
  5038. FinishNurse: nurseID,
  5039. FinishModifier: adminUserInfo.AdminUser.Id,
  5040. PuncturePointHaematoma: puncture_point_haematoma,
  5041. BloodAccessInternalFistula: blood_access_internal_fistula,
  5042. Catheter: catheter,
  5043. Cruor: cruor,
  5044. Mission: mission,
  5045. Condenser: condenser,
  5046. }
  5047. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5048. redis := service.RedisClient()
  5049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5050. //清空key 值
  5051. redis.Set(key, "", time.Second)
  5052. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5053. //清空key 值
  5054. redis.Set(keyOne, "", time.Second)
  5055. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5056. redis.Set(keySeven, "", time.Second)
  5057. redis.Close()
  5058. if updateErr != nil {
  5059. c.ErrorLog("修改下机失败:%v", updateErr)
  5060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5061. return
  5062. }
  5063. if updateErr == nil {
  5064. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5065. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5066. a, b := math.Modf(value)
  5067. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5068. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5069. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5070. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5071. redis := service.RedisClient()
  5072. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5073. redis.Set(keyTen, "", time.Second)
  5074. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5075. redis.Set(keyTwo, "", time.Second)
  5076. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5077. redis.Set(key, "", time.Second)
  5078. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5079. redis.Set(keyThree, "", time.Second)
  5080. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5081. redis.Set(keySeven, "", time.Second)
  5082. defer redis.Close()
  5083. if updateAssessmentErr != nil {
  5084. utils.ErrorLog("%v", updateAssessmentErr)
  5085. }
  5086. }
  5087. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5088. c.ServeSuccessJSON(map[string]interface{}{
  5089. "dialysis_order": dialysisRecords,
  5090. })
  5091. }
  5092. func (c *DialysisAPIController) GetLongAdvice() {
  5093. patient_id, _ := c.GetInt64("id")
  5094. adminUserInfo := c.GetMobileAdminUserInfo()
  5095. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5096. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5097. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5098. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5099. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5100. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5101. c.ServeSuccessJSON(map[string]interface{}{
  5102. "status": "1",
  5103. })
  5104. return
  5105. } else { //开启推送提醒
  5106. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5107. var advice_three []*models.DoctorAdvice
  5108. recordDateStr := time.Now().Format("2006-01-02")
  5109. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5110. nowtime := recordDate.Unix()
  5111. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5112. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5113. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5114. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5115. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5116. for _, advice := range advices {
  5117. if advice.FrequencyType == 3 {
  5118. t := time.Now()
  5119. week := int(t.Weekday())
  5120. fmt.Println(t.Weekday())
  5121. fmt.Println(week)
  5122. switch week {
  5123. case 1:
  5124. if strings.Index(advice.WeekDay, "周一") == -1 {
  5125. advice_three = append(advice_three, advice)
  5126. }
  5127. break
  5128. case 2:
  5129. if strings.Index(advice.WeekDay, "周二") == -1 {
  5130. advice_three = append(advice_three, advice)
  5131. }
  5132. break
  5133. case 3:
  5134. if strings.Index(advice.WeekDay, "周三") == -1 {
  5135. advice_three = append(advice_three, advice)
  5136. }
  5137. break
  5138. case 4:
  5139. if strings.Index(advice.WeekDay, "周四") == -1 {
  5140. advice_three = append(advice_three, advice)
  5141. }
  5142. break
  5143. case 5:
  5144. if strings.Index(advice.WeekDay, "周五") == -1 {
  5145. advice_three = append(advice_three, advice)
  5146. }
  5147. break
  5148. case 6:
  5149. if strings.Index(advice.WeekDay, "周六") == -1 {
  5150. advice_three = append(advice_three, advice)
  5151. }
  5152. break
  5153. case 0:
  5154. if strings.Index(advice.WeekDay, "周日") == -1 {
  5155. advice_three = append(advice_three, advice)
  5156. }
  5157. break
  5158. }
  5159. }
  5160. }
  5161. for _, advice := range advices_two {
  5162. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5163. now := p.Unix()
  5164. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5165. dayStr2 := "-" + dayStr
  5166. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5167. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5168. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5169. for _, ad := range advices {
  5170. advice_three = append(advice_three, ad)
  5171. }
  5172. }
  5173. if err == nil {
  5174. c.ServeSuccessJSON(map[string]interface{}{
  5175. "status": "2",
  5176. "advices": advices,
  5177. "advices_two": RemoveRepeatedElement(advice_three),
  5178. "is_open_remind": config.IsOpenRemind,
  5179. "his_config_open": hisConfig.IsOpen,
  5180. "is_advice_open": is_advice_open.IsAdviceOpen,
  5181. "prescription_open": prescription_open.IsOpen,
  5182. })
  5183. }
  5184. }
  5185. }
  5186. func (c *DialysisAPIController) GetLongAdviceOne() {
  5187. patient_id, _ := c.GetInt64("id")
  5188. startTime := c.GetString("schedule_date")
  5189. timeLayout := "2006-01-02"
  5190. loc, _ := time.LoadLocation("Local")
  5191. var theStartTime int64
  5192. if len(startTime) > 0 {
  5193. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5194. if err != nil {
  5195. utils.ErrorLog(err.Error())
  5196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5197. return
  5198. }
  5199. theStartTime = theTime.Unix()
  5200. }
  5201. adminUserInfo := c.GetMobileAdminUserInfo()
  5202. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5203. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5204. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5205. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5206. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5207. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5208. c.ServeSuccessJSON(map[string]interface{}{
  5209. "status": "1",
  5210. })
  5211. return
  5212. } else { //开启推送提醒
  5213. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5214. var advice_three []*models.DoctorAdvice
  5215. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5216. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5217. for _, advice := range advices {
  5218. if advice.FrequencyType == 3 {
  5219. t := time.Now()
  5220. week := int(t.Weekday())
  5221. fmt.Println(t.Weekday())
  5222. fmt.Println(week)
  5223. switch week {
  5224. case 1:
  5225. if strings.Index(advice.WeekDay, "周一") == -1 {
  5226. advice_three = append(advice_three, advice)
  5227. }
  5228. break
  5229. case 2:
  5230. if strings.Index(advice.WeekDay, "周二") == -1 {
  5231. advice_three = append(advice_three, advice)
  5232. }
  5233. break
  5234. case 3:
  5235. if strings.Index(advice.WeekDay, "周三") == -1 {
  5236. advice_three = append(advice_three, advice)
  5237. }
  5238. break
  5239. case 4:
  5240. if strings.Index(advice.WeekDay, "周四") == -1 {
  5241. advice_three = append(advice_three, advice)
  5242. }
  5243. break
  5244. case 5:
  5245. if strings.Index(advice.WeekDay, "周五") == -1 {
  5246. advice_three = append(advice_three, advice)
  5247. }
  5248. break
  5249. case 6:
  5250. if strings.Index(advice.WeekDay, "周六") == -1 {
  5251. advice_three = append(advice_three, advice)
  5252. }
  5253. break
  5254. case 0:
  5255. if strings.Index(advice.WeekDay, "周日") == -1 {
  5256. advice_three = append(advice_three, advice)
  5257. }
  5258. break
  5259. }
  5260. }
  5261. }
  5262. for _, advice := range advices_two {
  5263. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5264. now := p.Unix()
  5265. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5266. dayStr2 := "-" + dayStr
  5267. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5268. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5269. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5270. for _, ad := range advices {
  5271. advice_three = append(advice_three, ad)
  5272. }
  5273. }
  5274. if err == nil {
  5275. c.ServeSuccessJSON(map[string]interface{}{
  5276. "status": "2",
  5277. "advices": advices,
  5278. "advices_two": RemoveRepeatedElement(advice_three),
  5279. "is_open_remind": config.IsOpenRemind,
  5280. "his_config_open": hisConfig.IsOpen,
  5281. "is_advice_open": is_advice_open.IsAdviceOpen,
  5282. "prescription_open": prescription_open.IsOpen,
  5283. })
  5284. }
  5285. }
  5286. }
  5287. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5288. newArr = make([]*models.DoctorAdvice, 0)
  5289. for i := 0; i < len(arr); i++ {
  5290. repeat := false
  5291. for j := i + 1; j < len(arr); j++ {
  5292. if arr[i].ID == arr[j].ID {
  5293. repeat = true
  5294. break
  5295. }
  5296. }
  5297. if !repeat {
  5298. newArr = append(newArr, arr[i])
  5299. }
  5300. }
  5301. return
  5302. }
  5303. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5304. patient, _ := c.GetInt64("id", 0)
  5305. groupNo, _ := c.GetInt64("groupno", 0)
  5306. if patient <= 0 {
  5307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5308. return
  5309. }
  5310. adminUserInfo := c.GetMobileAdminUserInfo()
  5311. dataBody := make(map[string]interface{}, 0)
  5312. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5313. if err != nil {
  5314. utils.ErrorLog(err.Error())
  5315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5316. return
  5317. }
  5318. utils.ErrorLog("%v", dataBody)
  5319. timeLayout := "2006-01-02 15:04"
  5320. loc, _ := time.LoadLocation("Local")
  5321. timeLayout2 := "2006-01-02"
  5322. loc2, _ := time.LoadLocation("Local")
  5323. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5324. utils.ErrorLog("advice_type")
  5325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5326. return
  5327. }
  5328. adviceType := int64(2)
  5329. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5330. utils.ErrorLog("advice_date")
  5331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5332. return
  5333. }
  5334. adviceDate, _ := dataBody["advice_date"].(string)
  5335. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5336. AdviceDate := theTime.Unix()
  5337. RecordDate := theTime.Unix()
  5338. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5339. utils.ErrorLog("start_time")
  5340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5341. return
  5342. }
  5343. startTime, _ := dataBody["start_time"].(string)
  5344. if len(startTime) == 0 {
  5345. utils.ErrorLog("len(start_time) == 0")
  5346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5347. return
  5348. }
  5349. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5350. if err != nil {
  5351. utils.ErrorLog(err.Error())
  5352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5353. return
  5354. }
  5355. StartTime := theTime.Unix()
  5356. Remark := ""
  5357. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5358. remark, _ := dataBody["remark"].(string)
  5359. Remark = remark
  5360. }
  5361. var advices []*models.GroupAdvice
  5362. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5363. utils.ErrorLog("advices")
  5364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5365. return
  5366. }
  5367. adviceNames := dataBody["advices"].([]interface{})
  5368. for _, adviceNameMap := range adviceNames {
  5369. adviceNameM := adviceNameMap.(map[string]interface{})
  5370. var advice models.GroupAdvice
  5371. advice.Remark = Remark
  5372. advice.AdviceType = adviceType
  5373. advice.StartTime = StartTime
  5374. advice.AdviceDate = AdviceDate
  5375. advice.RecordDate = RecordDate
  5376. advice.Status = 1
  5377. advice.CreatedTime = time.Now().Unix()
  5378. advice.UpdatedTime = time.Now().Unix()
  5379. advice.StopState = 2
  5380. advice.ExecutionState = 2
  5381. advice.UserOrgId = adminUserInfo.Org.Id
  5382. advice.PatientId = patient
  5383. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5384. advice.IsSettle = 2
  5385. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5386. utils.ErrorLog("advice_name")
  5387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5388. return
  5389. }
  5390. adviceName, _ := adviceNameM["advice_name"].(string)
  5391. if len(adviceName) == 0 {
  5392. utils.ErrorLog("len(advice_name) == 0")
  5393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5394. return
  5395. }
  5396. advice.AdviceName = adviceName
  5397. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5398. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5399. advice.DrugSpec = drugSpec
  5400. }
  5401. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5402. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5403. advice.AdviceDesc = adviceDesc
  5404. }
  5405. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5406. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5407. advice.DrugSpecUnit = drugSpecUnit
  5408. }
  5409. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5410. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5411. // advice.SingleDose = singleDose
  5412. //}
  5413. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5414. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5415. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5416. }
  5417. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5418. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5419. advice.SingleDoseUnit = singleDoseUnit
  5420. }
  5421. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5422. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5423. // advice.PrescribingNumber = prescribingNumber
  5424. //}
  5425. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5426. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5427. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5428. }
  5429. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5430. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5431. advice.PrescribingNumberUnit = prescribingNumberUnit
  5432. }
  5433. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5434. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5435. advice.DeliveryWay = deliveryWay
  5436. }
  5437. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5438. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5439. advice.ExecutionFrequency = executionFrequency
  5440. }
  5441. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5442. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5443. advice.FrequencyType = frequency_type
  5444. }
  5445. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5446. day_count := int64(adviceNameM["day_count"].(float64))
  5447. advice.DayCount = day_count
  5448. }
  5449. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5450. week_day, _ := adviceNameM["week_day"].(string)
  5451. advice.WeekDay = week_day
  5452. }
  5453. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5454. way := int64(adviceNameM["way"].(float64))
  5455. advice.Way = way
  5456. }
  5457. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5458. drug_id := int64(adviceNameM["drug_id"].(float64))
  5459. advice.DrugId = drug_id
  5460. }
  5461. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5462. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5463. advice.DrugNameId = drug_name_id
  5464. }
  5465. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5466. remark, _ := adviceNameM["remark"].(string)
  5467. advice.Remark = remark
  5468. }
  5469. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5470. groupno := int64(adviceNameM["groupno"].(float64))
  5471. advice.GroupNo = groupno
  5472. }
  5473. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5474. template_id, _ := adviceNameM["template_id"].(string)
  5475. advice.TemplateId = template_id
  5476. }
  5477. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5478. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5479. advice.ExecutionFrequency = executionFrequency
  5480. }
  5481. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5482. children := adviceNameM["child"].([]interface{})
  5483. if len(children) > 0 {
  5484. for _, childrenMap := range children {
  5485. childMap := childrenMap.(map[string]interface{})
  5486. var child models.GroupAdvice
  5487. child.Remark = Remark
  5488. child.AdviceType = adviceType
  5489. child.StartTime = StartTime
  5490. child.AdviceDate = AdviceDate
  5491. child.RecordDate = RecordDate
  5492. child.Status = 1
  5493. child.CreatedTime = time.Now().Unix()
  5494. child.UpdatedTime = time.Now().Unix()
  5495. child.StopState = 2
  5496. child.ExecutionState = 2
  5497. child.UserOrgId = adminUserInfo.Org.Id
  5498. child.PatientId = patient
  5499. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5500. child.IsSettle = 1
  5501. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5502. utils.ErrorLog("child advice_name")
  5503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5504. return
  5505. }
  5506. childAdviceName, _ := childMap["advice_name"].(string)
  5507. if len(childAdviceName) == 0 {
  5508. utils.ErrorLog("len(child advice_name) == 0")
  5509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5510. return
  5511. }
  5512. child.AdviceName = childAdviceName
  5513. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5514. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5515. child.AdviceDesc = childAdviceDesc
  5516. }
  5517. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5518. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5519. child.DrugSpec = childDrugSpec
  5520. }
  5521. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5522. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5523. child.DrugSpecUnit = childDrugSpecUnit
  5524. }
  5525. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5526. child.SingleDose = childMap["single_dose"].(float64)
  5527. }
  5528. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5529. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5530. child.SingleDoseUnit = childSingleDoseUnit
  5531. }
  5532. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5533. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5534. }
  5535. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5536. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5537. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5538. }
  5539. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5540. groupno := int64(childMap["groupno"].(float64))
  5541. advice.GroupNo = groupno
  5542. }
  5543. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5544. remark, _ := childMap["remark"].(string)
  5545. child.Remark = remark
  5546. }
  5547. child.DeliveryWay = advice.DeliveryWay
  5548. child.ExecutionFrequency = advice.ExecutionFrequency
  5549. advice.Children = append(advice.Children, &child)
  5550. }
  5551. }
  5552. }
  5553. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5554. if temp_advice.ID == 0 {
  5555. advices = append(advices, &advice)
  5556. }
  5557. }
  5558. if len(advices) > 0 {
  5559. finish := models.XtDialysisFinish{
  5560. IsFinish: 1,
  5561. UserOrgId: adminUserInfo.Org.Id,
  5562. Status: 1,
  5563. Ctime: time.Now().Unix(),
  5564. Mtime: 0,
  5565. Module: 4,
  5566. RecordDate: AdviceDate,
  5567. Sourse: 1,
  5568. PatientId: patient,
  5569. }
  5570. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5571. if dialysisFinish.ID == 0 {
  5572. service.CreateDialysisFinish(finish)
  5573. }
  5574. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5575. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5576. for _, item := range advices {
  5577. byterequest, _ := json.Marshal(item)
  5578. adviceLog := models.XtDoctorAdviceLog{
  5579. UserOrgId: adminUserInfo.Org.Id,
  5580. PatientId: patient,
  5581. AdminUserId: adminUserInfo.AdminUser.Id,
  5582. Module: 1,
  5583. ErrLog: string(byterequest),
  5584. Status: 1,
  5585. Ctime: time.Now().Unix(),
  5586. Mtime: 0,
  5587. Source: "手机端医嘱推送",
  5588. RecordDate: item.AdviceDate,
  5589. }
  5590. service.CreateDoctorAdviceLog(adviceLog)
  5591. }
  5592. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5593. redis := service.RedisClient()
  5594. //清空key 值
  5595. redis.Set(key, "", time.Second)
  5596. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5597. redis.Set(keyOne, "", time.Second)
  5598. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5599. defer redis.Close()
  5600. redis.Set(keyThree, "", time.Second)
  5601. if err != nil {
  5602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5603. return
  5604. }
  5605. c.ServeSuccessJSON(map[string]interface{}{
  5606. "msg": "ok",
  5607. "advices": list,
  5608. })
  5609. } else {
  5610. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5611. for _, item := range advices {
  5612. byterequest, _ := json.Marshal(item)
  5613. adviceLog := models.XtDoctorAdviceLog{
  5614. UserOrgId: adminUserInfo.Org.Id,
  5615. PatientId: patient,
  5616. AdminUserId: adminUserInfo.AdminUser.Id,
  5617. Module: 1,
  5618. ErrLog: string(byterequest),
  5619. Status: 1,
  5620. Ctime: time.Now().Unix(),
  5621. Mtime: 0,
  5622. Source: "手机端医嘱推送",
  5623. RecordDate: item.AdviceDate,
  5624. }
  5625. service.CreateDoctorAdviceLog(adviceLog)
  5626. }
  5627. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5628. redis := service.RedisClient()
  5629. //清空key 值
  5630. redis.Set(key, "", time.Second)
  5631. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5632. redis.Set(keyOne, "", time.Second)
  5633. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5634. defer redis.Close()
  5635. redis.Set(keyThree, "", time.Second)
  5636. if err != nil {
  5637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5638. return
  5639. }
  5640. c.ServeSuccessJSON(map[string]interface{}{
  5641. "msg": "ok",
  5642. "advices": list,
  5643. })
  5644. }
  5645. } else {
  5646. c.ServeSuccessJSON(map[string]interface{}{
  5647. "msg": "ok",
  5648. })
  5649. }
  5650. return
  5651. }
  5652. func (c *DialysisAPIController) UploadDryWeight() {
  5653. patient_id, _ := c.GetInt64("id")
  5654. dry_weight, _ := c.GetFloat("dry_weight")
  5655. doctor_id, _ := c.GetInt64("doctor_id")
  5656. remark := c.GetString("remark")
  5657. adminUserInfo := c.GetMobileAdminUserInfo()
  5658. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5659. if err == gorm.ErrRecordNotFound {
  5660. dryWeight := &models.SgjPatientDryweight{
  5661. PatientId: patient_id,
  5662. DryWeight: dry_weight,
  5663. Remakes: remark,
  5664. Ctime: time.Now().Unix(),
  5665. Mtime: time.Now().Unix(),
  5666. Creator: doctor_id,
  5667. Status: 1,
  5668. UserOrgId: adminUserInfo.Org.Id,
  5669. AdjustedValue: "/",
  5670. UserId: adminUserInfo.AdminUser.Id,
  5671. }
  5672. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5673. redis := service.RedisClient()
  5674. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5675. redis.Set(keyOne, "", time.Second)
  5676. loc, _ := time.LoadLocation("Local")
  5677. nowTime := time.Now()
  5678. nowDay := nowTime.Format("2006-01-02")
  5679. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5680. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5681. redis.Set(key, "", time.Second)
  5682. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5683. redis.Set(keyTwo, "", time.Second)
  5684. redis.Close()
  5685. if createErr == nil {
  5686. c.ServeSuccessJSON(map[string]interface{}{
  5687. "msg": "提交成功",
  5688. "weight": dryWeight,
  5689. })
  5690. }
  5691. } else {
  5692. dryWeight := &models.SgjPatientDryweight{
  5693. PatientId: patient_id,
  5694. DryWeight: dry_weight,
  5695. Remakes: remark,
  5696. Ctime: time.Now().Unix(),
  5697. Mtime: time.Now().Unix(),
  5698. Creator: doctor_id,
  5699. Status: 1,
  5700. UserOrgId: adminUserInfo.Org.Id,
  5701. AdjustedValue: "/",
  5702. UserId: adminUserInfo.AdminUser.Id,
  5703. }
  5704. var value float64
  5705. value = dry_weight - weightAdjust.DryWeight
  5706. if value < 0 {
  5707. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5708. } else if value == 0 {
  5709. dryWeight.AdjustedValue = "/"
  5710. } else if value > 0 {
  5711. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5712. }
  5713. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5714. //康桥
  5715. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5716. timeNowStr := time.Now().Format("2006-01-02")
  5717. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5718. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5719. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5720. if beforAssesment.ID > 0 {
  5721. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5722. var dewater_amount float64
  5723. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5724. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5725. //获取key,清空redis
  5726. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5727. redis := service.RedisClient()
  5728. //清空key 值
  5729. redis.Set(key, "", time.Second)
  5730. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5731. //清空key 值
  5732. redis.Set(keyOne, "", time.Second)
  5733. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5734. //清空key 值
  5735. redis.Set(keyTwo, "", time.Second)
  5736. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5737. redis.Set(keySix, "", time.Second)
  5738. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5739. redis.Set(keySeven, "", time.Second)
  5740. }
  5741. }
  5742. redis := service.RedisClient()
  5743. loc, _ := time.LoadLocation("Local")
  5744. nowTime := time.Now()
  5745. nowDay := nowTime.Format("2006-01-02")
  5746. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5747. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5748. redis.Set(keyOne, "", time.Second)
  5749. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5750. redis.Set(key, "", time.Second)
  5751. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5752. redis.Set(keyTwo, "", time.Second)
  5753. redis.Close()
  5754. if createErr == nil {
  5755. c.ServeSuccessJSON(map[string]interface{}{
  5756. "msg": "提交成功",
  5757. "weight": dryWeight,
  5758. })
  5759. }
  5760. }
  5761. }
  5762. func (c *DialysisAPIController) GetSolution() {
  5763. patient_id, _ := c.GetInt64("patient_id")
  5764. mode_id, _ := c.GetInt64("mode_id")
  5765. adminUserInfo := c.GetMobileAdminUserInfo()
  5766. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5767. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5768. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5769. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5770. if err != nil {
  5771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5772. return
  5773. }
  5774. c.ServeSuccessJSON(map[string]interface{}{
  5775. "solution": solution,
  5776. "prescription": prescription,
  5777. "system_prescription": system_prescription,
  5778. "dialysisPrescription": dialysisPrescription,
  5779. })
  5780. }
  5781. func (c *DialysisAPIController) GetSchedule() {
  5782. schedual_type, _ := c.GetInt64("schedual_type")
  5783. adminUserInfo := c.GetMobileAdminUserInfo()
  5784. scheduleTime, _ := c.GetInt64("record_date")
  5785. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5786. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5787. c.ServeSuccessJSON(map[string]interface{}{
  5788. "number": deviceNumber,
  5789. "list": list,
  5790. })
  5791. }
  5792. func (c *DialysisAPIController) GetPatientId() {
  5793. id, _ := c.GetInt64("id")
  5794. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5795. patientId, _ := service.GetPatientId(id)
  5796. //获取该患者的所有传染病
  5797. list, _ := service.GetPatientInfectious(id)
  5798. c.ServeSuccessJSON(map[string]interface{}{
  5799. "patient": patientId,
  5800. "infectioulist": list,
  5801. })
  5802. }
  5803. func (this *DialysisAPIController) GetDialysisSchedule() {
  5804. schedualDate := this.GetString("date")
  5805. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5806. if parseDateErr != nil {
  5807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5808. return
  5809. }
  5810. adminInfo := this.GetMobileAdminUserInfo()
  5811. orgID := adminInfo.Org.Id
  5812. redis := service.RedisClient()
  5813. defer redis.Close()
  5814. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5815. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5816. if len(scheduals) > 0 {
  5817. //缓存数据
  5818. scheduals_json, err := json.Marshal(scheduals)
  5819. if err == nil {
  5820. redis.Set(key, scheduals_json, time.Second*30)
  5821. }
  5822. }
  5823. this.ServeSuccessJSON(map[string]interface{}{
  5824. "scheduals": scheduals,
  5825. })
  5826. }
  5827. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5828. change_type, _ := this.GetInt64("type", 0)
  5829. record_date := this.GetString("record_time")
  5830. patient_id, _ := this.GetInt64("patient_id", 0)
  5831. timeLayout := "2006-01-02"
  5832. loc, _ := time.LoadLocation("Local")
  5833. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5834. record_time := theAdviceRecordTime.Unix()
  5835. adminUserInfo := this.GetMobileAdminUserInfo()
  5836. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5837. if err == nil {
  5838. if len(advices) == 0 {
  5839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5840. return
  5841. } else {
  5842. this.ServeSuccessJSON(map[string]interface{}{
  5843. "advices": advices,
  5844. "schedule": sch,
  5845. })
  5846. return
  5847. }
  5848. } else {
  5849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5850. return
  5851. }
  5852. }
  5853. func (c *DialysisAPIController) CreateConsumables() {
  5854. record_date := c.GetString("record_time")
  5855. patient_id, _ := c.GetInt64("patient_id", 0)
  5856. active, _ := c.GetInt64("active")
  5857. adminUser := c.GetMobileAdminUserInfo()
  5858. timeLayout := "2006-01-02"
  5859. loc, _ := time.LoadLocation("Local")
  5860. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5861. record_time := theRecordTime.Unix()
  5862. // 查询信息规挡的设置天数
  5863. orgid := c.GetMobileAdminUserInfo().Org.Id
  5864. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5865. if infor.ID > 0 {
  5866. var cha_time int64
  5867. timeNowStr := time.Now().Format("2006-01-02")
  5868. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5869. //今日的日期减去设置的日期
  5870. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5871. if cha_time >= record_time {
  5872. //查询审核是否允许
  5873. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5874. //申请状态不允许的情况 拒绝修改
  5875. if infor.ApplicationStatus != 1 {
  5876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5877. return
  5878. }
  5879. }
  5880. }
  5881. dataBody := make(map[string]interface{}, 0)
  5882. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5883. if err != nil {
  5884. utils.ErrorLog(err.Error())
  5885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5886. return
  5887. }
  5888. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5889. var beforePrepares []*models.DialysisBeforePrepareGoods
  5890. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5891. var dialysisBefor []*models.DialysisBeforePrepare
  5892. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5893. goods, _ := dataBody["goods"].([]interface{})
  5894. if len(goods) > 0 {
  5895. for _, item := range goods {
  5896. items := item.(map[string]interface{})
  5897. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5898. utils.ErrorLog("good_id")
  5899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5900. return
  5901. }
  5902. good_id := int64(items["good_id"].(float64))
  5903. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5904. utils.ErrorLog("good_type_id")
  5905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5906. return
  5907. }
  5908. good_type_id := int64(items["good_type_id"].(float64))
  5909. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5910. utils.ErrorLog("count")
  5911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5912. return
  5913. }
  5914. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5915. commdity_code := items["commdity_code"].(string)
  5916. fmt.Println("commdity", commdity_code)
  5917. prepareGoods := &models.DialysisBeforePrepareGoods{
  5918. GoodTypeId: good_type_id,
  5919. GoodId: good_id,
  5920. Count: count,
  5921. StorehouseId: houseConfig.StorehouseOutInfo,
  5922. }
  5923. beforePrepares = append(beforePrepares, prepareGoods)
  5924. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5925. GoodTypeId: good_type_id,
  5926. GoodId: good_id,
  5927. Count: count,
  5928. StorehouseId: houseConfig.StorehouseOutInfo,
  5929. }
  5930. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5931. prepare := &models.DialysisBeforePrepare{
  5932. GoodTypeId: good_type_id,
  5933. GoodId: good_id,
  5934. Count: count,
  5935. PatientId: patient_id,
  5936. RecordDate: record_time,
  5937. UserOrgId: adminUser.Org.Id,
  5938. Status: 1,
  5939. Ctime: time.Now().Unix(),
  5940. Creater: adminUser.AdminUser.Id,
  5941. CommdityCode: commdity_code,
  5942. StorehouseId: houseConfig.StorehouseOutInfo,
  5943. }
  5944. dialysisBefor = append(dialysisBefor, prepare)
  5945. }
  5946. }
  5947. //查询是否有库存
  5948. for _, item := range dialysisBefor {
  5949. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5950. if err == gorm.ErrRecordNotFound {
  5951. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5952. c.ServeSuccessJSON(map[string]interface{}{
  5953. "message": "1",
  5954. "good_name": goodObj.GoodName,
  5955. "specification_name": goodObj.SpecificationName,
  5956. })
  5957. return
  5958. }
  5959. if err != nil {
  5960. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5961. c.ServeSuccessJSON(map[string]interface{}{
  5962. "message": "1",
  5963. "good_name": goodObj.GoodName,
  5964. "specification_name": goodObj.SpecificationName,
  5965. })
  5966. return
  5967. }
  5968. }
  5969. fmt.Println("active-----------------------", active)
  5970. fmt.Println("len(goods)-----------------------", len(goods))
  5971. //新增
  5972. if active == 1 && len(goods) > 0 {
  5973. for _, item := range dialysisBefor {
  5974. dialyPrepareOne := models.DialysisBeforePrepare{
  5975. GoodTypeId: item.GoodTypeId,
  5976. GoodId: item.GoodId,
  5977. PatientId: item.PatientId,
  5978. RecordDate: item.RecordDate,
  5979. UserOrgId: item.UserOrgId,
  5980. Count: item.Count,
  5981. Ctime: time.Now().Unix(),
  5982. Creater: item.Creater,
  5983. CommdityCode: item.CommdityCode,
  5984. Status: 1,
  5985. StorehouseId: houseConfig.StorehouseOutInfo,
  5986. }
  5987. //先清除再插入
  5988. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5989. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5990. //查询默认仓库
  5991. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5992. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5993. var total_count int64
  5994. for _, it := range stockList {
  5995. total_count += it.StockCount
  5996. }
  5997. //基础库插入数据
  5998. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5999. //更新库存
  6000. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6001. var flush_count int64
  6002. for _, it := range goodList {
  6003. flush_count += it.StockCount
  6004. }
  6005. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6006. }
  6007. if err == nil {
  6008. c.ServeSuccessJSON(map[string]interface{}{
  6009. "msg": "保存成功",
  6010. "message": "2",
  6011. })
  6012. return
  6013. } else {
  6014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6015. return
  6016. }
  6017. }
  6018. if len(beforePrepares) > 0 && active == 2 {
  6019. for _, item := range beforePrepares {
  6020. //1.查看该患者该耗材型号最后一次出库数量
  6021. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6022. //判断当前出库数量和最后一次出库数量的大小
  6023. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6024. if item.Count <= goodInfo.Count {
  6025. //退库
  6026. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6027. //查询今日出库数据
  6028. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6029. for _, it := range list {
  6030. prepare := models.DialysisBeforePrepare{
  6031. UserOrgId: it.OrgId,
  6032. PatientId: patient_id,
  6033. RecordDate: it.RecordTime,
  6034. GoodId: it.GoodId,
  6035. GoodTypeId: it.GoodTypeId,
  6036. Count: it.Count,
  6037. Ctime: time.Now().Unix(),
  6038. Creater: adminUser.AdminUser.Id,
  6039. Status: 1,
  6040. StorehouseId: houseConfig.StorehouseOutInfo,
  6041. }
  6042. //删除准备表数据
  6043. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6044. service.CreateDialysisBeforePrepareOne(&prepare)
  6045. }
  6046. }
  6047. var last_total int64
  6048. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6049. if item.Count >= goodInfo.Count {
  6050. //查询当前批次当前耗材最后一条出库数据
  6051. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6052. //计算当前出库和最后一次出库数据相差数据
  6053. last_total = item.Count - lastOutInfo.Count
  6054. //查询该批次剩余库存
  6055. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6056. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6057. if lastInfo.StockCount >= last_total {
  6058. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6059. //查询今日出库数据
  6060. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6061. for _, it := range list {
  6062. prepare := models.DialysisBeforePrepare{
  6063. UserOrgId: it.OrgId,
  6064. PatientId: patient_id,
  6065. RecordDate: it.RecordTime,
  6066. GoodId: it.GoodId,
  6067. GoodTypeId: it.GoodTypeId,
  6068. Count: it.Count,
  6069. Ctime: time.Now().Unix(),
  6070. Creater: adminUser.AdminUser.Id,
  6071. Status: 1,
  6072. StorehouseId: houseConfig.StorehouseOutInfo,
  6073. }
  6074. //删除准备表数据
  6075. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6076. service.CreateDialysisBeforePrepareOne(&prepare)
  6077. //查询默认仓库
  6078. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6079. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6080. var total_count int64
  6081. for _, it := range stockList {
  6082. total_count += it.StockCount
  6083. }
  6084. //基础库插入数据
  6085. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6086. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6087. var flush_count int64
  6088. for _, it := range goodList {
  6089. flush_count += it.StockCount
  6090. }
  6091. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6092. }
  6093. }
  6094. //如果库存不够,则出库到下一个批次
  6095. if lastInfo.StockCount < last_total {
  6096. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6097. //查询今日出库数据
  6098. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6099. for _, it := range list {
  6100. prepare := models.DialysisBeforePrepare{
  6101. UserOrgId: it.OrgId,
  6102. PatientId: patient_id,
  6103. RecordDate: it.RecordTime,
  6104. GoodId: it.GoodId,
  6105. GoodTypeId: it.GoodTypeId,
  6106. Count: it.Count,
  6107. Ctime: time.Now().Unix(),
  6108. Creater: adminUser.AdminUser.Id,
  6109. Status: 1,
  6110. StorehouseId: houseConfig.StorehouseOutInfo,
  6111. }
  6112. //删除准备表数据
  6113. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6114. service.CreateDialysisBeforePrepareOne(&prepare)
  6115. //查询默认仓库
  6116. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6117. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6118. var total_count int64
  6119. for _, it := range stockList {
  6120. total_count += it.StockCount
  6121. }
  6122. //基础库插入数据
  6123. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6124. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6125. var flush_count int64
  6126. for _, it := range goodList {
  6127. flush_count += it.StockCount
  6128. }
  6129. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6130. }
  6131. if err != nil {
  6132. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6133. c.ServeSuccessJSON(map[string]interface{}{
  6134. "message": "1",
  6135. "good_name": goodObj.GoodName,
  6136. "specification_name": goodObj.SpecificationName,
  6137. })
  6138. return
  6139. }
  6140. }
  6141. }
  6142. if err != nil {
  6143. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6144. c.ServeSuccessJSON(map[string]interface{}{
  6145. "message": "1",
  6146. "good_name": goodObj.GoodName,
  6147. "specification_name": goodObj.SpecificationName,
  6148. })
  6149. return
  6150. }
  6151. }
  6152. }
  6153. }
  6154. var errs error
  6155. if errs == nil {
  6156. c.ServeSuccessJSON(map[string]interface{}{
  6157. "msg": "提交成功",
  6158. "message": "2",
  6159. "good_name": "",
  6160. "specification_name": "",
  6161. })
  6162. return
  6163. } else {
  6164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6165. return
  6166. }
  6167. }
  6168. func (c *DialysisAPIController) CreateStockOutInfo() {
  6169. patient_id, _ := c.GetInt64("patient_id", 0)
  6170. record_date := c.GetString("record_time")
  6171. if patient_id <= 0 {
  6172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6173. return
  6174. }
  6175. adminInfo := c.GetMobileAdminUserInfo()
  6176. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6177. timeLayout := "2006-01-02"
  6178. loc, _ := time.LoadLocation("Local")
  6179. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6180. record_time := theRecordTime.Unix()
  6181. // 查询信息规挡的设置天数
  6182. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6183. if infor.ID > 0 && infor.WeekDay > 0 {
  6184. var cha_time int64
  6185. timeNowStr := time.Now().Format("2006-01-02")
  6186. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6187. //今日的日期减去设置的日期
  6188. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6189. if cha_time >= record_time {
  6190. //查询审核是否允许
  6191. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6192. //申请状态不允许的情况 拒绝修改
  6193. if infor.ApplicationStatus != 1 {
  6194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6195. return
  6196. }
  6197. }
  6198. }
  6199. //创建步骤表
  6200. finish := models.XtDialysisFinish{
  6201. IsFinish: 1,
  6202. UserOrgId: adminInfo.Org.Id,
  6203. Status: 1,
  6204. Ctime: time.Now().Unix(),
  6205. Mtime: 0,
  6206. Module: 11,
  6207. RecordDate: record_time,
  6208. Sourse: 1,
  6209. PatientId: patient_id,
  6210. }
  6211. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6212. if dialysisFinish.ID == 0 {
  6213. service.CreateDialysisFinish(finish)
  6214. }
  6215. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6216. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6217. //去重
  6218. consumables = RemoveRepeatedGood(consumables)
  6219. if adminInfo.Org.Id == 9919 {
  6220. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6221. //查询是否有库存
  6222. for _, item := range consumables {
  6223. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6224. if item.Count > warehouse.Count {
  6225. goodErrcode := models.XtGoodErrcode{
  6226. UserOrgId: item.UserOrgId,
  6227. Errcode: "自动出库库存不足",
  6228. GoodId: item.GoodId,
  6229. Status: 1,
  6230. Ctime: time.Now().Unix(),
  6231. Mtime: 0,
  6232. Count: 0,
  6233. StockCount: 0,
  6234. Creater: creator,
  6235. BatchNumberId: warehouse.ID,
  6236. WarehouseOutId: 0,
  6237. }
  6238. service.CreateGoodErrcode(goodErrcode)
  6239. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6240. c.ServeSuccessJSON(map[string]interface{}{
  6241. "message": "1",
  6242. "good_name": goodObj.GoodName,
  6243. "specification_name": goodObj.SpecificationName,
  6244. })
  6245. return
  6246. }
  6247. }
  6248. //查询是否有出库单
  6249. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6250. if err == gorm.ErrRecordNotFound {
  6251. //没有记录,则创建出库单
  6252. timeStr := time.Now().Format("2006-01-02")
  6253. timeArr := strings.Split(timeStr, "-")
  6254. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6255. total = total + 1
  6256. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6257. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6258. number = number + total
  6259. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6260. creater := adminInfo.AdminUser.Id
  6261. warehouseOut := models.WarehouseOut{
  6262. WarehouseOutOrderNumber: warehousing_out_order,
  6263. OperationTime: time.Now().Unix(),
  6264. OrgId: adminInfo.Org.Id,
  6265. Creater: creater,
  6266. Ctime: time.Now().Unix(),
  6267. Status: 1,
  6268. WarehouseOutTime: record_time,
  6269. Dealer: 0,
  6270. Manufacturer: 0,
  6271. Type: 1,
  6272. IsSys: 1,
  6273. StorehouseId: houseConfig.StorehouseOutInfo,
  6274. IsCheck: 1,
  6275. }
  6276. err := service.AddSigleWarehouseOut(&warehouseOut)
  6277. if err != nil {
  6278. goodErrcode := models.XtGoodErrcode{
  6279. UserOrgId: adminInfo.Org.Id,
  6280. Errcode: "创建出库单失败",
  6281. GoodId: 0,
  6282. Status: 1,
  6283. Ctime: time.Now().Unix(),
  6284. Mtime: 0,
  6285. Count: 0,
  6286. StockCount: 0,
  6287. Creater: creator,
  6288. BatchNumberId: 0,
  6289. WarehouseOutId: 0,
  6290. }
  6291. service.CreateGoodErrcode(goodErrcode)
  6292. utils.TraceLog("创建出库单失败 err = %v", err)
  6293. } else {
  6294. for _, item := range consumables {
  6295. //出库
  6296. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6297. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6298. if err == nil {
  6299. goodErrcode := models.XtGoodErrcode{
  6300. UserOrgId: adminInfo.Org.Id,
  6301. Errcode: "自动出库接口报错",
  6302. GoodId: 0,
  6303. Status: 1,
  6304. Ctime: time.Now().Unix(),
  6305. Mtime: 0,
  6306. Count: 0,
  6307. StockCount: 0,
  6308. Creater: creator,
  6309. BatchNumberId: 0,
  6310. WarehouseOutId: 0,
  6311. }
  6312. service.CreateGoodErrcode(goodErrcode)
  6313. utils.TraceLog("创建出库单失败 err = %v", err)
  6314. }
  6315. //查询
  6316. //出库数量相加
  6317. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6318. if errs != nil {
  6319. goodErrcode := models.XtGoodErrcode{
  6320. UserOrgId: item.UserOrgId,
  6321. Errcode: "创建剩余库存字段报错",
  6322. GoodId: item.GoodId,
  6323. Status: 1,
  6324. Ctime: time.Now().Unix(),
  6325. Mtime: 0,
  6326. Count: 0,
  6327. StockCount: 0,
  6328. Creater: creater,
  6329. BatchNumberId: 0,
  6330. WarehouseOutId: 0,
  6331. }
  6332. service.CreateGoodErrcode(goodErrcode)
  6333. }
  6334. }
  6335. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6336. if len(list) == 0 {
  6337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6338. return
  6339. }
  6340. for _, item := range list {
  6341. prepare := models.DialysisBeforePrepare{
  6342. UserOrgId: adminInfo.Org.Id,
  6343. PatientId: patient_id,
  6344. RecordDate: record_time,
  6345. GoodId: item.GoodId,
  6346. GoodTypeId: item.GoodTypeId,
  6347. Count: item.Count,
  6348. Creater: adminInfo.AdminUser.Id,
  6349. Status: 1,
  6350. Ctime: time.Now().Unix(),
  6351. StorehouseId: houseConfig.StorehouseOutInfo,
  6352. }
  6353. //清空准备表数据
  6354. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6355. if err != nil {
  6356. goodErrcode := models.XtGoodErrcode{
  6357. UserOrgId: item.OrgId,
  6358. Errcode: "自动出库清空准备表数据报错",
  6359. GoodId: item.GoodId,
  6360. Status: 1,
  6361. Ctime: time.Now().Unix(),
  6362. Mtime: 0,
  6363. Count: 0,
  6364. StockCount: 0,
  6365. Creater: creater,
  6366. BatchNumberId: 0,
  6367. WarehouseOutId: 0,
  6368. }
  6369. service.CreateGoodErrcode(goodErrcode)
  6370. }
  6371. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6372. if errs != nil {
  6373. goodErrcode := models.XtGoodErrcode{
  6374. UserOrgId: item.OrgId,
  6375. Errcode: "自动出库创建准备表数据报错",
  6376. GoodId: item.GoodId,
  6377. Status: 1,
  6378. Ctime: time.Now().Unix(),
  6379. Mtime: 0,
  6380. Count: 0,
  6381. StockCount: 0,
  6382. Creater: creater,
  6383. BatchNumberId: 0,
  6384. WarehouseOutId: 0,
  6385. }
  6386. service.CreateGoodErrcode(goodErrcode)
  6387. }
  6388. //查询默认仓库
  6389. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6390. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6391. var total_count int64
  6392. for _, it := range stockList {
  6393. total_count += it.StockCount
  6394. }
  6395. //基础库插入数据
  6396. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6397. if errcodes != nil {
  6398. goodErrcode := models.XtGoodErrcode{
  6399. UserOrgId: item.OrgId,
  6400. Errcode: "自动出库基础库插入数据",
  6401. GoodId: item.GoodId,
  6402. Status: 1,
  6403. Ctime: time.Now().Unix(),
  6404. Mtime: 0,
  6405. Count: 0,
  6406. StockCount: 0,
  6407. Creater: creater,
  6408. BatchNumberId: 0,
  6409. WarehouseOutId: 0,
  6410. }
  6411. service.CreateGoodErrcode(goodErrcode)
  6412. }
  6413. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6414. var flush_count int64
  6415. for _, it := range goodList {
  6416. flush_count += it.StockCount
  6417. }
  6418. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6419. if errsss != nil {
  6420. goodErrcode := models.XtGoodErrcode{
  6421. UserOrgId: item.OrgId,
  6422. Errcode: "自动出库剩余库存更新数据",
  6423. GoodId: item.GoodId,
  6424. Status: 1,
  6425. Ctime: time.Now().Unix(),
  6426. Mtime: 0,
  6427. Count: 0,
  6428. StockCount: 0,
  6429. Creater: creater,
  6430. BatchNumberId: 0,
  6431. WarehouseOutId: 0,
  6432. }
  6433. service.CreateGoodErrcode(goodErrcode)
  6434. }
  6435. }
  6436. }
  6437. //
  6438. } else if err == nil {
  6439. for _, item := range consumables {
  6440. //出库
  6441. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6442. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6443. if err != nil {
  6444. goodErrcode := models.XtGoodErrcode{
  6445. UserOrgId: adminInfo.Org.Id,
  6446. Errcode: "自动出库接口报错",
  6447. GoodId: 0,
  6448. Status: 1,
  6449. Ctime: time.Now().Unix(),
  6450. Mtime: 0,
  6451. Count: 0,
  6452. StockCount: 0,
  6453. Creater: creator,
  6454. BatchNumberId: 0,
  6455. WarehouseOutId: 0,
  6456. }
  6457. service.CreateGoodErrcode(goodErrcode)
  6458. }
  6459. //出库数量相加
  6460. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6461. if errss != nil {
  6462. goodErrcode := models.XtGoodErrcode{
  6463. UserOrgId: item.UserOrgId,
  6464. Errcode: "创建剩余库存字段报错",
  6465. GoodId: item.GoodId,
  6466. Status: 1,
  6467. Ctime: time.Now().Unix(),
  6468. Mtime: time.Now().Unix(),
  6469. Count: 0,
  6470. StockCount: 0,
  6471. Creater: item.Creater,
  6472. BatchNumberId: 0,
  6473. WarehouseOutId: 0,
  6474. }
  6475. service.CreateGoodErrcode(goodErrcode)
  6476. }
  6477. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6478. if len(list) == 0 {
  6479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6480. return
  6481. }
  6482. for _, item := range list {
  6483. prepare := models.DialysisBeforePrepare{
  6484. UserOrgId: adminInfo.Org.Id,
  6485. PatientId: patient_id,
  6486. RecordDate: record_time,
  6487. GoodId: item.GoodId,
  6488. GoodTypeId: item.GoodTypeId,
  6489. Count: item.Count,
  6490. Creater: adminInfo.AdminUser.Id,
  6491. Status: 1,
  6492. Ctime: time.Now().Unix(),
  6493. StorehouseId: houseConfig.StorehouseOutInfo,
  6494. }
  6495. //清空准备表数据
  6496. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6497. if errs != nil {
  6498. goodErrcode := models.XtGoodErrcode{
  6499. UserOrgId: adminInfo.Org.Id,
  6500. Errcode: "自动出库清空准备表数据报错",
  6501. GoodId: 0,
  6502. Status: 1,
  6503. Ctime: time.Now().Unix(),
  6504. Mtime: 0,
  6505. Count: 0,
  6506. StockCount: 0,
  6507. Creater: creator,
  6508. BatchNumberId: 0,
  6509. WarehouseOutId: 0,
  6510. }
  6511. service.CreateGoodErrcode(goodErrcode)
  6512. }
  6513. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6514. if errcodes != nil {
  6515. goodErrcode := models.XtGoodErrcode{
  6516. UserOrgId: adminInfo.Org.Id,
  6517. Errcode: "自动出库创建准备表数据报错",
  6518. GoodId: 0,
  6519. Status: 1,
  6520. Ctime: time.Now().Unix(),
  6521. Mtime: 0,
  6522. Count: 0,
  6523. StockCount: 0,
  6524. Creater: creator,
  6525. BatchNumberId: 0,
  6526. WarehouseOutId: 0,
  6527. }
  6528. service.CreateGoodErrcode(goodErrcode)
  6529. }
  6530. //查询默认仓库
  6531. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6532. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6533. var total_count int64
  6534. for _, it := range stockList {
  6535. total_count += it.StockCount
  6536. }
  6537. //基础库插入数据
  6538. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6539. if errcodes != nil {
  6540. goodErrcode := models.XtGoodErrcode{
  6541. UserOrgId: adminInfo.Org.Id,
  6542. Errcode: "自动出库基础库插入数据报错",
  6543. GoodId: 0,
  6544. Status: 1,
  6545. Ctime: time.Now().Unix(),
  6546. Mtime: 0,
  6547. Count: 0,
  6548. StockCount: 0,
  6549. Creater: creator,
  6550. BatchNumberId: 0,
  6551. WarehouseOutId: 0,
  6552. }
  6553. service.CreateGoodErrcode(goodErrcode)
  6554. }
  6555. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6556. var flush_count int64
  6557. for _, it := range goodList {
  6558. flush_count += it.StockCount
  6559. }
  6560. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6561. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6562. if errss != nil {
  6563. goodErrcode := models.XtGoodErrcode{
  6564. UserOrgId: item.OrgId,
  6565. Errcode: "自动出库剩余库存更新数据",
  6566. GoodId: item.GoodId,
  6567. Status: 1,
  6568. Ctime: time.Now().Unix(),
  6569. Mtime: 0,
  6570. Count: 0,
  6571. StockCount: 0,
  6572. Creater: creater,
  6573. BatchNumberId: 0,
  6574. WarehouseOutId: 0,
  6575. }
  6576. service.CreateGoodErrcode(goodErrcode)
  6577. }
  6578. }
  6579. }
  6580. }
  6581. c.ServeSuccessJSON(map[string]interface{}{
  6582. "msg": "提交成功",
  6583. "message": "2",
  6584. "good_name": "",
  6585. "specification_name": "",
  6586. })
  6587. return
  6588. }
  6589. if record.IsOpen == 1 {
  6590. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6591. //查询是否有库存
  6592. for _, item := range consumables {
  6593. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6594. if item.Count > warehouse.Count {
  6595. goodErrcode := models.XtGoodErrcode{
  6596. UserOrgId: item.UserOrgId,
  6597. Errcode: "自动出库库存不足",
  6598. GoodId: item.GoodId,
  6599. Status: 1,
  6600. Ctime: time.Now().Unix(),
  6601. Mtime: 0,
  6602. Count: 0,
  6603. StockCount: 0,
  6604. Creater: creator,
  6605. BatchNumberId: warehouse.ID,
  6606. WarehouseOutId: 0,
  6607. }
  6608. service.CreateGoodErrcode(goodErrcode)
  6609. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6610. c.ServeSuccessJSON(map[string]interface{}{
  6611. "message": "1",
  6612. "good_name": goodObj.GoodName,
  6613. "specification_name": goodObj.SpecificationName,
  6614. })
  6615. return
  6616. }
  6617. }
  6618. //查询是否有出库单
  6619. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6620. if err == gorm.ErrRecordNotFound {
  6621. //没有记录,则创建出库单
  6622. timeStr := time.Now().Format("2006-01-02")
  6623. timeArr := strings.Split(timeStr, "-")
  6624. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6625. total = total + 1
  6626. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6627. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6628. number = number + total
  6629. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6630. creater := adminInfo.AdminUser.Id
  6631. warehouseOut := models.WarehouseOut{
  6632. WarehouseOutOrderNumber: warehousing_out_order,
  6633. OperationTime: time.Now().Unix(),
  6634. OrgId: adminInfo.Org.Id,
  6635. Creater: creater,
  6636. Ctime: time.Now().Unix(),
  6637. Status: 1,
  6638. WarehouseOutTime: record_time,
  6639. Dealer: 0,
  6640. Manufacturer: 0,
  6641. Type: 1,
  6642. IsSys: 1,
  6643. StorehouseId: houseConfig.StorehouseOutInfo,
  6644. IsCheck: 1,
  6645. }
  6646. err := service.AddSigleWarehouseOut(&warehouseOut)
  6647. if err != nil {
  6648. goodErrcode := models.XtGoodErrcode{
  6649. UserOrgId: adminInfo.Org.Id,
  6650. Errcode: "创建出库单失败",
  6651. GoodId: 0,
  6652. Status: 1,
  6653. Ctime: time.Now().Unix(),
  6654. Mtime: 0,
  6655. Count: 0,
  6656. StockCount: 0,
  6657. Creater: creator,
  6658. BatchNumberId: 0,
  6659. WarehouseOutId: 0,
  6660. }
  6661. service.CreateGoodErrcode(goodErrcode)
  6662. utils.TraceLog("创建出库单失败 err = %v", err)
  6663. } else {
  6664. for _, item := range consumables {
  6665. //出库
  6666. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6667. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6668. if err == nil {
  6669. goodErrcode := models.XtGoodErrcode{
  6670. UserOrgId: adminInfo.Org.Id,
  6671. Errcode: "自动出库接口报错",
  6672. GoodId: 0,
  6673. Status: 1,
  6674. Ctime: time.Now().Unix(),
  6675. Mtime: 0,
  6676. Count: 0,
  6677. StockCount: 0,
  6678. Creater: creator,
  6679. BatchNumberId: 0,
  6680. WarehouseOutId: 0,
  6681. }
  6682. service.CreateGoodErrcode(goodErrcode)
  6683. utils.TraceLog("创建出库单失败 err = %v", err)
  6684. }
  6685. //查询
  6686. //出库数量相加
  6687. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6688. if errs != nil {
  6689. goodErrcode := models.XtGoodErrcode{
  6690. UserOrgId: item.UserOrgId,
  6691. Errcode: "创建剩余库存字段报错",
  6692. GoodId: item.GoodId,
  6693. Status: 1,
  6694. Ctime: time.Now().Unix(),
  6695. Mtime: 0,
  6696. Count: 0,
  6697. StockCount: 0,
  6698. Creater: creater,
  6699. BatchNumberId: 0,
  6700. WarehouseOutId: 0,
  6701. }
  6702. service.CreateGoodErrcode(goodErrcode)
  6703. }
  6704. }
  6705. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6706. if len(list) == 0 {
  6707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6708. return
  6709. }
  6710. for _, item := range list {
  6711. prepare := models.DialysisBeforePrepare{
  6712. UserOrgId: adminInfo.Org.Id,
  6713. PatientId: patient_id,
  6714. RecordDate: record_time,
  6715. GoodId: item.GoodId,
  6716. GoodTypeId: item.GoodTypeId,
  6717. Count: item.Count,
  6718. Creater: adminInfo.AdminUser.Id,
  6719. Status: 1,
  6720. Ctime: time.Now().Unix(),
  6721. StorehouseId: houseConfig.StorehouseOutInfo,
  6722. }
  6723. //清空准备表数据
  6724. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6725. if err != nil {
  6726. goodErrcode := models.XtGoodErrcode{
  6727. UserOrgId: item.OrgId,
  6728. Errcode: "自动出库清空准备表数据报错",
  6729. GoodId: item.GoodId,
  6730. Status: 1,
  6731. Ctime: time.Now().Unix(),
  6732. Mtime: 0,
  6733. Count: 0,
  6734. StockCount: 0,
  6735. Creater: creater,
  6736. BatchNumberId: 0,
  6737. WarehouseOutId: 0,
  6738. }
  6739. service.CreateGoodErrcode(goodErrcode)
  6740. }
  6741. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6742. if errs != nil {
  6743. goodErrcode := models.XtGoodErrcode{
  6744. UserOrgId: item.OrgId,
  6745. Errcode: "自动出库创建准备表数据报错",
  6746. GoodId: item.GoodId,
  6747. Status: 1,
  6748. Ctime: time.Now().Unix(),
  6749. Mtime: 0,
  6750. Count: 0,
  6751. StockCount: 0,
  6752. Creater: creater,
  6753. BatchNumberId: 0,
  6754. WarehouseOutId: 0,
  6755. }
  6756. service.CreateGoodErrcode(goodErrcode)
  6757. }
  6758. //查询默认仓库
  6759. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6760. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6761. var total_count int64
  6762. for _, it := range stockList {
  6763. total_count += it.StockCount
  6764. }
  6765. //基础库插入数据
  6766. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6767. if errcodes != nil {
  6768. goodErrcode := models.XtGoodErrcode{
  6769. UserOrgId: item.OrgId,
  6770. Errcode: "自动出库基础库插入数据",
  6771. GoodId: item.GoodId,
  6772. Status: 1,
  6773. Ctime: time.Now().Unix(),
  6774. Mtime: 0,
  6775. Count: 0,
  6776. StockCount: 0,
  6777. Creater: creater,
  6778. BatchNumberId: 0,
  6779. WarehouseOutId: 0,
  6780. }
  6781. service.CreateGoodErrcode(goodErrcode)
  6782. }
  6783. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6784. var flush_count int64
  6785. for _, it := range goodList {
  6786. flush_count += it.StockCount
  6787. }
  6788. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6789. if errsss != nil {
  6790. goodErrcode := models.XtGoodErrcode{
  6791. UserOrgId: item.OrgId,
  6792. Errcode: "自动出库剩余库存更新数据",
  6793. GoodId: item.GoodId,
  6794. Status: 1,
  6795. Ctime: time.Now().Unix(),
  6796. Mtime: 0,
  6797. Count: 0,
  6798. StockCount: 0,
  6799. Creater: creater,
  6800. BatchNumberId: 0,
  6801. WarehouseOutId: 0,
  6802. }
  6803. service.CreateGoodErrcode(goodErrcode)
  6804. }
  6805. }
  6806. }
  6807. //
  6808. } else if err == nil {
  6809. for _, item := range consumables {
  6810. //出库
  6811. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6812. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6813. if err != nil {
  6814. goodErrcode := models.XtGoodErrcode{
  6815. UserOrgId: adminInfo.Org.Id,
  6816. Errcode: "自动出库接口报错",
  6817. GoodId: 0,
  6818. Status: 1,
  6819. Ctime: time.Now().Unix(),
  6820. Mtime: 0,
  6821. Count: 0,
  6822. StockCount: 0,
  6823. Creater: creator,
  6824. BatchNumberId: 0,
  6825. WarehouseOutId: 0,
  6826. }
  6827. service.CreateGoodErrcode(goodErrcode)
  6828. }
  6829. //出库数量相加
  6830. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6831. if errss != nil {
  6832. goodErrcode := models.XtGoodErrcode{
  6833. UserOrgId: item.UserOrgId,
  6834. Errcode: "创建剩余库存字段报错",
  6835. GoodId: item.GoodId,
  6836. Status: 1,
  6837. Ctime: time.Now().Unix(),
  6838. Mtime: time.Now().Unix(),
  6839. Count: 0,
  6840. StockCount: 0,
  6841. Creater: item.Creater,
  6842. BatchNumberId: 0,
  6843. WarehouseOutId: 0,
  6844. }
  6845. service.CreateGoodErrcode(goodErrcode)
  6846. }
  6847. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6848. if len(list) == 0 {
  6849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6850. return
  6851. }
  6852. for _, item := range list {
  6853. prepare := models.DialysisBeforePrepare{
  6854. UserOrgId: adminInfo.Org.Id,
  6855. PatientId: patient_id,
  6856. RecordDate: record_time,
  6857. GoodId: item.GoodId,
  6858. GoodTypeId: item.GoodTypeId,
  6859. Count: item.Count,
  6860. Creater: adminInfo.AdminUser.Id,
  6861. Status: 1,
  6862. Ctime: time.Now().Unix(),
  6863. StorehouseId: houseConfig.StorehouseOutInfo,
  6864. }
  6865. //清空准备表数据
  6866. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6867. if errs != nil {
  6868. goodErrcode := models.XtGoodErrcode{
  6869. UserOrgId: adminInfo.Org.Id,
  6870. Errcode: "自动出库清空准备表数据报错",
  6871. GoodId: 0,
  6872. Status: 1,
  6873. Ctime: time.Now().Unix(),
  6874. Mtime: 0,
  6875. Count: 0,
  6876. StockCount: 0,
  6877. Creater: creator,
  6878. BatchNumberId: 0,
  6879. WarehouseOutId: 0,
  6880. }
  6881. service.CreateGoodErrcode(goodErrcode)
  6882. }
  6883. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6884. if errcodes != nil {
  6885. goodErrcode := models.XtGoodErrcode{
  6886. UserOrgId: adminInfo.Org.Id,
  6887. Errcode: "自动出库创建准备表数据报错",
  6888. GoodId: 0,
  6889. Status: 1,
  6890. Ctime: time.Now().Unix(),
  6891. Mtime: 0,
  6892. Count: 0,
  6893. StockCount: 0,
  6894. Creater: creator,
  6895. BatchNumberId: 0,
  6896. WarehouseOutId: 0,
  6897. }
  6898. service.CreateGoodErrcode(goodErrcode)
  6899. }
  6900. //查询默认仓库
  6901. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6902. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6903. var total_count int64
  6904. for _, it := range stockList {
  6905. total_count += it.StockCount
  6906. }
  6907. //基础库插入数据
  6908. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6909. if errcodes != nil {
  6910. goodErrcode := models.XtGoodErrcode{
  6911. UserOrgId: adminInfo.Org.Id,
  6912. Errcode: "自动出库基础库插入数据报错",
  6913. GoodId: 0,
  6914. Status: 1,
  6915. Ctime: time.Now().Unix(),
  6916. Mtime: 0,
  6917. Count: 0,
  6918. StockCount: 0,
  6919. Creater: creator,
  6920. BatchNumberId: 0,
  6921. WarehouseOutId: 0,
  6922. }
  6923. service.CreateGoodErrcode(goodErrcode)
  6924. }
  6925. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6926. var flush_count int64
  6927. for _, it := range goodList {
  6928. flush_count += it.StockCount
  6929. }
  6930. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6931. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6932. if errss != nil {
  6933. goodErrcode := models.XtGoodErrcode{
  6934. UserOrgId: item.OrgId,
  6935. Errcode: "自动出库剩余库存更新数据",
  6936. GoodId: item.GoodId,
  6937. Status: 1,
  6938. Ctime: time.Now().Unix(),
  6939. Mtime: 0,
  6940. Count: 0,
  6941. StockCount: 0,
  6942. Creater: creater,
  6943. BatchNumberId: 0,
  6944. WarehouseOutId: 0,
  6945. }
  6946. service.CreateGoodErrcode(goodErrcode)
  6947. }
  6948. }
  6949. }
  6950. }
  6951. c.ServeSuccessJSON(map[string]interface{}{
  6952. "msg": "提交成功",
  6953. "message": "2",
  6954. "good_name": "",
  6955. "specification_name": "",
  6956. })
  6957. return
  6958. } else {
  6959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6960. return
  6961. }
  6962. }
  6963. func (c *DialysisAPIController) EditConsumables() {
  6964. patient_id, _ := c.GetInt64("patient_id", 0)
  6965. record_date := c.GetString("record_time")
  6966. if patient_id <= 0 {
  6967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6968. return
  6969. }
  6970. adminInfo := c.GetMobileAdminUserInfo()
  6971. timeLayout := "2006-01-02"
  6972. loc, _ := time.LoadLocation("Local")
  6973. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6974. record_time := theRecordTime.Unix()
  6975. // 查询信息规挡的设置天数
  6976. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6977. if infor.ID > 0 && infor.WeekDay > 0 {
  6978. var cha_time int64
  6979. timeNowStr := time.Now().Format("2006-01-02")
  6980. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6981. //今日的日期减去设置的日期
  6982. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6983. if cha_time >= record_time {
  6984. //查询审核是否允许
  6985. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6986. //申请状态不允许的情况 拒绝修改
  6987. if infor.ApplicationStatus != 1 {
  6988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6989. return
  6990. }
  6991. }
  6992. }
  6993. dataBody := make(map[string]interface{}, 0)
  6994. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6995. if err != nil {
  6996. utils.ErrorLog(err.Error())
  6997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6998. return
  6999. }
  7000. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7001. var beforePrepares []*models.DialysisBeforePrepareGoods
  7002. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7003. var cancelbefor []*models.DialysisBeforePrepareGoods
  7004. var outbefor []*models.DialysisBeforePrepareGoods
  7005. //判断是否开启自动出库
  7006. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7007. if record.IsOpen == 1 {
  7008. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7009. goods, _ := dataBody["goods"].([]interface{})
  7010. if len(goods) > 0 {
  7011. for _, item := range goods {
  7012. items := item.(map[string]interface{})
  7013. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7014. utils.ErrorLog("good_id")
  7015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7016. return
  7017. }
  7018. good_id := int64(items["good_id"].(float64))
  7019. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7020. utils.ErrorLog("good_type_id")
  7021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7022. return
  7023. }
  7024. good_type_id := int64(items["good_type_id"].(float64))
  7025. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7026. utils.ErrorLog("count")
  7027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7028. return
  7029. }
  7030. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7031. commdity_code := items["commdity_code"].(string)
  7032. fmt.Println(commdity_code)
  7033. prepareGoods := &models.DialysisBeforePrepareGoods{
  7034. GoodTypeId: good_type_id,
  7035. GoodId: good_id,
  7036. Count: count,
  7037. StorehouseId: houseConfig.StorehouseOutInfo,
  7038. }
  7039. beforePrepares = append(beforePrepares, prepareGoods)
  7040. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7041. GoodTypeId: good_type_id,
  7042. GoodId: good_id,
  7043. Count: count,
  7044. StorehouseId: houseConfig.StorehouseOutInfo,
  7045. }
  7046. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7047. }
  7048. for _, item := range beforePrepares {
  7049. //1.查看该患者该耗材型号最后一次出库数量
  7050. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7051. //判断当前出库数量和最后一次出库数量的大小
  7052. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7053. if item.Count < goodInfo.Count {
  7054. cancelbefor = append(cancelbefor, item)
  7055. }
  7056. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7057. if item.Count > goodInfo.Count {
  7058. outbefor = append(outbefor, item)
  7059. }
  7060. //处理编辑耗材新增不了的问题
  7061. if goodInfo.Count == item.Count {
  7062. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7063. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7064. }
  7065. }
  7066. if len(cancelbefor) > 0 {
  7067. //退库
  7068. for _, item := range cancelbefor {
  7069. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7070. creater := adminInfo.AdminUser.Id
  7071. //查询该患者当天已经出库的耗材信息
  7072. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7073. var delete_count int64 = 0
  7074. delete_count = warehouseOutInfos.Count - item.Count
  7075. //增加库存数量
  7076. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7077. //减少实际出库库存数量
  7078. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7079. // 删除出库完成后,要增加对应批次的库存数量
  7080. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7081. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7082. //更新剩余库存
  7083. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7084. var flush_count int64
  7085. for _, it := range goodListOne {
  7086. flush_count += it.StockCount
  7087. }
  7088. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7089. //查询剩余库存
  7090. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7091. var sum_count int64
  7092. for _, item := range goodList {
  7093. sum_count += item.StockCount
  7094. }
  7095. // 在出库记录表里记录退库详情
  7096. warehouseOutInfo := &models.WarehouseOutInfo{
  7097. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7098. WarehouseOutId: warehouseOut.ID,
  7099. Status: 1,
  7100. Ctime: time.Now().Unix(),
  7101. OrgId: adminInfo.Org.Id,
  7102. Type: 1,
  7103. IsSys: 1,
  7104. SysRecordTime: record_time,
  7105. GoodTypeId: item.GoodTypeId,
  7106. GoodId: item.GoodId,
  7107. PatientId: patient_id,
  7108. ConsumableType: 2,
  7109. StorehouseId: houseConfig.StorehouseOutInfo,
  7110. IsCheck: 1,
  7111. OverCount: sum_count,
  7112. }
  7113. warehouseOutInfo.Count = item.Count
  7114. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7115. warehouseOutInfo.Price = stockInInfo.Price
  7116. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7117. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7118. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7119. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7120. warehouseOutInfo.Number = warehouseOutInfos.Number
  7121. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7122. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7123. //查找当天是否存在出库记录
  7124. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7125. if errcod == gorm.ErrRecordNotFound {
  7126. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7127. //插入详情明细表
  7128. stockFlow := models.VmStockFlow{
  7129. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7130. WarehouseOutId: warehouseOut.ID,
  7131. GoodId: item.GoodId,
  7132. Number: warehouseOutInfos.Number,
  7133. ProductDate: stockInInfo.ProductDate,
  7134. ExpireDate: stockInInfo.ExpiryDate,
  7135. Count: item.Count,
  7136. Price: stockInInfo.Price,
  7137. Status: 1,
  7138. Ctime: record_time,
  7139. UserOrgId: adminInfo.Org.Id,
  7140. Manufacturer: stockInInfo.Manufacturer,
  7141. Dealer: stockInInfo.Dealer,
  7142. LicenseNumber: stockInInfo.LicenseNumber,
  7143. IsEdit: 2,
  7144. Creator: creater,
  7145. SystemTime: record_time,
  7146. ConsumableType: 3,
  7147. WarehousingDetailId: 0,
  7148. IsSys: 1,
  7149. UpdateCreator: creater,
  7150. PatientId: patient_id,
  7151. StorehouseId: houseConfig.StorehouseOutInfo,
  7152. }
  7153. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7154. if errflow == gorm.ErrRecordNotFound {
  7155. //创建流水表
  7156. err := service.CreateStockFlowOne(stockFlow)
  7157. fmt.Println("err", err)
  7158. } else if errflow == nil {
  7159. //插入详情明细表
  7160. stockFlow := models.VmStockFlow{
  7161. ID: exsit.ID,
  7162. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7163. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7164. WarehouseOutId: warehouseOut.ID,
  7165. GoodId: item.GoodId,
  7166. Number: warehouseOutInfos.Number,
  7167. ProductDate: stockInInfo.ProductDate,
  7168. ExpireDate: stockInInfo.ExpiryDate,
  7169. Count: exsit.Count - delete_count,
  7170. Price: stockInInfo.Price,
  7171. Status: 1,
  7172. Ctime: record_time,
  7173. UserOrgId: adminInfo.Org.Id,
  7174. Manufacturer: stockInInfo.Manufacturer,
  7175. Dealer: stockInInfo.Dealer,
  7176. LicenseNumber: stockInInfo.LicenseNumber,
  7177. IsEdit: 2,
  7178. Creator: creater,
  7179. SystemTime: record_time,
  7180. ConsumableType: 3,
  7181. WarehousingDetailId: 0,
  7182. IsSys: 1,
  7183. UpdateCreator: creater,
  7184. PatientId: patient_id,
  7185. StorehouseId: houseConfig.StorehouseOutInfo,
  7186. }
  7187. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7188. }
  7189. } else if errcod == nil {
  7190. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7191. //查询剩余库存
  7192. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7193. var sum_count int64
  7194. for _, item := range goodList {
  7195. sum_count += item.StockCount
  7196. }
  7197. //创建退库单,生成退库数据
  7198. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7199. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7200. operation_time := time.Now().Unix()
  7201. creater := adminInfo.AdminUser.Id
  7202. //创建退库单
  7203. timeStr := time.Now().Format("2006-01-02")
  7204. timeArr := strings.Split(timeStr, "-")
  7205. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7206. total = total + 1
  7207. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7208. cancelStock := models.CancelStock{
  7209. OrderNumber: orderNumber,
  7210. OperaTime: operation_time,
  7211. OrgId: adminInfo.Org.Id,
  7212. Creater: creater,
  7213. Ctime: time.Now().Unix(),
  7214. Status: 1,
  7215. ReturnTime: record_time,
  7216. Type: 1,
  7217. StorehouseId: houseConfig.StorehouseOutInfo,
  7218. IsCheck: 1,
  7219. }
  7220. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7221. if msgerrkonde == gorm.ErrRecordNotFound {
  7222. service.AddSigleCancelStock(&cancelStock)
  7223. }
  7224. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7225. //查询是否有出库
  7226. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7227. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7228. deaerler, _ := service.GetDealerById(info.Dealer)
  7229. if info.ID > 0 {
  7230. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7231. cancelStockInfo := models.CancelStockInfo{
  7232. GoodId: item.GoodId,
  7233. CancelStockId: cancel.ID,
  7234. GoodTypeId: good.GoodTypeId,
  7235. Count: delete_count,
  7236. Price: info.Price,
  7237. Total: 0,
  7238. ProductDate: info.ProductDate,
  7239. ExpiryDate: info.ExpiryDate,
  7240. Ctime: time.Now().Unix(),
  7241. Status: 1,
  7242. OrgId: adminInfo.Org.Id,
  7243. OrderNumber: cancel.OrderNumber,
  7244. Type: 0,
  7245. Dealer: deaerler.DealerName,
  7246. Manufacturer: manufacturer.ManufacturerName,
  7247. Number: info.Number,
  7248. RegisterAccount: "",
  7249. Remark: "",
  7250. WarehouseInfoId: info.WarehouseInfotId,
  7251. PatientId: info.PatientId,
  7252. RecordDate: info.SysRecordTime,
  7253. StorehouseId: houseConfig.StorehouseOutInfo,
  7254. IsCheck: 1,
  7255. }
  7256. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7257. //退库数量增加
  7258. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7259. //查询剩余库存
  7260. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7261. var over_count int64
  7262. for _, it := range goodList {
  7263. over_count += it.StockCount
  7264. }
  7265. flow := models.VmStockFlow{
  7266. WarehousingId: info.WarehouseInfotId,
  7267. GoodId: item.GoodId,
  7268. Number: info.Number,
  7269. LicenseNumber: info.LicenseNumber,
  7270. Count: delete_count,
  7271. UserOrgId: adminInfo.Org.Id,
  7272. PatientId: patient_id,
  7273. SystemTime: info.SysRecordTime,
  7274. ConsumableType: 7,
  7275. IsSys: 0,
  7276. WarehousingOrder: "",
  7277. WarehouseOutId: info.WarehouseOutId,
  7278. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7279. IsEdit: 0,
  7280. CancelStockId: cancel.ID,
  7281. CancelOrderNumber: cancel.OrderNumber,
  7282. Manufacturer: manufacturer.ID,
  7283. Dealer: 0,
  7284. Creator: adminInfo.AdminUser.Id,
  7285. UpdateCreator: 0,
  7286. Status: 1,
  7287. Ctime: record_time,
  7288. Mtime: 0,
  7289. Price: info.Price,
  7290. WarehousingDetailId: info.WarehouseInfotId,
  7291. WarehouseOutDetailId: info.ID,
  7292. CancelOutDetailId: cancelInfo.ID,
  7293. ProductDate: info.ProductDate,
  7294. ExpireDate: info.ExpiryDate,
  7295. StorehouseId: houseConfig.StorehouseOutInfo,
  7296. OverCount: over_count,
  7297. }
  7298. service.CreateStockFlowOne(flow)
  7299. }
  7300. }
  7301. //更改自动出库的表格
  7302. details := models.BloodAutomaticReduceDetail{
  7303. WarehouseOutId: warehouseOutInfo.ID,
  7304. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7305. PatientId: patient_id,
  7306. Ctime: time.Now().Unix(),
  7307. Mtime: time.Now().Unix(),
  7308. Status: 1,
  7309. RecordTime: record_time,
  7310. OrgId: adminInfo.Org.Id,
  7311. GoodId: item.GoodId,
  7312. GoodTypeId: item.GoodTypeId,
  7313. Count: item.Count,
  7314. StorehouseId: houseConfig.StorehouseOutInfo,
  7315. }
  7316. //查询当天耗材是否已经存在数据
  7317. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7318. if errcode == gorm.ErrRecordNotFound {
  7319. service.CreateAutoReduceRecord(&details)
  7320. } else if errcode == nil {
  7321. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7322. service.CreateAutoReduceRecord(&details)
  7323. }
  7324. //查询默认仓库
  7325. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7326. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7327. var total_count int64
  7328. for _, it := range stockList {
  7329. total_count += it.StockCount
  7330. }
  7331. //基础库插入数据
  7332. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7333. }
  7334. }
  7335. if len(outbefor) > 0 {
  7336. //出库
  7337. for _, item := range outbefor {
  7338. var last_total int64
  7339. //1.查看该患者该耗材型号最后一次出库数量
  7340. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7341. //计算当前出库和最后一次出库数据相差数据
  7342. last_total = item.Count - goodInfoOne.Count
  7343. //查询该耗材的总库存
  7344. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7345. // 如果库存差大于剩余库存则提示库存不足
  7346. if last_total > wareinfo.StockCount {
  7347. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7348. c.ServeSuccessJSON(map[string]interface{}{
  7349. "message": "1",
  7350. "good_name": goodObj.GoodName,
  7351. "specification_name": goodObj.SpecificationName,
  7352. })
  7353. return
  7354. } else {
  7355. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7356. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7357. if err == gorm.ErrRecordNotFound {
  7358. //没有记录,则创建出库单
  7359. timeStr := time.Now().Format("2006-01-02")
  7360. timeArr := strings.Split(timeStr, "-")
  7361. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7362. total = total + 1
  7363. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7364. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7365. number = number + total
  7366. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7367. warehouseOut := models.WarehouseOut{
  7368. WarehouseOutOrderNumber: warehousing_out_order,
  7369. OperationTime: time.Now().Unix(),
  7370. OrgId: adminInfo.Org.Id,
  7371. Creater: adminInfo.AdminUser.Id,
  7372. Ctime: time.Now().Unix(),
  7373. Status: 1,
  7374. WarehouseOutTime: record_time,
  7375. Dealer: 0,
  7376. Manufacturer: 0,
  7377. Type: 1,
  7378. IsSys: 1,
  7379. StorehouseId: houseConfig.StorehouseOutInfo,
  7380. IsCheck: 1,
  7381. }
  7382. service.AddSigleWarehouseOut(&warehouseOut)
  7383. }
  7384. //出库
  7385. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7386. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7387. //1.查看该患者该耗材型号最后一次出库数量
  7388. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7389. prepare := models.DialysisBeforePrepare{
  7390. UserOrgId: adminInfo.Org.Id,
  7391. PatientId: patient_id,
  7392. RecordDate: record_time,
  7393. GoodId: item.GoodId,
  7394. GoodTypeId: item.GoodTypeId,
  7395. Count: item.Count - goodInfoTwo.Count,
  7396. Ctime: time.Now().Unix(),
  7397. Mtime: 0,
  7398. Creater: adminInfo.AdminUser.Id,
  7399. Modifier: adminInfo.AdminUser.Id,
  7400. Status: 1,
  7401. CommdityCode: "",
  7402. NewCount: 0,
  7403. ProjectId: 0,
  7404. StorehouseId: houseConfig.StorehouseOutInfo,
  7405. }
  7406. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7407. //增加出库数量
  7408. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7409. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7410. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7411. var total_count int64
  7412. for _, it := range stockList {
  7413. total_count += it.StockCount
  7414. }
  7415. //基础库插入数据
  7416. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7417. //剩余库存
  7418. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7419. var flush_count int64
  7420. for _, it := range goodList {
  7421. flush_count += it.StockCount
  7422. }
  7423. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7424. }
  7425. }
  7426. }
  7427. //查询今日出库数据
  7428. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7429. for _, it := range list {
  7430. prepare := models.DialysisBeforePrepare{
  7431. UserOrgId: it.OrgId,
  7432. PatientId: patient_id,
  7433. RecordDate: it.RecordTime,
  7434. GoodId: it.GoodId,
  7435. GoodTypeId: it.GoodTypeId,
  7436. Count: it.Count,
  7437. Ctime: time.Now().Unix(),
  7438. Creater: adminInfo.AdminUser.Id,
  7439. Status: 1,
  7440. StorehouseId: houseConfig.StorehouseOutInfo,
  7441. ProjectId: it.ProjectId,
  7442. }
  7443. //删除准备表数据
  7444. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7445. service.CreateDialysisBeforePrepareOne(&prepare)
  7446. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7447. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7448. var total_count int64
  7449. for _, it := range stockList {
  7450. total_count += it.StockCount
  7451. }
  7452. //基础库插入数据
  7453. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7454. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7455. var flush_count int64
  7456. for _, it := range goodList {
  7457. flush_count += it.StockCount
  7458. }
  7459. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7460. }
  7461. }
  7462. }
  7463. //更新自动出库的地方
  7464. var errs error
  7465. if errs == nil {
  7466. c.ServeSuccessJSON(map[string]interface{}{
  7467. "msg": "修改成功",
  7468. "message": "2",
  7469. "good_name": "",
  7470. "specification_name": "",
  7471. })
  7472. return
  7473. } else {
  7474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7475. return
  7476. }
  7477. }
  7478. }
  7479. func (c *DialysisAPIController) GetDialysisGoods() {
  7480. schedualDate := c.GetString("schedule_date")
  7481. schedule_type, _ := c.GetInt64("schedule_type")
  7482. partition_id, _ := c.GetInt64("partition_id")
  7483. page, _ := c.GetInt("page")
  7484. patient_id, _ := c.GetInt64("patient_id")
  7485. schedualEndDate := int64(0)
  7486. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7487. if parseDateErr != nil && len(schedualDate) != 0 {
  7488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7489. return
  7490. }
  7491. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7492. if parseDateErr != nil && len(schedualDate) != 0 {
  7493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7494. return
  7495. }
  7496. schedualEndDate = endDate.Unix()
  7497. adminUser := c.GetMobileAdminUserInfo()
  7498. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7499. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7500. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7501. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7502. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7503. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7504. //获取当天该病人的透析处方
  7505. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7506. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7507. if err == gorm.ErrRecordNotFound {
  7508. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7509. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7510. if patient_id != 0 {
  7511. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7512. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7513. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7514. //获取患者总的出库数据
  7515. item.LastAutomaticReduceDetail = goodUser
  7516. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7517. item.Project = project
  7518. for _, it := range item.AutomaticReduceDetail {
  7519. var total int64
  7520. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7521. for _, its := range auto {
  7522. total += its.Count
  7523. }
  7524. it.Count = total
  7525. }
  7526. }
  7527. }
  7528. c.ServeSuccessJSON(map[string]interface{}{
  7529. "dialysis_goods": dialysisGoods,
  7530. "good_type": goodTypes,
  7531. "total": total,
  7532. "prescribe": prescribe,
  7533. "good_info": good_info,
  7534. "warehouseOutList": warehouseOutList,
  7535. "config": config,
  7536. "outConfig": outConfig,
  7537. "settleConfig": settleConfig,
  7538. })
  7539. return
  7540. } else if err == nil {
  7541. //获取当天排班的每个患者的库存使用情况
  7542. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7543. //获取患者总的出库数据
  7544. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7545. if patient_id != 0 {
  7546. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7547. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7548. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7549. item.Project = project
  7550. item.LastAutomaticReduceDetail = goodUser
  7551. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7552. for _, it := range item.AutomaticReduceDetail {
  7553. var total int64
  7554. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7555. for _, its := range auto {
  7556. total += its.Count
  7557. }
  7558. it.Count = total
  7559. }
  7560. }
  7561. }
  7562. if err == nil {
  7563. c.ServeSuccessJSON(map[string]interface{}{
  7564. "dialysis_goods": dialysisGoods,
  7565. "good_type": goodTypes,
  7566. "total": total,
  7567. "prescribe": prescribe,
  7568. "good_info": good_info,
  7569. "project": project,
  7570. "warehouseOutList": warehouseOutList,
  7571. "config": config,
  7572. "outConfig": outConfig,
  7573. "settleConfig": settleConfig,
  7574. })
  7575. return
  7576. } else {
  7577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7578. return
  7579. }
  7580. } else if err != nil {
  7581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7582. return
  7583. }
  7584. }
  7585. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7586. start_time := c.GetString("start_time")
  7587. end_time := c.GetString("end_time")
  7588. timeLayout := "2006-01-02"
  7589. loc, _ := time.LoadLocation("Local")
  7590. var theStartTime int64
  7591. if len(start_time) > 0 {
  7592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7593. if err != nil {
  7594. utils.ErrorLog(err.Error())
  7595. }
  7596. theStartTime = theTime.Unix()
  7597. }
  7598. var theEndtTime int64
  7599. if len(end_time) > 0 {
  7600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7601. if err != nil {
  7602. utils.ErrorLog(err.Error())
  7603. }
  7604. theEndtTime = theTime.Unix()
  7605. }
  7606. adminUser := c.GetMobileAdminUserInfo()
  7607. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7608. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7609. if err == nil {
  7610. c.ServeSuccessJSON(map[string]interface{}{
  7611. "stock_out": outInfo,
  7612. "stockCount": stockCount,
  7613. })
  7614. return
  7615. } else {
  7616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7617. return
  7618. }
  7619. }
  7620. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7621. patient_id, _ := c.GetInt64("patient_id", 0)
  7622. record_time := c.GetString("record_time")
  7623. adminUser := c.GetMobileAdminUserInfo()
  7624. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7625. if parseDateErr != nil && len(record_time) != 0 {
  7626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7627. return
  7628. }
  7629. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7630. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7631. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7632. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7633. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7634. //获取今日患者的透析处方参数
  7635. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7636. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7637. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7638. c.ServeSuccessJSON(map[string]interface{}{
  7639. "good_type": goodTypes,
  7640. "good_user": goodUser,
  7641. "good_info": good_info,
  7642. "last_good_user": lastGoodUserDetial,
  7643. "project": project,
  7644. "prescription": prescribe,
  7645. "outInfo": outInfo,
  7646. "configs": configs,
  7647. })
  7648. return
  7649. }
  7650. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7651. patient_id, _ := c.GetInt64("patient_id", 0)
  7652. record_date := c.GetString("record_time")
  7653. timeLayout := "2006-01-02"
  7654. loc, _ := time.LoadLocation("Local")
  7655. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7656. record_time := theRecordTime.Unix()
  7657. adminInfo := c.GetMobileAdminUserInfo()
  7658. dataBody := make(map[string]interface{}, 0)
  7659. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7660. if err != nil {
  7661. utils.ErrorLog(err.Error())
  7662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7663. return
  7664. }
  7665. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7666. var beforePrepares []*models.DialysisBeforePrepareGoods
  7667. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7668. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7669. goods, _ := dataBody["goods"].([]interface{})
  7670. if len(goods) > 0 {
  7671. for _, item := range goods {
  7672. items := item.(map[string]interface{})
  7673. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7674. utils.ErrorLog("good_id")
  7675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7676. return
  7677. }
  7678. good_id := int64(items["good_id"].(float64))
  7679. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7680. utils.ErrorLog("good_type_id")
  7681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7682. return
  7683. }
  7684. good_type_id := int64(items["good_type_id"].(float64))
  7685. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7686. utils.ErrorLog("count")
  7687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7688. return
  7689. }
  7690. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7691. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7692. utils.ErrorLog("project_id")
  7693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7694. return
  7695. }
  7696. project_id := int64(items["project_id"].(float64))
  7697. new_count := int64(items["new_count"].(float64))
  7698. old_count := int64(items["old_count"].(float64))
  7699. prepare := &models.DialysisBeforePrepareGoods{
  7700. GoodId: good_id,
  7701. GoodTypeId: good_type_id,
  7702. Count: count,
  7703. ProjectId: project_id,
  7704. StorehouseId: houseConfig.StorehouseOutInfo,
  7705. NewCount: new_count,
  7706. OldCount: old_count,
  7707. }
  7708. beforePrepares = append(beforePrepares, prepare)
  7709. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7710. GoodId: good_id,
  7711. GoodTypeId: good_type_id,
  7712. Count: count,
  7713. ProjectId: project_id,
  7714. StorehouseId: houseConfig.StorehouseOutInfo,
  7715. NewCount: new_count,
  7716. OldCount: old_count,
  7717. }
  7718. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7719. }
  7720. }
  7721. }
  7722. //查询是否有库存
  7723. for _, item := range beforePrepares {
  7724. if item.NewCount > 0 {
  7725. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7726. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7727. if item.Count > warehouse.Count {
  7728. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7729. c.ServeSuccessJSON(map[string]interface{}{
  7730. "message": "1",
  7731. "good_name": goodObj.GoodName,
  7732. "specification_name": goodObj.SpecificationName,
  7733. })
  7734. return
  7735. }
  7736. }
  7737. }
  7738. // 查询信息规挡的设置天数
  7739. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7740. if infor.ID > 0 && infor.WeekDay > 0 {
  7741. var cha_time int64
  7742. timeNowStr := time.Now().Format("2006-01-02")
  7743. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7744. //今日的日期减去设置的日期
  7745. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7746. if cha_time >= record_time {
  7747. //查询审核是否允许
  7748. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7749. //申请状态不允许的情况 拒绝修改
  7750. if infor.ApplicationStatus != 1 {
  7751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7752. return
  7753. }
  7754. }
  7755. }
  7756. //出库逻辑
  7757. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7758. if err != nil {
  7759. utils.ErrorLog(err.Error())
  7760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7761. return
  7762. }
  7763. finish := models.XtDialysisFinish{
  7764. IsFinish: 1,
  7765. UserOrgId: adminInfo.Org.Id,
  7766. Status: 1,
  7767. Ctime: time.Now().Unix(),
  7768. Mtime: 0,
  7769. Module: 11,
  7770. RecordDate: record_time,
  7771. Sourse: 1,
  7772. PatientId: patient_id,
  7773. }
  7774. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7775. if dialysisFinish.ID == 0 {
  7776. service.CreateDialysisFinish(finish)
  7777. }
  7778. //查询当天出库的数据
  7779. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7780. for _, item := range list {
  7781. prepare := models.DialysisBeforePrepare{
  7782. UserOrgId: item.OrgId,
  7783. PatientId: item.PatientId,
  7784. RecordDate: item.RecordTime,
  7785. GoodId: item.GoodId,
  7786. GoodTypeId: item.GoodTypeId,
  7787. Count: item.Count,
  7788. Creater: adminInfo.AdminUser.Id,
  7789. Status: 1,
  7790. Ctime: time.Now().Unix(),
  7791. ProjectId: item.ProjectId,
  7792. StorehouseId: houseConfig.StorehouseOutInfo,
  7793. }
  7794. //清空准备表的数据
  7795. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7796. //插入准备表数据
  7797. service.CreateDialysisBeforePrepareOne(&prepare)
  7798. //查询默认仓库
  7799. //查询默认仓库
  7800. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7801. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7802. var total_count int64
  7803. for _, it := range stockList {
  7804. total_count += it.StockCount
  7805. }
  7806. //基础库插入数据
  7807. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7808. ////更新剩余库存
  7809. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7810. var flush_count int64
  7811. for _, it := range goodList {
  7812. flush_count += it.StockCount
  7813. }
  7814. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7815. if errs != nil {
  7816. goodErrcode := models.XtGoodErrcode{
  7817. UserOrgId: item.OrgId,
  7818. Errcode: "手动出库更新剩余出库失败",
  7819. GoodId: item.GoodId,
  7820. Status: 1,
  7821. Ctime: time.Now().Unix(),
  7822. Mtime: 0,
  7823. Count: 0,
  7824. StockCount: 0,
  7825. Creater: adminInfo.AdminUser.Id,
  7826. BatchNumberId: 0,
  7827. WarehouseOutId: 0,
  7828. }
  7829. service.CreateGoodErrcode(goodErrcode)
  7830. }
  7831. }
  7832. //更新自动出库的地方
  7833. var errs error
  7834. if errs == nil {
  7835. c.ServeSuccessJSON(map[string]interface{}{
  7836. "msg": "修改成功",
  7837. "message": "2",
  7838. "good_name": "",
  7839. "specification_name": "",
  7840. })
  7841. return
  7842. } else {
  7843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7844. return
  7845. }
  7846. }
  7847. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7848. newArr = make([]*models.DialysisBeforePrepare, 0)
  7849. for i := 0; i < len(arr); i++ {
  7850. repeat := false
  7851. for j := i + 1; j < len(arr); j++ {
  7852. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7853. repeat = true
  7854. break
  7855. }
  7856. }
  7857. if !repeat {
  7858. newArr = append(newArr, arr[i])
  7859. }
  7860. }
  7861. return
  7862. }
  7863. func (c *DialysisAPIController) GetAllDrug() {
  7864. patient_id, _ := c.GetInt64("patient_id", 0)
  7865. adminInfo := c.GetMobileAdminUserInfo()
  7866. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7867. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7868. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7869. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7870. c.ServeSuccessJSON(map[string]interface{}{
  7871. "base_drug_config": drugStockConfig,
  7872. "private_drug_config": privateDrugConfig,
  7873. "base_drug_list": drugList,
  7874. "private_drug_list": privateDrugList,
  7875. })
  7876. }
  7877. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7878. newArr = make([]*models.DialysisBeforePrepare, 0)
  7879. for i := 0; i < len(arr); i++ {
  7880. repeat := false
  7881. for j := i + 1; j < len(arr); j++ {
  7882. if arr[i].GoodId == arr[j].GoodId {
  7883. repeat = true
  7884. break
  7885. }
  7886. }
  7887. if !repeat {
  7888. newArr = append(newArr, arr[i])
  7889. }
  7890. }
  7891. return
  7892. }
  7893. func (c *DialysisAPIController) GetDepartment() {
  7894. adminInfo := c.GetMobileAdminUserInfo()
  7895. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7896. if err == nil {
  7897. c.ServeSuccessJSON(map[string]interface{}{
  7898. "departments": departments,
  7899. })
  7900. } else {
  7901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7902. return
  7903. }
  7904. }
  7905. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7906. types, _ := c.GetInt("type", 0)
  7907. start_time := c.GetString("start_time")
  7908. end_time := c.GetString("end_time")
  7909. orgId := c.GetMobileAdminUserInfo().Org.Id
  7910. timeLayout := "2006-01-02"
  7911. loc, _ := time.LoadLocation("Local")
  7912. var startTime int64
  7913. if len(start_time) > 0 {
  7914. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7915. if err != nil {
  7916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7917. return
  7918. }
  7919. startTime = theTime.Unix()
  7920. }
  7921. var endTime int64
  7922. if len(end_time) > 0 {
  7923. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7924. if err != nil {
  7925. utils.ErrorLog(err.Error())
  7926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7927. return
  7928. }
  7929. endTime = theTime.Unix()
  7930. }
  7931. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7932. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7933. if err != nil {
  7934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7935. } else {
  7936. c.ServeSuccessJSON(map[string]interface{}{
  7937. "list": list,
  7938. "type": types,
  7939. "stockTotal": stockTotal,
  7940. })
  7941. }
  7942. }
  7943. func (c *DialysisAPIController) GetPrescriptionList() {
  7944. start_time := c.GetString("start_time")
  7945. end_time := c.GetString("end_time")
  7946. schedule_type, _ := c.GetInt64("schedule_type")
  7947. partion_id, _ := c.GetInt64("partion_id")
  7948. orgId := c.GetMobileAdminUserInfo().Org.Id
  7949. timeLayout := "2006-01-02"
  7950. loc, _ := time.LoadLocation("Local")
  7951. var startTime int64
  7952. if len(start_time) > 0 {
  7953. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7954. if err != nil {
  7955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7956. return
  7957. }
  7958. startTime = theTime.Unix()
  7959. }
  7960. var endTime int64
  7961. if len(end_time) > 0 {
  7962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7963. if err != nil {
  7964. utils.ErrorLog(err.Error())
  7965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7966. return
  7967. }
  7968. endTime = theTime.Unix()
  7969. }
  7970. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7971. fmt.Println("schedulelist22222222", schedulelist)
  7972. c.ServeSuccessJSON(map[string]interface{}{
  7973. "list": schedulelist,
  7974. })
  7975. return
  7976. }
  7977. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7978. ids := c.GetString("ids")
  7979. //patient_id, _ := c.GetInt64("patient_id")
  7980. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7981. idArray := strings.Split(ids, ",")
  7982. err := service.BatchDeleteMonitor(idArray)
  7983. fmt.Print("err", err)
  7984. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7985. //redis := service.RedisClient()
  7986. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7987. //redis.Set(key, "", time.Second)
  7988. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7989. //redis.Set(keyOne, "", time.Second)
  7990. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7991. //redis.Close()
  7992. c.ServeSuccessJSON(map[string]interface{}{
  7993. "msg": "批量删除成功",
  7994. })
  7995. return
  7996. }
  7997. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7998. id, _ := c.GetInt64("id")
  7999. timeLayout := "2006-01-02"
  8000. loc, _ := time.LoadLocation("Local")
  8001. //start_time := time.Now().Format("2006-01-02")
  8002. start_time := c.GetString("start_time")
  8003. end_time := c.GetString("end_time")
  8004. var startdateunix int64
  8005. if len(start_time) > 0 {
  8006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8007. if err != nil {
  8008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8009. return
  8010. }
  8011. startdateunix = theTime.Unix()
  8012. }
  8013. var enddateunix int64
  8014. if len(end_time) > 0 {
  8015. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8016. if err != nil {
  8017. utils.ErrorLog(err.Error())
  8018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8019. return
  8020. }
  8021. enddateunix = theTime.Unix()
  8022. }
  8023. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8024. //nowTime := time.Now()
  8025. //endTime := nowTime.AddDate(-30, 0, 0)
  8026. //endTimes := endTime.Format("2006-01-02")
  8027. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8028. org_id := c.GetMobileAdminUserInfo().Org.Id
  8029. //if org_id == 10579 {
  8030. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8031. // c.ServeSuccessJSON(map[string]interface{}{
  8032. // "list": list,
  8033. // })
  8034. // return
  8035. //} else {
  8036. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8037. // c.ServeSuccessJSON(map[string]interface{}{
  8038. // "list": list,
  8039. // })
  8040. // return
  8041. //}
  8042. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8043. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8044. c.ServeSuccessJSON(map[string]interface{}{
  8045. "list": list,
  8046. })
  8047. return
  8048. } else {
  8049. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8050. c.ServeSuccessJSON(map[string]interface{}{
  8051. "list": list,
  8052. })
  8053. }
  8054. return
  8055. }
  8056. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8057. dataBody := make(map[string]interface{}, 0)
  8058. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8059. ids := c.GetString("ids")
  8060. idArray := strings.Split(ids, ",")
  8061. origin, _ := c.GetInt64("origin")
  8062. if origin == 1 {
  8063. err = service.BatchDeleteAdvice(idArray)
  8064. fmt.Print("err", err)
  8065. c.ServeSuccessJSON(map[string]interface{}{
  8066. "msg": "批量删除成功",
  8067. })
  8068. return
  8069. }
  8070. if origin == 2 {
  8071. service.BatchDeleteHisAdvice(idArray)
  8072. }
  8073. }
  8074. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8075. good_id, _ := c.GetInt64("good_id")
  8076. count, _ := c.GetInt64("count")
  8077. record_time, _ := c.GetInt64("record_time")
  8078. patient_id, _ := c.GetInt64("patient_id")
  8079. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8080. c.ServeSuccessJSON(map[string]interface{}{
  8081. "detail": detail,
  8082. })
  8083. return
  8084. }
  8085. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8086. good_id, _ := c.GetInt64("good_id")
  8087. record_time, _ := c.GetInt64("record_time")
  8088. patient_id, _ := c.GetInt64("patient_id")
  8089. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8090. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8091. fmt.Print("err", err)
  8092. c.ServeSuccessJSON(map[string]interface{}{
  8093. "msg": "批量删除成功",
  8094. })
  8095. return
  8096. }
  8097. func (c *DialysisAPIController) BatchAdviceCheck() {
  8098. ids := c.GetString("ids")
  8099. idArray := strings.Split(ids, ",")
  8100. creator, _ := c.GetInt64("creator")
  8101. origin, _ := c.GetInt64("origin")
  8102. if origin == 1 {
  8103. err := service.BatchAdviceCheck(idArray, creator)
  8104. fmt.Println(err)
  8105. list, _ := service.GetAdviceExecutionById(idArray)
  8106. c.ServeSuccessJSON(map[string]interface{}{
  8107. "list": list,
  8108. })
  8109. return
  8110. }
  8111. if origin == 2 {
  8112. service.BatchHisAdviceCheck(idArray, creator)
  8113. list, _ := service.GetHisAdviceExecutionById(idArray)
  8114. c.ServeSuccessJSON(map[string]interface{}{
  8115. "list": list,
  8116. })
  8117. return
  8118. }
  8119. }
  8120. func (c *DialysisAPIController) BatchAdviceExecution() {
  8121. ids := c.GetString("ids")
  8122. idArray := strings.Split(ids, ",")
  8123. executionTime := c.GetString("execution_time")
  8124. creator, _ := c.GetInt64("creator")
  8125. timeLayout := "2006-01-02 15:04:05"
  8126. loc, _ := time.LoadLocation("Local")
  8127. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8128. orgin, _ := c.GetInt64("origin")
  8129. if orgin == 1 {
  8130. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8131. list, _ := service.GetAdviceExecutionById(idArray)
  8132. fmt.Println(err)
  8133. c.ServeSuccessJSON(map[string]interface{}{
  8134. "list": list,
  8135. })
  8136. return
  8137. }
  8138. if orgin == 2 {
  8139. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8140. list, _ := service.GetHisAdviceExecutionById(idArray)
  8141. fmt.Println(err)
  8142. c.ServeSuccessJSON(map[string]interface{}{
  8143. "list": list,
  8144. })
  8145. return
  8146. }
  8147. }
  8148. func (c *DialysisAPIController) UpdateStockGoods() {
  8149. good_id, _ := c.GetInt64("good_id")
  8150. record_time, _ := c.GetInt64("record_time")
  8151. patient_id, _ := c.GetInt64("patient_id")
  8152. count, _ := c.GetInt64("count")
  8153. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8154. fmt.Print("err", err)
  8155. c.ServeSuccessJSON(map[string]interface{}{
  8156. "msg": "更新成功",
  8157. })
  8158. return
  8159. }
  8160. // 当前数据比上一次出库数据少
  8161. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8162. //查询该患者当天已经出库的耗材信息
  8163. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8164. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8165. for i := len(goods_yc) - 1; i >= 0; i-- {
  8166. goods_yc_temp := goods_yc[i]
  8167. for j := len(goods) - 1; j >= 0; j-- {
  8168. goods_temp := goods[j]
  8169. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8170. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8171. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8172. if goods_yc_temp.Count == goods_temp.Count {
  8173. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8174. goods = append(goods[:j], goods[j+1:]...)
  8175. break
  8176. }
  8177. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8178. if goods_yc_temp.Count > goods_temp.Count {
  8179. temp_count := goods_yc_temp.Count - goods_temp.Count
  8180. goods_yc[i].Count = temp_count
  8181. goods = append(goods[:j], goods[j+1:]...)
  8182. break
  8183. }
  8184. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8185. if goods_yc_temp.Count < goods_temp.Count {
  8186. temp_count := goods_temp.Count - goods_yc_temp.Count
  8187. goods[j].Count = temp_count
  8188. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8189. break
  8190. }
  8191. }
  8192. }
  8193. }
  8194. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8195. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8196. //退库
  8197. if len(goods_yc) > 0 {
  8198. for _, good_yc := range goods_yc {
  8199. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8200. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8201. }
  8202. }
  8203. return nil
  8204. }
  8205. // 耗材出库删除
  8206. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8207. // 先根据相关信息查询当天该耗材的出库信息
  8208. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8209. if err != nil {
  8210. return err
  8211. }
  8212. var delete_count int64 = 0
  8213. delete_count = warehouseOutInfos.Count - count
  8214. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8215. // 在出库记录表里记录退库详情
  8216. warehouseOutInfo := &models.WarehouseOutInfo{
  8217. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8218. WarehouseOutId: warehouseOut.ID,
  8219. Status: 1,
  8220. Ctime: time.Now().Unix(),
  8221. OrgId: orgID,
  8222. Type: 1,
  8223. IsSys: 1,
  8224. SysRecordTime: record_time,
  8225. GoodTypeId: good_yc.GoodTypeId,
  8226. GoodId: good_yc.GoodId,
  8227. PatientId: good_yc.PatientId,
  8228. ConsumableType: 2,
  8229. StorehouseId: houseConfig.StorehouseOutInfo,
  8230. IsCheck: 1,
  8231. }
  8232. warehouseOutInfo.Count = count
  8233. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8234. warehouseOutInfo.Price = stockInInfo.Price
  8235. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8236. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8237. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8238. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8239. warehouseOutInfo.Number = warehouseOutInfos.Number
  8240. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8241. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8242. //查找当天是否存在出库记录
  8243. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8244. if errcod == gorm.ErrRecordNotFound {
  8245. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8246. //插入详情明细表
  8247. stockFlow := models.VmStockFlow{
  8248. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8249. WarehouseOutId: warehouseOut.ID,
  8250. GoodId: good_yc.GoodId,
  8251. Number: warehouseOutInfos.Number,
  8252. ProductDate: stockInInfo.ProductDate,
  8253. ExpireDate: stockInInfo.ExpiryDate,
  8254. Count: count,
  8255. Price: stockInInfo.Price,
  8256. Status: 1,
  8257. Ctime: time.Now().Unix(),
  8258. UserOrgId: good_yc.OrgId,
  8259. Manufacturer: stockInInfo.Manufacturer,
  8260. Dealer: stockInInfo.Dealer,
  8261. LicenseNumber: stockInInfo.LicenseNumber,
  8262. IsEdit: 2,
  8263. Creator: creater,
  8264. SystemTime: record_time,
  8265. ConsumableType: 3,
  8266. WarehousingDetailId: 0,
  8267. IsSys: 1,
  8268. UpdateCreator: creater,
  8269. PatientId: patient_id,
  8270. StorehouseId: houseConfig.StorehouseOutInfo,
  8271. }
  8272. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8273. if errflow == gorm.ErrRecordNotFound {
  8274. //创建流水表
  8275. err := service.CreateStockFlowOne(stockFlow)
  8276. fmt.Println("err", err)
  8277. } else if errflow == nil {
  8278. //插入详情明细表
  8279. stockFlow := models.VmStockFlow{
  8280. ID: exsit.ID,
  8281. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8282. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8283. WarehouseOutId: warehouseOut.ID,
  8284. GoodId: good_yc.GoodId,
  8285. Number: warehouseOutInfos.Number,
  8286. ProductDate: stockInInfo.ProductDate,
  8287. ExpireDate: stockInInfo.ExpiryDate,
  8288. Count: exsit.Count - delete_count,
  8289. Price: stockInInfo.Price,
  8290. Status: 1,
  8291. Ctime: time.Now().Unix(),
  8292. UserOrgId: good_yc.OrgId,
  8293. Manufacturer: stockInInfo.Manufacturer,
  8294. Dealer: stockInInfo.Dealer,
  8295. LicenseNumber: stockInInfo.LicenseNumber,
  8296. IsEdit: 2,
  8297. Creator: creater,
  8298. SystemTime: record_time,
  8299. ConsumableType: 3,
  8300. WarehousingDetailId: 0,
  8301. IsSys: 1,
  8302. UpdateCreator: creater,
  8303. PatientId: patient_id,
  8304. StorehouseId: houseConfig.StorehouseOutInfo,
  8305. }
  8306. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8307. }
  8308. if errOne != nil {
  8309. return errOne
  8310. }
  8311. } else if errcod == nil {
  8312. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8313. //插入详情明细表
  8314. stockFlow := models.VmStockFlow{
  8315. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8316. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8317. WarehouseOutId: warehouseOut.ID,
  8318. GoodId: good_yc.GoodId,
  8319. Number: warehouseOutInfos.Number,
  8320. ProductDate: stockInInfo.ProductDate,
  8321. ExpireDate: stockInInfo.ExpiryDate,
  8322. Count: count,
  8323. Price: stockInInfo.Price,
  8324. Status: 1,
  8325. Ctime: time.Now().Unix(),
  8326. UserOrgId: good_yc.OrgId,
  8327. Manufacturer: stockInInfo.Manufacturer,
  8328. Dealer: stockInInfo.Dealer,
  8329. LicenseNumber: stockInInfo.LicenseNumber,
  8330. IsEdit: 2,
  8331. Creator: creater,
  8332. SystemTime: record_time,
  8333. ConsumableType: 3,
  8334. WarehousingDetailId: 0,
  8335. IsSys: 1,
  8336. UpdateCreator: creater,
  8337. PatientId: patient_id,
  8338. ReturnCount: delete_count,
  8339. StorehouseId: houseConfig.StorehouseOutInfo,
  8340. }
  8341. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8342. if errflows == gorm.ErrRecordNotFound {
  8343. //创建流水表
  8344. service.CreateStockFlowOne(stockFlow)
  8345. } else if errflows == nil {
  8346. stockFlow := models.VmStockFlow{
  8347. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8348. ID: exsit.ID,
  8349. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8350. WarehouseOutId: warehouseOut.ID,
  8351. GoodId: good_yc.GoodId,
  8352. Number: warehouseOutInfos.Number,
  8353. ProductDate: stockInInfo.ProductDate,
  8354. ExpireDate: stockInInfo.ExpiryDate,
  8355. Count: exsit.Count - delete_count,
  8356. Price: stockInInfo.Price,
  8357. Status: 1,
  8358. Ctime: time.Now().Unix(),
  8359. UserOrgId: good_yc.OrgId,
  8360. Manufacturer: stockInInfo.Manufacturer,
  8361. Dealer: stockInInfo.Dealer,
  8362. LicenseNumber: stockInInfo.LicenseNumber,
  8363. IsEdit: 2,
  8364. Creator: creater,
  8365. SystemTime: record_time,
  8366. ConsumableType: 3,
  8367. WarehousingDetailId: 0,
  8368. IsSys: 1,
  8369. UpdateCreator: creater,
  8370. PatientId: patient_id,
  8371. ReturnCount: delete_count,
  8372. StorehouseId: houseConfig.StorehouseOutInfo,
  8373. }
  8374. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8375. }
  8376. }
  8377. //更改自动出库的表格
  8378. details := models.BloodAutomaticReduceDetail{
  8379. WarehouseOutId: warehouseOutInfo.ID,
  8380. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8381. PatientId: patient_id,
  8382. Ctime: time.Now().Unix(),
  8383. Mtime: time.Now().Unix(),
  8384. Status: 1,
  8385. RecordTime: record_time,
  8386. OrgId: orgID,
  8387. GoodId: good_yc.GoodId,
  8388. GoodTypeId: good_yc.GoodTypeId,
  8389. Count: count,
  8390. StorehouseId: houseConfig.StorehouseOutInfo,
  8391. }
  8392. //查询当天耗材是否已经存在数据
  8393. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8394. if errcode == gorm.ErrRecordNotFound {
  8395. errTwo := service.CreateAutoReduceRecord(&details)
  8396. if errTwo != nil {
  8397. return errTwo
  8398. }
  8399. } else if errcode == nil {
  8400. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8401. service.CreateAutoReduceRecord(&details)
  8402. }
  8403. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8404. //增加出库库存数量
  8405. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8406. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8407. fmt.Println("errOne", errOne)
  8408. // 删除出库完成后,要增加对应批次的库存数量
  8409. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8410. if errThree != nil {
  8411. return errThree
  8412. }
  8413. if good_yc.Count == 0 {
  8414. return nil
  8415. } else {
  8416. return errors.New("退库和出库数据不匹配")
  8417. }
  8418. }
  8419. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8420. //查询该患者当天已经出库的耗材信息
  8421. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8422. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8423. for i := len(goods_yc) - 1; i >= 0; i-- {
  8424. goods_yc_temp := goods_yc[i]
  8425. for j := len(goods) - 1; j >= 0; j-- {
  8426. goods_temp := goods[j]
  8427. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8428. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8429. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8430. if goods_yc_temp.Count == goods_temp.Count {
  8431. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8432. goods = append(goods[:j], goods[j+1:]...)
  8433. break
  8434. }
  8435. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8436. if goods_yc_temp.Count > goods_temp.Count {
  8437. temp_count := goods_yc_temp.Count - goods_temp.Count
  8438. goods_yc[i].Count = temp_count
  8439. goods = append(goods[:j], goods[j+1:]...)
  8440. break
  8441. }
  8442. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8443. if goods_yc_temp.Count < goods_temp.Count {
  8444. temp_count := goods_temp.Count - goods_yc_temp.Count
  8445. goods[j].Count = temp_count
  8446. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8447. break
  8448. }
  8449. }
  8450. }
  8451. }
  8452. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8453. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8454. fmt.Println("剩余需要出库的", len(goods))
  8455. if len(goods) > 0 {
  8456. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8457. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8458. if err == gorm.ErrRecordNotFound {
  8459. //没有记录,则创建出库单
  8460. timeStr := time.Now().Format("2006-01-02")
  8461. timeArr := strings.Split(timeStr, "-")
  8462. total, _ := service.FindAllWarehouseOut(orgID)
  8463. total = total + 1
  8464. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8465. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8466. number = number + total
  8467. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8468. warehouseOut := models.WarehouseOut{
  8469. WarehouseOutOrderNumber: warehousing_out_order,
  8470. OperationTime: time.Now().Unix(),
  8471. OrgId: orgID,
  8472. Creater: creater,
  8473. Ctime: time.Now().Unix(),
  8474. Status: 1,
  8475. WarehouseOutTime: record_time,
  8476. Dealer: 0,
  8477. Manufacturer: 0,
  8478. Type: 1,
  8479. IsSys: 1,
  8480. StorehouseId: houseConfig.StorehouseOutInfo,
  8481. IsCheck: 1,
  8482. }
  8483. err := service.AddSigleWarehouseOut(&warehouseOut)
  8484. if err != nil {
  8485. utils.TraceLog("创建出库单失败 err = %v", err)
  8486. return err
  8487. } else {
  8488. out = warehouseOut
  8489. }
  8490. }
  8491. for _, item := range goods {
  8492. var newCount int64 = 0
  8493. for _, it := range goodOne {
  8494. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8495. newCount = it.Count
  8496. }
  8497. }
  8498. prepare := models.DialysisBeforePrepare{
  8499. GoodTypeId: item.GoodTypeId,
  8500. GoodId: item.GoodId,
  8501. Count: item.Count,
  8502. StorehouseId: houseConfig.StorehouseOutInfo,
  8503. }
  8504. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8505. //增加出库数量
  8506. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8507. }
  8508. }
  8509. if len(goods_yc) > 0 {
  8510. for _, good_yc := range goods_yc {
  8511. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8512. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8513. }
  8514. }
  8515. return nil
  8516. }
  8517. // 耗材出库删除
  8518. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8519. // 先根据相关信息查询当天该耗材的出库信息
  8520. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8521. if err != nil {
  8522. return err
  8523. }
  8524. var delete_count int64 = 0
  8525. for _, ware := range warehouseOutInfos {
  8526. // 判断当前出库的数据和删除出库数量
  8527. if good_yc.Count <= ware.Count {
  8528. delete_count = good_yc.Count
  8529. } else {
  8530. delete_count = ware.Count
  8531. }
  8532. warehouseOutInfo := &models.WarehouseOutInfo{
  8533. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8534. WarehouseOutId: warehouseOut.ID,
  8535. Status: 1,
  8536. Ctime: time.Now().Unix(),
  8537. Remark: "",
  8538. OrgId: orgID,
  8539. Type: 1,
  8540. Manufacturer: 0,
  8541. Dealer: 0,
  8542. IsSys: 0,
  8543. SysRecordTime: record_time,
  8544. GoodTypeId: good_yc.GoodTypeId,
  8545. GoodId: good_yc.GoodId,
  8546. StorehouseId: warehouseOut.StorehouseId,
  8547. IsCheck: 1,
  8548. }
  8549. warehouseOutInfo.Count = delete_count
  8550. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8551. warehouseOutInfo.Price = stockInInfo.Price
  8552. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8553. if errOne != nil {
  8554. return errOne
  8555. }
  8556. // 删除出库完成后,要改变流水库存(有疑问)
  8557. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8558. fmt.Println("errOne", errOne)
  8559. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8560. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8561. //扣减出库数量
  8562. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8563. if errThree != nil {
  8564. return errThree
  8565. }
  8566. }
  8567. if good_yc.Count == 0 {
  8568. return nil
  8569. } else {
  8570. return errors.New("退库和出库数据不匹配")
  8571. }
  8572. }
  8573. func (this *DialysisAPIController) GetMobileScheduleList() {
  8574. limit, _ := this.GetInt64("limit")
  8575. page, _ := this.GetInt64("page")
  8576. type_options_visible, _ := this.GetInt64("type_options_visible")
  8577. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8578. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8579. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8580. }
  8581. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8582. newArr = make([]*models.HisPrescriptionProject, 0)
  8583. for i := 0; i < len(arr); i++ {
  8584. repeat := false
  8585. for j := i + 1; j < len(arr); j++ {
  8586. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8587. repeat = true
  8588. break
  8589. }
  8590. }
  8591. if !repeat {
  8592. newArr = append(newArr, arr[i])
  8593. }
  8594. }
  8595. return
  8596. }
  8597. func (this *DialysisAPIController) GetRoleList() {
  8598. admin_user_id, _ := this.GetInt64("admin_user_id")
  8599. orgid := this.GetMobileAdminUserInfo().Org.Id
  8600. list, err := service.GetRoleList(orgid, admin_user_id)
  8601. fmt.Println(err)
  8602. this.ServeSuccessJSON(map[string]interface{}{
  8603. "list": list,
  8604. })
  8605. return
  8606. }
  8607. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8608. // 先根据相关信息查询当天该耗材的出库信息
  8609. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8610. if err != nil {
  8611. return err
  8612. }
  8613. var delete_count int64 = 0
  8614. delete_count = warehouseOutInfos.Count - count
  8615. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8616. // 删除出库完成后,要增加对应批次的库存数量
  8617. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8618. if errThree != nil {
  8619. return errThree
  8620. }
  8621. //增加退库数量
  8622. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8623. //扣减出库数量
  8624. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8625. //查询剩余库存
  8626. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8627. var sum_count int64
  8628. for _, item := range goodList {
  8629. sum_count += item.StockCount
  8630. }
  8631. // 在出库记录表里记录退库详情
  8632. warehouseOutInfo := &models.WarehouseOutInfo{
  8633. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8634. WarehouseOutId: warehouseOut.ID,
  8635. Status: 1,
  8636. Ctime: time.Now().Unix(),
  8637. OrgId: orgID,
  8638. Type: 1,
  8639. IsSys: 1,
  8640. SysRecordTime: record_time,
  8641. GoodTypeId: good_yc.GoodTypeId,
  8642. GoodId: good_yc.GoodId,
  8643. PatientId: good_yc.PatientId,
  8644. ConsumableType: 2,
  8645. StorehouseId: houseConfig.StorehouseOutInfo,
  8646. IsCheck: 1,
  8647. OverCount: sum_count,
  8648. }
  8649. warehouseOutInfo.Count = count
  8650. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8651. warehouseOutInfo.Price = stockInInfo.Price
  8652. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8653. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8654. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8655. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8656. warehouseOutInfo.Number = warehouseOutInfos.Number
  8657. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8658. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8659. //查找当天是否存在出库记录
  8660. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8661. if errcod == gorm.ErrRecordNotFound {
  8662. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8663. //插入详情明细表
  8664. if errOne != nil {
  8665. return errOne
  8666. }
  8667. //插入详情明细表
  8668. stockFlow := models.VmStockFlow{
  8669. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8670. WarehouseOutId: warehouseOut.ID,
  8671. GoodId: good_yc.GoodId,
  8672. Number: warehouseOutInfos.Number,
  8673. ProductDate: stockInInfo.ProductDate,
  8674. ExpireDate: stockInInfo.ExpiryDate,
  8675. Count: count,
  8676. Price: stockInInfo.Price,
  8677. Status: 1,
  8678. Ctime: record_time,
  8679. UserOrgId: good_yc.OrgId,
  8680. Manufacturer: stockInInfo.Manufacturer,
  8681. Dealer: stockInInfo.Dealer,
  8682. LicenseNumber: stockInInfo.LicenseNumber,
  8683. IsEdit: 2,
  8684. Creator: creater,
  8685. SystemTime: record_time,
  8686. ConsumableType: 3,
  8687. WarehousingDetailId: 0,
  8688. IsSys: 1,
  8689. UpdateCreator: creater,
  8690. PatientId: patient_id,
  8691. StorehouseId: houseConfig.StorehouseOutInfo,
  8692. OverCount: sum_count,
  8693. ProjectId: good_yc.ProjectId,
  8694. }
  8695. err := service.CreateStockFlowOne(stockFlow)
  8696. fmt.Println("err", err)
  8697. } else if errcod == nil {
  8698. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8699. }
  8700. //创建退库单
  8701. operation_time := time.Now().Unix()
  8702. //创建退库单
  8703. timeStr := time.Now().Format("2006-01-02")
  8704. timeArr := strings.Split(timeStr, "-")
  8705. total, _ := service.FindAllCancelStockTotal(orgID)
  8706. total = total + 1
  8707. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8708. cancelStock := models.CancelStock{
  8709. OrderNumber: orderNumber,
  8710. OperaTime: operation_time,
  8711. OrgId: orgID,
  8712. Creater: warehouseOut.Creater,
  8713. Ctime: time.Now().Unix(),
  8714. Status: 1,
  8715. ReturnTime: record_time,
  8716. Type: 1,
  8717. StorehouseId: stockInInfo.StorehouseId,
  8718. IsCheck: 1,
  8719. }
  8720. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8721. if msgerrkonde == gorm.ErrRecordNotFound {
  8722. service.AddSigleCancelStock(&cancelStock)
  8723. }
  8724. cancel, _ := service.GetLastCancelStockById(orgID)
  8725. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8726. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8727. cancelStockInfo := models.CancelStockInfo{
  8728. GoodId: stockInInfo.GoodId,
  8729. CancelStockId: cancel.ID,
  8730. GoodTypeId: stockInInfo.GoodTypeId,
  8731. Count: delete_count,
  8732. Price: stockInInfo.PackingPrice,
  8733. Total: 0,
  8734. ProductDate: stockInInfo.ProductDate,
  8735. ExpiryDate: stockInInfo.ExpiryDate,
  8736. Ctime: record_time,
  8737. Status: 1,
  8738. OrgId: orgID,
  8739. OrderNumber: cancel.OrderNumber,
  8740. Type: 0,
  8741. Dealer: deaerler.DealerName,
  8742. Manufacturer: manufacturer.ManufacturerName,
  8743. Number: stockInInfo.Number,
  8744. RegisterAccount: "",
  8745. Remark: "",
  8746. WarehouseInfoId: stockInInfo.ID,
  8747. PatientId: patient_id,
  8748. RecordDate: record_time,
  8749. StorehouseId: stockInInfo.StorehouseId,
  8750. IsCheck: 1,
  8751. }
  8752. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8753. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8754. flow := models.VmStockFlow{
  8755. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8756. GoodId: good_yc.GoodId,
  8757. Number: warehouseOutInfos.Number,
  8758. LicenseNumber: stockInInfo.LicenseNumber,
  8759. Count: delete_count,
  8760. UserOrgId: orgID,
  8761. PatientId: patient_id,
  8762. SystemTime: record_time,
  8763. ConsumableType: 7,
  8764. IsSys: 0,
  8765. WarehousingOrder: "",
  8766. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8767. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8768. IsEdit: 0,
  8769. CancelStockId: cancel.ID,
  8770. CancelOrderNumber: cancel.OrderNumber,
  8771. Manufacturer: manufacturer.ID,
  8772. Dealer: 0,
  8773. Creator: warehouseOut.Creater,
  8774. UpdateCreator: 0,
  8775. Status: 1,
  8776. Ctime: record_time,
  8777. Mtime: 0,
  8778. Price: stockInInfo.Price,
  8779. WarehousingDetailId: stockInInfo.ID,
  8780. WarehouseOutDetailId: warehouseOutInfos.ID,
  8781. CancelOutDetailId: cancelInfo.ID,
  8782. ProductDate: stockInInfo.ProductDate,
  8783. ExpireDate: stockInInfo.ExpiryDate,
  8784. StorehouseId: houseConfig.StorehouseOutInfo,
  8785. OverCount: sum_count,
  8786. }
  8787. service.CreateStockFlowOne(flow)
  8788. //更改自动出库的表格
  8789. details := models.BloodAutomaticReduceDetail{
  8790. WarehouseOutId: warehouseOutInfo.ID,
  8791. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8792. PatientId: patient_id,
  8793. Ctime: time.Now().Unix(),
  8794. Mtime: time.Now().Unix(),
  8795. Status: 1,
  8796. RecordTime: record_time,
  8797. OrgId: orgID,
  8798. GoodId: good_yc.GoodId,
  8799. GoodTypeId: good_yc.GoodTypeId,
  8800. Count: count,
  8801. StorehouseId: houseConfig.StorehouseOutInfo,
  8802. }
  8803. //查询当天耗材是否已经存在数据
  8804. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8805. if errcode == gorm.ErrRecordNotFound {
  8806. errTwo := service.CreateAutoReduceRecord(&details)
  8807. if errTwo != nil {
  8808. return errTwo
  8809. }
  8810. } else if errcode == nil {
  8811. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8812. service.CreateAutoReduceRecord(&details)
  8813. }
  8814. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8815. //增加出库库存数量
  8816. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8817. if good_yc.Count == 0 {
  8818. return nil
  8819. } else {
  8820. return errors.New("退库和出库数据不匹配")
  8821. }
  8822. }
  8823. func (this *DialysisAPIController) SavePatientSign() {
  8824. adminUserInfo := this.GetMobileAdminUserInfo()
  8825. patient_id, _ := this.GetInt64("patient_id")
  8826. dialysis_date, _ := this.GetInt64("dialysis_date")
  8827. orgid := adminUserInfo.Org.Id
  8828. var esdata models.DialysisOrder
  8829. var err error
  8830. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8832. return
  8833. }
  8834. esdata.Hash = esdata.Hash
  8835. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8836. order := models.DialysisOrder{
  8837. Hash: esdata.Hash,
  8838. Url: esdata.Url,
  8839. }
  8840. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8841. redis := service.RedisClient()
  8842. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8843. redis.Set(key, "", time.Second)
  8844. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8845. //清空key 值
  8846. redis.Set(keyOne, "", time.Second)
  8847. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8848. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8849. //redis.Set(keyTwo, "", time.Second)
  8850. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8851. redis.Set(keyThree, "", time.Second)
  8852. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8853. redis.Set(keyFour, "", time.Second)
  8854. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8855. redis.Set(keyFive, "", time.Second)
  8856. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8857. redis.Set(keySix, "", time.Second)
  8858. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8859. redis.Set(keySeven, "", time.Second)
  8860. if err != nil {
  8861. fmt.Println(err)
  8862. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8863. return
  8864. }
  8865. this.ServeSuccessJSON(map[string]interface{}{
  8866. "electronic_signature": esdata,
  8867. })
  8868. }
  8869. func (this *DialysisAPIController) GetPatientSign() {
  8870. patient_id, _ := this.GetInt64("patient_id")
  8871. dialysis_date, _ := this.GetInt64("dialysis_date")
  8872. adminUserInfo := this.GetMobileAdminUserInfo()
  8873. orgId := adminUserInfo.Org.Id
  8874. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8875. if err != nil {
  8876. fmt.Println(err)
  8877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8878. return
  8879. }
  8880. this.ServeSuccessJSON(map[string]interface{}{
  8881. "dialysisOrder": dialysisOrder,
  8882. })
  8883. }
  8884. func (this *DialysisAPIController) GetScheduleByPatient() {
  8885. patient_id, _ := this.GetInt64("patient_id")
  8886. schedule_date, _ := this.GetInt64("schedule_date")
  8887. orgid := this.GetMobileAdminUserInfo().Org.Id
  8888. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8889. this.ServeSuccessJSON(map[string]interface{}{
  8890. "schedule": schedule,
  8891. })
  8892. }
  8893. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8894. org_id := this.GetMobileAdminUserInfo().Org.Id
  8895. patient_id, _ := this.GetInt64("patient_id")
  8896. schedule_date, _ := this.GetInt64("schedule_date")
  8897. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8898. this.ServeSuccessJSON(map[string]interface{}{
  8899. "order": order,
  8900. })
  8901. }
  8902. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8903. org_id := this.GetMobileAdminUserInfo().Org.Id
  8904. schedule_date := this.GetString("schedule_date")
  8905. schedule_type, _ := this.GetInt64("schedule_type")
  8906. timeLayout := "2006-01-02"
  8907. loc, _ := time.LoadLocation("Local")
  8908. var startdateunix int64
  8909. if len(schedule_date) > 0 {
  8910. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8911. if err != nil {
  8912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8913. return
  8914. }
  8915. startdateunix = theTime.Unix()
  8916. }
  8917. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8918. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8919. devices, _ := service.GetAllDevicetByListSix(org_id)
  8920. for key, item := range scheduals {
  8921. // 床位信息
  8922. for _, device := range devices {
  8923. if item.BedId == device.ID {
  8924. scheduals[key].DeviceNumber = device
  8925. break
  8926. }
  8927. }
  8928. }
  8929. this.ServeSuccessJSON(map[string]interface{}{
  8930. "list": list,
  8931. "scheduals": scheduals,
  8932. })
  8933. }
  8934. func (this *DialysisAPIController) SavePatientPicture() {
  8935. patient_id, _ := this.GetInt64("patient_id")
  8936. dialysis_date, _ := this.GetInt64("schedule_date")
  8937. avatar := this.GetString("avatar")
  8938. fmt.Println("patient_id", patient_id)
  8939. orgId := this.GetMobileAdminUserInfo().Org.Id
  8940. order := models.DialysisOrder{
  8941. Url: avatar,
  8942. }
  8943. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8944. redis := service.RedisClient()
  8945. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8946. redis.Set(key, "", time.Second)
  8947. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8948. //清空key 值
  8949. redis.Set(keyOne, "", time.Second)
  8950. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8951. redis.Set(keyThree, "", time.Second)
  8952. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8953. redis.Set(keyFour, "", time.Second)
  8954. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8955. redis.Set(keyFive, "", time.Second)
  8956. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8957. redis.Set(keySix, "", time.Second)
  8958. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8959. redis.Set(keySeven, "", time.Second)
  8960. if err != nil {
  8961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8962. return
  8963. }
  8964. this.ServeSuccessJSON(map[string]interface{}{
  8965. "order": order,
  8966. })
  8967. }
  8968. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8969. ids := this.GetString("ids")
  8970. idSplit := strings.Split(ids, ",")
  8971. orgId := this.GetMobileAdminUserInfo().Org.Id
  8972. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8973. execution_time := this.GetString("exce_time")
  8974. timeLayout2 := "2006-01-02 15:04:05"
  8975. loc, _ := time.LoadLocation("Local")
  8976. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8977. if errs != nil {
  8978. utils.ErrorLog(errs.Error())
  8979. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8980. return
  8981. }
  8982. //his客户
  8983. if config.IsOpen == 1 {
  8984. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8985. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8986. for _, item := range list {
  8987. for _, it := range adviceList {
  8988. if item.DrugId == it.DrugId {
  8989. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8990. }
  8991. }
  8992. }
  8993. for _, item := range list {
  8994. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8995. var sum_out_count int64
  8996. for _, itemThree := range item.ChildDoctorAdvice {
  8997. var prescribing_number int64
  8998. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8999. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9000. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9001. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9002. }
  9003. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9004. prescribing_number = parseIntPrescribingNumber
  9005. }
  9006. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9007. prescribing_number = parseIntPrescribingNumber
  9008. }
  9009. sum_out_count += prescribing_number
  9010. }
  9011. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9012. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9013. //库存不足
  9014. if sum_out_count > drugStockOut.FlushCount {
  9015. this.ServeSuccessJSON(map[string]interface{}{
  9016. "msg": "2",
  9017. "drug": medical,
  9018. "ids": ids,
  9019. })
  9020. return
  9021. }
  9022. }
  9023. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9024. //执行医嘱
  9025. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9026. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9027. for _, item := range advices {
  9028. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9029. redis := service.RedisClient()
  9030. //清空key 值
  9031. redis.Set(key, "", time.Second)
  9032. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9033. redis.Set(keyTwo, "", time.Second)
  9034. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9035. redis.Set(keyThree, "", time.Second)
  9036. recordDate := theTime.Format("2006-01-02")
  9037. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9038. redis.Set(keyFour, "", time.Second)
  9039. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9040. redis.Set(keyFive, "", time.Second)
  9041. defer redis.Close()
  9042. }
  9043. if errs == nil {
  9044. //药品管理信息
  9045. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9046. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9047. if drugStockConfig.IsOpen == 1 {
  9048. for _, item := range advices {
  9049. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9050. config, _ := service.GetDrugOpenConfigOne(orgId)
  9051. if config.IsOpen != 1 {
  9052. //查询该药品是否有库存
  9053. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9054. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9055. if medical.IsUse == 2 {
  9056. if config.IsOpen != 1 {
  9057. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9058. service.HisDrugsDelivery(orgId, creater, &advice)
  9059. if orgId == 3877 || orgId == 10265 {
  9060. //查询该药品是否有出库记录
  9061. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9062. if len(flowMap) == 0 {
  9063. errs := service.UpdateHisAdviceById(advice.ID)
  9064. if errs != nil {
  9065. drugError := models.XtDrugError{
  9066. UserOrgId: orgId,
  9067. DrugId: item.DrugId,
  9068. RecordDate: item.AdviceDate,
  9069. PatientId: item.PatientId,
  9070. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9071. Status: 1,
  9072. Ctime: time.Now().Unix(),
  9073. Mtime: 0,
  9074. SumCount: 0,
  9075. Prescribingnumber: advice.PrescribingNumber,
  9076. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9077. }
  9078. service.CreateDrugError(drugError)
  9079. }
  9080. this.ServeSuccessJSON(map[string]interface{}{
  9081. "msg": "2",
  9082. "drug": medical,
  9083. "ids": ids,
  9084. })
  9085. return
  9086. }
  9087. }
  9088. }
  9089. if pharmacyConfig.IsOpen != 1 {
  9090. service.HisDrugsDelivery(orgId, creater, &advice)
  9091. if orgId == 3877 || orgId == 10265 {
  9092. //查询该药品是否有出库记录
  9093. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9094. if len(flowMap) == 0 {
  9095. errs := service.UpdateHisAdviceById(advice.ID)
  9096. if errs != nil {
  9097. drugError := models.XtDrugError{
  9098. UserOrgId: orgId,
  9099. DrugId: item.DrugId,
  9100. RecordDate: item.AdviceDate,
  9101. PatientId: item.PatientId,
  9102. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9103. Status: 1,
  9104. Ctime: time.Now().Unix(),
  9105. Mtime: 0,
  9106. SumCount: 0,
  9107. Prescribingnumber: advice.PrescribingNumber,
  9108. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9109. }
  9110. service.CreateDrugError(drugError)
  9111. }
  9112. this.ServeSuccessJSON(map[string]interface{}{
  9113. "msg": "2",
  9114. "drug": medical,
  9115. "ids": ids,
  9116. })
  9117. return
  9118. }
  9119. }
  9120. }
  9121. //更新字典里面的库存
  9122. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9123. var sum_count int64
  9124. for _, its := range stockInfo {
  9125. if its.MaxUnit == medical.MaxUnit {
  9126. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9127. }
  9128. sum_count += its.StockMaxNumber + its.StockMinNumber
  9129. }
  9130. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9131. //剩余库存
  9132. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9133. }
  9134. }
  9135. }
  9136. }
  9137. }
  9138. this.ServeSuccessJSON(map[string]interface{}{
  9139. "msg": "1",
  9140. "ids": ids,
  9141. })
  9142. return
  9143. } else {
  9144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9145. }
  9146. }
  9147. //血透客户
  9148. if config.IsOpen == 2 || config.IsOpen == 0 {
  9149. //药品管理信息
  9150. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9151. if drugStockConfig.IsOpen == 1 {
  9152. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9153. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9154. for _, item := range list {
  9155. for _, it := range adviceList {
  9156. if item.DrugId == it.DrugId {
  9157. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9158. }
  9159. }
  9160. }
  9161. for _, item := range list {
  9162. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9163. var sum_out_count int64
  9164. for _, itemThree := range item.ChildDoctorAdvice {
  9165. var prescribing_number int64
  9166. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9167. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9168. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9169. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9170. }
  9171. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9172. prescribing_number = parseIntPrescribingNumber
  9173. }
  9174. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9175. prescribing_number = parseIntPrescribingNumber
  9176. }
  9177. sum_out_count += prescribing_number
  9178. }
  9179. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9180. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9181. //库存不足
  9182. if sum_out_count > drugStockOut.FlushCount {
  9183. this.ServeSuccessJSON(map[string]interface{}{
  9184. "msg": "2",
  9185. "drug": medical,
  9186. "ids": ids,
  9187. })
  9188. return
  9189. }
  9190. }
  9191. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9192. //执行医嘱
  9193. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9194. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9195. for _, item := range advices {
  9196. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9197. redis := service.RedisClient()
  9198. //清空key 值
  9199. redis.Set(key, "", time.Second)
  9200. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9201. redis.Set(keyTwo, "", time.Second)
  9202. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9203. redis.Set(keyThree, "", time.Second)
  9204. recordDate := theTime.Format("2006-01-02")
  9205. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9206. redis.Set(keyFour, "", time.Second)
  9207. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9208. redis.Set(keyFive, "", time.Second)
  9209. defer redis.Close()
  9210. }
  9211. if errs == nil {
  9212. for _, item := range advices {
  9213. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9214. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9215. //查询是否出库按钮开启
  9216. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9217. if adviceSetting.IsAdviceOpen == 1 {
  9218. //查询是否出库按钮开启
  9219. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9220. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9221. if prescriptionConfig.IsOpen == 1 {
  9222. if medical.IsUse == 2 {
  9223. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9224. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9225. }
  9226. if pharmacyConfig.IsOpen != 1 {
  9227. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9228. }
  9229. //更新字典里面的库存
  9230. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9231. var sum_count int64
  9232. for _, its := range stockInfo {
  9233. if its.MaxUnit == medical.MaxUnit {
  9234. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9235. }
  9236. sum_count += its.StockMaxNumber + its.StockMinNumber
  9237. }
  9238. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9239. //剩余库存
  9240. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9241. }
  9242. }
  9243. } else {
  9244. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9245. if medical.IsUse == 2 {
  9246. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9247. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9248. }
  9249. if pharmacyConfig.IsOpen != 1 {
  9250. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9251. }
  9252. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9253. var sum_count int64
  9254. for _, its := range stockInfo {
  9255. if its.MaxUnit == medical.MaxUnit {
  9256. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9257. }
  9258. sum_count += its.StockMaxNumber + its.StockMinNumber
  9259. }
  9260. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9261. //剩余库存
  9262. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9263. }
  9264. }
  9265. }
  9266. }
  9267. this.ServeSuccessJSON(map[string]interface{}{
  9268. "msg": "1",
  9269. "ids": ids,
  9270. })
  9271. return
  9272. } else {
  9273. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9274. //执行医嘱
  9275. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9276. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9277. for _, item := range advices {
  9278. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9279. redis := service.RedisClient()
  9280. //清空key 值
  9281. redis.Set(key, "", time.Second)
  9282. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9283. redis.Set(keyTwo, "", time.Second)
  9284. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9285. redis.Set(keyThree, "", time.Second)
  9286. recordDate := theTime.Format("2006-01-02")
  9287. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9288. redis.Set(keyFour, "", time.Second)
  9289. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9290. redis.Set(keyFive, "", time.Second)
  9291. defer redis.Close()
  9292. }
  9293. this.ServeSuccessJSON(map[string]interface{}{
  9294. "msg": "1",
  9295. "ids": ids,
  9296. })
  9297. return
  9298. }
  9299. }
  9300. }
  9301. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9302. ids := this.GetString("ids")
  9303. idSplit := strings.Split(ids, ",")
  9304. orgId := this.GetMobileAdminUserInfo().Org.Id
  9305. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9306. if config.IsOpen == 1 {
  9307. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9308. this.ServeSuccessJSON(map[string]interface{}{
  9309. "msg": "1",
  9310. "ids": ids,
  9311. })
  9312. return
  9313. }
  9314. if config.IsOpen == 0 || config.IsOpen == 2 {
  9315. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9316. this.ServeSuccessJSON(map[string]interface{}{
  9317. "msg": "1",
  9318. "ids": ids,
  9319. })
  9320. return
  9321. }
  9322. }
  9323. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9324. ids := this.GetString("ids")
  9325. idSplit := strings.Split(ids, ",")
  9326. orgId := this.GetMobileAdminUserInfo().Org.Id
  9327. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9328. //his
  9329. if config.IsOpen == 1 {
  9330. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9331. theTime := time.Now()
  9332. advices := models.HisDoctorAdviceThirty{
  9333. CheckTime: theTime.Unix(),
  9334. Checker: checker,
  9335. UpdatedTime: time.Now().Unix(),
  9336. }
  9337. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9338. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9339. for _, item := range list {
  9340. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9341. redis := service.RedisClient()
  9342. //清空key 值
  9343. redis.Set(key, "", time.Second)
  9344. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9345. redis.Set(keyTwo, "", time.Second)
  9346. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9347. redis.Set(keyThree, "", time.Second)
  9348. recordDate := theTime.Format("2006-01-02")
  9349. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9350. redis.Set(keyFour, "", time.Second)
  9351. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9352. redis.Set(keyFive, "", time.Second)
  9353. defer redis.Close()
  9354. }
  9355. this.ServeSuccessJSON(map[string]interface{}{
  9356. "msg": "1",
  9357. "ids": ids,
  9358. })
  9359. return
  9360. }
  9361. //血透
  9362. if config.IsOpen == 0 || config.IsOpen == 2 {
  9363. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9364. theTime := time.Now()
  9365. advices := models.DoctorAdvice{
  9366. CheckTime: theTime.Unix(),
  9367. Checker: checker,
  9368. UpdatedTime: time.Now().Unix(),
  9369. }
  9370. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9371. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9372. for _, item := range list {
  9373. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9374. redis := service.RedisClient()
  9375. //清空key 值
  9376. redis.Set(key, "", time.Second)
  9377. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9378. redis.Set(keyTwo, "", time.Second)
  9379. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9380. redis.Set(keyThree, "", time.Second)
  9381. recordDate := theTime.Format("2006-01-02")
  9382. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9383. redis.Set(keyFour, "", time.Second)
  9384. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9385. redis.Set(keyFive, "", time.Second)
  9386. defer redis.Close()
  9387. }
  9388. this.ServeSuccessJSON(map[string]interface{}{
  9389. "msg": "1",
  9390. "ids": ids,
  9391. })
  9392. return
  9393. }
  9394. }
  9395. func (this *DialysisAPIController) CheckSchedule() {
  9396. patientID, _ := this.GetInt64("patient_id")
  9397. recordDateStr := this.GetString("record_date")
  9398. nurseID, _ := this.GetInt64("start_nurse")
  9399. schedual_type, _ := this.GetInt64("schedual_type")
  9400. bedID, _ := this.GetInt64("bed")
  9401. start_time := this.GetString("start_time")
  9402. fmt.Println("patientID", patientID)
  9403. fmt.Println("recordDateStr", recordDateStr)
  9404. fmt.Println("nurseID", nurseID)
  9405. fmt.Println("schedual_type------", schedual_type)
  9406. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9408. return
  9409. }
  9410. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9411. if parseStartDateErr != nil {
  9412. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9414. return
  9415. }
  9416. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9417. if parseErr != nil {
  9418. this.ErrorLog("时间解析失败:%v", parseErr)
  9419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9420. return
  9421. }
  9422. adminUserInfo := this.GetMobileAdminUserInfo()
  9423. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9424. if getPatientErr != nil {
  9425. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9427. return
  9428. } else if patient == nil {
  9429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9430. return
  9431. }
  9432. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9433. if getNurseErr != nil {
  9434. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9436. return
  9437. } else if nurse == nil {
  9438. this.ErrorLog("护士不存在")
  9439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9440. return
  9441. }
  9442. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9443. if getDeviceNumberErr != nil {
  9444. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9446. return
  9447. } else if deviceNumber == nil {
  9448. this.ErrorLog("床位号不存在")
  9449. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9450. return
  9451. }
  9452. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9453. if getRecordErr != nil {
  9454. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9456. return
  9457. } else if dialysisRecord != nil {
  9458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9459. return
  9460. }
  9461. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9462. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9463. timeLayout := "2006-01-02 15:04:05"
  9464. loc, _ := time.LoadLocation("Local")
  9465. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9466. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9467. schedulestartTime := theStartTime.Unix()
  9468. scheduleendTime := theEndTime.Unix()
  9469. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9470. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9471. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9472. //查询该床位是否有人用了
  9473. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9474. if err == nil {
  9475. if schedule.ID == 0 {
  9476. this.ServeSuccessJSON(map[string]interface{}{
  9477. "status": 0,
  9478. "msg": "请求失败",
  9479. })
  9480. } else {
  9481. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9482. if order.ID > 0 { //该机位被其他人占用了
  9483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9484. return
  9485. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9486. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9487. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9488. this.ServeSuccessJSON(map[string]interface{}{
  9489. "status": 1,
  9490. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9491. })
  9492. return
  9493. } else {
  9494. this.ServeSuccessJSON(map[string]interface{}{
  9495. "status": 0,
  9496. "msg": "",
  9497. })
  9498. }
  9499. }
  9500. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9501. this.ServeSuccessJSON(map[string]interface{}{
  9502. "status": 2,
  9503. "msg": "当前机位已有患者在使用,请重新选择!",
  9504. })
  9505. }
  9506. }
  9507. } else {
  9508. this.ServeSuccessJSON(map[string]interface{}{
  9509. "status": 0,
  9510. "msg": "",
  9511. })
  9512. }
  9513. }
  9514. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9515. orgId := this.GetMobileAdminUserInfo().Org.Id
  9516. schedule_type, _ := this.GetInt64("schedule_type")
  9517. partion_type, _ := this.GetInt64("partion_type")
  9518. start_time := this.GetString("start_time")
  9519. timeLayout := "2006-01-02"
  9520. loc, _ := time.LoadLocation("Local")
  9521. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9522. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9523. _, config := service.FindXTHisRecordByOrgId(orgId)
  9524. appId := this.GetMobileAdminUserInfo().App.Id
  9525. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9526. if err == nil {
  9527. this.ServeSuccessJSON(map[string]interface{}{
  9528. "list": list,
  9529. "config": config,
  9530. "doctorList": doctorList,
  9531. })
  9532. return
  9533. } else {
  9534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9535. return
  9536. }
  9537. }
  9538. func (this *DialysisAPIController) SaveMobileInformation() {
  9539. patient_id, _ := this.GetInt64("patient_id")
  9540. record_date, _ := this.GetInt64("record_date")
  9541. startTime := this.GetString("start_time")
  9542. module, _ := this.GetInt64("module")
  9543. remark := this.GetString("remark")
  9544. timeLayout := "2006-01-02 15:04"
  9545. loc, _ := time.LoadLocation("Local")
  9546. if len(startTime) == 0 {
  9547. utils.ErrorLog("len(start_time) == 0")
  9548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9549. return
  9550. }
  9551. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9552. if err != nil {
  9553. utils.ErrorLog(err.Error())
  9554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9555. return
  9556. }
  9557. StartTime := theTime.Unix()
  9558. fmt.Println("startime-------------", StartTime)
  9559. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9560. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9561. information := models.XtDialysisInformation{
  9562. Module: module,
  9563. PatientId: patient_id,
  9564. RecordDate: record_date,
  9565. ApplicationDate: StartTime,
  9566. Creater: creater,
  9567. ApplicationStatus: 2,
  9568. Checker: 0,
  9569. CheckTime: 0,
  9570. Remark: remark,
  9571. UserOrgId: user_org_id,
  9572. Ctime: time.Now().Unix(),
  9573. Status: 1,
  9574. Mtime: 0,
  9575. }
  9576. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9577. if infor.ID == 0 {
  9578. service.SaveDialysisInformation(information)
  9579. }
  9580. if infor.ID > 0 {
  9581. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9582. }
  9583. this.ServeSuccessJSON(map[string]interface{}{
  9584. "information": information,
  9585. })
  9586. return
  9587. }
  9588. func (this *DialysisAPIController) GetMobileInformation() {
  9589. limit, _ := this.GetInt64("limit")
  9590. page, _ := this.GetInt64("page")
  9591. orgid := this.GetMobileAdminUserInfo().Org.Id
  9592. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9593. appid := this.GetMobileAdminUserInfo().App.Id
  9594. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9595. patients, _ := service.GetAllpatientThirty(orgid)
  9596. this.ServeSuccessJSON(map[string]interface{}{
  9597. "information": information,
  9598. "total": total,
  9599. "doclist": doclist,
  9600. "patients": patients,
  9601. })
  9602. return
  9603. }
  9604. func (this *DialysisAPIController) GetMobileInformationOne() {
  9605. limit, _ := this.GetInt64("limit")
  9606. page, _ := this.GetInt64("page")
  9607. orgid := this.GetMobileAdminUserInfo().Org.Id
  9608. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9609. appid := this.GetMobileAdminUserInfo().App.Id
  9610. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9611. patients, _ := service.GetAllpatientThirty(orgid)
  9612. this.ServeSuccessJSON(map[string]interface{}{
  9613. "information": information,
  9614. "total": total,
  9615. "doclist": doclist,
  9616. "patients": patients,
  9617. })
  9618. return
  9619. }
  9620. func (this *DialysisAPIController) CheckMobileInformation() {
  9621. id, _ := this.GetInt64("id")
  9622. application_status, _ := this.GetInt64("application_status")
  9623. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9624. checktime := time.Now().Unix()
  9625. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9626. if err == nil {
  9627. this.ServeSuccessJSON(map[string]interface{}{
  9628. "msg": "ok",
  9629. })
  9630. return
  9631. }
  9632. }
  9633. func (c *DialysisAPIController) GetControlMonitorList() {
  9634. partition, _ := c.GetInt64("partition")
  9635. monitorDate := c.GetString("date")
  9636. patient_id, _ := c.GetInt64("patient_id")
  9637. pat_type, _ := c.GetInt64("pat_type")
  9638. timeLayout := "2006-01-02"
  9639. loc, _ := time.LoadLocation("Local")
  9640. var theStartTime int64
  9641. if len(monitorDate) > 0 {
  9642. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9643. if err != nil {
  9644. theStartTime = 0
  9645. }
  9646. theStartTime = theTime.Unix()
  9647. }
  9648. adminInfo := c.GetMobileAdminUserInfo()
  9649. orgID := adminInfo.Org.Id
  9650. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9651. if err != nil {
  9652. c.ErrorLog("获取排班信息失败:%v", err)
  9653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9654. } else {
  9655. if len(monitor) > 0 {
  9656. //获取所有床位
  9657. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9658. //获取所有分区
  9659. zoneList, _ := service.GetAllZoneByList(orgID)
  9660. //获取透析处方
  9661. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9662. //获取透前评估
  9663. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9664. //获取上机
  9665. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9666. //获取透后
  9667. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9668. //获取透后监测
  9669. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9670. //获取所有的患者
  9671. patients, _ := service.GetAllPatientListByListOne(orgID)
  9672. //获取所有透析模式
  9673. treatments, _ := service.GetAllTreatModeByList(orgID)
  9674. //获取所有医嘱
  9675. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9676. //获取双人核对
  9677. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9678. //治疗小结
  9679. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9680. //待消毒
  9681. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9682. for key, item := range monitor {
  9683. // 获取床位信息
  9684. for _, it := range numberList {
  9685. if item.BedId == it.ID {
  9686. monitor[key].DeviceNumber = it
  9687. break
  9688. }
  9689. }
  9690. //获取分区信息
  9691. for _, it := range zoneList {
  9692. if item.PartitionId == it.ID {
  9693. monitor[key].DeviceZone = it
  9694. }
  9695. }
  9696. for _, prescription := range prescriptions {
  9697. if item.PatientId == prescription.PatientId {
  9698. monitor[key].Prescription = prescription
  9699. break
  9700. }
  9701. }
  9702. for _, it := range checkList {
  9703. if item.PatientId == it.PatientId {
  9704. monitor[key].DoubleCheck = it
  9705. break
  9706. }
  9707. }
  9708. for _, it := range summaryList {
  9709. if item.PatientId == it.PatientId {
  9710. monitor[key].TreatmentSummaryForList = it
  9711. break
  9712. }
  9713. }
  9714. // 透前评估
  9715. for _, assessmentBefore := range assessmentBefores {
  9716. if item.PatientId == assessmentBefore.PatientId {
  9717. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9718. break
  9719. }
  9720. }
  9721. // 透析上下机
  9722. for _, dialysisOrder := range dialysisOrders {
  9723. if item.PatientId == dialysisOrder.PatientId {
  9724. monitor[key].DialysisOrder = dialysisOrder
  9725. break
  9726. }
  9727. }
  9728. // 治疗小节
  9729. for _, afterDislysis := range AssessmentAfterDislysis {
  9730. if item.PatientId == afterDislysis.PatientId {
  9731. monitor[key].AssessmentAfterDislysis = afterDislysis
  9732. break
  9733. }
  9734. }
  9735. for _, it := range monitorlist {
  9736. if item.PatientId == it.PatientId {
  9737. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9738. }
  9739. }
  9740. for _, it := range adviceList {
  9741. if item.PatientId == it.PatientId {
  9742. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9743. }
  9744. }
  9745. for _, patient := range patients {
  9746. if item.PatientId == patient.ID {
  9747. monitor[key].MonitorPatients = patient
  9748. break
  9749. }
  9750. }
  9751. for _, treatment := range treatments {
  9752. if item.ModeId == treatment.ID {
  9753. monitor[key].TreatmentMode = treatment
  9754. break
  9755. }
  9756. }
  9757. for _, infor := range informationList {
  9758. if item.PatientId == infor.PatientId {
  9759. monitor[key].NewDeviceInformation = infor
  9760. break
  9761. }
  9762. }
  9763. }
  9764. }
  9765. }
  9766. patients, err := service.GetAllpatientFourty(orgID)
  9767. var mds []*models.NewMonitorDialysisScheduleList
  9768. if pat_type == 0 {
  9769. for _, item := range monitor {
  9770. mds = append(mds, item)
  9771. }
  9772. }
  9773. //待医嘱核对
  9774. if pat_type == 1 {
  9775. for _, item := range monitor {
  9776. if len(item.AdviceList) > 0 {
  9777. mds = append(mds, item)
  9778. }
  9779. }
  9780. }
  9781. //待开小结
  9782. if pat_type == 2 {
  9783. for _, item := range monitor {
  9784. if item.TreatmentSummaryForList == nil {
  9785. mds = append(mds, item)
  9786. }
  9787. }
  9788. }
  9789. //待下机
  9790. if pat_type == 3 {
  9791. for _, item := range monitor {
  9792. if item.DialysisOrder != nil {
  9793. if item.DialysisOrder.ID > 0 {
  9794. mds = append(mds, item)
  9795. }
  9796. }
  9797. }
  9798. }
  9799. //待消毒
  9800. if pat_type == 4 {
  9801. for _, item := range monitor {
  9802. if item.NewDeviceInformation == nil {
  9803. mds = append(mds, item)
  9804. }
  9805. }
  9806. }
  9807. //待双人核对
  9808. if pat_type == 5 {
  9809. for _, item := range monitor {
  9810. if item.DoubleCheck == nil {
  9811. mds = append(mds, item)
  9812. }
  9813. }
  9814. }
  9815. //医嘱未执行
  9816. if pat_type == 6 {
  9817. for _, item := range monitor {
  9818. if len(item.AdviceList) > 0 {
  9819. mds = append(mds, item)
  9820. }
  9821. }
  9822. }
  9823. //患者未签名
  9824. if pat_type == 7 {
  9825. for _, item := range monitor {
  9826. if item.DialysisOrder != nil {
  9827. if item.DialysisOrder.ID > 0 {
  9828. mds = append(mds, item)
  9829. }
  9830. }
  9831. }
  9832. }
  9833. //目标超滤于实际超滤不同
  9834. if pat_type == 8 {
  9835. for _, item := range monitor {
  9836. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9837. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9838. mds = append(mds, item)
  9839. }
  9840. }
  9841. }
  9842. }
  9843. //血压少于5次
  9844. if pat_type == 9 {
  9845. for _, item := range monitor {
  9846. if len(item.MonitoringRecord) < 5 {
  9847. mds = append(mds, item)
  9848. }
  9849. }
  9850. }
  9851. if pat_type == 10 {
  9852. for _, item := range monitor {
  9853. if len(item.MonitoringRecord) == 0 {
  9854. mds = append(mds, item)
  9855. }
  9856. }
  9857. }
  9858. if pat_type == 11 {
  9859. for _, item := range monitor {
  9860. if len(item.MonitoringRecord) > 0 {
  9861. mds = append(mds, item)
  9862. }
  9863. }
  9864. }
  9865. if pat_type == 12 {
  9866. for _, item := range monitor {
  9867. if len(item.MonitoringRecord) > 0 {
  9868. mds = append(mds, item)
  9869. }
  9870. }
  9871. }
  9872. if err == nil {
  9873. c.ServeSuccessJSON(map[string]interface{}{
  9874. "monitor": mds,
  9875. "patients": patients,
  9876. })
  9877. } else {
  9878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9879. }
  9880. }
  9881. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9882. admin_user_id, _ := c.GetInt64("admin_user_id")
  9883. timeStr := time.Now().Format("2006-01-02")
  9884. timeLayout := "2006-01-02 15:04:05"
  9885. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9886. timenow := timeStringToTime.Unix()
  9887. orgId := c.GetMobileAdminUserInfo().Org.Id
  9888. //查询当前护士的患者
  9889. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9890. var patientIds []int64
  9891. for _, item := range orderList {
  9892. patientIds = append(patientIds, item.PatientId)
  9893. }
  9894. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9895. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9896. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9897. //药品管理信息
  9898. _, drugStockConfig := service.FindHisConfig(orgId)
  9899. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9900. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9901. c.ServeSuccessJSON(map[string]interface{}{
  9902. "adviceList": adviceList,
  9903. "hisAdviceList": hisAdviceList,
  9904. "projectList": projectList,
  9905. "drugStockConfig": drugStockConfig,
  9906. "patientList": patientList,
  9907. "projectConfig": projectConfig,
  9908. })
  9909. }
  9910. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9911. patient_id, _ := c.GetInt64("patient_id")
  9912. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9913. c.ServeSuccessJSON(map[string]interface{}{
  9914. "recrods": recrods,
  9915. })
  9916. }
  9917. func (c *DialysisAPIController) ExMobileChangeSch() {
  9918. id_one, _ := c.GetInt64("id_one")
  9919. id_two, _ := c.GetInt64("id_two")
  9920. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9921. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9922. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9923. //if order2.ID > 0 {
  9924. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9925. // return
  9926. //}
  9927. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9928. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9929. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9930. if count > 0 {
  9931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9932. return
  9933. }
  9934. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9935. if count1 > 0 {
  9936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9937. return
  9938. }
  9939. }
  9940. err := service.UpdateScheduleThree(sch, sch_two)
  9941. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9942. if order.ID > 0 {
  9943. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9944. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9945. redis := service.RedisClient()
  9946. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9947. redis.Set(key, "", time.Second)
  9948. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9949. //清空key 值
  9950. redis.Set(keyOne, "", time.Second)
  9951. }
  9952. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9953. if orderOne.ID > 0 {
  9954. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9955. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9956. redis := service.RedisClient()
  9957. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9958. redis.Set(key, "", time.Second)
  9959. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9960. //清空key 值
  9961. redis.Set(keyOne, "", time.Second)
  9962. }
  9963. if err == nil {
  9964. //去除当天患者排班中重复数据,保留最后一条数据
  9965. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9966. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9967. c.ServeSuccessJSON(map[string]interface{}{
  9968. "msg": "交换成功",
  9969. })
  9970. } else {
  9971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9972. return
  9973. }
  9974. }
  9975. func (c *DialysisAPIController) MobileCoverSch() {
  9976. id_one, _ := c.GetInt64("id_one")
  9977. id_two, _ := c.GetInt64("id_two")
  9978. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9979. //针对凤凰医院
  9980. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9981. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9982. if len(advice) > 0 {
  9983. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9984. }
  9985. }
  9986. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9987. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9988. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9989. if len(hisAdvice) > 0 {
  9990. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9991. }
  9992. if len(project) > 0 {
  9993. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9994. }
  9995. }
  9996. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9997. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9998. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9999. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10000. if count > 0 {
  10001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10002. return
  10003. }
  10004. }
  10005. var new_sch models.Schedule
  10006. new_sch = sch
  10007. new_sch.BedId = sch_two.BedId
  10008. new_sch.ScheduleDate = sch_two.ScheduleDate
  10009. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10010. new_sch.PartitionId = sch_two.PartitionId
  10011. new_sch.ScheduleType = sch_two.ScheduleType
  10012. new_sch.ID = 0
  10013. //删除原来的排班
  10014. err := service.SaveSchTwo(sch, sch_two)
  10015. //生成新的排班
  10016. if err == nil {
  10017. err2 := service.SaveSch(&new_sch)
  10018. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10019. if order.ID > 0 {
  10020. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10021. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10022. redis := service.RedisClient()
  10023. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10024. redis.Set(key, "", time.Second)
  10025. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10026. //清空key 值
  10027. redis.Set(keyOne, "", time.Second)
  10028. }
  10029. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10030. if orderOne.ID > 0 {
  10031. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10032. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10033. redis := service.RedisClient()
  10034. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10035. redis.Set(key, "", time.Second)
  10036. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10037. //清空key 值
  10038. redis.Set(keyOne, "", time.Second)
  10039. }
  10040. if err2 == nil {
  10041. //去除当天患者排班中重复数据,保留最后一条数据
  10042. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10043. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10044. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10045. c.ServeSuccessJSON(map[string]interface{}{
  10046. "msg": "覆盖成功",
  10047. "new_sch": new_sch,
  10048. })
  10049. } else {
  10050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10051. return
  10052. }
  10053. } else {
  10054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10055. return
  10056. }
  10057. }
  10058. func (c *DialysisAPIController) BatchCheckAdvice() {
  10059. patient_id, _ := c.GetInt64("patient_id")
  10060. advice_date, _ := c.GetInt64("advice_date")
  10061. org_id := c.GetMobileAdminUserInfo().Org.Id
  10062. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10063. //查询是his系统还是血透系统
  10064. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10065. //his客户
  10066. if configs.IsOpen == 1 {
  10067. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10068. for _, item := range adviceList {
  10069. service.BatchCheckHisAdvice(item.ID, creater)
  10070. }
  10071. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10072. for _, item := range projectList {
  10073. service.BatchCheckProject(item.ID, creater)
  10074. }
  10075. c.ServeSuccessJSON(map[string]interface{}{
  10076. "adviceList": adviceList,
  10077. "projectList": projectList,
  10078. })
  10079. }
  10080. if configs.IsOpen != 1 {
  10081. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10082. for _, item := range adviceList {
  10083. service.BatchAdviceList(item.ID, creater)
  10084. }
  10085. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10086. for _, item := range projectList {
  10087. service.BatchCheckProject(item.ID, creater)
  10088. }
  10089. c.ServeSuccessJSON(map[string]interface{}{
  10090. "adviceList": adviceList,
  10091. "projectList": projectList,
  10092. })
  10093. }
  10094. return
  10095. }
  10096. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10097. org_id := c.GetMobileAdminUserInfo().Org.Id
  10098. drugList, _ := service.GetAllDrugList(org_id)
  10099. c.ServeSuccessJSON(map[string]interface{}{
  10100. "drugList": drugList,
  10101. })
  10102. }
  10103. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10104. org_id := c.GetMobileAdminUserInfo().Org.Id
  10105. dataBody := make(map[string]interface{}, 0)
  10106. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10107. if err != nil {
  10108. utils.ErrorLog(err.Error())
  10109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10110. return
  10111. }
  10112. timeLayout := "2006-01-02"
  10113. loc, _ := time.LoadLocation("Local")
  10114. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10115. utils.ErrorLog("advice_type")
  10116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10117. return
  10118. }
  10119. adviceType := int64(dataBody["advice_type"].(float64))
  10120. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10121. utils.ErrorLog("start_time")
  10122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10123. return
  10124. }
  10125. startTime2, _ := dataBody["start_time"].(string)
  10126. time_arr := strings.Split(startTime2, " ")
  10127. if len(time_arr) > 0 {
  10128. startTime2 = time_arr[0]
  10129. }
  10130. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10131. utils.ErrorLog("advice_date")
  10132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10133. return
  10134. }
  10135. advice_date, _ := dataBody["advice_date"].(string)
  10136. var advicedateunix int64
  10137. if len(advice_date) > 0 {
  10138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10139. if err != nil {
  10140. fmt.Println(err)
  10141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10142. return
  10143. }
  10144. advicedateunix = theTime.Unix()
  10145. }
  10146. adviceDate := startTime2
  10147. if len(adviceDate) == 0 {
  10148. utils.ErrorLog("len(adviceDate) == 0")
  10149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10150. return
  10151. }
  10152. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10153. if err != nil {
  10154. utils.ErrorLog(err.Error())
  10155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10156. return
  10157. }
  10158. AdviceDate := advicedateunix
  10159. RecordDate := advicedateunix
  10160. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10161. utils.ErrorLog("start_time")
  10162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10163. return
  10164. }
  10165. startTime, _ := dataBody["start_time"].(string)
  10166. if len(startTime) == 0 {
  10167. utils.ErrorLog("len(start_time) == 0")
  10168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10169. return
  10170. }
  10171. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10172. if err != nil {
  10173. utils.ErrorLog(err.Error())
  10174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10175. return
  10176. }
  10177. StartTime := theTime.Unix()
  10178. advice_name, _ := dataBody["advice_name"].(string)
  10179. advice_desc, _ := dataBody["advice_desc"].(string)
  10180. delivery_way, _ := dataBody["delivery_way"].(string)
  10181. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10182. frequency_type := int64(dataBody["frequency_type"].(float64))
  10183. frequency_week, _ := dataBody["frequency_week"].(string)
  10184. prescribing_number := dataBody["prescribing_number"].(float64)
  10185. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10186. remark := dataBody["remark"].(string)
  10187. single_dose := dataBody["single_dose"].(float64)
  10188. single_dose_unit := dataBody["single_dose_unit"].(string)
  10189. patient_id := int64(dataBody["patient_id"].(float64))
  10190. day_count := int64(dataBody["day_count"].(float64))
  10191. groupNo := int64(dataBody["group_no"].(float64))
  10192. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10193. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10194. if groupNo <= 0 {
  10195. group := service.GetMaxAdviceGroupID(org_id)
  10196. groupNo = group + 1
  10197. }
  10198. var template_id = ""
  10199. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10200. template_id = "M" + adviceLastId
  10201. advice := models.DoctorAdvice{
  10202. UserOrgId: org_id,
  10203. PatientId: patient_id,
  10204. AdviceType: adviceType,
  10205. AdviceDate: AdviceDate,
  10206. StartTime: StartTime,
  10207. AdviceName: advice_name,
  10208. AdviceDesc: advice_desc,
  10209. ReminderDate: 0,
  10210. SingleDose: single_dose,
  10211. SingleDoseUnit: single_dose_unit,
  10212. DrugSpec: 0,
  10213. DrugSpecUnit: "",
  10214. PrescribingNumber: prescribing_number,
  10215. PrescribingNumberUnit: prescribing_number_unit,
  10216. DeliveryWay: delivery_way,
  10217. ExecutionFrequency: execution_frequency,
  10218. AdviceDoctor: advice_doctor,
  10219. Status: 1,
  10220. CreatedTime: time.Now().Unix(),
  10221. UpdatedTime: 0,
  10222. AdviceAffirm: "",
  10223. Remark: remark,
  10224. StopTime: 0,
  10225. StopReason: "",
  10226. StopDoctor: 0,
  10227. StopState: 0,
  10228. ParentId: 0,
  10229. ExecutionTime: 0,
  10230. ExecutionStaff: 0,
  10231. ExecutionState: 0,
  10232. Checker: 0,
  10233. RecordDate: RecordDate,
  10234. DialysisOrderId: 0,
  10235. CheckTime: 0,
  10236. CheckState: 0,
  10237. AdviceId: 0,
  10238. RemindType: 0,
  10239. FrequencyType: frequency_type,
  10240. DayCount: day_count,
  10241. WeekDay: frequency_week,
  10242. ChildDoctorAdvice: nil,
  10243. TemplateId: template_id,
  10244. Modifier: 0,
  10245. IsCheck: 0,
  10246. Way: 0,
  10247. DrugId: 0,
  10248. DrugNameId: 0,
  10249. IsMedicine: 0,
  10250. PushStartTime: 0,
  10251. IsSettle: 0,
  10252. IsPrescription: 0,
  10253. GroupNo: groupNo,
  10254. }
  10255. service.CreateMobileAdivce(advice)
  10256. c.ServeSuccessJSON(map[string]interface{}{
  10257. "msg": "保存成功!",
  10258. })
  10259. }
  10260. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10261. patient_id, _ := c.GetInt64("patient_id")
  10262. org_id := c.GetMobileAdminUserInfo().Org.Id
  10263. app_id := c.GetMobileAdminUserInfo().App.Id
  10264. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10265. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10266. c.ServeSuccessJSON(map[string]interface{}{
  10267. "adviceList": adviceList,
  10268. "adminRoles": adminRoles,
  10269. })
  10270. }
  10271. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10272. org_id := c.GetMobileAdminUserInfo().Org.Id
  10273. dataBody := make(map[string]interface{}, 0)
  10274. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10275. if err != nil {
  10276. utils.ErrorLog(err.Error())
  10277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10278. return
  10279. }
  10280. timeLayout := "2006-01-02"
  10281. loc, _ := time.LoadLocation("Local")
  10282. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10283. utils.ErrorLog("start_time")
  10284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10285. return
  10286. }
  10287. startTime2, _ := dataBody["start_time"].(string)
  10288. time_arr := strings.Split(startTime2, " ")
  10289. if len(time_arr) > 0 {
  10290. startTime2 = time_arr[0]
  10291. }
  10292. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10293. utils.ErrorLog("advice_date")
  10294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10295. return
  10296. }
  10297. advice_date, _ := dataBody["advice_date"].(string)
  10298. var advicedateunix int64
  10299. if len(advice_date) > 0 {
  10300. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10301. if err != nil {
  10302. fmt.Println(err)
  10303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10304. return
  10305. }
  10306. advicedateunix = theTime.Unix()
  10307. }
  10308. adviceDate := startTime2
  10309. if len(adviceDate) == 0 {
  10310. utils.ErrorLog("len(adviceDate) == 0")
  10311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10312. return
  10313. }
  10314. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10315. if err != nil {
  10316. utils.ErrorLog(err.Error())
  10317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10318. return
  10319. }
  10320. AdviceDate := advicedateunix
  10321. RecordDate := advicedateunix
  10322. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10323. utils.ErrorLog("start_time")
  10324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10325. return
  10326. }
  10327. startTime, _ := dataBody["start_time"].(string)
  10328. if len(startTime) == 0 {
  10329. utils.ErrorLog("len(start_time) == 0")
  10330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10331. return
  10332. }
  10333. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10334. if err != nil {
  10335. utils.ErrorLog(err.Error())
  10336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10337. return
  10338. }
  10339. StartTime := theTime.Unix()
  10340. advice_name, _ := dataBody["advice_name"].(string)
  10341. advice_desc, _ := dataBody["advice_desc"].(string)
  10342. delivery_way, _ := dataBody["delivery_way"].(string)
  10343. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10344. prescribing_number := dataBody["prescribing_number"].(float64)
  10345. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10346. remark := dataBody["remark"].(string)
  10347. single_dose := dataBody["single_dose"].(float64)
  10348. single_dose_unit := dataBody["single_dose_unit"].(string)
  10349. patient_id := int64(dataBody["patient_id"].(float64))
  10350. groupNo := int64(dataBody["group_no"].(float64))
  10351. parent_id := int64(dataBody["parent_id"].(float64))
  10352. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10353. advice := models.XtDoctorAdviceOne{
  10354. UserOrgId: org_id,
  10355. PatientId: patient_id,
  10356. AdviceType: 1,
  10357. AdviceDate: AdviceDate,
  10358. StartTime: StartTime,
  10359. AdviceName: advice_name,
  10360. AdviceDesc: advice_desc,
  10361. ReminderDate: 0,
  10362. SingleDose: single_dose,
  10363. SingleDoseUnit: single_dose_unit,
  10364. PrescribingNumber: prescribing_number,
  10365. PrescribingNumberUnit: prescribing_number_unit,
  10366. DeliveryWay: delivery_way,
  10367. ExecutionFrequency: execution_frequency,
  10368. AdviceDoctor: advice_doctor,
  10369. Status: 1,
  10370. CreatedTime: time.Now().Unix(),
  10371. UpdatedTime: time.Now().Unix(),
  10372. AdviceAffirm: "",
  10373. Remark: remark,
  10374. StopTime: 0,
  10375. StopReason: "",
  10376. StopDoctor: 0,
  10377. StopState: 0,
  10378. ParentId: parent_id,
  10379. ExecutionTime: 0,
  10380. ExecutionStaff: 0,
  10381. ExecutionState: 0,
  10382. Checker: 0,
  10383. RecordDate: RecordDate,
  10384. DialysisOrderId: 0,
  10385. CheckTime: 0,
  10386. CheckState: 0,
  10387. DrugSpec: 0,
  10388. DrugSpecUnit: "",
  10389. Groupno: groupNo,
  10390. RemindType: 0,
  10391. FrequencyType: 0,
  10392. DayCount: 0,
  10393. WeekDay: "",
  10394. TemplateId: "",
  10395. Modifier: 0,
  10396. }
  10397. service.CreateMobileAdivceOne(advice)
  10398. c.ServeSuccessJSON(map[string]interface{}{
  10399. "msg": "保存成功!",
  10400. })
  10401. }
  10402. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10403. id, _ := c.GetInt64("id")
  10404. service.DeleteSelfAdviceSubAdvice(id)
  10405. c.ServeSuccessJSON(map[string]interface{}{
  10406. "msg": "保存成功!",
  10407. })
  10408. }
  10409. func (c *DialysisAPIController) GetEditAdviceAction() {
  10410. id, _ := c.GetInt64("id")
  10411. org_id := c.GetMobileAdminUserInfo().Org.Id
  10412. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10413. drugList, _ := service.GetAllDrugList(org_id)
  10414. c.ServeSuccessJSON(map[string]interface{}{
  10415. "advice": advice,
  10416. "drugList": drugList,
  10417. })
  10418. }
  10419. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10420. dataBody := make(map[string]interface{}, 0)
  10421. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10422. if err != nil {
  10423. utils.ErrorLog(err.Error())
  10424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10425. return
  10426. }
  10427. timeLayout := "2006-01-02"
  10428. loc, _ := time.LoadLocation("Local")
  10429. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10430. utils.ErrorLog("start_time")
  10431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10432. return
  10433. }
  10434. startTime2, _ := dataBody["start_time"].(string)
  10435. time_arr := strings.Split(startTime2, " ")
  10436. if len(time_arr) > 0 {
  10437. startTime2 = time_arr[0]
  10438. }
  10439. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10440. utils.ErrorLog("advice_date")
  10441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10442. return
  10443. }
  10444. advice_date, _ := dataBody["advice_date"].(string)
  10445. var advicedateunix int64
  10446. if len(advice_date) > 0 {
  10447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10448. if err != nil {
  10449. fmt.Println(err)
  10450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10451. return
  10452. }
  10453. advicedateunix = theTime.Unix()
  10454. }
  10455. adviceDate := startTime2
  10456. if len(adviceDate) == 0 {
  10457. utils.ErrorLog("len(adviceDate) == 0")
  10458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10459. return
  10460. }
  10461. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10462. if err != nil {
  10463. utils.ErrorLog(err.Error())
  10464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10465. return
  10466. }
  10467. AdviceDate := advicedateunix
  10468. RecordDate := advicedateunix
  10469. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10470. utils.ErrorLog("start_time")
  10471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10472. return
  10473. }
  10474. startTime, _ := dataBody["start_time"].(string)
  10475. if len(startTime) == 0 {
  10476. utils.ErrorLog("len(start_time) == 0")
  10477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10478. return
  10479. }
  10480. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10481. if err != nil {
  10482. utils.ErrorLog(err.Error())
  10483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10484. return
  10485. }
  10486. StartTime := theTime.Unix()
  10487. advice_name, _ := dataBody["advice_name"].(string)
  10488. advice_desc, _ := dataBody["advice_desc"].(string)
  10489. delivery_way, _ := dataBody["delivery_way"].(string)
  10490. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10491. prescribing_number := dataBody["prescribing_number"].(float64)
  10492. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10493. remark := dataBody["remark"].(string)
  10494. single_dose := dataBody["single_dose"].(float64)
  10495. single_dose_unit := dataBody["single_dose_unit"].(string)
  10496. id := int64(dataBody["id"].(float64))
  10497. frequency_type := int64(dataBody["frequency_type"].(float64))
  10498. frequency_week, _ := dataBody["frequency_week"].(string)
  10499. day_count := int64(dataBody["day_count"].(float64))
  10500. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10501. advice := models.XtDoctorAdviceOne{
  10502. AdviceDate: AdviceDate,
  10503. StartTime: StartTime,
  10504. AdviceName: advice_name,
  10505. AdviceDesc: advice_desc,
  10506. SingleDose: single_dose,
  10507. SingleDoseUnit: single_dose_unit,
  10508. PrescribingNumber: prescribing_number,
  10509. PrescribingNumberUnit: prescribing_number_unit,
  10510. DeliveryWay: delivery_way,
  10511. ExecutionFrequency: execution_frequency,
  10512. AdviceDoctor: advice_doctor,
  10513. Remark: remark,
  10514. RecordDate: RecordDate,
  10515. FrequencyType: frequency_type,
  10516. DayCount: day_count,
  10517. WeekDay: frequency_week,
  10518. }
  10519. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10520. c.ServeSuccessJSON(map[string]interface{}{
  10521. "advice": advice,
  10522. })
  10523. }
  10524. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10525. dataBody := make(map[string]interface{}, 0)
  10526. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10527. if err != nil {
  10528. utils.ErrorLog(err.Error())
  10529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10530. return
  10531. }
  10532. timeLayout := "2006-01-02"
  10533. loc, _ := time.LoadLocation("Local")
  10534. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10535. utils.ErrorLog("start_time")
  10536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10537. return
  10538. }
  10539. startTime2, _ := dataBody["start_time"].(string)
  10540. time_arr := strings.Split(startTime2, " ")
  10541. if len(time_arr) > 0 {
  10542. startTime2 = time_arr[0]
  10543. }
  10544. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10545. utils.ErrorLog("advice_date")
  10546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10547. return
  10548. }
  10549. advice_date, _ := dataBody["advice_date"].(string)
  10550. var advicedateunix int64
  10551. if len(advice_date) > 0 {
  10552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10553. if err != nil {
  10554. fmt.Println(err)
  10555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10556. return
  10557. }
  10558. advicedateunix = theTime.Unix()
  10559. }
  10560. adviceDate := startTime2
  10561. if len(adviceDate) == 0 {
  10562. utils.ErrorLog("len(adviceDate) == 0")
  10563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10564. return
  10565. }
  10566. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10567. if err != nil {
  10568. utils.ErrorLog(err.Error())
  10569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10570. return
  10571. }
  10572. AdviceDate := advicedateunix
  10573. RecordDate := advicedateunix
  10574. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10575. utils.ErrorLog("start_time")
  10576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10577. return
  10578. }
  10579. startTime, _ := dataBody["start_time"].(string)
  10580. if len(startTime) == 0 {
  10581. utils.ErrorLog("len(start_time) == 0")
  10582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10583. return
  10584. }
  10585. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10586. if err != nil {
  10587. utils.ErrorLog(err.Error())
  10588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10589. return
  10590. }
  10591. StartTime := theTime.Unix()
  10592. advice_name, _ := dataBody["advice_name"].(string)
  10593. advice_desc, _ := dataBody["advice_desc"].(string)
  10594. delivery_way, _ := dataBody["delivery_way"].(string)
  10595. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10596. prescribing_number := dataBody["prescribing_number"].(float64)
  10597. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10598. remark := dataBody["remark"].(string)
  10599. single_dose := dataBody["single_dose"].(float64)
  10600. single_dose_unit := dataBody["single_dose_unit"].(string)
  10601. id := int64(dataBody["id"].(float64))
  10602. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10603. advice := models.XtDoctorAdviceOne{
  10604. AdviceDate: AdviceDate,
  10605. StartTime: StartTime,
  10606. AdviceName: advice_name,
  10607. AdviceDesc: advice_desc,
  10608. SingleDose: single_dose,
  10609. SingleDoseUnit: single_dose_unit,
  10610. PrescribingNumber: prescribing_number,
  10611. PrescribingNumberUnit: prescribing_number_unit,
  10612. DeliveryWay: delivery_way,
  10613. ExecutionFrequency: execution_frequency,
  10614. AdviceDoctor: advice_doctor,
  10615. Remark: remark,
  10616. RecordDate: RecordDate,
  10617. }
  10618. service.UpdateMobileDoctorAdviceById(id, advice)
  10619. c.ServeSuccessJSON(map[string]interface{}{
  10620. "advice": advice,
  10621. })
  10622. }
  10623. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10624. dataBody := make(map[string]interface{}, 0)
  10625. timeLayout := "2006-01-02"
  10626. loc, _ := time.LoadLocation("Local")
  10627. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10628. if err != nil {
  10629. utils.ErrorLog(err.Error())
  10630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10631. return
  10632. }
  10633. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10634. utils.ErrorLog("start_time")
  10635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10636. return
  10637. }
  10638. startTime2, _ := dataBody["start_time"].(string)
  10639. time_arr := strings.Split(startTime2, " ")
  10640. if len(time_arr) > 0 {
  10641. startTime2 = time_arr[0]
  10642. }
  10643. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10644. utils.ErrorLog("advice_date")
  10645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10646. return
  10647. }
  10648. advice_date, _ := dataBody["advice_date"].(string)
  10649. var advicedateunix int64
  10650. if len(advice_date) > 0 {
  10651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10652. if err != nil {
  10653. fmt.Println(err)
  10654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10655. return
  10656. }
  10657. advicedateunix = theTime.Unix()
  10658. }
  10659. adviceDate := startTime2
  10660. if len(adviceDate) == 0 {
  10661. utils.ErrorLog("len(adviceDate) == 0")
  10662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10663. return
  10664. }
  10665. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10666. if err != nil {
  10667. utils.ErrorLog(err.Error())
  10668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10669. return
  10670. }
  10671. RecordDate := advicedateunix
  10672. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10673. utils.ErrorLog("start_time")
  10674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10675. return
  10676. }
  10677. startTime, _ := dataBody["start_time"].(string)
  10678. if len(startTime) == 0 {
  10679. utils.ErrorLog("len(start_time) == 0")
  10680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10681. return
  10682. }
  10683. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10684. if err != nil {
  10685. utils.ErrorLog(err.Error())
  10686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10687. return
  10688. }
  10689. StartTime := theTime.Unix()
  10690. patient_id := int64(dataBody["patient_id"].(float64))
  10691. group_no := int64(dataBody["group_no"].(float64))
  10692. org_id := c.GetMobileAdminUserInfo().Org.Id
  10693. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10694. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10695. utils.ErrorLog("advices")
  10696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10697. return
  10698. }
  10699. adviceNames := dataBody["advices"].([]interface{})
  10700. var advices []*models.GroupAdvice
  10701. for _, adviceNameMap := range adviceNames {
  10702. var advice models.GroupAdvice
  10703. adviceNameM := adviceNameMap.(map[string]interface{})
  10704. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10705. utils.ErrorLog("advice_name")
  10706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10707. return
  10708. }
  10709. adviceName, _ := adviceNameM["advice_name"].(string)
  10710. if len(adviceName) == 0 {
  10711. utils.ErrorLog("len(advice_name) == 0")
  10712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10713. return
  10714. }
  10715. advice.AdviceName = adviceName
  10716. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10717. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10718. advice.DrugSpec = drugSpec
  10719. }
  10720. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10721. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10722. advice.AdviceDesc = adviceDesc
  10723. }
  10724. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10725. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10726. advice.DrugSpecUnit = drugSpecUnit
  10727. }
  10728. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10729. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10730. advice.SingleDose = singleDose
  10731. }
  10732. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10733. singleDose := adviceNameM["single_dose"].(float64)
  10734. advice.SingleDose = singleDose
  10735. }
  10736. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10737. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10738. advice.SingleDoseUnit = singleDoseUnit
  10739. }
  10740. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10741. tmp := adviceNameM["single_dose_unit"].(float64)
  10742. singleDoseUnit := service.TypeConversion(tmp)
  10743. advice.SingleDoseUnit = singleDoseUnit
  10744. }
  10745. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10746. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10747. advice.PrescribingNumber = prescribingNumber
  10748. }
  10749. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10750. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10751. advice.PrescribingNumber = prescribingNumber
  10752. }
  10753. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10754. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10755. advice.PrescribingNumberUnit = prescribingNumberUnit
  10756. }
  10757. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10758. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10759. advice.DeliveryWay = deliveryWay
  10760. }
  10761. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10762. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10763. advice.ExecutionFrequency = executionFrequency
  10764. }
  10765. remark, _ := adviceNameM["remark"].(string)
  10766. advice.Remark = remark
  10767. advice.AdviceType = 1
  10768. advice.StartTime = StartTime
  10769. advice.RecordDate = RecordDate
  10770. advice.PatientId = patient_id
  10771. advice.UserOrgId = org_id
  10772. advice.AdviceDoctor = advice_doctor
  10773. advices = append(advices, &advice)
  10774. }
  10775. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10776. c.ServeSuccessJSON(map[string]interface{}{
  10777. "advice": newAdvices,
  10778. })
  10779. }
  10780. func (c *DialysisAPIController) StopLongAdvice() {
  10781. stop_time := c.GetString("execution_time")
  10782. id, _ := c.GetInt64("id")
  10783. if len(stop_time) <= 0 {
  10784. utils.ErrorLog("stop_time")
  10785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10786. return
  10787. }
  10788. timeLayout2 := "2006-01-02 15:04:05"
  10789. loc, _ := time.LoadLocation("Local")
  10790. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10791. if errs != nil {
  10792. utils.ErrorLog(errs.Error())
  10793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10794. return
  10795. }
  10796. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10797. c.ServeSuccessJSON(map[string]interface{}{
  10798. "advice": advice,
  10799. })
  10800. }