dialysis_api_controller.go 436KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225
  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. if id <= 0 {
  1323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1324. return
  1325. }
  1326. adminUserInfo := c.GetMobileAdminUserInfo()
  1327. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1328. if patient.ID == 0 {
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1330. return
  1331. }
  1332. if len(recordDateStr) == 0 {
  1333. recordDateStr = time.Now().Format("2006-01-02")
  1334. }
  1335. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1336. fmt.Println("parseDateErr", parseDateErr)
  1337. if parseDateErr != nil {
  1338. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1340. return
  1341. }
  1342. //now := time.Now()
  1343. //year, month, day := now.Date()
  1344. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1345. //todayTimeStamp := today_time.Unix()
  1346. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1347. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1348. UserOrgId: adminUserInfo.Org.Id,
  1349. PatientId: id,
  1350. AssessmentDate: recordDate.Unix(),
  1351. Temperature: temperature,
  1352. PulseFrequency: pulse_frequency,
  1353. BreathingRate: breathing_rate,
  1354. SystolicBloodPressure: systolic_blood_pressure,
  1355. DiastolicBloodPressure: diastolic_blood_pressure,
  1356. ActualUltrafiltration: actual_ultrafiltration,
  1357. ActualDisplacement: actual_displacement,
  1358. ActualTreatmentHour: actualtreatHour,
  1359. ActualTreatmentMinute: actualtreatmin,
  1360. WeightAfter: weightAfter,
  1361. AdditionalWeight: additionalWeight,
  1362. WeightLoss: weightReduce,
  1363. Cruor: cruor,
  1364. SymptomAfterDialysis: symptomsAfterDialysi,
  1365. InternalFistula: internalFistula,
  1366. Catheter: catheter,
  1367. Complication: complications,
  1368. DialysisIntakes: dialysateVolume,
  1369. CreatedTime: time.Now().Unix(),
  1370. UpdatedTime: time.Now().Unix(),
  1371. Status: 1,
  1372. Remark: remark,
  1373. BloodAccessPartId: blood_access_part_id,
  1374. BloodAccessPartOperaId: blood_access_part_opera_id,
  1375. DialysisIntakesUnit: dialysis_intakes_unit,
  1376. PuncturePointOozingBlood: puncturePointOozingBlood,
  1377. PuncturePointHaematoma: puncturePointHaematoma,
  1378. InternalFistulaTremorAc: internalFistulaTremorAc,
  1379. PatientGose: patientGose,
  1380. InpatientDepartment: inpatientDepartment,
  1381. ObservationContent: observationContent,
  1382. ObservationContentOther: observationContentOther,
  1383. DialysisProcess: dialysis_process,
  1384. InAdvanceMinute: in_advance_minute,
  1385. InAdvanceReason: in_advance_reason,
  1386. HemostasisMinute: hemostasis_minute,
  1387. HemostasisOpera: hemostasis_opera,
  1388. TremorNoise: tremor_noise,
  1389. DisequilibriumSyndrome: disequilibrium_syndrome,
  1390. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1391. ArterialTube: arterial_tube,
  1392. IntravenousTube: intravenous_tube,
  1393. Dialyzer: dialyzer,
  1394. InAdvanceReasonOther: in_advance_reason_other,
  1395. IsEat: is_eat,
  1396. CvcA: cvc_a,
  1397. CvcV: cvc_v,
  1398. Channel: channels,
  1399. ReturnBlood: return_blood,
  1400. RehydrationVolume: rehydration_volume,
  1401. DialysisDuring: dialysis_during,
  1402. StrokeVolume: stroke_volume,
  1403. BloodFlow: blood_flow,
  1404. SealingFluidDispose: sealing_fluid_dispose,
  1405. SealingFluidSpecial: sealing_fluid_special,
  1406. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1407. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1408. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1409. SettingPressure: setting_pressure,
  1410. DiastolicPressure: diastolic_pressure,
  1411. OtherComplication: other_complication,
  1412. Ktv: ktv,
  1413. Urr: urr,
  1414. Hypopiesia: hypopiesia,
  1415. Hypertenison: hypertenison,
  1416. Lapse: lapse,
  1417. LeaveOfficeMethod: leave_office_method,
  1418. Consciousness: consciousness,
  1419. Fallrisk: fallrisk,
  1420. MachineRun: machine_run,
  1421. AfterUrea: after_urea,
  1422. PipCoagulation: pip_coagulation,
  1423. AccumulatedBloodVolume: accumulated_blood_volume,
  1424. TransfusionVolume: transfusion_volume,
  1425. LastAfterWeight: last_after_weight,
  1426. DisplaceLiquiValue: displace_liqui_value,
  1427. }
  1428. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1429. // 查询信息规挡的设置天数
  1430. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1431. if infor.ID > 0 && infor.WeekDay > 0 {
  1432. var cha_time int64
  1433. timeNowStr := time.Now().Format("2006-01-02")
  1434. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1435. //今日的日期减去设置的日期
  1436. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1437. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1438. if cha_time >= recordDate.Unix() {
  1439. //查询审核是否允许
  1440. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1441. //申请状态不允许的情况 拒绝修改
  1442. if infor.ApplicationStatus != 1 {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1444. return
  1445. }
  1446. }
  1447. }
  1448. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1449. if assessmentAfter.ID == 0 { //新增
  1450. if appRole.UserType == 2 || appRole.UserType == 1 {
  1451. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1452. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1453. } else {
  1454. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1455. }
  1456. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1457. if assessmentAfterDislysis.UserOrgId != 10340 {
  1458. if assessmentAfterDislysis.WeightAfter == 0 {
  1459. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1460. }
  1461. }
  1462. if adminUserInfo.Org.Id == 10693 {
  1463. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1464. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1465. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1466. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1467. }
  1468. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1471. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1472. }
  1473. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.PulseFrequency == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1481. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1482. }
  1483. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1486. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1487. }
  1488. }
  1489. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1490. //记录日志
  1491. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1492. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1493. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1494. PatientId: assessmentAfterDislysis.PatientId,
  1495. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1496. Status: 1,
  1497. ErrLog: string(byterequest),
  1498. AdminUserId: adminUserInfo.AdminUser.Id,
  1499. Ctime: 0,
  1500. Mtime: 0,
  1501. Source: "手机端保存透后评估",
  1502. }
  1503. service.CreateAfterDialysisLog(afterDialysisLog)
  1504. finish := models.XtDialysisFinish{
  1505. IsFinish: 1,
  1506. UserOrgId: adminUserInfo.Org.Id,
  1507. Status: 1,
  1508. Ctime: time.Now().Unix(),
  1509. Mtime: 0,
  1510. Module: 9,
  1511. RecordDate: recordDate.Unix(),
  1512. Sourse: 1,
  1513. PatientId: id,
  1514. }
  1515. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1516. if dialysisFinish.ID == 0 {
  1517. service.CreateDialysisFinish(finish)
  1518. }
  1519. redis := service.RedisClient()
  1520. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1521. redis.Set(keyTwo, "", time.Second)
  1522. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1523. //清空key 值
  1524. redis.Set(key, "", time.Second)
  1525. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1526. redis.Set(keyOne, "", time.Second)
  1527. defer redis.Close()
  1528. if err == nil {
  1529. c.ServeSuccessJSON(map[string]interface{}{
  1530. "assessmentAfterDislysis": assessmentAfterDislysis,
  1531. })
  1532. }
  1533. return
  1534. } else { //修改
  1535. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1536. if infor.ID > 0 && infor.WeekDay > 0 {
  1537. var cha_time int64
  1538. timeNowStr := time.Now().Format("2006-01-02")
  1539. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1540. //今日的日期减去设置的日期
  1541. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1542. if cha_time >= recordDate.Unix() {
  1543. //查询审核是否允许
  1544. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1545. //申请状态不允许的情况 拒绝修改
  1546. if infor.ApplicationStatus != 1 {
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1548. return
  1549. }
  1550. }
  1551. }
  1552. if appRole.UserType == 2 || appRole.UserType == 1 {
  1553. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1554. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1555. } else {
  1556. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1557. if assessmentAfterDislysis.Creater == 0 {
  1558. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1559. }
  1560. }
  1561. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1562. assessmentAfterDislysis.ID = assessmentAfter.ID
  1563. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1564. if assessmentAfterDislysis.UserOrgId != 10340 {
  1565. if assessmentAfterDislysis.WeightAfter == 0 {
  1566. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1567. }
  1568. }
  1569. if adminUserInfo.Org.Id == 10693 {
  1570. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1571. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1572. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1573. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1574. }
  1575. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1578. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1579. }
  1580. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.PulseFrequency == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1588. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1589. }
  1590. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1593. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1594. }
  1595. }
  1596. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1597. //记录日志
  1598. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1599. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1600. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1601. PatientId: assessmentAfterDislysis.PatientId,
  1602. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1603. Status: 1,
  1604. ErrLog: string(byterequest),
  1605. AdminUserId: adminUserInfo.AdminUser.Id,
  1606. Ctime: time.Now().Unix(),
  1607. Mtime: 0,
  1608. Source: "手机端修改保存透后评估",
  1609. }
  1610. service.CreateAfterDialysisLog(afterDialysisLog)
  1611. redis := service.RedisClient()
  1612. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1613. redis.Set(keyTwo, "", time.Second)
  1614. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1615. //清空key 值
  1616. redis.Set(key, "", time.Second)
  1617. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1618. redis.Set(keyOne, "", time.Second)
  1619. if err == nil {
  1620. c.ServeSuccessJSON(map[string]interface{}{
  1621. "assessmentAfterDislysis": assessmentAfterDislysis,
  1622. })
  1623. return
  1624. }
  1625. }
  1626. return
  1627. }
  1628. func (c *DialysisAPIController) PostDialysisPrescription() {
  1629. id, _ := c.GetInt64("patient", 0)
  1630. recordDateStr := c.GetString("record_date")
  1631. if id <= 0 {
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1633. return
  1634. }
  1635. adminUserInfo := c.GetMobileAdminUserInfo()
  1636. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1637. if patient.ID == 0 {
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1639. return
  1640. }
  1641. if len(recordDateStr) == 0 {
  1642. recordDateStr = time.Now().Format("2006-01-02")
  1643. }
  1644. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1645. if parseDateErr != nil {
  1646. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1648. return
  1649. }
  1650. mode_id, _ := c.GetInt64("mode_id", 0)
  1651. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1652. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1653. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1654. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1655. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1656. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1657. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1658. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1659. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1660. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1661. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1662. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1663. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1664. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1665. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1666. kalium, _ := c.GetFloat("kalium", 0)
  1667. sodium, _ := c.GetFloat("sodium", 0)
  1668. calcium, _ := c.GetFloat("calcium", 0)
  1669. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1670. glucose, _ := c.GetFloat("glucose", 0)
  1671. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1672. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1673. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1674. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1675. conductivity, _ := c.GetFloat("conductivity", 0)
  1676. remark := c.GetString("remark")
  1677. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1678. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1679. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1680. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1681. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1682. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1683. special_medicine_other := c.GetString("special_medicine_other")
  1684. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1685. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1686. blood_access, _ := c.GetInt64("blood_access", 0)
  1687. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1688. body_fluid_other := c.GetString("body_fluid_other")
  1689. niprocart, _ := c.GetInt64("niprocart", 0)
  1690. jms, _ := c.GetInt64("jms", 0)
  1691. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1692. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1693. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1694. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1695. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1696. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1697. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1698. injector, _ := c.GetInt64("injector", 0)
  1699. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1700. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1701. safe_package, _ := c.GetInt64("package", 0)
  1702. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1703. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1704. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1705. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1706. blood := c.GetString("blood")
  1707. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1708. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1709. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1710. displace_speed := c.GetString("displace_speed")
  1711. illness, _ := c.GetInt64("illness")
  1712. amylaceum := c.GetString("amylaceum")
  1713. single_time := c.GetString("single_time")
  1714. single_water := c.GetString("single_water")
  1715. replacement_flow := c.GetString("replacement_flow")
  1716. plasma_separator := c.GetString("plasma_separator")
  1717. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1718. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1719. oxygen_flow := c.GetString("oxygen_flow")
  1720. oxygen_time := c.GetString("oxygen_time")
  1721. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1722. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1723. puncture_needle := c.GetString("puncture_needle")
  1724. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1725. epo := c.GetString("epo")
  1726. epo_count, _ := c.GetFloat("epo_count", 0)
  1727. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1728. admin_user_id, _ := c.GetInt64("admin_user_id")
  1729. is_water := c.GetString("is_water")
  1730. var is_war int64
  1731. if is_water == "是" {
  1732. is_war = 1
  1733. }
  1734. if is_water == "否" {
  1735. is_war = 2
  1736. }
  1737. if is_water == "请选择" {
  1738. is_war = 0
  1739. }
  1740. drhy_water := c.GetString("drhy_water")
  1741. dry_water_hour := c.GetString("dry_water_hour")
  1742. water_machine := c.GetString("water_machine")
  1743. add_amount, _ := c.GetFloat("add_amount")
  1744. reduce_amount, _ := c.GetFloat("reduce_amount")
  1745. dialysis_remark := c.GetString("dialysis_remark")
  1746. prescribing_number, _ := c.GetFloat("prescribing_number")
  1747. prescription_sodium := c.GetString("prescription_sodium")
  1748. start_sodium := c.GetString("start_sodium")
  1749. sodium_curve := c.GetString("sodium_curve")
  1750. treatment_remark := c.GetString("treatment_remark")
  1751. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1752. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1753. prescription_water, _ := c.GetFloat("prescription_water")
  1754. dialysis_strainer := c.GetString("dialysis_strainer")
  1755. chaptalization := c.GetString("chaptalization")
  1756. washing_time := c.GetString("washing_time")
  1757. warsh_count := c.GetString("warsh_count")
  1758. blood_access_part_id := c.GetString("blood_access_part_id")
  1759. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1760. dialyzate := c.GetString("dialyzate")
  1761. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1762. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1763. //
  1764. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1765. // if appRole.UserType == 3 {
  1766. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1767. // if getPermissionErr != nil {
  1768. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1769. // return
  1770. // } else if headNursePermission == nil {
  1771. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1772. // return
  1773. // }
  1774. // }
  1775. //}
  1776. // 查询信息规挡的设置天数
  1777. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1778. if infor.ID > 0 && infor.WeekDay > 0 {
  1779. var cha_time int64
  1780. timeNowStr := time.Now().Format("2006-01-02")
  1781. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1782. //今日的日期减去设置的日期
  1783. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1784. if cha_time >= recordDate.Unix() {
  1785. //查询审核是否允许
  1786. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1787. //申请状态不允许的情况 拒绝修改
  1788. if infor.ApplicationStatus != 1 {
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1790. return
  1791. }
  1792. }
  1793. }
  1794. if mode_id > 0 {
  1795. var str string
  1796. //查找该机构用的是什么透析器
  1797. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1798. if filedConfig.ID > 0 {
  1799. str = dialyzerPerfusionApparatus
  1800. } else {
  1801. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1802. }
  1803. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1804. }
  1805. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1806. var dialysis_dialyszers_id int64
  1807. var dialysis_strainer_id int64
  1808. var dialysis_irrigation_id int64
  1809. if len(goodList) > 0 {
  1810. for _, item := range goodList {
  1811. if item.SpecificationName == dialysis_dialyszers {
  1812. dialysis_dialyszers_id = item.ID
  1813. }
  1814. if item.SpecificationName == dialysis_irrigation {
  1815. dialysis_irrigation_id = item.ID
  1816. }
  1817. if item.SpecificationName == dialysis_strainer {
  1818. dialysis_strainer_id = item.ID
  1819. }
  1820. }
  1821. }
  1822. //TODO 需要根据角色去判断
  1823. prescription := models.DialysisPrescription{
  1824. UserOrgId: adminUserInfo.Org.Id,
  1825. PatientId: id,
  1826. RecordDate: recordDate.Unix(),
  1827. ModeId: mode_id,
  1828. DialysisDuration: dialysis_duration,
  1829. Dialyzer: dialyzer,
  1830. PerfusionApparatus: perfusion_apparatus,
  1831. BloodFlowVolume: blood_flow_volume,
  1832. DewaterAmount: dewater_amount,
  1833. DisplaceLiqui: displace_liqui,
  1834. ReplacementWay: replacement_way,
  1835. Anticoagulant: anticoagulant,
  1836. AnticoagulantShouji: anticoagulant_shouji,
  1837. AnticoagulantWeichi: anticoagulant_weichi,
  1838. AnticoagulantZongliang: anticoagulant_zongliang,
  1839. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1840. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1841. Kalium: kalium,
  1842. Sodium: sodium,
  1843. Calcium: calcium,
  1844. Bicarbonate: bicarbonate,
  1845. Glucose: glucose,
  1846. // DryWeight: dry_weight,
  1847. DialysateFlow: dialysate_flow,
  1848. DialysateTemperature: dialysate_temperature,
  1849. // PrescriptionDoctor: prescription_doctor,
  1850. ReplacementTotal: replacement_total,
  1851. Conductivity: conductivity,
  1852. Remark: remark,
  1853. Status: 1,
  1854. CreatedTime: time.Now().Unix(),
  1855. UpdatedTime: time.Now().Unix(),
  1856. DialysisDurationMinute: dialysisDurationMinute,
  1857. DialysisDurationHour: dialysisDurationHour,
  1858. TargetUltrafiltration: targetUltrafiltration,
  1859. DialysateFormulation: dialysateFormulation,
  1860. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1861. BodyFluid: body_fluid,
  1862. SpecialMedicine: special_medicine,
  1863. SpecialMedicineOther: special_medicine_other,
  1864. DisplaceLiquiPart: displace_liqui_part,
  1865. DisplaceLiquiValue: displace_liqui_value,
  1866. BloodAccess: blood_access,
  1867. Ultrafiltration: ultrafiltration,
  1868. BodyFluidOther: body_fluid_other,
  1869. Niprocart: niprocart,
  1870. Jms: jms,
  1871. FistulaNeedleSet: fistula_needle_set,
  1872. FistulaNeedleSet16: fistula_needle_set_16,
  1873. Hemoperfusion: hemoperfusion,
  1874. DialyserSterilised: dialyser_sterilised,
  1875. Filtryzer: filtryzer,
  1876. Dialyzers: dialyzers,
  1877. Injector: injector,
  1878. Bloodlines: bloodlines,
  1879. TubingHemodialysis: tubing_hemodialysis,
  1880. Package: safe_package,
  1881. ALiquid: a_liquid,
  1882. TargetKtv: target_ktv,
  1883. PreImpulse: pre_impulse,
  1884. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1885. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1886. Blood: blood,
  1887. DialysisDialyszers: dialysis_dialyszers,
  1888. DialysisIrrigation: dialysis_irrigation,
  1889. AntioxidantCommodityName: antioxidant_commodity_name,
  1890. DisplaceSpeed: displace_speed,
  1891. Illness: illness,
  1892. Amylaceum: amylaceum,
  1893. SingleTime: single_time,
  1894. SingleWater: single_water,
  1895. ReplacementFlow: replacement_flow,
  1896. PlasmaSeparator: plasma_separator,
  1897. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1898. OxygenUptake: oxygen_uptake,
  1899. OxygenFlow: oxygen_flow,
  1900. OxygenTime: oxygen_time,
  1901. HemodialysisPipelines: hemodialysis_pipelines,
  1902. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1903. PunctureNeedle: puncture_needle,
  1904. PunctureNeedleCount: puncture_needle_count,
  1905. Epo: epo,
  1906. EpoCount: epo_count,
  1907. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1908. AdminUserId: admin_user_id,
  1909. IsWater: is_war,
  1910. DrhyWater: drhy_water,
  1911. DryWaterHour: dry_water_hour,
  1912. WaterMachine: water_machine,
  1913. AddAmount: add_amount,
  1914. ReduceAmount: reduce_amount,
  1915. DialysisRemark: dialysis_remark,
  1916. PrescribingNumber: prescribing_number,
  1917. StartSodium: start_sodium,
  1918. SodiumCurve: sodium_curve,
  1919. TreatmentRemark: treatment_remark,
  1920. PrescriptionSodium: prescription_sodium,
  1921. DialysisFluidFlow: dialysis_fluid_flow,
  1922. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1923. PrescriptionWater: prescription_water,
  1924. DialysisStrainer: dialysis_strainer,
  1925. Chaptalization: chaptalization,
  1926. WashingTime: washing_time,
  1927. WarshCount: warsh_count,
  1928. BloodAccessPartId: blood_access_part_id,
  1929. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1930. Dialyzate: dialyzate,
  1931. DialysisDialyszersId: dialysis_dialyszers_id,
  1932. DialysisIrrigationId: dialysis_irrigation_id,
  1933. DialysisStrainerId: dialysis_strainer_id,
  1934. }
  1935. //查询最近透析准备表里是否存在 透析器 灌流器
  1936. //
  1937. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1938. //
  1939. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1940. //
  1941. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1942. //if len(mation)>0{
  1943. // for _, item := range splitStr {
  1944. // for _,it := range mation{
  1945. // if(item == it.SpecificationName){
  1946. //
  1947. // //查询最近一次的透析器
  1948. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1949. //
  1950. // if errcode == gorm.ErrRecordNotFound{
  1951. // //插入数据
  1952. // prepare := models.DialysisBeforePrepare{
  1953. // UserOrgId: adminUserInfo.Org.Id,
  1954. // PatientId: id,
  1955. // RecordDate: recordDate.Unix(),
  1956. // GoodTypeId: it.GoodTypeId,
  1957. // GoodId: it.ID,
  1958. // Count: 1,
  1959. // Ctime: time.Now().Unix(),
  1960. // Creater: adminUserInfo.AdminUser.Id,
  1961. // Status:1,
  1962. //
  1963. // }
  1964. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1965. // fmt.Println("",errcode)
  1966. // }
  1967. // }
  1968. // }
  1969. //
  1970. // }
  1971. //
  1972. // for _, item := range splitIrrigation {
  1973. // for _,it := range mation{
  1974. // if(item == it.SpecificationName){
  1975. // //查询最近一次的透析器
  1976. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1977. // if errcode == gorm.ErrRecordNotFound{
  1978. // //插入数据
  1979. // prepare := models.DialysisBeforePrepare{
  1980. // UserOrgId: adminUserInfo.Org.Id,
  1981. // PatientId: id,
  1982. // RecordDate: recordDate.Unix(),
  1983. // GoodTypeId: it.GoodTypeId,
  1984. // GoodId: it.ID,
  1985. // Count: 1,
  1986. // Ctime: time.Now().Unix(),
  1987. // Creater: adminUserInfo.AdminUser.Id,
  1988. // Status:1,
  1989. //
  1990. // }
  1991. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1992. // fmt.Println(errcode)
  1993. // }
  1994. // }
  1995. // }
  1996. // }
  1997. //}
  1998. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1999. if dialysisPrescription.ID == 0 { //新增
  2000. if appRole.UserType == 2 || appRole.UserType == 1 {
  2001. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2002. }
  2003. prescription.Creater = adminUserInfo.AdminUser.Id
  2004. //针对河间咸得
  2005. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2006. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2007. prescription.DisplaceLiquiPart = 0
  2008. prescription.DisplaceLiquiValue = 0
  2009. }
  2010. }
  2011. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2012. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2013. }
  2014. err := service.AddSigleRecord(&prescription)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(prescription)
  2017. prescriptionLog := models.XtDialysisPrescriptionLog{
  2018. UserOrgId: prescription.UserOrgId,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. ErrLog: string(byterequest),
  2022. AdminUserId: adminUserInfo.AdminUser.Id,
  2023. RecordDate: prescription.RecordDate,
  2024. PatientId: prescription.PatientId,
  2025. Source: "手机端新增保存处方",
  2026. Status: 1,
  2027. }
  2028. service.CreatePrescriptionLog(prescriptionLog)
  2029. finish := models.XtDialysisFinish{
  2030. IsFinish: 1,
  2031. UserOrgId: adminUserInfo.Org.Id,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Module: 1,
  2036. RecordDate: recordDate.Unix(),
  2037. Sourse: 1,
  2038. PatientId: id,
  2039. }
  2040. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2041. if dialysisFinish.ID == 0 {
  2042. service.CreateDialysisFinish(finish)
  2043. }
  2044. //长沙南雅医院,自动生成抗凝剂的临时处方
  2045. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2046. if prescribing_number == 0 {
  2047. prescribing_number = 1
  2048. }
  2049. if prescribing_number == 0 && id == 14682 {
  2050. prescribing_number = 2
  2051. }
  2052. if prescribing_number == 0 && id == 18560 {
  2053. prescribing_number = 2
  2054. }
  2055. advice := models.DoctorAdvice{
  2056. UserOrgId: adminUserInfo.Org.Id,
  2057. PatientId: id,
  2058. GroupNo: 0,
  2059. AdviceType: 2,
  2060. RecordDate: recordDate.Unix(),
  2061. AdviceDate: recordDate.Unix(),
  2062. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2063. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2064. AdviceDesc: "",
  2065. ReminderDate: 0,
  2066. SingleDose: anticoagulant_zongliang,
  2067. SingleDoseUnit: "iu",
  2068. DrugSpec: 0,
  2069. DrugSpecUnit: "",
  2070. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2071. PrescribingNumberUnit: "支",
  2072. DeliveryWay: "静脉注射",
  2073. ExecutionFrequency: "上机前",
  2074. AdviceDoctor: 0,
  2075. Status: 1,
  2076. CreatedTime: time.Now().Unix(),
  2077. UpdatedTime: time.Now().Unix(),
  2078. IsPrescription: 1,
  2079. ExecutionState: 2,
  2080. StopState: 2,
  2081. IsSettle: 2,
  2082. }
  2083. // 查询排班信息
  2084. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2085. if schedulePatient.ID > 0 {
  2086. if schedulePatient.ScheduleType == 1 {
  2087. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2088. }
  2089. if schedulePatient.ScheduleType == 2 {
  2090. advice.StartTime = recordDate.Unix() + 9*60*60
  2091. }
  2092. }
  2093. // 抗凝剂名称
  2094. switch anticoagulant {
  2095. case 1:
  2096. advice.AdviceName = "无肝素"
  2097. break
  2098. case 2:
  2099. advice.AdviceName = "普通肝素"
  2100. break
  2101. case 3:
  2102. advice.AdviceName = "低分子肝素"
  2103. break
  2104. case 4:
  2105. advice.AdviceName = "阿加曲班"
  2106. break
  2107. case 5:
  2108. advice.AdviceName = "枸橼酸钠"
  2109. break
  2110. case 6:
  2111. advice.AdviceName = "低分子肝素钙"
  2112. break
  2113. case 7:
  2114. advice.AdviceName = "低分子肝素钠"
  2115. break
  2116. case 8:
  2117. advice.AdviceName = "依诺肝素"
  2118. break
  2119. case 9:
  2120. advice.AdviceName = "达肝素"
  2121. break
  2122. case 10:
  2123. advice.AdviceName = "体外抗凝"
  2124. break
  2125. case 11:
  2126. advice.AdviceName = "那曲肝素"
  2127. break
  2128. case 12:
  2129. advice.AdviceName = "无抗凝剂"
  2130. break
  2131. }
  2132. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2133. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2134. advice.AdviceDoctor = appRole.AdminUserId
  2135. }
  2136. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2137. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2138. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2139. advice.AdviceName = "低分子肝素钠注射液"
  2140. // 修改患者临时医嘱里的抗凝剂医嘱
  2141. advice.ID = advicePrescription.ID
  2142. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2143. } else {
  2144. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2145. advice.AdviceName = "低分子肝素钠注射液"
  2146. // 新增患者临时医嘱里的抗凝剂医嘱
  2147. service.CreateDoctorAdvice(&advice)
  2148. }
  2149. }
  2150. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2151. redis := service.RedisClient()
  2152. defer redis.Close()
  2153. //清空key 值
  2154. redis.Set(key, "", time.Second)
  2155. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2156. redis.Set(keyOne, "", time.Second)
  2157. }
  2158. //获取key,清空redis
  2159. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2160. redis := service.RedisClient()
  2161. //清空key 值
  2162. redis.Set(key, "", time.Second)
  2163. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2164. //清空key 值
  2165. redis.Set(keyOne, "", time.Second)
  2166. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2167. //清空key 值
  2168. redis.Set(keyTwo, "", time.Second)
  2169. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2170. redis.Set(keySix, "", time.Second)
  2171. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2172. redis.Set(keySeven, "", time.Second)
  2173. if err == nil {
  2174. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2175. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2176. //清空key 值
  2177. redis.Set(keyThree, "", time.Second)
  2178. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2179. //清空key 值
  2180. redis.Set(keyFour, "", time.Second)
  2181. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2182. redis.Set(keyFive, "", time.Second)
  2183. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2184. redis.Set(keySix, "", time.Second)
  2185. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2186. redis.Set(keySeven, "", time.Second)
  2187. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2188. //清空key 值
  2189. redis.Set(keyOne, "", time.Second)
  2190. if updateErr != nil {
  2191. utils.ErrorLog("%v", updateErr)
  2192. }
  2193. defer redis.Close()
  2194. c.ServeSuccessJSON(map[string]interface{}{
  2195. "prescription": prescription,
  2196. })
  2197. }
  2198. } else { //修改
  2199. //if mode_id > 0 {
  2200. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2201. //}
  2202. //if template.TemplateId == 1 {
  2203. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2204. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2205. // if getPermissionErr != nil {
  2206. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2207. // return
  2208. // } else if headNursePermission == nil {
  2209. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2210. // return
  2211. // }
  2212. // }
  2213. //}
  2214. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2215. prescription.Modifier = adminUserInfo.AdminUser.Id
  2216. if appRole.UserType == 2 || appRole.UserType == 1 {
  2217. prescription_doctor := adminUserInfo.AdminUser.Id
  2218. prescription.PrescriptionDoctor = prescription_doctor
  2219. } else {
  2220. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2221. }
  2222. if dialysisPrescription.Creater == 0 { //体重称
  2223. prescription.Creater = adminUserInfo.AdminUser.Id
  2224. } else {
  2225. prescription.Creater = dialysisPrescription.Creater
  2226. if adminUserInfo.Org.Id == 9882 {
  2227. if appRole.UserType == 2 || appRole.UserType == 1 {
  2228. prescription_doctor := adminUserInfo.AdminUser.Id
  2229. prescription.PrescriptionDoctor = prescription_doctor
  2230. prescription.Creater = prescription_doctor
  2231. }
  2232. }
  2233. }
  2234. prescription.ID = dialysisPrescription.ID
  2235. service.UpDateDialysisPrescription(&prescription)
  2236. //记录日志
  2237. byterequest, _ := json.Marshal(prescription)
  2238. prescriptionLog := models.XtDialysisPrescriptionLog{
  2239. UserOrgId: prescription.UserOrgId,
  2240. Ctime: time.Now().Unix(),
  2241. Mtime: 0,
  2242. ErrLog: string(byterequest),
  2243. AdminUserId: adminUserInfo.AdminUser.Id,
  2244. RecordDate: prescription.RecordDate,
  2245. PatientId: prescription.PatientId,
  2246. Source: "手机端修改处方",
  2247. Status: 1,
  2248. }
  2249. service.CreatePrescriptionLog(prescriptionLog)
  2250. finish := models.XtDialysisFinish{
  2251. IsFinish: 1,
  2252. UserOrgId: adminUserInfo.Org.Id,
  2253. Status: 1,
  2254. Ctime: time.Now().Unix(),
  2255. Mtime: 0,
  2256. Module: 1,
  2257. RecordDate: recordDate.Unix(),
  2258. Sourse: 1,
  2259. PatientId: id,
  2260. }
  2261. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2262. if dialysisFinish.ID == 0 {
  2263. service.CreateDialysisFinish(finish)
  2264. }
  2265. //修改处方
  2266. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2267. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2268. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2269. if advicePrescription.ID > 0 {
  2270. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2271. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2272. redis := service.RedisClient()
  2273. defer redis.Close()
  2274. //清空key 值
  2275. redis.Set(key, "", time.Second)
  2276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2277. redis.Set(keyOne, "", time.Second)
  2278. }
  2279. }
  2280. //获取key,清空redis
  2281. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2282. redis := service.RedisClient()
  2283. //清空key 值
  2284. redis.Set(key, "", time.Second)
  2285. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2286. //清空key 值
  2287. redis.Set(keyOne, "", time.Second)
  2288. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2289. redis.Set(keySix, "", time.Second)
  2290. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2291. redis.Set(keySeven, "", time.Second)
  2292. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2293. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2294. //清空key 值
  2295. redis.Set(keyTwoOne, "", time.Second)
  2296. defer redis.Close()
  2297. if updateErr != nil {
  2298. utils.ErrorLog("%v", updateErr)
  2299. }
  2300. c.ServeSuccessJSON(map[string]interface{}{
  2301. "prescription": prescription,
  2302. })
  2303. }
  2304. }
  2305. func (c *DialysisAPIController) Finish() {
  2306. id, _ := c.GetInt64("patient", 0)
  2307. recordDateStr := c.GetString("record_date")
  2308. nurseID, _ := c.GetInt64("nurse")
  2309. end_time := c.GetString("end_time")
  2310. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2311. internal_fistula := c.GetString("blood_access_internal_fistula")
  2312. catheter := c.GetString("catheter")
  2313. cruor := c.GetString("cruor")
  2314. mission := c.GetString("mission")
  2315. condenser := c.GetString("condenser")
  2316. if id <= 0 || nurseID <= 0 {
  2317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2318. return
  2319. }
  2320. adminUserInfo := c.GetMobileAdminUserInfo()
  2321. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2322. if patient.ID == 0 {
  2323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2324. return
  2325. }
  2326. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2327. if getNurseErr != nil {
  2328. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2330. return
  2331. } else if nurse == nil {
  2332. c.ErrorLog("护士不存在")
  2333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2334. return
  2335. }
  2336. if len(recordDateStr) == 0 {
  2337. recordDateStr = time.Now().Format("2006-01-02")
  2338. }
  2339. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2340. if parseDateErr != nil {
  2341. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2343. return
  2344. }
  2345. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2346. if parseEndDateErr != nil {
  2347. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2349. return
  2350. }
  2351. // 查询信息规挡的设置天数
  2352. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2353. if infor.ID > 0 && infor.WeekDay > 0 {
  2354. var cha_time int64
  2355. timeNowStr := time.Now().Format("2006-01-02")
  2356. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2357. //今日的日期减去设置的日期
  2358. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2359. if cha_time >= recordDate.Unix() {
  2360. //查询审核是否允许
  2361. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2362. //申请状态不允许的情况 拒绝修改
  2363. if infor.ApplicationStatus != 1 {
  2364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2365. return
  2366. }
  2367. }
  2368. }
  2369. //now := time.Now()
  2370. //year, month, day := now.Date()
  2371. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2372. //todayTimeStamp := today_time.Unix()
  2373. // 获取当天的第一条透析纪录
  2374. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2375. if getMonitorRecordsErr != nil {
  2376. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2378. return
  2379. }
  2380. // 获取当前的最后一条透析纪录
  2381. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2382. if getMonitorRecordsErr != nil {
  2383. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2385. return
  2386. }
  2387. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2388. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2389. if getAADErr != nil {
  2390. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2392. return
  2393. }
  2394. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2395. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2396. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2397. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2398. if assessmentAfterDislysis != nil {
  2399. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2400. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2401. } else {
  2402. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2403. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2404. tempassessmentAfterDislysis.Status = 1
  2405. tempassessmentAfterDislysis.PatientId = id
  2406. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2407. }
  2408. //长沙南雅
  2409. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2410. //获取最后一条透析处方数据
  2411. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2412. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2413. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2414. }
  2415. if dialysisOrder.Stage == 1 {
  2416. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2417. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2418. fmt.Println(value)
  2419. a, b := math.Modf(value)
  2420. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2421. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2422. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2423. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2424. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2425. }
  2426. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2427. //var num1 int64
  2428. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2429. //fmt.Println(num1)
  2430. //sub := float64(num1 / 3600)
  2431. //fmt.Println(sub)
  2432. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2433. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2434. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2435. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2436. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2437. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2438. if adminUserInfo.Org.Id != 10375 {
  2439. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2440. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2441. }
  2442. if adminUserInfo.Org.Id != 10445 {
  2443. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2444. }
  2445. //北方营口医院
  2446. if adminUserInfo.Org.Id == 10445 {
  2447. //获取最后一条透析处方数据
  2448. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2449. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2450. } else {
  2451. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2452. }
  2453. //新化博翔
  2454. if adminUserInfo.Org.Id == 10447 {
  2455. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2456. }
  2457. //阳春
  2458. if adminUserInfo.Org.Id == 10485 {
  2459. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2460. }
  2461. if adminUserInfo.Org.Id == 10551 {
  2462. //获取最后一条透析处方数据
  2463. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2464. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2465. }
  2466. if adminUserInfo.Org.Id == 10580 {
  2467. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2468. }
  2469. if adminUserInfo.Org.Id == 10612 {
  2470. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2471. }
  2472. //孝康
  2473. if adminUserInfo.Org.Id == 10693 {
  2474. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2475. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2476. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2477. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2478. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2479. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2480. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2481. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2482. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2483. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2484. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2485. }
  2486. if adminUserInfo.Org.Id == 10721 {
  2487. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2488. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2489. }
  2490. if adminUserInfo.Org.Id == 10697 {
  2491. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2492. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2493. lastWeightAfter.LastAfterWeight = floatAfeter
  2494. }
  2495. }
  2496. 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 {
  2497. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2498. if evaluation.SystolicBloodPressure == 0 {
  2499. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2500. if adminUserInfo.Org.Id == 10693 {
  2501. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2502. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2503. }
  2504. pre := models.PredialysisEvaluation{
  2505. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2506. }
  2507. fmt.Println("prew", pre)
  2508. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2509. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2510. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2511. redis := service.RedisClient()
  2512. redis.Set(key, "", time.Second)
  2513. redis.Set(keyOne, "", time.Second)
  2514. defer redis.Close()
  2515. fmt.Println(getNurseErr)
  2516. }
  2517. if evaluation.DiastolicBloodPressure == 0 {
  2518. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2519. if adminUserInfo.Org.Id == 10693 {
  2520. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2521. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2522. }
  2523. pres := models.PredialysisEvaluation{
  2524. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2525. }
  2526. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2528. redis := service.RedisClient()
  2529. redis.Set(key, "", time.Second)
  2530. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2531. redis.Set(keyOne, "", time.Second)
  2532. defer redis.Close()
  2533. fmt.Println(getNurseErr)
  2534. }
  2535. if evaluation.PulseFrequency == 0 {
  2536. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2537. if adminUserInfo.Org.Id == 10693 {
  2538. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2539. evaluation.PulseFrequency = pulseFrequency
  2540. }
  2541. press := models.PredialysisEvaluation{
  2542. PulseFrequency: evaluation.PulseFrequency,
  2543. }
  2544. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2545. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2546. redis := service.RedisClient()
  2547. redis.Set(key, "", time.Second)
  2548. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2549. redis.Set(keyOne, "", time.Second)
  2550. defer redis.Close()
  2551. fmt.Println(getNurseErr)
  2552. }
  2553. if evaluation.Temperature == 0 {
  2554. evaluation.Temperature = fmonitorRecords.Temperature
  2555. press := models.PredialysisEvaluation{
  2556. Temperature: evaluation.Temperature,
  2557. }
  2558. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2559. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2560. redis := service.RedisClient()
  2561. redis.Set(key, "", time.Second)
  2562. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2563. redis.Set(keyOne, "", time.Second)
  2564. defer redis.Close()
  2565. fmt.Println(getNurseErr)
  2566. }
  2567. }
  2568. if adminUserInfo.Org.Id == 9583 {
  2569. //获取透析处方的最后一条数据
  2570. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2571. if diaerr != nil {
  2572. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2574. return
  2575. }
  2576. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2577. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2578. }
  2579. }
  2580. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2581. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2582. }
  2583. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2584. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2585. }
  2586. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2587. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2588. }
  2589. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2590. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2591. }
  2592. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2593. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2594. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2595. }
  2596. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2597. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2598. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2599. }
  2600. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2601. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2602. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2603. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2604. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2605. }
  2606. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2607. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2608. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2609. }
  2610. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2611. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2612. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2613. }
  2614. if lastAssessmentAfterDislysis != nil {
  2615. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2616. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2617. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2618. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2619. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2620. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2621. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2622. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2623. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2624. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2625. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2626. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2627. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2628. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2629. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2630. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2631. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2632. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2633. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2634. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2635. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2636. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2637. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2638. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2639. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2640. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2641. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2642. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2643. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2644. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2645. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2646. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2647. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2648. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2649. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2650. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2651. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2652. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2653. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2654. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2655. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2656. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2657. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2658. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2659. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2660. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2661. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2662. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2663. if tempassessmentAfterDislysis.PatientId == 18695 {
  2664. tempassessmentAfterDislysis.ActualDisplacement = 0
  2665. }
  2666. if adminUserInfo.Org.Id != 10375 {
  2667. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2668. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2669. }
  2670. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2671. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2672. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2673. }
  2674. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2675. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2676. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2677. }
  2678. }
  2679. finish := models.XtDialysisFinish{
  2680. IsFinish: 1,
  2681. UserOrgId: adminUserInfo.Org.Id,
  2682. Status: 1,
  2683. Ctime: time.Now().Unix(),
  2684. Mtime: 0,
  2685. Module: 9,
  2686. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2687. Sourse: 1,
  2688. PatientId: tempassessmentAfterDislysis.PatientId,
  2689. }
  2690. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2691. if dialysisFinish.ID == 0 {
  2692. service.CreateDialysisFinish(finish)
  2693. }
  2694. //孝康
  2695. if adminUserInfo.Org.Id == 10693 {
  2696. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2697. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2698. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2699. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2700. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2701. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2702. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2703. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2704. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2705. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2706. }
  2707. if adminUserInfo.Org.Id == 10697 {
  2708. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2709. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2710. lastWeightAfter.LastAfterWeight = floatAfeter
  2711. }
  2712. if adminUserInfo.Org.Id == 10721 {
  2713. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2714. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2715. }
  2716. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2717. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2718. redis := service.RedisClient()
  2719. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2720. redis.Set(keyOne, "", time.Second)
  2721. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2722. redis.Set(keyTwo, "", time.Second)
  2723. defer redis.Close()
  2724. //清空key 值
  2725. redis.Set(key, "", time.Second)
  2726. if err != nil {
  2727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2728. return
  2729. }
  2730. if dialysisOrder == nil {
  2731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2732. return
  2733. }
  2734. if dialysisOrder.Stage == 2 {
  2735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2736. return
  2737. }
  2738. if dialysisOrder.Stage == 1 {
  2739. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2740. finish := models.XtDialysisFinish{
  2741. IsFinish: 1,
  2742. UserOrgId: adminUserInfo.Org.Id,
  2743. Status: 1,
  2744. Ctime: time.Now().Unix(),
  2745. Mtime: 0,
  2746. Module: 8,
  2747. RecordDate: recordDate.Unix(),
  2748. Sourse: 1,
  2749. PatientId: id,
  2750. }
  2751. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2752. if dialysisFinish.ID == 0 {
  2753. service.CreateDialysisFinish(finish)
  2754. }
  2755. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2756. redis := service.RedisClient()
  2757. defer redis.Close()
  2758. //清空key 值
  2759. redis.Set(key, "", time.Second)
  2760. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2761. redis.Set(keyOne, "", time.Second)
  2762. //结束时候透析次数加1
  2763. service.UpdateSolutionByPatientId(id)
  2764. //下机完自动消毒,针对长沙南雅
  2765. if dialysisOrder.Stage == 1 {
  2766. 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 {
  2767. //根据床位号获取设备型号
  2768. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2769. //查询使用消毒最后一条消毒记录
  2770. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2771. fmt.Println("err", err)
  2772. if err == gorm.ErrRecordNotFound {
  2773. //查找排班
  2774. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2775. //查询改设备是否有消毒计划
  2776. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2777. //根据床位号获取设备id
  2778. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2779. //查询病人信息
  2780. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2781. var con = ""
  2782. if patients.IsInfectious == 0 {
  2783. con = ""
  2784. }
  2785. if patients.IsInfectious == 1 {
  2786. con = "无"
  2787. }
  2788. if patients.IsInfectious == 2 {
  2789. con = "有"
  2790. }
  2791. if errcode == nil {
  2792. var end_time int64
  2793. end_time = endDate.Unix() + plan.DisinfecTime*60
  2794. //新增消毒
  2795. information := models.DeviceInformation{
  2796. Date: dialysisOrder.DialysisDate,
  2797. Zone: dialysisOrder.ZoneId,
  2798. Class: dialysisOrder.SchedualType,
  2799. BedNumber: dialysisOrder.BedID,
  2800. PatientId: dialysisOrder.PatientId,
  2801. DialysisMode: scheduleByPatient.ModeId,
  2802. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2803. Disinfection: 1,
  2804. DialysisConcentration: 1,
  2805. DisinfectionStatus: 1,
  2806. Move: 1,
  2807. UserOrgId: dialysisOrder.UserOrgId,
  2808. DisinfectType: plan.Way,
  2809. DisinfectantType: plan.MachineDisinfectant,
  2810. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2811. Disinfectant: plan.Disinfectant,
  2812. Ctime: time.Now().Unix(),
  2813. Status: 1,
  2814. SignName: nurseID,
  2815. EquimentId: addmacher.ID,
  2816. DisinfectionResidue: 2,
  2817. Bed: addmacher.BedNumber,
  2818. StartTime: dialysisOrder.StartTime,
  2819. EndTime: dialysisOrder.EndTime,
  2820. Contagion: con,
  2821. WeightLoss: 0,
  2822. Hyperfiltratio: 0,
  2823. DialysisHour: "",
  2824. MachineRun: 1,
  2825. DisinfecStartime: endDate.Unix(),
  2826. DisinfecEndtime: end_time,
  2827. }
  2828. err := service.CreateInformationTwo(&information)
  2829. fmt.Println("报错", err)
  2830. }
  2831. }
  2832. }
  2833. }
  2834. dialysisOrder.Stage = 2
  2835. dialysisOrder.FinishNurse = nurseID
  2836. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2837. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2838. dialysisOrder.EndTime = endDate.Unix()
  2839. // 长沙南雅需求
  2840. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2841. //获取最后1条监测的数据
  2842. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2843. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2844. var accumulatedBloodVolume float64
  2845. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2846. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2847. fmt.Println(err)
  2848. // 查询未执行的医嘱
  2849. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2850. for _, item := range doctorAdvice {
  2851. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2852. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2853. redis := service.RedisClient()
  2854. //清空key 值
  2855. redis.Set(key, "", time.Second)
  2856. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2857. redis.Set(keyTwo, "", time.Second)
  2858. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2859. redis.Set(keyThree, "", time.Second)
  2860. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2861. theTime := toTime.Format("2006-01-02")
  2862. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2863. redis.Set(keyFour, "", time.Second)
  2864. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2865. redis.Set(keyFive, "", time.Second)
  2866. defer redis.Close()
  2867. }
  2868. }
  2869. go func() {
  2870. ssoDomain := beego.AppConfig.String("call_domain")
  2871. api := ssoDomain + "/index/downpatient"
  2872. values := make(url.Values)
  2873. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2874. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2875. values.Set("patient_id", strconv.FormatInt(id, 10))
  2876. http.PostForm(api, values)
  2877. }()
  2878. if err == nil {
  2879. c.ServeSuccessJSON(map[string]interface{}{
  2880. "dialysisOrder": dialysisOrder,
  2881. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2882. })
  2883. } else {
  2884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2885. }
  2886. }
  2887. }
  2888. func (c *DialysisAPIController) GetAllZone() {
  2889. adminUserInfo := c.GetMobileAdminUserInfo()
  2890. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2891. if err == nil {
  2892. c.ServeSuccessJSON(map[string]interface{}{
  2893. "zone": zone,
  2894. })
  2895. }
  2896. }
  2897. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2898. adminUserInfo := c.GetMobileAdminUserInfo()
  2899. page, _ := c.GetInt64("page", 1)
  2900. limit, _ := c.GetInt64("limit", 10)
  2901. schedulType, _ := c.GetInt64("schedul_type", 0)
  2902. startTime, _ := c.GetInt64("schedul_time", 0)
  2903. partitionType, _ := c.GetInt64("partition_type", 0)
  2904. keywords := c.GetString("keywords")
  2905. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2906. if err == nil {
  2907. c.ServeSuccessJSON(map[string]interface{}{
  2908. "schedule": dialysisSchedule,
  2909. })
  2910. }
  2911. return
  2912. }
  2913. // /m/api/dialysis/start [post]
  2914. // @param patient_id:int
  2915. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2916. // @param nurse:int 上机护士
  2917. // @param bed:int 床位号
  2918. func (this *DialysisAPIController) StartDialysis() {
  2919. patientID, _ := this.GetInt64("patient_id")
  2920. recordDateStr := this.GetString("record_date")
  2921. nurseID, _ := this.GetInt64("start_nurse")
  2922. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2923. blood_drawing, _ := this.GetInt64("blood_drawing")
  2924. schedual_type, _ := this.GetInt64("schedual_type")
  2925. bedID, _ := this.GetInt64("bed")
  2926. start_time := this.GetString("start_time")
  2927. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2928. change_nurse, _ := this.GetInt64("change_nurse")
  2929. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2930. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2931. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2932. puncture_needle := this.GetString("puncture_needle")
  2933. puncture_way := this.GetString("puncture_way")
  2934. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2935. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2936. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2937. zone_id, _ := this.GetInt64("zone_id")
  2938. elecsign := this.GetString("url")
  2939. nuclein_date_str := this.GetString("nuclein_date_str")
  2940. schedule_remark := this.GetString("schedule_remark")
  2941. order_remark := this.GetString("order_remark")
  2942. catheter_operation := this.GetString("catheter_operation")
  2943. blood_flow_volume := this.GetString("blood_flow_volume")
  2944. dialysis_strainer := this.GetString("dialysis_strainer")
  2945. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2947. return
  2948. }
  2949. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2950. if parseStartDateErr != nil {
  2951. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2953. return
  2954. }
  2955. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2956. if parseErr != nil {
  2957. this.ErrorLog("时间解析失败:%v", parseErr)
  2958. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2959. return
  2960. }
  2961. adminUserInfo := this.GetMobileAdminUserInfo()
  2962. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2963. if getPatientErr != nil {
  2964. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2966. return
  2967. } else if patient == nil {
  2968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2969. return
  2970. }
  2971. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2972. if getNurseErr != nil {
  2973. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2974. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2975. return
  2976. } else if nurse == nil {
  2977. this.ErrorLog("护士不存在")
  2978. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2979. return
  2980. }
  2981. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2982. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2983. if getDeviceNumberErr != nil {
  2984. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. return
  2987. } else if deviceNumber == nil {
  2988. this.ErrorLog("床位号不存在")
  2989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2990. return
  2991. }
  2992. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2993. if getRecordErr != nil {
  2994. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2996. return
  2997. } else if dialysisRecord != nil {
  2998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2999. return
  3000. }
  3001. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3002. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3003. timeLayout := "2006-01-02 15:04:05"
  3004. loc, _ := time.LoadLocation("Local")
  3005. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3006. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3007. schedulestartTime := theStartTime.Unix()
  3008. scheduleendTime := theEndTime.Unix()
  3009. var theNucleinDate int64
  3010. timeLayoutOne := "2006-01-02"
  3011. if len(nuclein_date_str) > 0 {
  3012. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3013. if err != nil {
  3014. utils.ErrorLog(err.Error())
  3015. }
  3016. theNucleinDate = theTime.Unix()
  3017. }
  3018. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3019. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3020. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3021. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3022. //查询该床位是否有人用了
  3023. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3024. if err == gorm.ErrRecordNotFound { //空床位
  3025. // 修改了床位逻辑
  3026. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3027. if daySchedule.ID > 0 {
  3028. daySchedule.PartitionId = deviceNumber.ZoneID
  3029. daySchedule.BedId = bedID
  3030. daySchedule.ScheduleType = schedual_type
  3031. daySchedule.UpdatedTime = time.Now().Unix()
  3032. xtSchedule := models.Schedule{
  3033. PartitionId: deviceNumber.ZoneID,
  3034. BedId: bedID,
  3035. ScheduleType: schedual_type,
  3036. UpdatedTime: time.Now().Unix(),
  3037. }
  3038. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3039. if err != nil {
  3040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3041. return
  3042. }
  3043. }
  3044. } else if err == nil {
  3045. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3046. if order.ID > 0 { //该机位被其他人占用了
  3047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3048. return
  3049. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3050. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3051. if daySchedule.ID > 0 {
  3052. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3053. if err != nil {
  3054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3055. return
  3056. }
  3057. }
  3058. }
  3059. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3061. return
  3062. }
  3063. //else if order.ID == 0 { //该床位没被占用
  3064. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3065. // if daySchedule.ID > 0 {
  3066. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3067. // //daySchedule.BedId = bedID
  3068. // //daySchedule.ScheduleType = schedual_type
  3069. // //daySchedule.UpdatedTime = time.Now().Unix()
  3070. // //err := service.UpdateSchedule(&daySchedule)
  3071. // xtSchedule := models.Schedule{
  3072. // PartitionId: deviceNumber.ZoneID,
  3073. // BedId: bedID,
  3074. // ScheduleType: schedual_type,
  3075. // UpdatedTime: time.Now().Unix(),
  3076. // }
  3077. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3078. // if err != nil {
  3079. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3080. // return
  3081. // }
  3082. // }
  3083. //}
  3084. //}
  3085. } else if err != nil {
  3086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3087. return
  3088. }
  3089. // 查询信息规挡的设置天数
  3090. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3091. if infor.ID > 0 && infor.WeekDay > 0 {
  3092. var cha_time int64
  3093. timeNowStr := time.Now().Format("2006-01-02")
  3094. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3095. //今日的日期减去设置的日期
  3096. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3097. if cha_time >= recordDate.Unix() {
  3098. //查询审核是否允许
  3099. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3100. //申请状态不允许的情况 拒绝修改
  3101. if infor.ApplicationStatus != 1 {
  3102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3103. return
  3104. }
  3105. }
  3106. }
  3107. dialysisRecord = &models.DialysisOrder{
  3108. DialysisDate: recordDate.Unix(),
  3109. UserOrgId: adminUserInfo.Org.Id,
  3110. PatientId: patientID,
  3111. Stage: 1,
  3112. BedID: bedID,
  3113. StartNurse: nurseID,
  3114. Status: 1,
  3115. StartTime: startDate.Unix(),
  3116. CreatedTime: time.Now().Unix(),
  3117. UpdatedTime: time.Now().Unix(),
  3118. PunctureNurse: puncture_nurse,
  3119. Creator: adminUserInfo.AdminUser.Id,
  3120. Modifier: adminUserInfo.AdminUser.Id,
  3121. SchedualType: schedual_type,
  3122. WashpipeNurse: washpipe_nurse,
  3123. ChangeNurse: change_nurse,
  3124. DifficultPunctureNurse: difficult_puncture_nurse,
  3125. NewFistulaNurse: new_fistula_nurse,
  3126. ZoneId: zone_id,
  3127. QualityNurseId: quality_nurse_id,
  3128. PunctureNeedle: puncture_needle,
  3129. PunctureWay: puncture_way,
  3130. DialysisIrrigation: dialysis_irrigation,
  3131. DialysisDialyszers: dialysis_dialyszers,
  3132. BloodAccessId: blood_access_id,
  3133. Url: elecsign,
  3134. NucleinDate: theNucleinDate,
  3135. ScheduleRemark: schedule_remark,
  3136. OrderRemark: order_remark,
  3137. CatheterOperation: catheter_operation,
  3138. BloodFlowVolume: blood_flow_volume,
  3139. BloodDrawing: blood_drawing,
  3140. DialysisStrainer: dialysis_strainer,
  3141. }
  3142. //查询该床位是否有人用了
  3143. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3144. if errorscode == gorm.ErrRecordNotFound {
  3145. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3146. finish := models.XtDialysisFinish{
  3147. IsFinish: 1,
  3148. UserOrgId: adminUserInfo.Org.Id,
  3149. Status: 1,
  3150. Ctime: time.Now().Unix(),
  3151. Mtime: 0,
  3152. Module: 6,
  3153. RecordDate: schedulestartTime,
  3154. Sourse: 1,
  3155. PatientId: patientID,
  3156. }
  3157. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3158. if dialysisFinish.ID == 0 {
  3159. service.CreateDialysisFinish(finish)
  3160. }
  3161. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3162. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3163. //统计该患者总次数
  3164. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3165. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3166. }
  3167. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3168. //统计该患者总次数
  3169. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3170. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3171. }
  3172. redis := service.RedisClient()
  3173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3174. redis.Set(key, "", time.Second)
  3175. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3176. //清空key 值
  3177. redis.Set(keyOne, "", time.Second)
  3178. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3179. //清空key 值
  3180. redis.Set(keyTwo, "", time.Second)
  3181. if createErr != nil {
  3182. this.ErrorLog("上机失败:%v", createErr)
  3183. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3184. return
  3185. }
  3186. }
  3187. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3188. var tempdispose string
  3189. // 只针对中能建
  3190. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3191. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3192. }
  3193. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3194. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3195. }
  3196. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3197. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3198. //}
  3199. var ultrafiltration_rate float64
  3200. var ultrafiltration_rate_one string
  3201. var replacement_rate float64
  3202. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3203. //后期预增脱水量
  3204. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3205. if prescription.ID > 0 {
  3206. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3207. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3208. 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
  3209. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3210. }
  3211. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3212. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3213. }
  3214. //针对医师汇
  3215. if adminUserInfo.Org.Id == 10121 {
  3216. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3217. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3218. }
  3219. //针对通道
  3220. if adminUserInfo.Org.Id == 10234 {
  3221. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3222. }
  3223. //针对监利大垸医院
  3224. if template.TemplateId == 41 {
  3225. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3226. }
  3227. //针对肇庆三鹤血液透析中心
  3228. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3229. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3230. }
  3231. if adminUserInfo.Org.Id == 10469 {
  3232. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3233. }
  3234. if adminUserInfo.Org.Id == 10667 {
  3235. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3236. }
  3237. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3238. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3239. }
  3240. // 只针对方济医院
  3241. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3242. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3243. ultrafiltration_rate = value
  3244. }
  3245. //针对
  3246. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3247. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3248. ultrafiltration_rate = ultrafiltration_rate / 1000
  3249. }
  3250. if adminUserInfo.Org.Id == 10551 {
  3251. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3252. ultrafiltration_rate = ultrafiltration_rate / 1000
  3253. }
  3254. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3255. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3256. ultrafiltration_rate = ultrafiltration_rate / 1000
  3257. }
  3258. if adminUserInfo.Org.Id == 10580 {
  3259. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3260. ultrafiltration_rate = ultrafiltration_rate / 1000
  3261. }
  3262. if adminUserInfo.Org.Id == 10629 {
  3263. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3264. ultrafiltration_rate = ultrafiltration_rate / 1000
  3265. }
  3266. if adminUserInfo.Org.Id == 10644 {
  3267. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3268. ultrafiltration_rate = ultrafiltration_rate / 1000
  3269. }
  3270. if adminUserInfo.Org.Id == 10667 {
  3271. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3272. ultrafiltration_rate = ultrafiltration_rate / 1000
  3273. }
  3274. if adminUserInfo.Org.Id == 10693 {
  3275. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3276. ultrafiltration_rate = ultrafiltration_rate
  3277. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3278. }
  3279. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3280. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3281. ultrafiltration_rate = ultrafiltration_rate
  3282. }
  3283. if adminUserInfo.Org.Id == 10702 {
  3284. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3285. ultrafiltration_rate = ultrafiltration_rate / 1000
  3286. }
  3287. if adminUserInfo.Org.Id == 10723 {
  3288. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3289. ultrafiltration_rate = ultrafiltration_rate / 1000
  3290. }
  3291. if adminUserInfo.Org.Id == 10721 {
  3292. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3293. ultrafiltration_rate = ultrafiltration_rate / 1000
  3294. }
  3295. }
  3296. }
  3297. record := models.MonitoringRecord{
  3298. UserOrgId: adminUserInfo.Org.Id,
  3299. PatientId: patientID,
  3300. DialysisOrderId: dialysisRecord.ID,
  3301. MonitoringDate: schedulestartTime,
  3302. OperateTime: startDate.Unix(),
  3303. // MonitoringTime: recordTime,
  3304. MonitoringNurse: nurseID,
  3305. Dispose: tempdispose,
  3306. UltrafiltrationRate: ultrafiltration_rate,
  3307. UltrafiltrationVolume: 0,
  3308. Status: 1,
  3309. CreatedTime: time.Now().Unix(),
  3310. UpdatedTime: time.Now().Unix(),
  3311. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3312. ReplacementRate: replacement_rate,
  3313. }
  3314. //只针对广慈医院
  3315. 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 {
  3316. // 查询病人是否有透前评估数据
  3317. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3318. //如果有数据就插入
  3319. if errcode == nil {
  3320. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3321. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3322. record.BreathingRate = befor.BreathingRate
  3323. record.PulseFrequency = befor.PulseFrequency
  3324. record.Temperature = befor.Temperature
  3325. }
  3326. }
  3327. //孝昌
  3328. if adminUserInfo.Org.Id == 10693 {
  3329. // 查询病人是否有透前评估数据
  3330. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3331. //如果有数据就插入
  3332. if errcode == nil {
  3333. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3334. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3335. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3336. record.BreathingRate = befor.BreathingRate
  3337. }
  3338. }
  3339. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3340. if newdialysisRecord.ID > 0 {
  3341. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3342. record.Temperature = 36.5
  3343. record.ArterialPressure = -100
  3344. record.DialysateTemperature = 36.5
  3345. record.Conductivity = 14
  3346. record.BreathingRate = "20"
  3347. record.VenousPressure = 80
  3348. record.TransmembranePressure = 60
  3349. record.Dispose = catheter_operation
  3350. }
  3351. //针对新化博翔
  3352. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3353. record.BloodOxygenSaturation = "99"
  3354. record.Conductivity = 14
  3355. record.DialysateTemperature = 36.5
  3356. record.BreathingRate = "20"
  3357. }
  3358. //针对兰溪人民医院的需求
  3359. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3360. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3361. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3362. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3363. record.Temperature = befor.Temperature
  3364. record.PulseFrequency = befor.PulseFrequency
  3365. record.BreathingRate = befor.BreathingRate
  3366. }
  3367. //针对乐山友谊医院的需求
  3368. if adminUserInfo.Org.Id == 10677 {
  3369. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3370. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3371. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3372. record.Temperature = befor.Temperature
  3373. record.PulseFrequency = befor.PulseFrequency
  3374. record.BreathingRate = befor.BreathingRate
  3375. }
  3376. //新化博翔
  3377. if adminUserInfo.Org.Id == 10447 {
  3378. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3379. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3380. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3381. record.BreathingRate = befor.BreathingRate
  3382. }
  3383. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3384. record.PulseFrequency = 80
  3385. record.Temperature = 36.5
  3386. }
  3387. //诊断灵山圣康
  3388. if adminUserInfo.Org.Id == 10375 {
  3389. record.Conductivity = 13.8
  3390. record.DialysateTemperature = 37
  3391. record.DialysateFlow = 500
  3392. record.BloodFlowVolume = 200
  3393. record.BreathingRate = "18"
  3394. record.SodiumConcentration = 140
  3395. }
  3396. //江成肾病医院
  3397. if adminUserInfo.Org.Id == 10517 {
  3398. record.SodiumConcentration = 138
  3399. record.DialysateTemperature = 36.5
  3400. }
  3401. //濉溪杏康血液透析中心
  3402. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3403. record.BloodFlowVolume = prescription.BloodFlowVolume
  3404. }
  3405. if adminUserInfo.Org.Id != 10683 {
  3406. err = service.CreateMonitor(&record)
  3407. }
  3408. //记录日志
  3409. byterequest, _ := json.Marshal(record)
  3410. monitorRecordLog := models.XtMonitorRecordLog{
  3411. RecordDate: record.MonitoringDate,
  3412. PatientId: record.PatientId,
  3413. Module: 1,
  3414. AdminUserId: adminUserInfo.AdminUser.Id,
  3415. Ctime: time.Now().Unix(),
  3416. Mtime: 0,
  3417. Status: 1,
  3418. UserOrgId: record.UserOrgId,
  3419. ErrLog: string(byterequest),
  3420. Source: "执行上机时新增监测",
  3421. }
  3422. service.CreateMonitorRecordLog(monitorRecordLog)
  3423. finish := models.XtDialysisFinish{
  3424. IsFinish: 1,
  3425. UserOrgId: adminUserInfo.Org.Id,
  3426. Status: 1,
  3427. Ctime: time.Now().Unix(),
  3428. Mtime: 0,
  3429. Module: 7,
  3430. RecordDate: schedulestartTime,
  3431. Sourse: 1,
  3432. PatientId: patientID,
  3433. }
  3434. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3435. if dialysisFinish.ID == 0 {
  3436. service.CreateDialysisFinish(finish)
  3437. }
  3438. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3439. redis := service.RedisClient()
  3440. //清空key 值
  3441. redis.Set(key, "", time.Second)
  3442. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3443. redis.Set(keyOne, "", time.Second)
  3444. defer redis.Close()
  3445. if err != nil {
  3446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3447. return
  3448. }
  3449. }
  3450. go func() {
  3451. ssoDomain := beego.AppConfig.String("call_domain")
  3452. api := ssoDomain + "/index/uppatient"
  3453. values := make(url.Values)
  3454. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3455. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3456. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3457. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3458. http.PostForm(api, values)
  3459. }()
  3460. this.ServeSuccessJSON(map[string]interface{}{
  3461. "dialysis_order": newdialysisRecord,
  3462. "monitor": record,
  3463. })
  3464. return
  3465. }
  3466. func (c *DialysisAPIController) PostSolution() {
  3467. id, _ := c.GetInt64("patient", 0)
  3468. recordDateStr := c.GetString("record_date")
  3469. if id <= 0 {
  3470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3471. return
  3472. }
  3473. adminUserInfo := c.GetMobileAdminUserInfo()
  3474. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3475. if patient.ID == 0 {
  3476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3477. return
  3478. }
  3479. if len(recordDateStr) == 0 {
  3480. recordDateStr = time.Now().Format("2006-01-02")
  3481. }
  3482. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3483. if parseDateErr != nil {
  3484. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3486. return
  3487. }
  3488. mode_id, _ := c.GetInt64("mode_id", 0)
  3489. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3490. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3491. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3492. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3493. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3494. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3495. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3496. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3497. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3498. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3499. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3500. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3501. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3502. kalium, _ := c.GetFloat("kalium", 0)
  3503. sodium, _ := c.GetFloat("sodium", 0)
  3504. calcium, _ := c.GetFloat("calcium", 0)
  3505. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3506. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3507. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3508. glucose, _ := c.GetFloat("glucose", 0)
  3509. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3510. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3511. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3512. conductivity, _ := c.GetFloat("conductivity", 0)
  3513. remark := c.GetString("remark")
  3514. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3515. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3516. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3517. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3518. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3519. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3520. special_medicine_other := c.GetString("special_medicine_other")
  3521. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3522. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3523. blood_access, _ := c.GetInt64("blood_access", 0)
  3524. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3525. body_fluid_other := c.GetString("body_fluid_other")
  3526. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3527. niprocart, _ := c.GetInt64("niprocart", 0)
  3528. jms, _ := c.GetInt64("jms", 0)
  3529. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3530. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3531. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3532. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3533. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3534. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3535. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3536. injector, _ := c.GetInt64("injector", 0)
  3537. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3538. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3539. safe_package, _ := c.GetInt64("package", 0)
  3540. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3541. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3542. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3543. blood := c.GetString("blood")
  3544. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3545. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3546. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3547. displace_speed := c.GetString("displace_speed")
  3548. illness, _ := c.GetInt64("illness")
  3549. amylaceum := c.GetString("amylaceum")
  3550. single_time := c.GetString("single_time")
  3551. single_water := c.GetString("single_water")
  3552. replacement_flow := c.GetString("replacement_flow")
  3553. plasma_separator := c.GetString("plasma_separator")
  3554. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3555. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3556. oxygen_flow := c.GetString("oxygen_flow")
  3557. oxygen_time := c.GetString("oxygen_time")
  3558. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3559. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3560. puncture_needle := c.GetString("puncture_needle")
  3561. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3562. epo := c.GetString("epo")
  3563. epo_count, _ := c.GetFloat("epo_count", 0)
  3564. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3565. pre_impulse := c.GetString("pre_impulse")
  3566. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3567. admin_user_id, _ := c.GetInt64("admin_user_id")
  3568. is_water := c.GetString("is_water")
  3569. add_amount, _ := c.GetFloat("add_amount")
  3570. reduce_amount, _ := c.GetFloat("reduce_amount")
  3571. prescribing_number, _ := c.GetFloat("prescribing_number")
  3572. treatment_remark := c.GetString("treatment_remark")
  3573. prescription_sodium := c.GetString("prescription_sodium")
  3574. start_sodium := c.GetString("start_sodium")
  3575. sodium_curve := c.GetString("sodium_curve")
  3576. var is_war int64
  3577. if is_water == "是" {
  3578. is_war = 1
  3579. }
  3580. if is_water == "否" {
  3581. is_war = 2
  3582. }
  3583. if is_water == "请选择" {
  3584. is_war = 0
  3585. }
  3586. drhy_water := c.GetString("drhy_water")
  3587. dry_water_hour := c.GetString("dry_water_hour")
  3588. water_machine := c.GetString("water_machine")
  3589. dialysis_remark := c.GetString("dialysis_remark")
  3590. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3591. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3592. prescription_water, _ := c.GetFloat("prescription_water")
  3593. dialysis_strainer := c.GetString("dialysis_strainer")
  3594. chaptalization := c.GetString("chaptalization")
  3595. washing_time := c.GetString("washing_time")
  3596. warsh_count := c.GetString("warsh_count")
  3597. blood_access_part_id := c.GetString("blood_access_part_id")
  3598. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3599. dialyzate := c.GetString("dialyzate")
  3600. if mode_id > 0 {
  3601. var str string
  3602. //查找该机构用的是什么透析器
  3603. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3604. if filedConfig.ID > 0 {
  3605. str = dialyzerPerfusionApparatus
  3606. } else {
  3607. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3608. }
  3609. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3610. }
  3611. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3612. //
  3613. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3614. // if appRole.UserType == 3 {
  3615. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3616. // if getPermissionErr != nil {
  3617. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3618. // return
  3619. // } else if headNursePermission == nil {
  3620. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3621. // return
  3622. // }
  3623. // }
  3624. //}
  3625. // 查询信息规挡的设置天数
  3626. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3627. if infor.ID > 0 && infor.WeekDay > 0 {
  3628. var cha_time int64
  3629. timeNowStr := time.Now().Format("2006-01-02")
  3630. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3631. //今日的日期减去设置的日期
  3632. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3633. if cha_time >= recordDate.Unix() {
  3634. //查询审核是否允许
  3635. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3636. //申请状态不允许的情况 拒绝修改
  3637. if infor.ApplicationStatus != 1 {
  3638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3639. return
  3640. }
  3641. }
  3642. }
  3643. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3644. var dialysis_dialyszers_id int64
  3645. var dialysis_strainer_id int64
  3646. var dialysis_irrigation_id int64
  3647. if len(goodList) > 0 {
  3648. for _, item := range goodList {
  3649. if item.SpecificationName == dialysis_dialyszers {
  3650. dialysis_dialyszers_id = item.ID
  3651. }
  3652. if item.SpecificationName == dialysis_irrigation {
  3653. dialysis_irrigation_id = item.ID
  3654. }
  3655. if item.SpecificationName == dialysis_strainer {
  3656. dialysis_strainer_id = item.ID
  3657. }
  3658. }
  3659. }
  3660. prescription := models.DialysisPrescription{
  3661. UserOrgId: adminUserInfo.Org.Id,
  3662. PatientId: id,
  3663. RecordDate: recordDate.Unix(),
  3664. ModeId: mode_id,
  3665. DialysisDuration: dialysis_duration,
  3666. Dialyzer: dialyzer,
  3667. PerfusionApparatus: perfusion_apparatus,
  3668. BloodFlowVolume: blood_flow_volume,
  3669. DewaterAmount: dewater_amount,
  3670. DisplaceLiqui: displace_liqui,
  3671. ReplacementWay: replacement_way,
  3672. Anticoagulant: anticoagulant,
  3673. AnticoagulantShouji: anticoagulant_shouji,
  3674. AnticoagulantWeichi: anticoagulant_weichi,
  3675. AnticoagulantZongliang: anticoagulant_zongliang,
  3676. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3677. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3678. Kalium: kalium,
  3679. Sodium: sodium,
  3680. Calcium: calcium,
  3681. Bicarbonate: bicarbonate,
  3682. Glucose: glucose,
  3683. // DryWeight: dry_weight,
  3684. DialysateFlow: dialysate_flow,
  3685. DialysateTemperature: dialysate_temperature,
  3686. Conductivity: conductivity,
  3687. Remark: remark,
  3688. Status: 1,
  3689. CreatedTime: time.Now().Unix(),
  3690. UpdatedTime: time.Now().Unix(),
  3691. DialysisDurationMinute: dialysisDurationMinute,
  3692. DialysisDurationHour: dialysisDurationHour,
  3693. TargetUltrafiltration: targetUltrafiltration,
  3694. DialysateFormulation: dialysateFormulation,
  3695. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3696. BodyFluid: body_fluid,
  3697. SpecialMedicine: special_medicine,
  3698. SpecialMedicineOther: special_medicine_other,
  3699. DisplaceLiquiPart: displace_liqui_part,
  3700. DisplaceLiquiValue: displace_liqui_value,
  3701. BloodAccess: blood_access,
  3702. Ultrafiltration: ultrafiltration,
  3703. BodyFluidOther: body_fluid_other,
  3704. ReplacementTotal: replacement_total,
  3705. Niprocart: niprocart,
  3706. Jms: jms,
  3707. FistulaNeedleSet: fistula_needle_set,
  3708. FistulaNeedleSet16: fistula_needle_set_16,
  3709. Hemoperfusion: hemoperfusion,
  3710. DialyserSterilised: dialyser_sterilised,
  3711. Filtryzer: filtryzer,
  3712. TargetKtv: target_ktv,
  3713. Dialyzers: dialyzers,
  3714. Injector: injector,
  3715. Bloodlines: bloodlines,
  3716. TubingHemodialysis: tubing_hemodialysis,
  3717. Package: safe_package,
  3718. ALiquid: a_liquid,
  3719. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3720. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3721. Blood: blood,
  3722. DialysisDialyszers: dialysis_dialyszers,
  3723. DialysisIrrigation: dialysis_irrigation,
  3724. AntioxidantCommodityName: antioxidant_commodity_name,
  3725. DisplaceSpeed: displace_speed,
  3726. Illness: illness,
  3727. Amylaceum: amylaceum,
  3728. SingleWater: single_water,
  3729. SingleTime: single_time,
  3730. ReplacementFlow: replacement_flow,
  3731. PlasmaSeparator: plasma_separator,
  3732. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3733. OxygenUptake: oxygen_uptake,
  3734. OxygenTime: oxygen_time,
  3735. OxygenFlow: oxygen_flow,
  3736. HemodialysisPipelines: hemodialysis_pipelines,
  3737. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3738. PunctureNeedle: puncture_needle,
  3739. PunctureNeedleCount: puncture_needle_count,
  3740. Epo: epo,
  3741. EpoCount: epo_count,
  3742. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3743. PreImpulse: impulse,
  3744. AdminUserId: admin_user_id,
  3745. IsWater: is_war,
  3746. DrhyWater: drhy_water,
  3747. DryWaterHour: dry_water_hour,
  3748. WaterMachine: water_machine,
  3749. AddAmount: add_amount,
  3750. ReduceAmount: reduce_amount,
  3751. DialysisRemark: dialysis_remark,
  3752. PrescribingNumber: prescribing_number,
  3753. PrescriptionSodium: prescription_sodium,
  3754. StartSodium: start_sodium,
  3755. SodiumCurve: sodium_curve,
  3756. TreatmentRemark: treatment_remark,
  3757. DialysisFluidFlow: dialysis_fluid_flow,
  3758. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3759. PrescriptionWater: prescription_water,
  3760. DialysisStrainer: dialysis_strainer,
  3761. Chaptalization: chaptalization,
  3762. WashingTime: washing_time,
  3763. WarshCount: warsh_count,
  3764. BloodAccessPartId: blood_access_part_id,
  3765. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3766. Dialyzate: dialyzate,
  3767. DialysisDialyszersId: dialysis_dialyszers_id,
  3768. DialysisIrrigationId: dialysis_irrigation_id,
  3769. DialysisStrainerId: dialysis_strainer_id,
  3770. }
  3771. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3772. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3773. //
  3774. if appRole.UserType == 2 || appRole.UserType == 1 {
  3775. prescription_doctor = adminUserInfo.AdminUser.Id
  3776. prescription.PrescriptionDoctor = prescription_doctor
  3777. }
  3778. if dialysisPrescription.ID == 0 { //新增
  3779. prescription.Creater = adminUserInfo.AdminUser.Id
  3780. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3781. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3782. }
  3783. } else { //修改
  3784. if dialysisPrescription.Creater == 0 {
  3785. prescription.Creater = adminUserInfo.AdminUser.Id
  3786. } else {
  3787. prescription.Creater = dialysisPrescription.Creater
  3788. if adminUserInfo.Org.Id == 9882 {
  3789. if appRole.UserType == 2 || appRole.UserType == 1 {
  3790. prescription.Creater = adminUserInfo.AdminUser.Id
  3791. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3792. }
  3793. }
  3794. }
  3795. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3796. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3797. }
  3798. //if/**/
  3799. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3800. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3801. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3802. // if getPermissionErr != nil {
  3803. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3804. // return
  3805. // } else if headNursePermission == nil {
  3806. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3807. // return
  3808. // }
  3809. //}
  3810. //prescription.Creater = dialysisPrescription.Creater
  3811. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3812. prescription.Modifier = adminUserInfo.AdminUser.Id
  3813. prescription.ID = dialysisPrescription.ID
  3814. }
  3815. solution := models.DialysisSolution{
  3816. RegistrarsId: adminUserInfo.AdminUser.Id,
  3817. UserOrgId: adminUserInfo.Org.Id,
  3818. Doctor: prescription_doctor,
  3819. PatientId: id,
  3820. ModeId: mode_id,
  3821. DialysisDuration: dialysis_duration,
  3822. PerfusionApparatus: perfusion_apparatus,
  3823. BloodFlowVolume: blood_flow_volume,
  3824. Dewater: dewater_amount,
  3825. DisplaceLiqui: displace_liqui,
  3826. ReplacementWay: replacement_way,
  3827. Anticoagulant: anticoagulant,
  3828. AnticoagulantShouji: anticoagulant_shouji,
  3829. AnticoagulantWeichi: anticoagulant_weichi,
  3830. AnticoagulantZongliang: anticoagulant_zongliang,
  3831. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3832. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3833. Kalium: kalium,
  3834. Sodium: sodium,
  3835. Calcium: calcium,
  3836. Bicarbonate: bicarbonate,
  3837. Glucose: glucose,
  3838. // DryWeight: dry_weight,
  3839. DialysateFlow: dialysate_flow,
  3840. DialysateTemperature: dialysate_temperature,
  3841. Conductivity: conductivity,
  3842. Remark: remark,
  3843. Status: 1,
  3844. CreatedTime: time.Now().Unix(),
  3845. UpdatedTime: time.Now().Unix(),
  3846. DialysisDurationMinute: dialysisDurationMinute,
  3847. DialysisDurationHour: dialysisDurationHour,
  3848. TargetUltrafiltration: targetUltrafiltration,
  3849. DialysateFormulation: dialysateFormulation,
  3850. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3851. BodyFluid: body_fluid,
  3852. SpecialMedicine: special_medicine,
  3853. SpecialMedicineOther: special_medicine_other,
  3854. DisplaceLiquiPart: displace_liqui_part,
  3855. DisplaceLiquiValue: displace_liqui_value,
  3856. BloodAccess: blood_access,
  3857. Ultrafiltration: ultrafiltration,
  3858. BodyFluidOther: body_fluid_other,
  3859. ReplacementTotal: replacement_total,
  3860. TargetKtv: target_ktv,
  3861. DialysisDialyszers: dialysis_dialyszers,
  3862. DialysisIrrigation: dialysis_irrigation,
  3863. HemodialysisPipelines: hemodialysis_pipelines,
  3864. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3865. PunctureNeedle: puncture_needle,
  3866. PunctureNeedleCount: puncture_needle_count,
  3867. Epo: epo,
  3868. EpoCount: epo_count,
  3869. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3870. PreImpulse: impulse,
  3871. SolutionStatus: 1,
  3872. DialysisRemark: dialysis_remark,
  3873. PrescribingNumber: prescribing_number,
  3874. PrescriptionSodium: prescription_sodium,
  3875. StartSodium: start_sodium,
  3876. SodiumCurve: sodium_curve,
  3877. TreatmentRemark: treatment_remark,
  3878. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3879. DialysisFluidFlow: dialysis_fluid_flow,
  3880. PrescriptionWater: prescription_water,
  3881. DialysisStrainer: dialysis_strainer,
  3882. Chaptalization: chaptalization,
  3883. WashingTime: washing_time,
  3884. WarshCount: warsh_count,
  3885. BloodAccessPartId: blood_access_part_id,
  3886. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3887. Dialyzate: dialyzate,
  3888. DialysisDialyszersId: dialysis_dialyszers_id,
  3889. DialysisIrrigationId: dialysis_irrigation_id,
  3890. DialysisStrainerId: dialysis_strainer_id,
  3891. }
  3892. //针对河间咸的
  3893. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3894. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3895. solution.DisplaceLiquiPart = 0
  3896. solution.DisplaceLiquiValue = 0
  3897. }
  3898. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3899. prescription.DisplaceLiquiPart = 0
  3900. prescription.DisplaceLiquiValue = 0
  3901. }
  3902. }
  3903. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3904. if solution.PrescribingNumber == 0 {
  3905. solution.PrescribingNumber = 1
  3906. }
  3907. if prescription.PrescribingNumber == 0 {
  3908. prescription.PrescribingNumber = 1
  3909. }
  3910. if solution.PrescribingNumber == 0 && id == 14682 {
  3911. solution.PrescribingNumber = 2
  3912. }
  3913. if solution.PrescribingNumber == 0 && id == 18560 {
  3914. solution.PrescribingNumber = 2
  3915. }
  3916. if prescription.PrescribingNumber == 0 && id == 14682 {
  3917. prescription.PrescribingNumber = 2
  3918. }
  3919. if prescription.PrescribingNumber == 0 && id == 18560 {
  3920. prescription.PrescribingNumber = 2
  3921. }
  3922. }
  3923. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3924. //记录日志
  3925. byterequest, _ := json.Marshal(prescription)
  3926. prescriptionLog := models.XtDialysisPrescriptionLog{
  3927. UserOrgId: prescription.UserOrgId,
  3928. Ctime: time.Now().Unix(),
  3929. Mtime: 0,
  3930. ErrLog: string(byterequest),
  3931. AdminUserId: adminUserInfo.AdminUser.Id,
  3932. RecordDate: prescription.RecordDate,
  3933. PatientId: prescription.PatientId,
  3934. Source: "手机端新增长期处方",
  3935. Status: 1,
  3936. }
  3937. service.CreatePrescriptionLog(prescriptionLog)
  3938. finish := models.XtDialysisFinish{
  3939. IsFinish: 1,
  3940. UserOrgId: adminUserInfo.Org.Id,
  3941. Status: 1,
  3942. Ctime: time.Now().Unix(),
  3943. Mtime: 0,
  3944. Module: 1,
  3945. RecordDate: recordDate.Unix(),
  3946. Sourse: 1,
  3947. PatientId: id,
  3948. }
  3949. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3950. if dialysisFinish.ID == 0 {
  3951. service.CreateDialysisFinish(finish)
  3952. }
  3953. //获取最新1条
  3954. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3955. //更新状态
  3956. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3957. //长沙南雅医院,自动生成抗凝剂的临时处方
  3958. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3959. if prescribing_number == 0 {
  3960. prescribing_number = 1
  3961. }
  3962. advice := models.DoctorAdvice{
  3963. UserOrgId: adminUserInfo.Org.Id,
  3964. PatientId: id,
  3965. GroupNo: 0,
  3966. AdviceType: 2,
  3967. RecordDate: recordDate.Unix(),
  3968. AdviceDate: recordDate.Unix(),
  3969. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3970. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3971. AdviceDesc: "",
  3972. ReminderDate: 0,
  3973. SingleDose: prescription.AnticoagulantZongliang,
  3974. SingleDoseUnit: "iu",
  3975. DrugSpec: 0,
  3976. DrugSpecUnit: "",
  3977. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3978. PrescribingNumberUnit: "支",
  3979. DeliveryWay: "静脉注射",
  3980. ExecutionFrequency: "上机前",
  3981. AdviceDoctor: 0,
  3982. Status: 1,
  3983. CreatedTime: time.Now().Unix(),
  3984. UpdatedTime: time.Now().Unix(),
  3985. IsPrescription: 1,
  3986. ExecutionState: 2,
  3987. StopState: 2,
  3988. IsSettle: 2,
  3989. }
  3990. // 查询排班信息
  3991. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3992. if schedulePatient.ID > 0 {
  3993. if schedulePatient.ScheduleType == 1 {
  3994. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3995. }
  3996. if schedulePatient.ScheduleType == 2 {
  3997. advice.StartTime = recordDate.Unix() + 9*60*60
  3998. }
  3999. }
  4000. // 抗凝剂名称
  4001. switch anticoagulant {
  4002. case 1:
  4003. advice.AdviceName = "无肝素"
  4004. break
  4005. case 2:
  4006. advice.AdviceName = "普通肝素"
  4007. break
  4008. case 3:
  4009. advice.AdviceName = "低分子肝素"
  4010. break
  4011. case 4:
  4012. advice.AdviceName = "阿加曲班"
  4013. break
  4014. case 5:
  4015. advice.AdviceName = "枸橼酸钠"
  4016. break
  4017. case 6:
  4018. advice.AdviceName = "低分子肝素钙"
  4019. break
  4020. case 7:
  4021. advice.AdviceName = "低分子肝素钠"
  4022. break
  4023. case 8:
  4024. advice.AdviceName = "依诺肝素"
  4025. break
  4026. case 9:
  4027. advice.AdviceName = "达肝素"
  4028. break
  4029. case 10:
  4030. advice.AdviceName = "体外抗凝"
  4031. break
  4032. case 11:
  4033. advice.AdviceName = "那曲肝素"
  4034. break
  4035. case 12:
  4036. advice.AdviceName = "无抗凝剂"
  4037. break
  4038. }
  4039. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4040. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4041. advice.AdviceDoctor = appRole.AdminUserId
  4042. }
  4043. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4044. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4045. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4046. advice.AdviceName = "低分子肝素钠注射液"
  4047. // 修改患者临时医嘱里的抗凝剂医嘱
  4048. advice.ID = advicePrescription.ID
  4049. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4050. } else {
  4051. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4052. advice.AdviceName = "低分子肝素钠注射液"
  4053. service.CreateDoctorAdvice(&advice)
  4054. }
  4055. }
  4056. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4057. redis := service.RedisClient()
  4058. defer redis.Close()
  4059. //清空key 值
  4060. redis.Set(key, "", time.Second)
  4061. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4062. redis.Set(keyOne, "", time.Second)
  4063. }
  4064. //获取key,清空redis
  4065. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4066. redis := service.RedisClient()
  4067. defer redis.Close()
  4068. //清空key 值
  4069. redis.Set(key, "", time.Second)
  4070. //清空长期医嘱的key
  4071. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4072. redis.Set(soulution_key, "", time.Second)
  4073. //查询最近透析准备表里是否存在 透析器 灌流器
  4074. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4075. redis.Set(keyOne, "", time.Second)
  4076. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4077. redis.Set(keyTwo, "", time.Second)
  4078. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4079. redis.Set(keyThree, "", time.Second)
  4080. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4081. redis.Set(keyFour, "", time.Second)
  4082. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4083. //
  4084. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4085. //
  4086. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4087. //if len(mation)>0{
  4088. // for _, item := range splitStr {
  4089. // for _,it := range mation{
  4090. // if(item == it.SpecificationName){
  4091. //
  4092. // //查询最近一次的透析器
  4093. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4094. //
  4095. // if errcode == gorm.ErrRecordNotFound{
  4096. // //插入数据
  4097. // prepare := models.DialysisBeforePrepare{
  4098. // UserOrgId: adminUserInfo.Org.Id,
  4099. // PatientId: id,
  4100. // RecordDate: recordDate.Unix(),
  4101. // GoodTypeId: it.GoodTypeId,
  4102. // GoodId: it.ID,
  4103. // Count: 1,
  4104. // Ctime: time.Now().Unix(),
  4105. // Creater: adminUserInfo.AdminUser.Id,
  4106. // Status:1,
  4107. //
  4108. // }
  4109. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4110. // fmt.Println("",errcode)
  4111. // }
  4112. // }
  4113. // }
  4114. //
  4115. // }
  4116. //
  4117. // for _, item := range splitIrrigation {
  4118. // for _,it := range mation{
  4119. // if(item == it.SpecificationName){
  4120. // //查询最近一次的透析器
  4121. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4122. // if errcode == gorm.ErrRecordNotFound{
  4123. // //插入数据
  4124. // prepare := models.DialysisBeforePrepare{
  4125. // UserOrgId: adminUserInfo.Org.Id,
  4126. // PatientId: id,
  4127. // RecordDate: recordDate.Unix(),
  4128. // GoodTypeId: it.GoodTypeId,
  4129. // GoodId: it.ID,
  4130. // Count: 1,
  4131. // Ctime: time.Now().Unix(),
  4132. // Creater: adminUserInfo.AdminUser.Id,
  4133. // Status:1,
  4134. //
  4135. // }
  4136. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4137. // fmt.Println(errcode)
  4138. // }
  4139. // }
  4140. // }
  4141. // }
  4142. //}
  4143. c.ServeSuccessJSON(map[string]interface{}{
  4144. "solution": &solution,
  4145. "prescription": &prescription,
  4146. })
  4147. }
  4148. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4149. patient, _ := c.GetInt64("patient", 0)
  4150. adminUserInfo := c.GetMobileAdminUserInfo()
  4151. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4152. c.ServeSuccessJSON(map[string]interface{}{
  4153. "receiveTreatmentAsses": receiveTreatmentAsses,
  4154. })
  4155. }
  4156. func (this *DialysisAPIController) PostSignInfo() {
  4157. patientID, _ := this.GetInt64("patient_id")
  4158. recordDateStr := this.GetString("date")
  4159. if patientID <= 0 {
  4160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4161. return
  4162. }
  4163. if len(recordDateStr) == 0 {
  4164. recordDateStr = time.Now().Format("2006-01-02")
  4165. }
  4166. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4167. if parseDateErr != nil {
  4168. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4169. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4170. return
  4171. }
  4172. adminInfo := this.GetMobileAdminUserInfo()
  4173. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4174. if err != nil {
  4175. this.ErrorLog("签名失败:%v", err)
  4176. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4177. return
  4178. }
  4179. this.ServeSuccessJSON(map[string]interface{}{
  4180. "doctor_id": adminInfo.AdminUser.Id,
  4181. })
  4182. }
  4183. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4184. patientID, _ := this.GetInt64("patient_id")
  4185. adminInfo := this.GetMobileAdminUserInfo()
  4186. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4187. this.ServeSuccessJSON(map[string]interface{}{
  4188. "monitor": record,
  4189. })
  4190. }
  4191. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4192. thisTime := time.Now()
  4193. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4194. timeLayout := "2006-01-02 15:04:05"
  4195. loc, _ := time.LoadLocation("Local")
  4196. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4197. theAssessmentDateTime := theStartTime.Unix()
  4198. patientID, _ := this.GetInt64("patient_id")
  4199. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4200. adminInfo := this.GetMobileAdminUserInfo()
  4201. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4202. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4203. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4204. var ultrafiltration_rate float64
  4205. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4206. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4207. fmt.Println(evaluation)
  4208. fmt.Println("prescription.ID", prescription.ID)
  4209. if prescription.ID > 0 {
  4210. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4211. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4212. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4213. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4214. record.UltrafiltrationRate = ultrafiltration_rate
  4215. }
  4216. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4217. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4218. record.UltrafiltrationRate = ultrafiltration_rate
  4219. }
  4220. if adminInfo.Org.Id == 10510 {
  4221. record.UltrafiltrationRate = 0
  4222. }
  4223. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4224. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4225. record.UltrafiltrationRate = ultrafiltration_rate
  4226. }
  4227. if template.TemplateId == 20 || template.TemplateId == 22 {
  4228. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4229. record.UltrafiltrationRate = ultrafiltration_rate
  4230. }
  4231. // 只针对方济医院
  4232. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4233. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4234. ultrafiltration_rate = value
  4235. record.UltrafiltrationRate = ultrafiltration_rate
  4236. }
  4237. if template.TemplateId == 41 || template.TemplateId == 47 {
  4238. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4239. record.UltrafiltrationRate = ultrafiltration_rate
  4240. }
  4241. if template.TemplateId == 43 {
  4242. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4243. record.UltrafiltrationRate = ultrafiltration_rate
  4244. }
  4245. if template.TemplateId == 46 || template.TemplateId == 54 {
  4246. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4247. record.UltrafiltrationRate = ultrafiltration_rate
  4248. }
  4249. 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 {
  4250. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4251. record.UltrafiltrationRate = ultrafiltration_rate
  4252. }
  4253. if adminInfo.Org.Id == 10469 {
  4254. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4255. record.UltrafiltrationRate = ultrafiltration_rate
  4256. }
  4257. if adminInfo.Org.Id == 10667 {
  4258. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4259. record.UltrafiltrationRate = ultrafiltration_rate
  4260. }
  4261. if adminInfo.Org.Id == 10471 {
  4262. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4263. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4264. }
  4265. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4266. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4267. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4268. }
  4269. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4270. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4271. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4272. }
  4273. if adminInfo.Org.Id == 10721 {
  4274. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4275. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4276. }
  4277. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4278. record.UltrafiltrationRate = 0
  4279. }
  4280. //if template.TemplateId == 47 {
  4281. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4282. // record.UltrafiltrationRate = ultrafiltration_rate
  4283. //}
  4284. }
  4285. }
  4286. // record.UltrafiltrationRate = ultrafiltration_rate
  4287. record.UltrafiltrationVolume = 0
  4288. 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
  4289. if ultrafiltration_rate > 0 {
  4290. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4291. record.UltrafiltrationVolume = value
  4292. }
  4293. }
  4294. 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
  4295. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4296. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4297. record.UltrafiltrationVolume = ultrafiltration_volume
  4298. }
  4299. }
  4300. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4301. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4302. record.UltrafiltrationVolume = ultrafiltration_volume
  4303. }
  4304. //长沙南雅
  4305. 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 {
  4306. if ultrafiltration_rate > 0 {
  4307. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4308. record.UltrafiltrationVolume = ultrafiltration_volume
  4309. }
  4310. }
  4311. if adminInfo.Org.Id == 10471 {
  4312. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4313. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4314. }
  4315. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4316. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4317. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4318. }
  4319. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4320. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4321. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4322. }
  4323. //长沙南雅累计血容量自动计算
  4324. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4325. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4326. //}
  4327. if template.TemplateId == 47 || template.TemplateId == 54 {
  4328. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4329. }
  4330. if adminInfo.Org.Id == 10510 {
  4331. record.UltrafiltrationVolume = 0
  4332. }
  4333. if adminInfo.Org.Id == 10721 {
  4334. if ultrafiltration_rate > 0 {
  4335. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4336. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4337. }
  4338. }
  4339. if adminInfo.Org.Id == 10721 {
  4340. var replacement_rate float64
  4341. var displacement_quantity float64
  4342. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4343. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4344. fmt.Println("replacement_rate-----------------", replacement_rate)
  4345. record.ReplacementRate = replacement_rate
  4346. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4347. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4348. fmt.Println("displacement_quantity-----------------", displacement_quantity)
  4349. record.DisplacementQuantity = displacement_quantity
  4350. }
  4351. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4352. this.ServeSuccessJSON(map[string]interface{}{
  4353. "monitor": record,
  4354. "lastMonitorRecordList": lastMonitorRecordList,
  4355. })
  4356. }
  4357. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4358. record_id, _ := this.GetInt64("id")
  4359. nurseID, _ := this.GetInt64("start_nurse")
  4360. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4361. bedID, _ := this.GetInt64("bed")
  4362. start_time := this.GetString("start_time")
  4363. schedual_type, _ := this.GetInt64("schedual_type")
  4364. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4365. change_nurse, _ := this.GetInt64("change_nurse")
  4366. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4367. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4368. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4369. patient_id, _ := this.GetInt64("patient_id")
  4370. record_date, _ := this.GetInt64("record_date")
  4371. puncture_needle := this.GetString("puncture_needle")
  4372. puncture_way := this.GetString("puncture_way")
  4373. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4374. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4375. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4376. nuclein_date_str := this.GetString("nuclein_date_str")
  4377. order_remark := this.GetString("order_remark")
  4378. schedule_remark := this.GetString("schedule_remark")
  4379. catheter_operation := this.GetString("catheter_operation")
  4380. blood_flow_volume := this.GetString("blood_flow_volume")
  4381. blood_drawing, _ := this.GetInt64("blood_drawing")
  4382. dialysis_strainer := this.GetString("dialysis_strainer")
  4383. if record_id == 0 {
  4384. this.ErrorLog("id:%v", record_id)
  4385. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4386. return
  4387. }
  4388. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4389. if parseStartDateErr != nil {
  4390. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4392. return
  4393. }
  4394. adminUserInfo := this.GetMobileAdminUserInfo()
  4395. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4396. if getNurseErr != nil {
  4397. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4399. return
  4400. } else if nurse == nil {
  4401. this.ErrorLog("护士不存在")
  4402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4403. return
  4404. }
  4405. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4406. //if getNurseErr != nil {
  4407. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4408. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4409. // return
  4410. //} else if nurse == nil {
  4411. // this.ErrorLog("护士不存在")
  4412. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4413. // return
  4414. //}
  4415. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4416. if getDeviceNumberErr != nil {
  4417. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4419. return
  4420. } else if deviceNumber == nil {
  4421. this.ErrorLog("床位号不存在")
  4422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4423. return
  4424. }
  4425. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4426. //
  4427. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4428. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4429. // if getPermissionErr != nil {
  4430. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4431. // return
  4432. // } else if headNursePermission == nil {
  4433. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4434. // return
  4435. // }
  4436. //}
  4437. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4438. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4439. timeLayout := "2006-01-02 15:04:05"
  4440. loc, _ := time.LoadLocation("Local")
  4441. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4442. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4443. schedulestartTime := theStartTime.Unix()
  4444. scheduleendTime := theEndTime.Unix()
  4445. var theNucleinDate int64
  4446. timeLayoutOne := "2006-01-02"
  4447. if len(nuclein_date_str) > 0 {
  4448. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4449. if err != nil {
  4450. utils.ErrorLog(err.Error())
  4451. }
  4452. theNucleinDate = theTime.Unix()
  4453. }
  4454. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4455. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4456. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4457. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4458. if err == gorm.ErrRecordNotFound { //空床位
  4459. // 修改了床位逻辑
  4460. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4461. if daySchedule.ID > 0 {
  4462. //daySchedule.BedId = bedID
  4463. //daySchedule.PartitionId = deviceNumber.ZoneID
  4464. //daySchedule.ScheduleType = schedual_type
  4465. //daySchedule.UpdatedTime = time.Now().Unix()
  4466. //err := service.UpdateSchedule(&daySchedule)
  4467. xtSchedule := models.Schedule{
  4468. PartitionId: deviceNumber.ZoneID,
  4469. BedId: bedID,
  4470. ScheduleType: schedual_type,
  4471. UpdatedTime: time.Now().Unix(),
  4472. }
  4473. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4474. if err != nil {
  4475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4476. return
  4477. }
  4478. }
  4479. } else if err == nil {
  4480. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4481. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4482. if daySchedule.ID > 0 {
  4483. //daySchedule.BedId = bedID
  4484. //daySchedule.PartitionId = deviceNumber.ZoneID
  4485. //
  4486. //daySchedule.ScheduleType = schedual_type
  4487. //daySchedule.UpdatedTime = time.Now().Unix()
  4488. //err := service.UpdateSchedule(&daySchedule)
  4489. xtSchedule := models.Schedule{
  4490. PartitionId: deviceNumber.ZoneID,
  4491. BedId: bedID,
  4492. ScheduleType: schedual_type,
  4493. UpdatedTime: time.Now().Unix(),
  4494. }
  4495. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4496. if err != nil {
  4497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4498. return
  4499. }
  4500. }
  4501. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4503. return
  4504. }
  4505. } else if err != nil {
  4506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4507. return
  4508. }
  4509. }
  4510. dialysisRecord := &models.DialysisOrder{
  4511. ID: record_id,
  4512. UserOrgId: adminUserInfo.Org.Id,
  4513. BedID: bedID,
  4514. StartNurse: nurseID,
  4515. StartTime: startDate.Unix(),
  4516. PunctureNurse: puncture_nurse,
  4517. Creator: adminUserInfo.AdminUser.Id,
  4518. Modifier: adminUserInfo.AdminUser.Id,
  4519. WashpipeNurse: washpipe_nurse,
  4520. SchedualType: schedual_type,
  4521. ChangeNurse: change_nurse,
  4522. DifficultPunctureNurse: difficult_puncture_nurse,
  4523. NewFistulaNurse: new_fistula_nurse,
  4524. QualityNurseId: quality_nurse_id,
  4525. PunctureNeedle: puncture_needle,
  4526. PunctureWay: puncture_way,
  4527. DialysisDialyszers: dialysis_dialyszers,
  4528. DialysisIrrigation: dialysis_irrigation,
  4529. BloodAccessId: blood_access_id,
  4530. NucleinDate: theNucleinDate,
  4531. OrderRemark: order_remark,
  4532. ScheduleRemark: schedule_remark,
  4533. CatheterOperation: catheter_operation,
  4534. BloodFlowVolume: blood_flow_volume,
  4535. BloodDrawing: blood_drawing,
  4536. DialysisStrainer: dialysis_strainer,
  4537. }
  4538. //修改床位号需要重新消毒
  4539. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4540. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4541. //查询第一条监测
  4542. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4543. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4544. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4545. redis := service.RedisClient()
  4546. //清空key 值
  4547. redis.Set(key, "", time.Second)
  4548. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4549. redis.Set(keyOne, "", time.Second)
  4550. defer redis.Close()
  4551. }
  4552. // 查询信息规挡的设置天数
  4553. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4554. if infor.ID > 0 && infor.WeekDay > 0 {
  4555. var cha_time int64
  4556. timeNowStr := time.Now().Format("2006-01-02")
  4557. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4558. //今日的日期减去设置的日期
  4559. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4560. if cha_time >= record_date {
  4561. //查询审核是否允许
  4562. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4563. //申请状态不允许的情况 拒绝修改
  4564. if infor.ApplicationStatus != 1 {
  4565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4566. return
  4567. }
  4568. }
  4569. }
  4570. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4571. //修改床位后重新生成消毒计划
  4572. if adminUserInfo.Org.Id == 10340 {
  4573. //根据床位号获取设备型号
  4574. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4575. //查询使用消毒最后一条消毒记录
  4576. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4577. fmt.Println("err", err)
  4578. if err == gorm.ErrRecordNotFound {
  4579. //查找排班
  4580. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4581. //查询改设备是否有消毒计划
  4582. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4583. //根据床位号获取设备id
  4584. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4585. //查询病人信息
  4586. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4587. var con = ""
  4588. if patients.IsInfectious == 0 {
  4589. con = ""
  4590. }
  4591. if patients.IsInfectious == 1 {
  4592. con = "无"
  4593. }
  4594. if patients.IsInfectious == 2 {
  4595. con = "有"
  4596. }
  4597. if errcode == nil {
  4598. var end_time int64
  4599. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4600. //新增消毒
  4601. information := models.DeviceInformation{
  4602. Date: dialysisRecord.DialysisDate,
  4603. Zone: dialysisRecord.ZoneId,
  4604. Class: dialysisRecord.SchedualType,
  4605. BedNumber: dialysisRecord.BedID,
  4606. PatientId: dialysisRecord.PatientId,
  4607. DialysisMode: scheduleByPatient.ModeId,
  4608. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4609. Disinfection: 1,
  4610. DialysisConcentration: 1,
  4611. DisinfectionStatus: 1,
  4612. Move: 1,
  4613. UserOrgId: dialysisRecord.UserOrgId,
  4614. DisinfectType: plan.Way,
  4615. DisinfectantType: plan.MachineDisinfectant,
  4616. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4617. Disinfectant: plan.Disinfectant,
  4618. Ctime: time.Now().Unix(),
  4619. Status: 1,
  4620. SignName: nurseID,
  4621. EquimentId: addmacher.ID,
  4622. DisinfectionResidue: 2,
  4623. Bed: addmacher.BedNumber,
  4624. StartTime: dialysisRecord.StartTime,
  4625. EndTime: dialysisRecord.EndTime,
  4626. Contagion: con,
  4627. WeightLoss: 0,
  4628. Hyperfiltratio: 0,
  4629. DialysisHour: "",
  4630. MachineRun: 1,
  4631. DisinfecStartime: dialysisRecord.EndTime,
  4632. DisinfecEndtime: end_time,
  4633. }
  4634. err := service.CreateInformationTwo(&information)
  4635. fmt.Println("报错", err)
  4636. }
  4637. }
  4638. }
  4639. order, _ := service.GetLastPatientOrder(record_id)
  4640. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4641. redis := service.RedisClient()
  4642. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4643. redis.Set(key, "", time.Second)
  4644. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4645. //清空key 值
  4646. redis.Set(keyOne, "", time.Second)
  4647. scheduleDateStartOne := startDate.Format("2006-01-02")
  4648. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4649. redis.Set(keyTwo, "", time.Second)
  4650. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4651. redis.Set(keyThree, "", time.Second)
  4652. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4653. redis.Set(keyFour, "", time.Second)
  4654. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4655. redis.Set(keyFive, "", time.Second)
  4656. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4657. redis.Set(keySix, "", time.Second)
  4658. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4659. redis.Set(keySeven, "", time.Second)
  4660. if updateErr != nil {
  4661. this.ErrorLog("修改上机失败:%v", updateErr)
  4662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4663. return
  4664. }
  4665. if updateErr == nil {
  4666. if tempDialysisRecord.Stage == 2 {
  4667. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4668. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4669. fmt.Println(value)
  4670. a, b := math.Modf(value)
  4671. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4672. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4673. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4674. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4675. redis := service.RedisClient()
  4676. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4677. redis.Set(key, "", time.Second)
  4678. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4679. redis.Set(keyOne, "", time.Second)
  4680. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4681. //清空key 值
  4682. redis.Set(keySix, "", time.Second)
  4683. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4684. redis.Set(keySeven, "", time.Second)
  4685. redis.Close()
  4686. if updateAssessmentErr != nil {
  4687. utils.ErrorLog("%v", updateAssessmentErr)
  4688. }
  4689. }
  4690. }
  4691. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4692. this.ServeSuccessJSON(map[string]interface{}{
  4693. "dialysis_order": dialysisRecords,
  4694. })
  4695. }
  4696. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4697. record_id, _ := c.GetInt64("id")
  4698. nurseID, _ := c.GetInt64("nurse")
  4699. end_time := c.GetString("end_time")
  4700. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4701. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4702. catheter := c.GetString("catheter")
  4703. cruor := c.GetString("cruor")
  4704. mission := c.GetString("mission")
  4705. condenser := c.GetString("condenser")
  4706. if record_id <= 0 || nurseID <= 0 {
  4707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4708. return
  4709. }
  4710. adminUserInfo := c.GetMobileAdminUserInfo()
  4711. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4712. if getNurseErr != nil {
  4713. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4715. return
  4716. } else if nurse == nil {
  4717. c.ErrorLog("护士不存在")
  4718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4719. return
  4720. }
  4721. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4722. if parseEndDateErr != nil {
  4723. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4725. return
  4726. }
  4727. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4728. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4729. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4730. // if getPermissionErr != nil {
  4731. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4732. // return
  4733. // } else if headNursePermission == nil {
  4734. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4735. // return
  4736. // }
  4737. //}
  4738. // 查询信息规挡的设置天数
  4739. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4740. if infor.ID > 0 {
  4741. var cha_time int64
  4742. timeNowStr := time.Now().Format("2006-01-02")
  4743. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4744. //今日的日期减去设置的日期
  4745. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4746. if cha_time >= tempDialysisRecords.DialysisDate {
  4747. //查询审核是否允许
  4748. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4749. //申请状态不允许的情况 拒绝修改
  4750. if infor.ApplicationStatus != 1 {
  4751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4752. return
  4753. }
  4754. }
  4755. }
  4756. dialysisRecord := &models.DialysisOrder{
  4757. ID: record_id,
  4758. UserOrgId: adminUserInfo.Org.Id,
  4759. EndTime: endDate.Unix(),
  4760. FinishNurse: nurseID,
  4761. FinishModifier: adminUserInfo.AdminUser.Id,
  4762. PuncturePointHaematoma: puncture_point_haematoma,
  4763. BloodAccessInternalFistula: blood_access_internal_fistula,
  4764. Catheter: catheter,
  4765. Cruor: cruor,
  4766. Mission: mission,
  4767. Condenser: condenser,
  4768. }
  4769. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4770. redis := service.RedisClient()
  4771. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4772. //清空key 值
  4773. redis.Set(key, "", time.Second)
  4774. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4775. //清空key 值
  4776. redis.Set(keyOne, "", time.Second)
  4777. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4778. redis.Set(keySeven, "", time.Second)
  4779. redis.Close()
  4780. if updateErr != nil {
  4781. c.ErrorLog("修改下机失败:%v", updateErr)
  4782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4783. return
  4784. }
  4785. if updateErr == nil {
  4786. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4787. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4788. a, b := math.Modf(value)
  4789. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4790. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4791. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4792. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4793. redis := service.RedisClient()
  4794. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4795. redis.Set(keyTen, "", time.Second)
  4796. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4797. redis.Set(keyTwo, "", time.Second)
  4798. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4799. redis.Set(key, "", time.Second)
  4800. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4801. redis.Set(keyThree, "", time.Second)
  4802. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4803. redis.Set(keySeven, "", time.Second)
  4804. defer redis.Close()
  4805. if updateAssessmentErr != nil {
  4806. utils.ErrorLog("%v", updateAssessmentErr)
  4807. }
  4808. }
  4809. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4810. c.ServeSuccessJSON(map[string]interface{}{
  4811. "dialysis_order": dialysisRecords,
  4812. })
  4813. }
  4814. func (c *DialysisAPIController) GetLongAdvice() {
  4815. patient_id, _ := c.GetInt64("id")
  4816. adminUserInfo := c.GetMobileAdminUserInfo()
  4817. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4818. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4819. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4820. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4821. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4822. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4823. c.ServeSuccessJSON(map[string]interface{}{
  4824. "status": "1",
  4825. })
  4826. return
  4827. } else { //开启推送提醒
  4828. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4829. var advice_three []*models.DoctorAdvice
  4830. recordDateStr := time.Now().Format("2006-01-02")
  4831. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4832. nowtime := recordDate.Unix()
  4833. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4834. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4835. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4836. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4837. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4838. for _, advice := range advices {
  4839. if advice.FrequencyType == 3 {
  4840. t := time.Now()
  4841. week := int(t.Weekday())
  4842. fmt.Println(t.Weekday())
  4843. fmt.Println(week)
  4844. switch week {
  4845. case 1:
  4846. if strings.Index(advice.WeekDay, "周一") == -1 {
  4847. advice_three = append(advice_three, advice)
  4848. }
  4849. break
  4850. case 2:
  4851. if strings.Index(advice.WeekDay, "周二") == -1 {
  4852. advice_three = append(advice_three, advice)
  4853. }
  4854. break
  4855. case 3:
  4856. if strings.Index(advice.WeekDay, "周三") == -1 {
  4857. advice_three = append(advice_three, advice)
  4858. }
  4859. break
  4860. case 4:
  4861. if strings.Index(advice.WeekDay, "周四") == -1 {
  4862. advice_three = append(advice_three, advice)
  4863. }
  4864. break
  4865. case 5:
  4866. if strings.Index(advice.WeekDay, "周五") == -1 {
  4867. advice_three = append(advice_three, advice)
  4868. }
  4869. break
  4870. case 6:
  4871. if strings.Index(advice.WeekDay, "周六") == -1 {
  4872. advice_three = append(advice_three, advice)
  4873. }
  4874. break
  4875. case 0:
  4876. if strings.Index(advice.WeekDay, "周日") == -1 {
  4877. advice_three = append(advice_three, advice)
  4878. }
  4879. break
  4880. }
  4881. }
  4882. }
  4883. for _, advice := range advices_two {
  4884. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4885. now := p.Unix()
  4886. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4887. dayStr2 := "-" + dayStr
  4888. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4889. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4890. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4891. for _, ad := range advices {
  4892. advice_three = append(advice_three, ad)
  4893. }
  4894. }
  4895. if err == nil {
  4896. c.ServeSuccessJSON(map[string]interface{}{
  4897. "status": "2",
  4898. "advices": advices,
  4899. "advices_two": RemoveRepeatedElement(advice_three),
  4900. "is_open_remind": config.IsOpenRemind,
  4901. "his_config_open": hisConfig.IsOpen,
  4902. "is_advice_open": is_advice_open.IsAdviceOpen,
  4903. "prescription_open": prescription_open.IsOpen,
  4904. })
  4905. }
  4906. }
  4907. }
  4908. func (c *DialysisAPIController) GetLongAdviceOne() {
  4909. patient_id, _ := c.GetInt64("id")
  4910. startTime := c.GetString("schedule_date")
  4911. timeLayout := "2006-01-02"
  4912. loc, _ := time.LoadLocation("Local")
  4913. var theStartTime int64
  4914. if len(startTime) > 0 {
  4915. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4916. if err != nil {
  4917. utils.ErrorLog(err.Error())
  4918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4919. return
  4920. }
  4921. theStartTime = theTime.Unix()
  4922. }
  4923. adminUserInfo := c.GetMobileAdminUserInfo()
  4924. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4925. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4926. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4927. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4928. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4929. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4930. c.ServeSuccessJSON(map[string]interface{}{
  4931. "status": "1",
  4932. })
  4933. return
  4934. } else { //开启推送提醒
  4935. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4936. var advice_three []*models.DoctorAdvice
  4937. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4938. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4939. for _, advice := range advices {
  4940. if advice.FrequencyType == 3 {
  4941. t := time.Now()
  4942. week := int(t.Weekday())
  4943. fmt.Println(t.Weekday())
  4944. fmt.Println(week)
  4945. switch week {
  4946. case 1:
  4947. if strings.Index(advice.WeekDay, "周一") == -1 {
  4948. advice_three = append(advice_three, advice)
  4949. }
  4950. break
  4951. case 2:
  4952. if strings.Index(advice.WeekDay, "周二") == -1 {
  4953. advice_three = append(advice_three, advice)
  4954. }
  4955. break
  4956. case 3:
  4957. if strings.Index(advice.WeekDay, "周三") == -1 {
  4958. advice_three = append(advice_three, advice)
  4959. }
  4960. break
  4961. case 4:
  4962. if strings.Index(advice.WeekDay, "周四") == -1 {
  4963. advice_three = append(advice_three, advice)
  4964. }
  4965. break
  4966. case 5:
  4967. if strings.Index(advice.WeekDay, "周五") == -1 {
  4968. advice_three = append(advice_three, advice)
  4969. }
  4970. break
  4971. case 6:
  4972. if strings.Index(advice.WeekDay, "周六") == -1 {
  4973. advice_three = append(advice_three, advice)
  4974. }
  4975. break
  4976. case 0:
  4977. if strings.Index(advice.WeekDay, "周日") == -1 {
  4978. advice_three = append(advice_three, advice)
  4979. }
  4980. break
  4981. }
  4982. }
  4983. }
  4984. for _, advice := range advices_two {
  4985. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4986. now := p.Unix()
  4987. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4988. dayStr2 := "-" + dayStr
  4989. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4990. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4991. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4992. for _, ad := range advices {
  4993. advice_three = append(advice_three, ad)
  4994. }
  4995. }
  4996. if err == nil {
  4997. c.ServeSuccessJSON(map[string]interface{}{
  4998. "status": "2",
  4999. "advices": advices,
  5000. "advices_two": RemoveRepeatedElement(advice_three),
  5001. "is_open_remind": config.IsOpenRemind,
  5002. "his_config_open": hisConfig.IsOpen,
  5003. "is_advice_open": is_advice_open.IsAdviceOpen,
  5004. "prescription_open": prescription_open.IsOpen,
  5005. })
  5006. }
  5007. }
  5008. }
  5009. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5010. newArr = make([]*models.DoctorAdvice, 0)
  5011. for i := 0; i < len(arr); i++ {
  5012. repeat := false
  5013. for j := i + 1; j < len(arr); j++ {
  5014. if arr[i].ID == arr[j].ID {
  5015. repeat = true
  5016. break
  5017. }
  5018. }
  5019. if !repeat {
  5020. newArr = append(newArr, arr[i])
  5021. }
  5022. }
  5023. return
  5024. }
  5025. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5026. patient, _ := c.GetInt64("id", 0)
  5027. groupNo, _ := c.GetInt64("groupno", 0)
  5028. if patient <= 0 {
  5029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5030. return
  5031. }
  5032. adminUserInfo := c.GetMobileAdminUserInfo()
  5033. dataBody := make(map[string]interface{}, 0)
  5034. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5035. if err != nil {
  5036. utils.ErrorLog(err.Error())
  5037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5038. return
  5039. }
  5040. utils.ErrorLog("%v", dataBody)
  5041. timeLayout := "2006-01-02 15:04"
  5042. loc, _ := time.LoadLocation("Local")
  5043. timeLayout2 := "2006-01-02"
  5044. loc2, _ := time.LoadLocation("Local")
  5045. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5046. utils.ErrorLog("advice_type")
  5047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5048. return
  5049. }
  5050. adviceType := int64(2)
  5051. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5052. utils.ErrorLog("advice_date")
  5053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5054. return
  5055. }
  5056. adviceDate, _ := dataBody["advice_date"].(string)
  5057. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5058. AdviceDate := theTime.Unix()
  5059. RecordDate := theTime.Unix()
  5060. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5061. utils.ErrorLog("start_time")
  5062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5063. return
  5064. }
  5065. startTime, _ := dataBody["start_time"].(string)
  5066. if len(startTime) == 0 {
  5067. utils.ErrorLog("len(start_time) == 0")
  5068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5069. return
  5070. }
  5071. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5072. if err != nil {
  5073. utils.ErrorLog(err.Error())
  5074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5075. return
  5076. }
  5077. StartTime := theTime.Unix()
  5078. Remark := ""
  5079. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5080. remark, _ := dataBody["remark"].(string)
  5081. Remark = remark
  5082. }
  5083. var advices []*models.GroupAdvice
  5084. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5085. utils.ErrorLog("advices")
  5086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5087. return
  5088. }
  5089. adviceNames := dataBody["advices"].([]interface{})
  5090. for _, adviceNameMap := range adviceNames {
  5091. adviceNameM := adviceNameMap.(map[string]interface{})
  5092. var advice models.GroupAdvice
  5093. advice.Remark = Remark
  5094. advice.AdviceType = adviceType
  5095. advice.StartTime = StartTime
  5096. advice.AdviceDate = AdviceDate
  5097. advice.RecordDate = RecordDate
  5098. advice.Status = 1
  5099. advice.CreatedTime = time.Now().Unix()
  5100. advice.UpdatedTime = time.Now().Unix()
  5101. advice.StopState = 2
  5102. advice.ExecutionState = 2
  5103. advice.UserOrgId = adminUserInfo.Org.Id
  5104. advice.PatientId = patient
  5105. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5106. advice.IsSettle = 2
  5107. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5108. utils.ErrorLog("advice_name")
  5109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5110. return
  5111. }
  5112. adviceName, _ := adviceNameM["advice_name"].(string)
  5113. if len(adviceName) == 0 {
  5114. utils.ErrorLog("len(advice_name) == 0")
  5115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5116. return
  5117. }
  5118. advice.AdviceName = adviceName
  5119. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5120. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5121. advice.DrugSpec = drugSpec
  5122. }
  5123. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5124. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5125. advice.AdviceDesc = adviceDesc
  5126. }
  5127. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5128. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5129. advice.DrugSpecUnit = drugSpecUnit
  5130. }
  5131. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5132. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5133. // advice.SingleDose = singleDose
  5134. //}
  5135. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5136. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5137. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5138. }
  5139. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5140. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5141. advice.SingleDoseUnit = singleDoseUnit
  5142. }
  5143. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5144. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5145. // advice.PrescribingNumber = prescribingNumber
  5146. //}
  5147. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5148. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5149. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5150. }
  5151. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5152. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5153. advice.PrescribingNumberUnit = prescribingNumberUnit
  5154. }
  5155. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5156. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5157. advice.DeliveryWay = deliveryWay
  5158. }
  5159. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5160. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5161. advice.ExecutionFrequency = executionFrequency
  5162. }
  5163. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5164. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5165. advice.FrequencyType = frequency_type
  5166. }
  5167. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5168. day_count := int64(adviceNameM["day_count"].(float64))
  5169. advice.DayCount = day_count
  5170. }
  5171. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5172. week_day, _ := adviceNameM["week_day"].(string)
  5173. advice.WeekDay = week_day
  5174. }
  5175. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5176. way := int64(adviceNameM["way"].(float64))
  5177. advice.Way = way
  5178. }
  5179. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5180. drug_id := int64(adviceNameM["drug_id"].(float64))
  5181. advice.DrugId = drug_id
  5182. }
  5183. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5184. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5185. advice.DrugNameId = drug_name_id
  5186. }
  5187. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5188. remark, _ := adviceNameM["remark"].(string)
  5189. advice.Remark = remark
  5190. }
  5191. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5192. groupno := int64(adviceNameM["groupno"].(float64))
  5193. advice.GroupNo = groupno
  5194. }
  5195. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5196. template_id, _ := adviceNameM["template_id"].(string)
  5197. advice.TemplateId = template_id
  5198. }
  5199. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5200. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5201. advice.ExecutionFrequency = executionFrequency
  5202. }
  5203. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5204. children := adviceNameM["child"].([]interface{})
  5205. if len(children) > 0 {
  5206. for _, childrenMap := range children {
  5207. childMap := childrenMap.(map[string]interface{})
  5208. var child models.GroupAdvice
  5209. child.Remark = Remark
  5210. child.AdviceType = adviceType
  5211. child.StartTime = StartTime
  5212. child.AdviceDate = AdviceDate
  5213. child.RecordDate = RecordDate
  5214. child.Status = 1
  5215. child.CreatedTime = time.Now().Unix()
  5216. child.UpdatedTime = time.Now().Unix()
  5217. child.StopState = 2
  5218. child.ExecutionState = 2
  5219. child.UserOrgId = adminUserInfo.Org.Id
  5220. child.PatientId = patient
  5221. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5222. child.IsSettle = 1
  5223. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5224. utils.ErrorLog("child advice_name")
  5225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5226. return
  5227. }
  5228. childAdviceName, _ := childMap["advice_name"].(string)
  5229. if len(childAdviceName) == 0 {
  5230. utils.ErrorLog("len(child advice_name) == 0")
  5231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5232. return
  5233. }
  5234. child.AdviceName = childAdviceName
  5235. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5236. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5237. child.AdviceDesc = childAdviceDesc
  5238. }
  5239. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5240. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5241. child.DrugSpec = childDrugSpec
  5242. }
  5243. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5244. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5245. child.DrugSpecUnit = childDrugSpecUnit
  5246. }
  5247. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5248. child.SingleDose = childMap["single_dose"].(float64)
  5249. }
  5250. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5251. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5252. child.SingleDoseUnit = childSingleDoseUnit
  5253. }
  5254. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5255. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5256. }
  5257. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5258. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5259. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5260. }
  5261. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5262. groupno := int64(childMap["groupno"].(float64))
  5263. advice.GroupNo = groupno
  5264. }
  5265. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5266. remark, _ := childMap["remark"].(string)
  5267. child.Remark = remark
  5268. }
  5269. child.DeliveryWay = advice.DeliveryWay
  5270. child.ExecutionFrequency = advice.ExecutionFrequency
  5271. advice.Children = append(advice.Children, &child)
  5272. }
  5273. }
  5274. }
  5275. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5276. if temp_advice.ID == 0 {
  5277. advices = append(advices, &advice)
  5278. }
  5279. }
  5280. if len(advices) > 0 {
  5281. finish := models.XtDialysisFinish{
  5282. IsFinish: 1,
  5283. UserOrgId: adminUserInfo.Org.Id,
  5284. Status: 1,
  5285. Ctime: time.Now().Unix(),
  5286. Mtime: 0,
  5287. Module: 4,
  5288. RecordDate: AdviceDate,
  5289. Sourse: 1,
  5290. PatientId: patient,
  5291. }
  5292. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5293. if dialysisFinish.ID == 0 {
  5294. service.CreateDialysisFinish(finish)
  5295. }
  5296. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5297. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5298. for _, item := range advices {
  5299. byterequest, _ := json.Marshal(item)
  5300. adviceLog := models.XtDoctorAdviceLog{
  5301. UserOrgId: adminUserInfo.Org.Id,
  5302. PatientId: patient,
  5303. AdminUserId: adminUserInfo.AdminUser.Id,
  5304. Module: 1,
  5305. ErrLog: string(byterequest),
  5306. Status: 1,
  5307. Ctime: time.Now().Unix(),
  5308. Mtime: 0,
  5309. Source: "手机端医嘱推送",
  5310. RecordDate: item.AdviceDate,
  5311. }
  5312. service.CreateDoctorAdviceLog(adviceLog)
  5313. }
  5314. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5315. redis := service.RedisClient()
  5316. //清空key 值
  5317. redis.Set(key, "", time.Second)
  5318. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5319. redis.Set(keyOne, "", time.Second)
  5320. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5321. defer redis.Close()
  5322. redis.Set(keyThree, "", time.Second)
  5323. if err != nil {
  5324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5325. return
  5326. }
  5327. c.ServeSuccessJSON(map[string]interface{}{
  5328. "msg": "ok",
  5329. "advices": list,
  5330. })
  5331. } else {
  5332. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5333. for _, item := range advices {
  5334. byterequest, _ := json.Marshal(item)
  5335. adviceLog := models.XtDoctorAdviceLog{
  5336. UserOrgId: adminUserInfo.Org.Id,
  5337. PatientId: patient,
  5338. AdminUserId: adminUserInfo.AdminUser.Id,
  5339. Module: 1,
  5340. ErrLog: string(byterequest),
  5341. Status: 1,
  5342. Ctime: time.Now().Unix(),
  5343. Mtime: 0,
  5344. Source: "手机端医嘱推送",
  5345. RecordDate: item.AdviceDate,
  5346. }
  5347. service.CreateDoctorAdviceLog(adviceLog)
  5348. }
  5349. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5350. redis := service.RedisClient()
  5351. //清空key 值
  5352. redis.Set(key, "", time.Second)
  5353. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5354. redis.Set(keyOne, "", time.Second)
  5355. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5356. defer redis.Close()
  5357. redis.Set(keyThree, "", time.Second)
  5358. if err != nil {
  5359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5360. return
  5361. }
  5362. c.ServeSuccessJSON(map[string]interface{}{
  5363. "msg": "ok",
  5364. "advices": list,
  5365. })
  5366. }
  5367. } else {
  5368. c.ServeSuccessJSON(map[string]interface{}{
  5369. "msg": "ok",
  5370. })
  5371. }
  5372. return
  5373. }
  5374. func (c *DialysisAPIController) UploadDryWeight() {
  5375. patient_id, _ := c.GetInt64("id")
  5376. dry_weight, _ := c.GetFloat("dry_weight")
  5377. doctor_id, _ := c.GetInt64("doctor_id")
  5378. remark := c.GetString("remark")
  5379. adminUserInfo := c.GetMobileAdminUserInfo()
  5380. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5381. if err == gorm.ErrRecordNotFound {
  5382. dryWeight := &models.SgjPatientDryweight{
  5383. PatientId: patient_id,
  5384. DryWeight: dry_weight,
  5385. Remakes: remark,
  5386. Ctime: time.Now().Unix(),
  5387. Mtime: time.Now().Unix(),
  5388. Creator: doctor_id,
  5389. Status: 1,
  5390. UserOrgId: adminUserInfo.Org.Id,
  5391. AdjustedValue: "/",
  5392. UserId: adminUserInfo.AdminUser.Id,
  5393. }
  5394. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5395. redis := service.RedisClient()
  5396. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5397. redis.Set(keyOne, "", time.Second)
  5398. loc, _ := time.LoadLocation("Local")
  5399. nowTime := time.Now()
  5400. nowDay := nowTime.Format("2006-01-02")
  5401. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5402. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5403. redis.Set(key, "", time.Second)
  5404. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5405. redis.Set(keyTwo, "", time.Second)
  5406. redis.Close()
  5407. if createErr == nil {
  5408. c.ServeSuccessJSON(map[string]interface{}{
  5409. "msg": "提交成功",
  5410. "weight": dryWeight,
  5411. })
  5412. }
  5413. } else {
  5414. dryWeight := &models.SgjPatientDryweight{
  5415. PatientId: patient_id,
  5416. DryWeight: dry_weight,
  5417. Remakes: remark,
  5418. Ctime: time.Now().Unix(),
  5419. Mtime: time.Now().Unix(),
  5420. Creator: doctor_id,
  5421. Status: 1,
  5422. UserOrgId: adminUserInfo.Org.Id,
  5423. AdjustedValue: "/",
  5424. UserId: adminUserInfo.AdminUser.Id,
  5425. }
  5426. var value float64
  5427. value = dry_weight - weightAdjust.DryWeight
  5428. if value < 0 {
  5429. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5430. } else if value == 0 {
  5431. dryWeight.AdjustedValue = "/"
  5432. } else if value > 0 {
  5433. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5434. }
  5435. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5436. //康桥
  5437. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5438. timeNowStr := time.Now().Format("2006-01-02")
  5439. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5440. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5441. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5442. if beforAssesment.ID > 0 {
  5443. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5444. var dewater_amount float64
  5445. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5446. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5447. //获取key,清空redis
  5448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5449. redis := service.RedisClient()
  5450. //清空key 值
  5451. redis.Set(key, "", time.Second)
  5452. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5453. //清空key 值
  5454. redis.Set(keyOne, "", time.Second)
  5455. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5456. //清空key 值
  5457. redis.Set(keyTwo, "", time.Second)
  5458. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5459. redis.Set(keySix, "", time.Second)
  5460. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5461. redis.Set(keySeven, "", time.Second)
  5462. }
  5463. }
  5464. redis := service.RedisClient()
  5465. loc, _ := time.LoadLocation("Local")
  5466. nowTime := time.Now()
  5467. nowDay := nowTime.Format("2006-01-02")
  5468. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5469. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5470. redis.Set(keyOne, "", time.Second)
  5471. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5472. redis.Set(key, "", time.Second)
  5473. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5474. redis.Set(keyTwo, "", time.Second)
  5475. redis.Close()
  5476. if createErr == nil {
  5477. c.ServeSuccessJSON(map[string]interface{}{
  5478. "msg": "提交成功",
  5479. "weight": dryWeight,
  5480. })
  5481. }
  5482. }
  5483. }
  5484. func (c *DialysisAPIController) GetSolution() {
  5485. patient_id, _ := c.GetInt64("patient_id")
  5486. mode_id, _ := c.GetInt64("mode_id")
  5487. adminUserInfo := c.GetMobileAdminUserInfo()
  5488. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5489. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5490. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5491. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5492. if err != nil {
  5493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5494. return
  5495. }
  5496. c.ServeSuccessJSON(map[string]interface{}{
  5497. "solution": solution,
  5498. "prescription": prescription,
  5499. "system_prescription": system_prescription,
  5500. "dialysisPrescription": dialysisPrescription,
  5501. })
  5502. }
  5503. func (c *DialysisAPIController) GetSchedule() {
  5504. schedual_type, _ := c.GetInt64("schedual_type")
  5505. adminUserInfo := c.GetMobileAdminUserInfo()
  5506. scheduleTime, _ := c.GetInt64("record_date")
  5507. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5508. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5509. c.ServeSuccessJSON(map[string]interface{}{
  5510. "number": deviceNumber,
  5511. "list": list,
  5512. })
  5513. }
  5514. func (c *DialysisAPIController) GetPatientId() {
  5515. id, _ := c.GetInt64("id")
  5516. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5517. patientId, _ := service.GetPatientId(id)
  5518. //获取该患者的所有传染病
  5519. list, _ := service.GetPatientInfectious(id)
  5520. c.ServeSuccessJSON(map[string]interface{}{
  5521. "patient": patientId,
  5522. "infectioulist": list,
  5523. })
  5524. }
  5525. func (this *DialysisAPIController) GetDialysisSchedule() {
  5526. schedualDate := this.GetString("date")
  5527. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5528. if parseDateErr != nil {
  5529. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5530. return
  5531. }
  5532. adminInfo := this.GetMobileAdminUserInfo()
  5533. orgID := adminInfo.Org.Id
  5534. redis := service.RedisClient()
  5535. defer redis.Close()
  5536. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5537. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5538. if len(scheduals) > 0 {
  5539. //缓存数据
  5540. scheduals_json, err := json.Marshal(scheduals)
  5541. if err == nil {
  5542. redis.Set(key, scheduals_json, time.Second*30)
  5543. }
  5544. }
  5545. this.ServeSuccessJSON(map[string]interface{}{
  5546. "scheduals": scheduals,
  5547. })
  5548. }
  5549. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5550. change_type, _ := this.GetInt64("type", 0)
  5551. record_date := this.GetString("record_time")
  5552. patient_id, _ := this.GetInt64("patient_id", 0)
  5553. timeLayout := "2006-01-02"
  5554. loc, _ := time.LoadLocation("Local")
  5555. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5556. record_time := theAdviceRecordTime.Unix()
  5557. adminUserInfo := this.GetMobileAdminUserInfo()
  5558. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5559. if err == nil {
  5560. if len(advices) == 0 {
  5561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5562. return
  5563. } else {
  5564. this.ServeSuccessJSON(map[string]interface{}{
  5565. "advices": advices,
  5566. "schedule": sch,
  5567. })
  5568. return
  5569. }
  5570. } else {
  5571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5572. return
  5573. }
  5574. }
  5575. func (c *DialysisAPIController) CreateConsumables() {
  5576. record_date := c.GetString("record_time")
  5577. patient_id, _ := c.GetInt64("patient_id", 0)
  5578. active, _ := c.GetInt64("active")
  5579. adminUser := c.GetMobileAdminUserInfo()
  5580. timeLayout := "2006-01-02"
  5581. loc, _ := time.LoadLocation("Local")
  5582. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5583. record_time := theRecordTime.Unix()
  5584. // 查询信息规挡的设置天数
  5585. orgid := c.GetMobileAdminUserInfo().Org.Id
  5586. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5587. if infor.ID > 0 {
  5588. var cha_time int64
  5589. timeNowStr := time.Now().Format("2006-01-02")
  5590. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5591. //今日的日期减去设置的日期
  5592. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5593. if cha_time >= record_time {
  5594. //查询审核是否允许
  5595. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5596. //申请状态不允许的情况 拒绝修改
  5597. if infor.ApplicationStatus != 1 {
  5598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5599. return
  5600. }
  5601. }
  5602. }
  5603. dataBody := make(map[string]interface{}, 0)
  5604. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5605. if err != nil {
  5606. utils.ErrorLog(err.Error())
  5607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5608. return
  5609. }
  5610. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5611. var beforePrepares []*models.DialysisBeforePrepareGoods
  5612. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5613. var dialysisBefor []*models.DialysisBeforePrepare
  5614. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5615. goods, _ := dataBody["goods"].([]interface{})
  5616. if len(goods) > 0 {
  5617. for _, item := range goods {
  5618. items := item.(map[string]interface{})
  5619. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5620. utils.ErrorLog("good_id")
  5621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5622. return
  5623. }
  5624. good_id := int64(items["good_id"].(float64))
  5625. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5626. utils.ErrorLog("good_type_id")
  5627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5628. return
  5629. }
  5630. good_type_id := int64(items["good_type_id"].(float64))
  5631. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5632. utils.ErrorLog("count")
  5633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5634. return
  5635. }
  5636. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5637. commdity_code := items["commdity_code"].(string)
  5638. fmt.Println("commdity", commdity_code)
  5639. prepareGoods := &models.DialysisBeforePrepareGoods{
  5640. GoodTypeId: good_type_id,
  5641. GoodId: good_id,
  5642. Count: count,
  5643. StorehouseId: houseConfig.StorehouseOutInfo,
  5644. }
  5645. beforePrepares = append(beforePrepares, prepareGoods)
  5646. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5647. GoodTypeId: good_type_id,
  5648. GoodId: good_id,
  5649. Count: count,
  5650. StorehouseId: houseConfig.StorehouseOutInfo,
  5651. }
  5652. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5653. prepare := &models.DialysisBeforePrepare{
  5654. GoodTypeId: good_type_id,
  5655. GoodId: good_id,
  5656. Count: count,
  5657. PatientId: patient_id,
  5658. RecordDate: record_time,
  5659. UserOrgId: adminUser.Org.Id,
  5660. Status: 1,
  5661. Ctime: time.Now().Unix(),
  5662. Creater: adminUser.AdminUser.Id,
  5663. CommdityCode: commdity_code,
  5664. StorehouseId: houseConfig.StorehouseOutInfo,
  5665. }
  5666. dialysisBefor = append(dialysisBefor, prepare)
  5667. }
  5668. }
  5669. //查询是否有库存
  5670. for _, item := range dialysisBefor {
  5671. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5672. if err == gorm.ErrRecordNotFound {
  5673. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5674. c.ServeSuccessJSON(map[string]interface{}{
  5675. "message": "1",
  5676. "good_name": goodObj.GoodName,
  5677. "specification_name": goodObj.SpecificationName,
  5678. })
  5679. return
  5680. }
  5681. if err != nil {
  5682. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5683. c.ServeSuccessJSON(map[string]interface{}{
  5684. "message": "1",
  5685. "good_name": goodObj.GoodName,
  5686. "specification_name": goodObj.SpecificationName,
  5687. })
  5688. return
  5689. }
  5690. }
  5691. fmt.Println("active-----------------------", active)
  5692. fmt.Println("len(goods)-----------------------", len(goods))
  5693. //新增
  5694. if active == 1 && len(goods) > 0 {
  5695. for _, item := range dialysisBefor {
  5696. dialyPrepareOne := models.DialysisBeforePrepare{
  5697. GoodTypeId: item.GoodTypeId,
  5698. GoodId: item.GoodId,
  5699. PatientId: item.PatientId,
  5700. RecordDate: item.RecordDate,
  5701. UserOrgId: item.UserOrgId,
  5702. Count: item.Count,
  5703. Ctime: time.Now().Unix(),
  5704. Creater: item.Creater,
  5705. CommdityCode: item.CommdityCode,
  5706. Status: 1,
  5707. StorehouseId: houseConfig.StorehouseOutInfo,
  5708. }
  5709. //先清除再插入
  5710. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5711. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5712. //查询默认仓库
  5713. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5714. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5715. var total_count int64
  5716. for _, it := range stockList {
  5717. total_count += it.StockCount
  5718. }
  5719. //基础库插入数据
  5720. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5721. //更新库存
  5722. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5723. var flush_count int64
  5724. for _, it := range goodList {
  5725. flush_count += it.StockCount
  5726. }
  5727. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5728. }
  5729. if err == nil {
  5730. c.ServeSuccessJSON(map[string]interface{}{
  5731. "msg": "保存成功",
  5732. "message": "2",
  5733. })
  5734. return
  5735. } else {
  5736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5737. return
  5738. }
  5739. }
  5740. if len(beforePrepares) > 0 && active == 2 {
  5741. for _, item := range beforePrepares {
  5742. //1.查看该患者该耗材型号最后一次出库数量
  5743. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5744. //判断当前出库数量和最后一次出库数量的大小
  5745. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5746. if item.Count <= goodInfo.Count {
  5747. //退库
  5748. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5749. //查询今日出库数据
  5750. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5751. for _, it := range list {
  5752. prepare := models.DialysisBeforePrepare{
  5753. UserOrgId: it.OrgId,
  5754. PatientId: patient_id,
  5755. RecordDate: it.RecordTime,
  5756. GoodId: it.GoodId,
  5757. GoodTypeId: it.GoodTypeId,
  5758. Count: it.Count,
  5759. Ctime: time.Now().Unix(),
  5760. Creater: adminUser.AdminUser.Id,
  5761. Status: 1,
  5762. StorehouseId: houseConfig.StorehouseOutInfo,
  5763. }
  5764. //删除准备表数据
  5765. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5766. service.CreateDialysisBeforePrepareOne(&prepare)
  5767. }
  5768. }
  5769. var last_total int64
  5770. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5771. if item.Count >= goodInfo.Count {
  5772. //查询当前批次当前耗材最后一条出库数据
  5773. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5774. //计算当前出库和最后一次出库数据相差数据
  5775. last_total = item.Count - lastOutInfo.Count
  5776. //查询该批次剩余库存
  5777. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5778. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5779. if lastInfo.StockCount >= last_total {
  5780. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5781. //查询今日出库数据
  5782. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5783. for _, it := range list {
  5784. prepare := models.DialysisBeforePrepare{
  5785. UserOrgId: it.OrgId,
  5786. PatientId: patient_id,
  5787. RecordDate: it.RecordTime,
  5788. GoodId: it.GoodId,
  5789. GoodTypeId: it.GoodTypeId,
  5790. Count: it.Count,
  5791. Ctime: time.Now().Unix(),
  5792. Creater: adminUser.AdminUser.Id,
  5793. Status: 1,
  5794. StorehouseId: houseConfig.StorehouseOutInfo,
  5795. }
  5796. //删除准备表数据
  5797. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5798. service.CreateDialysisBeforePrepareOne(&prepare)
  5799. //查询默认仓库
  5800. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5801. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5802. var total_count int64
  5803. for _, it := range stockList {
  5804. total_count += it.StockCount
  5805. }
  5806. //基础库插入数据
  5807. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5808. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5809. var flush_count int64
  5810. for _, it := range goodList {
  5811. flush_count += it.StockCount
  5812. }
  5813. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5814. }
  5815. }
  5816. //如果库存不够,则出库到下一个批次
  5817. if lastInfo.StockCount < last_total {
  5818. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5819. //查询今日出库数据
  5820. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5821. for _, it := range list {
  5822. prepare := models.DialysisBeforePrepare{
  5823. UserOrgId: it.OrgId,
  5824. PatientId: patient_id,
  5825. RecordDate: it.RecordTime,
  5826. GoodId: it.GoodId,
  5827. GoodTypeId: it.GoodTypeId,
  5828. Count: it.Count,
  5829. Ctime: time.Now().Unix(),
  5830. Creater: adminUser.AdminUser.Id,
  5831. Status: 1,
  5832. StorehouseId: houseConfig.StorehouseOutInfo,
  5833. }
  5834. //删除准备表数据
  5835. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5836. service.CreateDialysisBeforePrepareOne(&prepare)
  5837. //查询默认仓库
  5838. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5839. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5840. var total_count int64
  5841. for _, it := range stockList {
  5842. total_count += it.StockCount
  5843. }
  5844. //基础库插入数据
  5845. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5846. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5847. var flush_count int64
  5848. for _, it := range goodList {
  5849. flush_count += it.StockCount
  5850. }
  5851. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5852. }
  5853. if err != nil {
  5854. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5855. c.ServeSuccessJSON(map[string]interface{}{
  5856. "message": "1",
  5857. "good_name": goodObj.GoodName,
  5858. "specification_name": goodObj.SpecificationName,
  5859. })
  5860. return
  5861. }
  5862. }
  5863. }
  5864. if err != nil {
  5865. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5866. c.ServeSuccessJSON(map[string]interface{}{
  5867. "message": "1",
  5868. "good_name": goodObj.GoodName,
  5869. "specification_name": goodObj.SpecificationName,
  5870. })
  5871. return
  5872. }
  5873. }
  5874. }
  5875. }
  5876. var errs error
  5877. if errs == nil {
  5878. c.ServeSuccessJSON(map[string]interface{}{
  5879. "msg": "提交成功",
  5880. "message": "2",
  5881. "good_name": "",
  5882. "specification_name": "",
  5883. })
  5884. return
  5885. } else {
  5886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5887. return
  5888. }
  5889. }
  5890. func (c *DialysisAPIController) CreateStockOutInfo() {
  5891. patient_id, _ := c.GetInt64("patient_id", 0)
  5892. record_date := c.GetString("record_time")
  5893. if patient_id <= 0 {
  5894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5895. return
  5896. }
  5897. adminInfo := c.GetMobileAdminUserInfo()
  5898. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5899. timeLayout := "2006-01-02"
  5900. loc, _ := time.LoadLocation("Local")
  5901. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5902. record_time := theRecordTime.Unix()
  5903. // 查询信息规挡的设置天数
  5904. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5905. if infor.ID > 0 && infor.WeekDay > 0 {
  5906. var cha_time int64
  5907. timeNowStr := time.Now().Format("2006-01-02")
  5908. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5909. //今日的日期减去设置的日期
  5910. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5911. if cha_time >= record_time {
  5912. //查询审核是否允许
  5913. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5914. //申请状态不允许的情况 拒绝修改
  5915. if infor.ApplicationStatus != 1 {
  5916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5917. return
  5918. }
  5919. }
  5920. }
  5921. //创建步骤表
  5922. finish := models.XtDialysisFinish{
  5923. IsFinish: 1,
  5924. UserOrgId: adminInfo.Org.Id,
  5925. Status: 1,
  5926. Ctime: time.Now().Unix(),
  5927. Mtime: 0,
  5928. Module: 11,
  5929. RecordDate: record_time,
  5930. Sourse: 1,
  5931. PatientId: patient_id,
  5932. }
  5933. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5934. if dialysisFinish.ID == 0 {
  5935. service.CreateDialysisFinish(finish)
  5936. }
  5937. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5938. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5939. //去重
  5940. consumables = RemoveRepeatedGood(consumables)
  5941. if adminInfo.Org.Id == 9919 {
  5942. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5943. //查询是否有库存
  5944. for _, item := range consumables {
  5945. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5946. if item.Count > warehouse.Count {
  5947. goodErrcode := models.XtGoodErrcode{
  5948. UserOrgId: item.UserOrgId,
  5949. Errcode: "自动出库库存不足",
  5950. GoodId: item.GoodId,
  5951. Status: 1,
  5952. Ctime: time.Now().Unix(),
  5953. Mtime: 0,
  5954. Count: 0,
  5955. StockCount: 0,
  5956. Creater: creator,
  5957. BatchNumberId: warehouse.ID,
  5958. WarehouseOutId: 0,
  5959. }
  5960. service.CreateGoodErrcode(goodErrcode)
  5961. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5962. c.ServeSuccessJSON(map[string]interface{}{
  5963. "message": "1",
  5964. "good_name": goodObj.GoodName,
  5965. "specification_name": goodObj.SpecificationName,
  5966. })
  5967. return
  5968. }
  5969. }
  5970. //查询是否有出库单
  5971. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5972. if err == gorm.ErrRecordNotFound {
  5973. //没有记录,则创建出库单
  5974. timeStr := time.Now().Format("2006-01-02")
  5975. timeArr := strings.Split(timeStr, "-")
  5976. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5977. total = total + 1
  5978. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5979. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5980. number = number + total
  5981. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5982. creater := adminInfo.AdminUser.Id
  5983. warehouseOut := models.WarehouseOut{
  5984. WarehouseOutOrderNumber: warehousing_out_order,
  5985. OperationTime: time.Now().Unix(),
  5986. OrgId: adminInfo.Org.Id,
  5987. Creater: creater,
  5988. Ctime: time.Now().Unix(),
  5989. Status: 1,
  5990. WarehouseOutTime: record_time,
  5991. Dealer: 0,
  5992. Manufacturer: 0,
  5993. Type: 1,
  5994. IsSys: 1,
  5995. StorehouseId: houseConfig.StorehouseOutInfo,
  5996. IsCheck: 1,
  5997. }
  5998. err := service.AddSigleWarehouseOut(&warehouseOut)
  5999. if err != nil {
  6000. goodErrcode := models.XtGoodErrcode{
  6001. UserOrgId: adminInfo.Org.Id,
  6002. Errcode: "创建出库单失败",
  6003. GoodId: 0,
  6004. Status: 1,
  6005. Ctime: time.Now().Unix(),
  6006. Mtime: 0,
  6007. Count: 0,
  6008. StockCount: 0,
  6009. Creater: creator,
  6010. BatchNumberId: 0,
  6011. WarehouseOutId: 0,
  6012. }
  6013. service.CreateGoodErrcode(goodErrcode)
  6014. utils.TraceLog("创建出库单失败 err = %v", err)
  6015. } else {
  6016. for _, item := range consumables {
  6017. //出库
  6018. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6019. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6020. if err == nil {
  6021. goodErrcode := models.XtGoodErrcode{
  6022. UserOrgId: adminInfo.Org.Id,
  6023. Errcode: "自动出库接口报错",
  6024. GoodId: 0,
  6025. Status: 1,
  6026. Ctime: time.Now().Unix(),
  6027. Mtime: 0,
  6028. Count: 0,
  6029. StockCount: 0,
  6030. Creater: creator,
  6031. BatchNumberId: 0,
  6032. WarehouseOutId: 0,
  6033. }
  6034. service.CreateGoodErrcode(goodErrcode)
  6035. utils.TraceLog("创建出库单失败 err = %v", err)
  6036. }
  6037. //查询
  6038. //出库数量相加
  6039. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6040. if errs != nil {
  6041. goodErrcode := models.XtGoodErrcode{
  6042. UserOrgId: item.UserOrgId,
  6043. Errcode: "创建剩余库存字段报错",
  6044. GoodId: item.GoodId,
  6045. Status: 1,
  6046. Ctime: time.Now().Unix(),
  6047. Mtime: 0,
  6048. Count: 0,
  6049. StockCount: 0,
  6050. Creater: creater,
  6051. BatchNumberId: 0,
  6052. WarehouseOutId: 0,
  6053. }
  6054. service.CreateGoodErrcode(goodErrcode)
  6055. }
  6056. }
  6057. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6058. if len(list) == 0 {
  6059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6060. return
  6061. }
  6062. for _, item := range list {
  6063. prepare := models.DialysisBeforePrepare{
  6064. UserOrgId: adminInfo.Org.Id,
  6065. PatientId: patient_id,
  6066. RecordDate: record_time,
  6067. GoodId: item.GoodId,
  6068. GoodTypeId: item.GoodTypeId,
  6069. Count: item.Count,
  6070. Creater: adminInfo.AdminUser.Id,
  6071. Status: 1,
  6072. Ctime: time.Now().Unix(),
  6073. StorehouseId: houseConfig.StorehouseOutInfo,
  6074. }
  6075. //清空准备表数据
  6076. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6077. if err != nil {
  6078. goodErrcode := models.XtGoodErrcode{
  6079. UserOrgId: item.OrgId,
  6080. Errcode: "自动出库清空准备表数据报错",
  6081. GoodId: item.GoodId,
  6082. Status: 1,
  6083. Ctime: time.Now().Unix(),
  6084. Mtime: 0,
  6085. Count: 0,
  6086. StockCount: 0,
  6087. Creater: creater,
  6088. BatchNumberId: 0,
  6089. WarehouseOutId: 0,
  6090. }
  6091. service.CreateGoodErrcode(goodErrcode)
  6092. }
  6093. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6094. if errs != nil {
  6095. goodErrcode := models.XtGoodErrcode{
  6096. UserOrgId: item.OrgId,
  6097. Errcode: "自动出库创建准备表数据报错",
  6098. GoodId: item.GoodId,
  6099. Status: 1,
  6100. Ctime: time.Now().Unix(),
  6101. Mtime: 0,
  6102. Count: 0,
  6103. StockCount: 0,
  6104. Creater: creater,
  6105. BatchNumberId: 0,
  6106. WarehouseOutId: 0,
  6107. }
  6108. service.CreateGoodErrcode(goodErrcode)
  6109. }
  6110. //查询默认仓库
  6111. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6112. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6113. var total_count int64
  6114. for _, it := range stockList {
  6115. total_count += it.StockCount
  6116. }
  6117. //基础库插入数据
  6118. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6119. if errcodes != nil {
  6120. goodErrcode := models.XtGoodErrcode{
  6121. UserOrgId: item.OrgId,
  6122. Errcode: "自动出库基础库插入数据",
  6123. GoodId: item.GoodId,
  6124. Status: 1,
  6125. Ctime: time.Now().Unix(),
  6126. Mtime: 0,
  6127. Count: 0,
  6128. StockCount: 0,
  6129. Creater: creater,
  6130. BatchNumberId: 0,
  6131. WarehouseOutId: 0,
  6132. }
  6133. service.CreateGoodErrcode(goodErrcode)
  6134. }
  6135. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6136. var flush_count int64
  6137. for _, it := range goodList {
  6138. flush_count += it.StockCount
  6139. }
  6140. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6141. if errsss != nil {
  6142. goodErrcode := models.XtGoodErrcode{
  6143. UserOrgId: item.OrgId,
  6144. Errcode: "自动出库剩余库存更新数据",
  6145. GoodId: item.GoodId,
  6146. Status: 1,
  6147. Ctime: time.Now().Unix(),
  6148. Mtime: 0,
  6149. Count: 0,
  6150. StockCount: 0,
  6151. Creater: creater,
  6152. BatchNumberId: 0,
  6153. WarehouseOutId: 0,
  6154. }
  6155. service.CreateGoodErrcode(goodErrcode)
  6156. }
  6157. }
  6158. }
  6159. //
  6160. } else if err == nil {
  6161. for _, item := range consumables {
  6162. //出库
  6163. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6164. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6165. if err != nil {
  6166. goodErrcode := models.XtGoodErrcode{
  6167. UserOrgId: adminInfo.Org.Id,
  6168. Errcode: "自动出库接口报错",
  6169. GoodId: 0,
  6170. Status: 1,
  6171. Ctime: time.Now().Unix(),
  6172. Mtime: 0,
  6173. Count: 0,
  6174. StockCount: 0,
  6175. Creater: creator,
  6176. BatchNumberId: 0,
  6177. WarehouseOutId: 0,
  6178. }
  6179. service.CreateGoodErrcode(goodErrcode)
  6180. }
  6181. //出库数量相加
  6182. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6183. if errss != nil {
  6184. goodErrcode := models.XtGoodErrcode{
  6185. UserOrgId: item.UserOrgId,
  6186. Errcode: "创建剩余库存字段报错",
  6187. GoodId: item.GoodId,
  6188. Status: 1,
  6189. Ctime: time.Now().Unix(),
  6190. Mtime: time.Now().Unix(),
  6191. Count: 0,
  6192. StockCount: 0,
  6193. Creater: item.Creater,
  6194. BatchNumberId: 0,
  6195. WarehouseOutId: 0,
  6196. }
  6197. service.CreateGoodErrcode(goodErrcode)
  6198. }
  6199. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6200. if len(list) == 0 {
  6201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6202. return
  6203. }
  6204. for _, item := range list {
  6205. prepare := models.DialysisBeforePrepare{
  6206. UserOrgId: adminInfo.Org.Id,
  6207. PatientId: patient_id,
  6208. RecordDate: record_time,
  6209. GoodId: item.GoodId,
  6210. GoodTypeId: item.GoodTypeId,
  6211. Count: item.Count,
  6212. Creater: adminInfo.AdminUser.Id,
  6213. Status: 1,
  6214. Ctime: time.Now().Unix(),
  6215. StorehouseId: houseConfig.StorehouseOutInfo,
  6216. }
  6217. //清空准备表数据
  6218. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6219. if errs != nil {
  6220. goodErrcode := models.XtGoodErrcode{
  6221. UserOrgId: adminInfo.Org.Id,
  6222. Errcode: "自动出库清空准备表数据报错",
  6223. GoodId: 0,
  6224. Status: 1,
  6225. Ctime: time.Now().Unix(),
  6226. Mtime: 0,
  6227. Count: 0,
  6228. StockCount: 0,
  6229. Creater: creator,
  6230. BatchNumberId: 0,
  6231. WarehouseOutId: 0,
  6232. }
  6233. service.CreateGoodErrcode(goodErrcode)
  6234. }
  6235. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6236. if errcodes != nil {
  6237. goodErrcode := models.XtGoodErrcode{
  6238. UserOrgId: adminInfo.Org.Id,
  6239. Errcode: "自动出库创建准备表数据报错",
  6240. GoodId: 0,
  6241. Status: 1,
  6242. Ctime: time.Now().Unix(),
  6243. Mtime: 0,
  6244. Count: 0,
  6245. StockCount: 0,
  6246. Creater: creator,
  6247. BatchNumberId: 0,
  6248. WarehouseOutId: 0,
  6249. }
  6250. service.CreateGoodErrcode(goodErrcode)
  6251. }
  6252. //查询默认仓库
  6253. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6254. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6255. var total_count int64
  6256. for _, it := range stockList {
  6257. total_count += it.StockCount
  6258. }
  6259. //基础库插入数据
  6260. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6261. if errcodes != nil {
  6262. goodErrcode := models.XtGoodErrcode{
  6263. UserOrgId: adminInfo.Org.Id,
  6264. Errcode: "自动出库基础库插入数据报错",
  6265. GoodId: 0,
  6266. Status: 1,
  6267. Ctime: time.Now().Unix(),
  6268. Mtime: 0,
  6269. Count: 0,
  6270. StockCount: 0,
  6271. Creater: creator,
  6272. BatchNumberId: 0,
  6273. WarehouseOutId: 0,
  6274. }
  6275. service.CreateGoodErrcode(goodErrcode)
  6276. }
  6277. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6278. var flush_count int64
  6279. for _, it := range goodList {
  6280. flush_count += it.StockCount
  6281. }
  6282. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6283. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6284. if errss != nil {
  6285. goodErrcode := models.XtGoodErrcode{
  6286. UserOrgId: item.OrgId,
  6287. Errcode: "自动出库剩余库存更新数据",
  6288. GoodId: item.GoodId,
  6289. Status: 1,
  6290. Ctime: time.Now().Unix(),
  6291. Mtime: 0,
  6292. Count: 0,
  6293. StockCount: 0,
  6294. Creater: creater,
  6295. BatchNumberId: 0,
  6296. WarehouseOutId: 0,
  6297. }
  6298. service.CreateGoodErrcode(goodErrcode)
  6299. }
  6300. }
  6301. }
  6302. }
  6303. c.ServeSuccessJSON(map[string]interface{}{
  6304. "msg": "提交成功",
  6305. "message": "2",
  6306. "good_name": "",
  6307. "specification_name": "",
  6308. })
  6309. return
  6310. }
  6311. if record.IsOpen == 1 {
  6312. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6313. //查询是否有库存
  6314. for _, item := range consumables {
  6315. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6316. if item.Count > warehouse.Count {
  6317. goodErrcode := models.XtGoodErrcode{
  6318. UserOrgId: item.UserOrgId,
  6319. Errcode: "自动出库库存不足",
  6320. GoodId: item.GoodId,
  6321. Status: 1,
  6322. Ctime: time.Now().Unix(),
  6323. Mtime: 0,
  6324. Count: 0,
  6325. StockCount: 0,
  6326. Creater: creator,
  6327. BatchNumberId: warehouse.ID,
  6328. WarehouseOutId: 0,
  6329. }
  6330. service.CreateGoodErrcode(goodErrcode)
  6331. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6332. c.ServeSuccessJSON(map[string]interface{}{
  6333. "message": "1",
  6334. "good_name": goodObj.GoodName,
  6335. "specification_name": goodObj.SpecificationName,
  6336. })
  6337. return
  6338. }
  6339. }
  6340. //查询是否有出库单
  6341. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6342. if err == gorm.ErrRecordNotFound {
  6343. //没有记录,则创建出库单
  6344. timeStr := time.Now().Format("2006-01-02")
  6345. timeArr := strings.Split(timeStr, "-")
  6346. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6347. total = total + 1
  6348. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6349. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6350. number = number + total
  6351. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6352. creater := adminInfo.AdminUser.Id
  6353. warehouseOut := models.WarehouseOut{
  6354. WarehouseOutOrderNumber: warehousing_out_order,
  6355. OperationTime: time.Now().Unix(),
  6356. OrgId: adminInfo.Org.Id,
  6357. Creater: creater,
  6358. Ctime: time.Now().Unix(),
  6359. Status: 1,
  6360. WarehouseOutTime: record_time,
  6361. Dealer: 0,
  6362. Manufacturer: 0,
  6363. Type: 1,
  6364. IsSys: 1,
  6365. StorehouseId: houseConfig.StorehouseOutInfo,
  6366. IsCheck: 1,
  6367. }
  6368. err := service.AddSigleWarehouseOut(&warehouseOut)
  6369. if err != nil {
  6370. goodErrcode := models.XtGoodErrcode{
  6371. UserOrgId: adminInfo.Org.Id,
  6372. Errcode: "创建出库单失败",
  6373. GoodId: 0,
  6374. Status: 1,
  6375. Ctime: time.Now().Unix(),
  6376. Mtime: 0,
  6377. Count: 0,
  6378. StockCount: 0,
  6379. Creater: creator,
  6380. BatchNumberId: 0,
  6381. WarehouseOutId: 0,
  6382. }
  6383. service.CreateGoodErrcode(goodErrcode)
  6384. utils.TraceLog("创建出库单失败 err = %v", err)
  6385. } else {
  6386. for _, item := range consumables {
  6387. //出库
  6388. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6389. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6390. if err == nil {
  6391. goodErrcode := models.XtGoodErrcode{
  6392. UserOrgId: adminInfo.Org.Id,
  6393. Errcode: "自动出库接口报错",
  6394. GoodId: 0,
  6395. Status: 1,
  6396. Ctime: time.Now().Unix(),
  6397. Mtime: 0,
  6398. Count: 0,
  6399. StockCount: 0,
  6400. Creater: creator,
  6401. BatchNumberId: 0,
  6402. WarehouseOutId: 0,
  6403. }
  6404. service.CreateGoodErrcode(goodErrcode)
  6405. utils.TraceLog("创建出库单失败 err = %v", err)
  6406. }
  6407. //查询
  6408. //出库数量相加
  6409. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6410. if errs != nil {
  6411. goodErrcode := models.XtGoodErrcode{
  6412. UserOrgId: item.UserOrgId,
  6413. Errcode: "创建剩余库存字段报错",
  6414. GoodId: item.GoodId,
  6415. Status: 1,
  6416. Ctime: time.Now().Unix(),
  6417. Mtime: 0,
  6418. Count: 0,
  6419. StockCount: 0,
  6420. Creater: creater,
  6421. BatchNumberId: 0,
  6422. WarehouseOutId: 0,
  6423. }
  6424. service.CreateGoodErrcode(goodErrcode)
  6425. }
  6426. }
  6427. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6428. if len(list) == 0 {
  6429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6430. return
  6431. }
  6432. for _, item := range list {
  6433. prepare := models.DialysisBeforePrepare{
  6434. UserOrgId: adminInfo.Org.Id,
  6435. PatientId: patient_id,
  6436. RecordDate: record_time,
  6437. GoodId: item.GoodId,
  6438. GoodTypeId: item.GoodTypeId,
  6439. Count: item.Count,
  6440. Creater: adminInfo.AdminUser.Id,
  6441. Status: 1,
  6442. Ctime: time.Now().Unix(),
  6443. StorehouseId: houseConfig.StorehouseOutInfo,
  6444. }
  6445. //清空准备表数据
  6446. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6447. if err != nil {
  6448. goodErrcode := models.XtGoodErrcode{
  6449. UserOrgId: item.OrgId,
  6450. Errcode: "自动出库清空准备表数据报错",
  6451. GoodId: item.GoodId,
  6452. Status: 1,
  6453. Ctime: time.Now().Unix(),
  6454. Mtime: 0,
  6455. Count: 0,
  6456. StockCount: 0,
  6457. Creater: creater,
  6458. BatchNumberId: 0,
  6459. WarehouseOutId: 0,
  6460. }
  6461. service.CreateGoodErrcode(goodErrcode)
  6462. }
  6463. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6464. if errs != nil {
  6465. goodErrcode := models.XtGoodErrcode{
  6466. UserOrgId: item.OrgId,
  6467. Errcode: "自动出库创建准备表数据报错",
  6468. GoodId: item.GoodId,
  6469. Status: 1,
  6470. Ctime: time.Now().Unix(),
  6471. Mtime: 0,
  6472. Count: 0,
  6473. StockCount: 0,
  6474. Creater: creater,
  6475. BatchNumberId: 0,
  6476. WarehouseOutId: 0,
  6477. }
  6478. service.CreateGoodErrcode(goodErrcode)
  6479. }
  6480. //查询默认仓库
  6481. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6482. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6483. var total_count int64
  6484. for _, it := range stockList {
  6485. total_count += it.StockCount
  6486. }
  6487. //基础库插入数据
  6488. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6489. if errcodes != nil {
  6490. goodErrcode := models.XtGoodErrcode{
  6491. UserOrgId: item.OrgId,
  6492. Errcode: "自动出库基础库插入数据",
  6493. GoodId: item.GoodId,
  6494. Status: 1,
  6495. Ctime: time.Now().Unix(),
  6496. Mtime: 0,
  6497. Count: 0,
  6498. StockCount: 0,
  6499. Creater: creater,
  6500. BatchNumberId: 0,
  6501. WarehouseOutId: 0,
  6502. }
  6503. service.CreateGoodErrcode(goodErrcode)
  6504. }
  6505. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6506. var flush_count int64
  6507. for _, it := range goodList {
  6508. flush_count += it.StockCount
  6509. }
  6510. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6511. if errsss != nil {
  6512. goodErrcode := models.XtGoodErrcode{
  6513. UserOrgId: item.OrgId,
  6514. Errcode: "自动出库剩余库存更新数据",
  6515. GoodId: item.GoodId,
  6516. Status: 1,
  6517. Ctime: time.Now().Unix(),
  6518. Mtime: 0,
  6519. Count: 0,
  6520. StockCount: 0,
  6521. Creater: creater,
  6522. BatchNumberId: 0,
  6523. WarehouseOutId: 0,
  6524. }
  6525. service.CreateGoodErrcode(goodErrcode)
  6526. }
  6527. }
  6528. }
  6529. //
  6530. } else if err == nil {
  6531. for _, item := range consumables {
  6532. //出库
  6533. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6534. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6535. if err != nil {
  6536. goodErrcode := models.XtGoodErrcode{
  6537. UserOrgId: adminInfo.Org.Id,
  6538. Errcode: "自动出库接口报错",
  6539. GoodId: 0,
  6540. Status: 1,
  6541. Ctime: time.Now().Unix(),
  6542. Mtime: 0,
  6543. Count: 0,
  6544. StockCount: 0,
  6545. Creater: creator,
  6546. BatchNumberId: 0,
  6547. WarehouseOutId: 0,
  6548. }
  6549. service.CreateGoodErrcode(goodErrcode)
  6550. }
  6551. //出库数量相加
  6552. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6553. if errss != nil {
  6554. goodErrcode := models.XtGoodErrcode{
  6555. UserOrgId: item.UserOrgId,
  6556. Errcode: "创建剩余库存字段报错",
  6557. GoodId: item.GoodId,
  6558. Status: 1,
  6559. Ctime: time.Now().Unix(),
  6560. Mtime: time.Now().Unix(),
  6561. Count: 0,
  6562. StockCount: 0,
  6563. Creater: item.Creater,
  6564. BatchNumberId: 0,
  6565. WarehouseOutId: 0,
  6566. }
  6567. service.CreateGoodErrcode(goodErrcode)
  6568. }
  6569. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6570. if len(list) == 0 {
  6571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6572. return
  6573. }
  6574. for _, item := range list {
  6575. prepare := models.DialysisBeforePrepare{
  6576. UserOrgId: adminInfo.Org.Id,
  6577. PatientId: patient_id,
  6578. RecordDate: record_time,
  6579. GoodId: item.GoodId,
  6580. GoodTypeId: item.GoodTypeId,
  6581. Count: item.Count,
  6582. Creater: adminInfo.AdminUser.Id,
  6583. Status: 1,
  6584. Ctime: time.Now().Unix(),
  6585. StorehouseId: houseConfig.StorehouseOutInfo,
  6586. }
  6587. //清空准备表数据
  6588. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6589. if errs != nil {
  6590. goodErrcode := models.XtGoodErrcode{
  6591. UserOrgId: adminInfo.Org.Id,
  6592. Errcode: "自动出库清空准备表数据报错",
  6593. GoodId: 0,
  6594. Status: 1,
  6595. Ctime: time.Now().Unix(),
  6596. Mtime: 0,
  6597. Count: 0,
  6598. StockCount: 0,
  6599. Creater: creator,
  6600. BatchNumberId: 0,
  6601. WarehouseOutId: 0,
  6602. }
  6603. service.CreateGoodErrcode(goodErrcode)
  6604. }
  6605. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6606. if errcodes != nil {
  6607. goodErrcode := models.XtGoodErrcode{
  6608. UserOrgId: adminInfo.Org.Id,
  6609. Errcode: "自动出库创建准备表数据报错",
  6610. GoodId: 0,
  6611. Status: 1,
  6612. Ctime: time.Now().Unix(),
  6613. Mtime: 0,
  6614. Count: 0,
  6615. StockCount: 0,
  6616. Creater: creator,
  6617. BatchNumberId: 0,
  6618. WarehouseOutId: 0,
  6619. }
  6620. service.CreateGoodErrcode(goodErrcode)
  6621. }
  6622. //查询默认仓库
  6623. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6624. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6625. var total_count int64
  6626. for _, it := range stockList {
  6627. total_count += it.StockCount
  6628. }
  6629. //基础库插入数据
  6630. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6631. if errcodes != nil {
  6632. goodErrcode := models.XtGoodErrcode{
  6633. UserOrgId: adminInfo.Org.Id,
  6634. Errcode: "自动出库基础库插入数据报错",
  6635. GoodId: 0,
  6636. Status: 1,
  6637. Ctime: time.Now().Unix(),
  6638. Mtime: 0,
  6639. Count: 0,
  6640. StockCount: 0,
  6641. Creater: creator,
  6642. BatchNumberId: 0,
  6643. WarehouseOutId: 0,
  6644. }
  6645. service.CreateGoodErrcode(goodErrcode)
  6646. }
  6647. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6648. var flush_count int64
  6649. for _, it := range goodList {
  6650. flush_count += it.StockCount
  6651. }
  6652. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6653. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6654. if errss != nil {
  6655. goodErrcode := models.XtGoodErrcode{
  6656. UserOrgId: item.OrgId,
  6657. Errcode: "自动出库剩余库存更新数据",
  6658. GoodId: item.GoodId,
  6659. Status: 1,
  6660. Ctime: time.Now().Unix(),
  6661. Mtime: 0,
  6662. Count: 0,
  6663. StockCount: 0,
  6664. Creater: creater,
  6665. BatchNumberId: 0,
  6666. WarehouseOutId: 0,
  6667. }
  6668. service.CreateGoodErrcode(goodErrcode)
  6669. }
  6670. }
  6671. }
  6672. }
  6673. c.ServeSuccessJSON(map[string]interface{}{
  6674. "msg": "提交成功",
  6675. "message": "2",
  6676. "good_name": "",
  6677. "specification_name": "",
  6678. })
  6679. return
  6680. } else {
  6681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6682. return
  6683. }
  6684. }
  6685. func (c *DialysisAPIController) EditConsumables() {
  6686. patient_id, _ := c.GetInt64("patient_id", 0)
  6687. record_date := c.GetString("record_time")
  6688. if patient_id <= 0 {
  6689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6690. return
  6691. }
  6692. adminInfo := c.GetMobileAdminUserInfo()
  6693. timeLayout := "2006-01-02"
  6694. loc, _ := time.LoadLocation("Local")
  6695. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6696. record_time := theRecordTime.Unix()
  6697. // 查询信息规挡的设置天数
  6698. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6699. if infor.ID > 0 && infor.WeekDay > 0 {
  6700. var cha_time int64
  6701. timeNowStr := time.Now().Format("2006-01-02")
  6702. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6703. //今日的日期减去设置的日期
  6704. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6705. if cha_time >= record_time {
  6706. //查询审核是否允许
  6707. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6708. //申请状态不允许的情况 拒绝修改
  6709. if infor.ApplicationStatus != 1 {
  6710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6711. return
  6712. }
  6713. }
  6714. }
  6715. dataBody := make(map[string]interface{}, 0)
  6716. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6717. if err != nil {
  6718. utils.ErrorLog(err.Error())
  6719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6720. return
  6721. }
  6722. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6723. var beforePrepares []*models.DialysisBeforePrepareGoods
  6724. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6725. var cancelbefor []*models.DialysisBeforePrepareGoods
  6726. var outbefor []*models.DialysisBeforePrepareGoods
  6727. //判断是否开启自动出库
  6728. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6729. if record.IsOpen == 1 {
  6730. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6731. goods, _ := dataBody["goods"].([]interface{})
  6732. if len(goods) > 0 {
  6733. for _, item := range goods {
  6734. items := item.(map[string]interface{})
  6735. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6736. utils.ErrorLog("good_id")
  6737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6738. return
  6739. }
  6740. good_id := int64(items["good_id"].(float64))
  6741. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6742. utils.ErrorLog("good_type_id")
  6743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6744. return
  6745. }
  6746. good_type_id := int64(items["good_type_id"].(float64))
  6747. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6748. utils.ErrorLog("count")
  6749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6750. return
  6751. }
  6752. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6753. commdity_code := items["commdity_code"].(string)
  6754. fmt.Println(commdity_code)
  6755. prepareGoods := &models.DialysisBeforePrepareGoods{
  6756. GoodTypeId: good_type_id,
  6757. GoodId: good_id,
  6758. Count: count,
  6759. StorehouseId: houseConfig.StorehouseOutInfo,
  6760. }
  6761. beforePrepares = append(beforePrepares, prepareGoods)
  6762. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6763. GoodTypeId: good_type_id,
  6764. GoodId: good_id,
  6765. Count: count,
  6766. StorehouseId: houseConfig.StorehouseOutInfo,
  6767. }
  6768. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6769. }
  6770. for _, item := range beforePrepares {
  6771. //1.查看该患者该耗材型号最后一次出库数量
  6772. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6773. //判断当前出库数量和最后一次出库数量的大小
  6774. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6775. if item.Count < goodInfo.Count {
  6776. cancelbefor = append(cancelbefor, item)
  6777. }
  6778. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6779. if item.Count > goodInfo.Count {
  6780. outbefor = append(outbefor, item)
  6781. }
  6782. //处理编辑耗材新增不了的问题
  6783. if goodInfo.Count == item.Count {
  6784. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6785. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6786. }
  6787. }
  6788. if len(cancelbefor) > 0 {
  6789. //退库
  6790. for _, item := range cancelbefor {
  6791. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6792. creater := adminInfo.AdminUser.Id
  6793. //查询该患者当天已经出库的耗材信息
  6794. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6795. var delete_count int64 = 0
  6796. delete_count = warehouseOutInfos.Count - item.Count
  6797. //增加库存数量
  6798. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6799. //减少实际出库库存数量
  6800. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6801. // 删除出库完成后,要增加对应批次的库存数量
  6802. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6803. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6804. //更新剩余库存
  6805. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6806. var flush_count int64
  6807. for _, it := range goodListOne {
  6808. flush_count += it.StockCount
  6809. }
  6810. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6811. //查询剩余库存
  6812. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6813. var sum_count int64
  6814. for _, item := range goodList {
  6815. sum_count += item.StockCount
  6816. }
  6817. // 在出库记录表里记录退库详情
  6818. warehouseOutInfo := &models.WarehouseOutInfo{
  6819. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6820. WarehouseOutId: warehouseOut.ID,
  6821. Status: 1,
  6822. Ctime: time.Now().Unix(),
  6823. OrgId: adminInfo.Org.Id,
  6824. Type: 1,
  6825. IsSys: 1,
  6826. SysRecordTime: record_time,
  6827. GoodTypeId: item.GoodTypeId,
  6828. GoodId: item.GoodId,
  6829. PatientId: patient_id,
  6830. ConsumableType: 2,
  6831. StorehouseId: houseConfig.StorehouseOutInfo,
  6832. IsCheck: 1,
  6833. OverCount: sum_count,
  6834. }
  6835. warehouseOutInfo.Count = item.Count
  6836. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6837. warehouseOutInfo.Price = stockInInfo.Price
  6838. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6839. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6840. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6841. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6842. warehouseOutInfo.Number = warehouseOutInfos.Number
  6843. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6844. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6845. //查找当天是否存在出库记录
  6846. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6847. if errcod == gorm.ErrRecordNotFound {
  6848. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6849. //插入详情明细表
  6850. stockFlow := models.VmStockFlow{
  6851. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6852. WarehouseOutId: warehouseOut.ID,
  6853. GoodId: item.GoodId,
  6854. Number: warehouseOutInfos.Number,
  6855. ProductDate: stockInInfo.ProductDate,
  6856. ExpireDate: stockInInfo.ExpiryDate,
  6857. Count: item.Count,
  6858. Price: stockInInfo.Price,
  6859. Status: 1,
  6860. Ctime: record_time,
  6861. UserOrgId: adminInfo.Org.Id,
  6862. Manufacturer: stockInInfo.Manufacturer,
  6863. Dealer: stockInInfo.Dealer,
  6864. LicenseNumber: stockInInfo.LicenseNumber,
  6865. IsEdit: 2,
  6866. Creator: creater,
  6867. SystemTime: record_time,
  6868. ConsumableType: 3,
  6869. WarehousingDetailId: 0,
  6870. IsSys: 1,
  6871. UpdateCreator: creater,
  6872. PatientId: patient_id,
  6873. StorehouseId: houseConfig.StorehouseOutInfo,
  6874. }
  6875. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6876. if errflow == gorm.ErrRecordNotFound {
  6877. //创建流水表
  6878. err := service.CreateStockFlowOne(stockFlow)
  6879. fmt.Println("err", err)
  6880. } else if errflow == nil {
  6881. //插入详情明细表
  6882. stockFlow := models.VmStockFlow{
  6883. ID: exsit.ID,
  6884. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6885. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6886. WarehouseOutId: warehouseOut.ID,
  6887. GoodId: item.GoodId,
  6888. Number: warehouseOutInfos.Number,
  6889. ProductDate: stockInInfo.ProductDate,
  6890. ExpireDate: stockInInfo.ExpiryDate,
  6891. Count: exsit.Count - delete_count,
  6892. Price: stockInInfo.Price,
  6893. Status: 1,
  6894. Ctime: record_time,
  6895. UserOrgId: adminInfo.Org.Id,
  6896. Manufacturer: stockInInfo.Manufacturer,
  6897. Dealer: stockInInfo.Dealer,
  6898. LicenseNumber: stockInInfo.LicenseNumber,
  6899. IsEdit: 2,
  6900. Creator: creater,
  6901. SystemTime: record_time,
  6902. ConsumableType: 3,
  6903. WarehousingDetailId: 0,
  6904. IsSys: 1,
  6905. UpdateCreator: creater,
  6906. PatientId: patient_id,
  6907. StorehouseId: houseConfig.StorehouseOutInfo,
  6908. }
  6909. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6910. }
  6911. } else if errcod == nil {
  6912. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6913. //查询剩余库存
  6914. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6915. var sum_count int64
  6916. for _, item := range goodList {
  6917. sum_count += item.StockCount
  6918. }
  6919. //创建退库单,生成退库数据
  6920. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6921. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6922. operation_time := time.Now().Unix()
  6923. creater := adminInfo.AdminUser.Id
  6924. //创建退库单
  6925. timeStr := time.Now().Format("2006-01-02")
  6926. timeArr := strings.Split(timeStr, "-")
  6927. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6928. total = total + 1
  6929. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6930. cancelStock := models.CancelStock{
  6931. OrderNumber: orderNumber,
  6932. OperaTime: operation_time,
  6933. OrgId: adminInfo.Org.Id,
  6934. Creater: creater,
  6935. Ctime: time.Now().Unix(),
  6936. Status: 1,
  6937. ReturnTime: record_time,
  6938. Type: 1,
  6939. StorehouseId: houseConfig.StorehouseOutInfo,
  6940. IsCheck: 1,
  6941. }
  6942. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6943. if msgerrkonde == gorm.ErrRecordNotFound {
  6944. service.AddSigleCancelStock(&cancelStock)
  6945. }
  6946. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6947. //查询是否有出库
  6948. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6949. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6950. deaerler, _ := service.GetDealerById(info.Dealer)
  6951. if info.ID > 0 {
  6952. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6953. cancelStockInfo := models.CancelStockInfo{
  6954. GoodId: item.GoodId,
  6955. CancelStockId: cancel.ID,
  6956. GoodTypeId: good.GoodTypeId,
  6957. Count: delete_count,
  6958. Price: info.Price,
  6959. Total: 0,
  6960. ProductDate: info.ProductDate,
  6961. ExpiryDate: info.ExpiryDate,
  6962. Ctime: time.Now().Unix(),
  6963. Status: 1,
  6964. OrgId: adminInfo.Org.Id,
  6965. OrderNumber: cancel.OrderNumber,
  6966. Type: 0,
  6967. Dealer: deaerler.DealerName,
  6968. Manufacturer: manufacturer.ManufacturerName,
  6969. Number: info.Number,
  6970. RegisterAccount: "",
  6971. Remark: "",
  6972. WarehouseInfoId: info.WarehouseInfotId,
  6973. PatientId: info.PatientId,
  6974. RecordDate: info.SysRecordTime,
  6975. StorehouseId: houseConfig.StorehouseOutInfo,
  6976. IsCheck: 1,
  6977. }
  6978. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6979. //退库数量增加
  6980. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6981. //查询剩余库存
  6982. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6983. var over_count int64
  6984. for _, it := range goodList {
  6985. over_count += it.StockCount
  6986. }
  6987. flow := models.VmStockFlow{
  6988. WarehousingId: info.WarehouseInfotId,
  6989. GoodId: item.GoodId,
  6990. Number: info.Number,
  6991. LicenseNumber: info.LicenseNumber,
  6992. Count: delete_count,
  6993. UserOrgId: adminInfo.Org.Id,
  6994. PatientId: patient_id,
  6995. SystemTime: info.SysRecordTime,
  6996. ConsumableType: 7,
  6997. IsSys: 0,
  6998. WarehousingOrder: "",
  6999. WarehouseOutId: info.WarehouseOutId,
  7000. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7001. IsEdit: 0,
  7002. CancelStockId: cancel.ID,
  7003. CancelOrderNumber: cancel.OrderNumber,
  7004. Manufacturer: manufacturer.ID,
  7005. Dealer: 0,
  7006. Creator: adminInfo.AdminUser.Id,
  7007. UpdateCreator: 0,
  7008. Status: 1,
  7009. Ctime: record_time,
  7010. Mtime: 0,
  7011. Price: info.Price,
  7012. WarehousingDetailId: info.WarehouseInfotId,
  7013. WarehouseOutDetailId: info.ID,
  7014. CancelOutDetailId: cancelInfo.ID,
  7015. ProductDate: info.ProductDate,
  7016. ExpireDate: info.ExpiryDate,
  7017. StorehouseId: houseConfig.StorehouseOutInfo,
  7018. OverCount: over_count,
  7019. }
  7020. service.CreateStockFlowOne(flow)
  7021. }
  7022. }
  7023. //更改自动出库的表格
  7024. details := models.BloodAutomaticReduceDetail{
  7025. WarehouseOutId: warehouseOutInfo.ID,
  7026. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7027. PatientId: patient_id,
  7028. Ctime: time.Now().Unix(),
  7029. Mtime: time.Now().Unix(),
  7030. Status: 1,
  7031. RecordTime: record_time,
  7032. OrgId: adminInfo.Org.Id,
  7033. GoodId: item.GoodId,
  7034. GoodTypeId: item.GoodTypeId,
  7035. Count: item.Count,
  7036. StorehouseId: houseConfig.StorehouseOutInfo,
  7037. }
  7038. //查询当天耗材是否已经存在数据
  7039. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7040. if errcode == gorm.ErrRecordNotFound {
  7041. service.CreateAutoReduceRecord(&details)
  7042. } else if errcode == nil {
  7043. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7044. service.CreateAutoReduceRecord(&details)
  7045. }
  7046. //查询默认仓库
  7047. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7048. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7049. var total_count int64
  7050. for _, it := range stockList {
  7051. total_count += it.StockCount
  7052. }
  7053. //基础库插入数据
  7054. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7055. }
  7056. }
  7057. if len(outbefor) > 0 {
  7058. //出库
  7059. for _, item := range outbefor {
  7060. var last_total int64
  7061. //1.查看该患者该耗材型号最后一次出库数量
  7062. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7063. //计算当前出库和最后一次出库数据相差数据
  7064. last_total = item.Count - goodInfoOne.Count
  7065. //查询该耗材的总库存
  7066. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7067. // 如果库存差大于剩余库存则提示库存不足
  7068. if last_total > wareinfo.StockCount {
  7069. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7070. c.ServeSuccessJSON(map[string]interface{}{
  7071. "message": "1",
  7072. "good_name": goodObj.GoodName,
  7073. "specification_name": goodObj.SpecificationName,
  7074. })
  7075. return
  7076. } else {
  7077. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7078. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7079. if err == gorm.ErrRecordNotFound {
  7080. //没有记录,则创建出库单
  7081. timeStr := time.Now().Format("2006-01-02")
  7082. timeArr := strings.Split(timeStr, "-")
  7083. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7084. total = total + 1
  7085. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7086. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7087. number = number + total
  7088. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7089. warehouseOut := models.WarehouseOut{
  7090. WarehouseOutOrderNumber: warehousing_out_order,
  7091. OperationTime: time.Now().Unix(),
  7092. OrgId: adminInfo.Org.Id,
  7093. Creater: adminInfo.AdminUser.Id,
  7094. Ctime: time.Now().Unix(),
  7095. Status: 1,
  7096. WarehouseOutTime: record_time,
  7097. Dealer: 0,
  7098. Manufacturer: 0,
  7099. Type: 1,
  7100. IsSys: 1,
  7101. StorehouseId: houseConfig.StorehouseOutInfo,
  7102. IsCheck: 1,
  7103. }
  7104. service.AddSigleWarehouseOut(&warehouseOut)
  7105. }
  7106. //出库
  7107. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7108. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7109. //1.查看该患者该耗材型号最后一次出库数量
  7110. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7111. prepare := models.DialysisBeforePrepare{
  7112. UserOrgId: adminInfo.Org.Id,
  7113. PatientId: patient_id,
  7114. RecordDate: record_time,
  7115. GoodId: item.GoodId,
  7116. GoodTypeId: item.GoodTypeId,
  7117. Count: item.Count - goodInfoTwo.Count,
  7118. Ctime: time.Now().Unix(),
  7119. Mtime: 0,
  7120. Creater: adminInfo.AdminUser.Id,
  7121. Modifier: adminInfo.AdminUser.Id,
  7122. Status: 1,
  7123. CommdityCode: "",
  7124. NewCount: 0,
  7125. ProjectId: 0,
  7126. StorehouseId: houseConfig.StorehouseOutInfo,
  7127. }
  7128. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7129. //增加出库数量
  7130. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7131. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7132. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7133. var total_count int64
  7134. for _, it := range stockList {
  7135. total_count += it.StockCount
  7136. }
  7137. //基础库插入数据
  7138. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7139. //剩余库存
  7140. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7141. var flush_count int64
  7142. for _, it := range goodList {
  7143. flush_count += it.StockCount
  7144. }
  7145. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7146. }
  7147. }
  7148. }
  7149. //查询今日出库数据
  7150. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7151. for _, it := range list {
  7152. prepare := models.DialysisBeforePrepare{
  7153. UserOrgId: it.OrgId,
  7154. PatientId: patient_id,
  7155. RecordDate: it.RecordTime,
  7156. GoodId: it.GoodId,
  7157. GoodTypeId: it.GoodTypeId,
  7158. Count: it.Count,
  7159. Ctime: time.Now().Unix(),
  7160. Creater: adminInfo.AdminUser.Id,
  7161. Status: 1,
  7162. StorehouseId: houseConfig.StorehouseOutInfo,
  7163. ProjectId: it.ProjectId,
  7164. }
  7165. //删除准备表数据
  7166. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7167. service.CreateDialysisBeforePrepareOne(&prepare)
  7168. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7169. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7170. var total_count int64
  7171. for _, it := range stockList {
  7172. total_count += it.StockCount
  7173. }
  7174. //基础库插入数据
  7175. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7176. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7177. var flush_count int64
  7178. for _, it := range goodList {
  7179. flush_count += it.StockCount
  7180. }
  7181. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7182. }
  7183. }
  7184. }
  7185. //更新自动出库的地方
  7186. var errs error
  7187. if errs == nil {
  7188. c.ServeSuccessJSON(map[string]interface{}{
  7189. "msg": "修改成功",
  7190. "message": "2",
  7191. "good_name": "",
  7192. "specification_name": "",
  7193. })
  7194. return
  7195. } else {
  7196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7197. return
  7198. }
  7199. }
  7200. }
  7201. func (c *DialysisAPIController) GetDialysisGoods() {
  7202. schedualDate := c.GetString("schedule_date")
  7203. schedule_type, _ := c.GetInt64("schedule_type")
  7204. partition_id, _ := c.GetInt64("partition_id")
  7205. page, _ := c.GetInt("page")
  7206. patient_id, _ := c.GetInt64("patient_id")
  7207. schedualEndDate := int64(0)
  7208. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7209. if parseDateErr != nil && len(schedualDate) != 0 {
  7210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7211. return
  7212. }
  7213. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7214. if parseDateErr != nil && len(schedualDate) != 0 {
  7215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7216. return
  7217. }
  7218. schedualEndDate = endDate.Unix()
  7219. adminUser := c.GetMobileAdminUserInfo()
  7220. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7221. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7222. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7223. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7224. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7225. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7226. //获取当天该病人的透析处方
  7227. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7228. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7229. if err == gorm.ErrRecordNotFound {
  7230. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7231. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7232. if patient_id != 0 {
  7233. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7234. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7235. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7236. //获取患者总的出库数据
  7237. item.LastAutomaticReduceDetail = goodUser
  7238. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7239. item.Project = project
  7240. for _, it := range item.AutomaticReduceDetail {
  7241. var total int64
  7242. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7243. for _, its := range auto {
  7244. total += its.Count
  7245. }
  7246. it.Count = total
  7247. }
  7248. }
  7249. }
  7250. c.ServeSuccessJSON(map[string]interface{}{
  7251. "dialysis_goods": dialysisGoods,
  7252. "good_type": goodTypes,
  7253. "total": total,
  7254. "prescribe": prescribe,
  7255. "good_info": good_info,
  7256. "warehouseOutList": warehouseOutList,
  7257. "config": config,
  7258. "outConfig": outConfig,
  7259. "settleConfig": settleConfig,
  7260. })
  7261. return
  7262. } else if err == nil {
  7263. //获取当天排班的每个患者的库存使用情况
  7264. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7265. //获取患者总的出库数据
  7266. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7267. if patient_id != 0 {
  7268. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7269. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7270. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7271. item.Project = project
  7272. item.LastAutomaticReduceDetail = goodUser
  7273. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7274. for _, it := range item.AutomaticReduceDetail {
  7275. var total int64
  7276. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7277. for _, its := range auto {
  7278. total += its.Count
  7279. }
  7280. it.Count = total
  7281. }
  7282. }
  7283. }
  7284. if err == nil {
  7285. c.ServeSuccessJSON(map[string]interface{}{
  7286. "dialysis_goods": dialysisGoods,
  7287. "good_type": goodTypes,
  7288. "total": total,
  7289. "prescribe": prescribe,
  7290. "good_info": good_info,
  7291. "project": project,
  7292. "warehouseOutList": warehouseOutList,
  7293. "config": config,
  7294. "outConfig": outConfig,
  7295. "settleConfig": settleConfig,
  7296. })
  7297. return
  7298. } else {
  7299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7300. return
  7301. }
  7302. } else if err != nil {
  7303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7304. return
  7305. }
  7306. }
  7307. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7308. start_time := c.GetString("start_time")
  7309. end_time := c.GetString("end_time")
  7310. timeLayout := "2006-01-02"
  7311. loc, _ := time.LoadLocation("Local")
  7312. var theStartTime int64
  7313. if len(start_time) > 0 {
  7314. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7315. if err != nil {
  7316. utils.ErrorLog(err.Error())
  7317. }
  7318. theStartTime = theTime.Unix()
  7319. }
  7320. var theEndtTime int64
  7321. if len(end_time) > 0 {
  7322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7323. if err != nil {
  7324. utils.ErrorLog(err.Error())
  7325. }
  7326. theEndtTime = theTime.Unix()
  7327. }
  7328. adminUser := c.GetMobileAdminUserInfo()
  7329. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7330. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7331. if err == nil {
  7332. c.ServeSuccessJSON(map[string]interface{}{
  7333. "stock_out": outInfo,
  7334. "stockCount": stockCount,
  7335. })
  7336. return
  7337. } else {
  7338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7339. return
  7340. }
  7341. }
  7342. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7343. patient_id, _ := c.GetInt64("patient_id", 0)
  7344. record_time := c.GetString("record_time")
  7345. adminUser := c.GetMobileAdminUserInfo()
  7346. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7347. if parseDateErr != nil && len(record_time) != 0 {
  7348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7349. return
  7350. }
  7351. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7352. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7353. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7354. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7355. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7356. //获取今日患者的透析处方参数
  7357. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7358. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7359. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7360. c.ServeSuccessJSON(map[string]interface{}{
  7361. "good_type": goodTypes,
  7362. "good_user": goodUser,
  7363. "good_info": good_info,
  7364. "last_good_user": lastGoodUserDetial,
  7365. "project": project,
  7366. "prescription": prescribe,
  7367. "outInfo": outInfo,
  7368. "configs": configs,
  7369. })
  7370. return
  7371. }
  7372. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7373. patient_id, _ := c.GetInt64("patient_id", 0)
  7374. record_date := c.GetString("record_time")
  7375. timeLayout := "2006-01-02"
  7376. loc, _ := time.LoadLocation("Local")
  7377. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7378. record_time := theRecordTime.Unix()
  7379. adminInfo := c.GetMobileAdminUserInfo()
  7380. dataBody := make(map[string]interface{}, 0)
  7381. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7382. if err != nil {
  7383. utils.ErrorLog(err.Error())
  7384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7385. return
  7386. }
  7387. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7388. var beforePrepares []*models.DialysisBeforePrepareGoods
  7389. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7390. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7391. goods, _ := dataBody["goods"].([]interface{})
  7392. if len(goods) > 0 {
  7393. for _, item := range goods {
  7394. items := item.(map[string]interface{})
  7395. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7396. utils.ErrorLog("good_id")
  7397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7398. return
  7399. }
  7400. good_id := int64(items["good_id"].(float64))
  7401. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7402. utils.ErrorLog("good_type_id")
  7403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7404. return
  7405. }
  7406. good_type_id := int64(items["good_type_id"].(float64))
  7407. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7408. utils.ErrorLog("count")
  7409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7410. return
  7411. }
  7412. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7413. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7414. utils.ErrorLog("project_id")
  7415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7416. return
  7417. }
  7418. project_id := int64(items["project_id"].(float64))
  7419. new_count := int64(items["new_count"].(float64))
  7420. old_count := int64(items["old_count"].(float64))
  7421. prepare := &models.DialysisBeforePrepareGoods{
  7422. GoodId: good_id,
  7423. GoodTypeId: good_type_id,
  7424. Count: count,
  7425. ProjectId: project_id,
  7426. StorehouseId: houseConfig.StorehouseOutInfo,
  7427. NewCount: new_count,
  7428. OldCount: old_count,
  7429. }
  7430. beforePrepares = append(beforePrepares, prepare)
  7431. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7432. GoodId: good_id,
  7433. GoodTypeId: good_type_id,
  7434. Count: count,
  7435. ProjectId: project_id,
  7436. StorehouseId: houseConfig.StorehouseOutInfo,
  7437. NewCount: new_count,
  7438. OldCount: old_count,
  7439. }
  7440. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7441. }
  7442. }
  7443. }
  7444. //查询是否有库存
  7445. for _, item := range beforePrepares {
  7446. if item.NewCount > 0 {
  7447. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7448. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7449. if item.Count > warehouse.Count {
  7450. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7451. c.ServeSuccessJSON(map[string]interface{}{
  7452. "message": "1",
  7453. "good_name": goodObj.GoodName,
  7454. "specification_name": goodObj.SpecificationName,
  7455. })
  7456. return
  7457. }
  7458. }
  7459. }
  7460. // 查询信息规挡的设置天数
  7461. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7462. if infor.ID > 0 && infor.WeekDay > 0 {
  7463. var cha_time int64
  7464. timeNowStr := time.Now().Format("2006-01-02")
  7465. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7466. //今日的日期减去设置的日期
  7467. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7468. if cha_time >= record_time {
  7469. //查询审核是否允许
  7470. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7471. //申请状态不允许的情况 拒绝修改
  7472. if infor.ApplicationStatus != 1 {
  7473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7474. return
  7475. }
  7476. }
  7477. }
  7478. //出库逻辑
  7479. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7480. if err != nil {
  7481. utils.ErrorLog(err.Error())
  7482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7483. return
  7484. }
  7485. finish := models.XtDialysisFinish{
  7486. IsFinish: 1,
  7487. UserOrgId: adminInfo.Org.Id,
  7488. Status: 1,
  7489. Ctime: time.Now().Unix(),
  7490. Mtime: 0,
  7491. Module: 11,
  7492. RecordDate: record_time,
  7493. Sourse: 1,
  7494. PatientId: patient_id,
  7495. }
  7496. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7497. if dialysisFinish.ID == 0 {
  7498. service.CreateDialysisFinish(finish)
  7499. }
  7500. //查询当天出库的数据
  7501. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7502. for _, item := range list {
  7503. prepare := models.DialysisBeforePrepare{
  7504. UserOrgId: item.OrgId,
  7505. PatientId: item.PatientId,
  7506. RecordDate: item.RecordTime,
  7507. GoodId: item.GoodId,
  7508. GoodTypeId: item.GoodTypeId,
  7509. Count: item.Count,
  7510. Creater: adminInfo.AdminUser.Id,
  7511. Status: 1,
  7512. Ctime: time.Now().Unix(),
  7513. ProjectId: item.ProjectId,
  7514. StorehouseId: houseConfig.StorehouseOutInfo,
  7515. }
  7516. //清空准备表的数据
  7517. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7518. //插入准备表数据
  7519. service.CreateDialysisBeforePrepareOne(&prepare)
  7520. //查询默认仓库
  7521. //查询默认仓库
  7522. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7523. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7524. var total_count int64
  7525. for _, it := range stockList {
  7526. total_count += it.StockCount
  7527. }
  7528. //基础库插入数据
  7529. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7530. ////更新剩余库存
  7531. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7532. var flush_count int64
  7533. for _, it := range goodList {
  7534. flush_count += it.StockCount
  7535. }
  7536. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7537. if errs != nil {
  7538. goodErrcode := models.XtGoodErrcode{
  7539. UserOrgId: item.OrgId,
  7540. Errcode: "手动出库更新剩余出库失败",
  7541. GoodId: item.GoodId,
  7542. Status: 1,
  7543. Ctime: time.Now().Unix(),
  7544. Mtime: 0,
  7545. Count: 0,
  7546. StockCount: 0,
  7547. Creater: adminInfo.AdminUser.Id,
  7548. BatchNumberId: 0,
  7549. WarehouseOutId: 0,
  7550. }
  7551. service.CreateGoodErrcode(goodErrcode)
  7552. }
  7553. }
  7554. //更新自动出库的地方
  7555. var errs error
  7556. if errs == nil {
  7557. c.ServeSuccessJSON(map[string]interface{}{
  7558. "msg": "修改成功",
  7559. "message": "2",
  7560. "good_name": "",
  7561. "specification_name": "",
  7562. })
  7563. return
  7564. } else {
  7565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7566. return
  7567. }
  7568. }
  7569. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7570. newArr = make([]*models.DialysisBeforePrepare, 0)
  7571. for i := 0; i < len(arr); i++ {
  7572. repeat := false
  7573. for j := i + 1; j < len(arr); j++ {
  7574. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7575. repeat = true
  7576. break
  7577. }
  7578. }
  7579. if !repeat {
  7580. newArr = append(newArr, arr[i])
  7581. }
  7582. }
  7583. return
  7584. }
  7585. func (c *DialysisAPIController) GetAllDrug() {
  7586. patient_id, _ := c.GetInt64("patient_id", 0)
  7587. adminInfo := c.GetMobileAdminUserInfo()
  7588. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7589. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7590. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7591. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7592. c.ServeSuccessJSON(map[string]interface{}{
  7593. "base_drug_config": drugStockConfig,
  7594. "private_drug_config": privateDrugConfig,
  7595. "base_drug_list": drugList,
  7596. "private_drug_list": privateDrugList,
  7597. })
  7598. }
  7599. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7600. newArr = make([]*models.DialysisBeforePrepare, 0)
  7601. for i := 0; i < len(arr); i++ {
  7602. repeat := false
  7603. for j := i + 1; j < len(arr); j++ {
  7604. if arr[i].GoodId == arr[j].GoodId {
  7605. repeat = true
  7606. break
  7607. }
  7608. }
  7609. if !repeat {
  7610. newArr = append(newArr, arr[i])
  7611. }
  7612. }
  7613. return
  7614. }
  7615. func (c *DialysisAPIController) GetDepartment() {
  7616. adminInfo := c.GetMobileAdminUserInfo()
  7617. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7618. if err == nil {
  7619. c.ServeSuccessJSON(map[string]interface{}{
  7620. "departments": departments,
  7621. })
  7622. } else {
  7623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7624. return
  7625. }
  7626. }
  7627. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7628. types, _ := c.GetInt("type", 0)
  7629. start_time := c.GetString("start_time")
  7630. end_time := c.GetString("end_time")
  7631. orgId := c.GetMobileAdminUserInfo().Org.Id
  7632. timeLayout := "2006-01-02"
  7633. loc, _ := time.LoadLocation("Local")
  7634. var startTime int64
  7635. if len(start_time) > 0 {
  7636. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7637. if err != nil {
  7638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7639. return
  7640. }
  7641. startTime = theTime.Unix()
  7642. }
  7643. var endTime int64
  7644. if len(end_time) > 0 {
  7645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7646. if err != nil {
  7647. utils.ErrorLog(err.Error())
  7648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7649. return
  7650. }
  7651. endTime = theTime.Unix()
  7652. }
  7653. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7654. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7655. if err != nil {
  7656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7657. } else {
  7658. c.ServeSuccessJSON(map[string]interface{}{
  7659. "list": list,
  7660. "type": types,
  7661. "stockTotal": stockTotal,
  7662. })
  7663. }
  7664. }
  7665. func (c *DialysisAPIController) GetPrescriptionList() {
  7666. start_time := c.GetString("start_time")
  7667. end_time := c.GetString("end_time")
  7668. schedule_type, _ := c.GetInt64("schedule_type")
  7669. partion_id, _ := c.GetInt64("partion_id")
  7670. orgId := c.GetMobileAdminUserInfo().Org.Id
  7671. timeLayout := "2006-01-02"
  7672. loc, _ := time.LoadLocation("Local")
  7673. var startTime int64
  7674. if len(start_time) > 0 {
  7675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7676. if err != nil {
  7677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7678. return
  7679. }
  7680. startTime = theTime.Unix()
  7681. }
  7682. var endTime int64
  7683. if len(end_time) > 0 {
  7684. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7685. if err != nil {
  7686. utils.ErrorLog(err.Error())
  7687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7688. return
  7689. }
  7690. endTime = theTime.Unix()
  7691. }
  7692. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7693. fmt.Println("schedulelist22222222", schedulelist)
  7694. c.ServeSuccessJSON(map[string]interface{}{
  7695. "list": schedulelist,
  7696. })
  7697. return
  7698. }
  7699. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7700. ids := c.GetString("ids")
  7701. //patient_id, _ := c.GetInt64("patient_id")
  7702. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7703. idArray := strings.Split(ids, ",")
  7704. err := service.BatchDeleteMonitor(idArray)
  7705. fmt.Print("err", err)
  7706. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7707. //redis := service.RedisClient()
  7708. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7709. //redis.Set(key, "", time.Second)
  7710. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7711. //redis.Set(keyOne, "", time.Second)
  7712. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7713. //redis.Close()
  7714. c.ServeSuccessJSON(map[string]interface{}{
  7715. "msg": "批量删除成功",
  7716. })
  7717. return
  7718. }
  7719. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7720. id, _ := c.GetInt64("id")
  7721. timeLayout := "2006-01-02"
  7722. loc, _ := time.LoadLocation("Local")
  7723. //start_time := time.Now().Format("2006-01-02")
  7724. start_time := c.GetString("start_time")
  7725. end_time := c.GetString("end_time")
  7726. var startdateunix int64
  7727. if len(start_time) > 0 {
  7728. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7729. if err != nil {
  7730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7731. return
  7732. }
  7733. startdateunix = theTime.Unix()
  7734. }
  7735. var enddateunix int64
  7736. if len(end_time) > 0 {
  7737. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7738. if err != nil {
  7739. utils.ErrorLog(err.Error())
  7740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7741. return
  7742. }
  7743. enddateunix = theTime.Unix()
  7744. }
  7745. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7746. //nowTime := time.Now()
  7747. //endTime := nowTime.AddDate(-30, 0, 0)
  7748. //endTimes := endTime.Format("2006-01-02")
  7749. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7750. org_id := c.GetMobileAdminUserInfo().Org.Id
  7751. //if org_id == 10579 {
  7752. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7753. // c.ServeSuccessJSON(map[string]interface{}{
  7754. // "list": list,
  7755. // })
  7756. // return
  7757. //} else {
  7758. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7759. // c.ServeSuccessJSON(map[string]interface{}{
  7760. // "list": list,
  7761. // })
  7762. // return
  7763. //}
  7764. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7765. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7766. c.ServeSuccessJSON(map[string]interface{}{
  7767. "list": list,
  7768. })
  7769. return
  7770. } else {
  7771. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7772. c.ServeSuccessJSON(map[string]interface{}{
  7773. "list": list,
  7774. })
  7775. }
  7776. return
  7777. }
  7778. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7779. dataBody := make(map[string]interface{}, 0)
  7780. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7781. ids := c.GetString("ids")
  7782. idArray := strings.Split(ids, ",")
  7783. origin, _ := c.GetInt64("origin")
  7784. if origin == 1 {
  7785. err = service.BatchDeleteAdvice(idArray)
  7786. fmt.Print("err", err)
  7787. c.ServeSuccessJSON(map[string]interface{}{
  7788. "msg": "批量删除成功",
  7789. })
  7790. return
  7791. }
  7792. if origin == 2 {
  7793. service.BatchDeleteHisAdvice(idArray)
  7794. }
  7795. }
  7796. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7797. good_id, _ := c.GetInt64("good_id")
  7798. count, _ := c.GetInt64("count")
  7799. record_time, _ := c.GetInt64("record_time")
  7800. patient_id, _ := c.GetInt64("patient_id")
  7801. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7802. c.ServeSuccessJSON(map[string]interface{}{
  7803. "detail": detail,
  7804. })
  7805. return
  7806. }
  7807. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7808. good_id, _ := c.GetInt64("good_id")
  7809. record_time, _ := c.GetInt64("record_time")
  7810. patient_id, _ := c.GetInt64("patient_id")
  7811. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7812. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7813. fmt.Print("err", err)
  7814. c.ServeSuccessJSON(map[string]interface{}{
  7815. "msg": "批量删除成功",
  7816. })
  7817. return
  7818. }
  7819. func (c *DialysisAPIController) BatchAdviceCheck() {
  7820. ids := c.GetString("ids")
  7821. idArray := strings.Split(ids, ",")
  7822. creator, _ := c.GetInt64("creator")
  7823. origin, _ := c.GetInt64("origin")
  7824. if origin == 1 {
  7825. err := service.BatchAdviceCheck(idArray, creator)
  7826. fmt.Println(err)
  7827. list, _ := service.GetAdviceExecutionById(idArray)
  7828. c.ServeSuccessJSON(map[string]interface{}{
  7829. "list": list,
  7830. })
  7831. return
  7832. }
  7833. if origin == 2 {
  7834. service.BatchHisAdviceCheck(idArray, creator)
  7835. list, _ := service.GetHisAdviceExecutionById(idArray)
  7836. c.ServeSuccessJSON(map[string]interface{}{
  7837. "list": list,
  7838. })
  7839. return
  7840. }
  7841. }
  7842. func (c *DialysisAPIController) BatchAdviceExecution() {
  7843. ids := c.GetString("ids")
  7844. idArray := strings.Split(ids, ",")
  7845. executionTime := c.GetString("execution_time")
  7846. creator, _ := c.GetInt64("creator")
  7847. timeLayout := "2006-01-02 15:04:05"
  7848. loc, _ := time.LoadLocation("Local")
  7849. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7850. orgin, _ := c.GetInt64("origin")
  7851. if orgin == 1 {
  7852. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7853. list, _ := service.GetAdviceExecutionById(idArray)
  7854. fmt.Println(err)
  7855. c.ServeSuccessJSON(map[string]interface{}{
  7856. "list": list,
  7857. })
  7858. return
  7859. }
  7860. if orgin == 2 {
  7861. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7862. list, _ := service.GetHisAdviceExecutionById(idArray)
  7863. fmt.Println(err)
  7864. c.ServeSuccessJSON(map[string]interface{}{
  7865. "list": list,
  7866. })
  7867. return
  7868. }
  7869. }
  7870. func (c *DialysisAPIController) UpdateStockGoods() {
  7871. good_id, _ := c.GetInt64("good_id")
  7872. record_time, _ := c.GetInt64("record_time")
  7873. patient_id, _ := c.GetInt64("patient_id")
  7874. count, _ := c.GetInt64("count")
  7875. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7876. fmt.Print("err", err)
  7877. c.ServeSuccessJSON(map[string]interface{}{
  7878. "msg": "更新成功",
  7879. })
  7880. return
  7881. }
  7882. // 当前数据比上一次出库数据少
  7883. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7884. //查询该患者当天已经出库的耗材信息
  7885. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7886. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7887. for i := len(goods_yc) - 1; i >= 0; i-- {
  7888. goods_yc_temp := goods_yc[i]
  7889. for j := len(goods) - 1; j >= 0; j-- {
  7890. goods_temp := goods[j]
  7891. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7892. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7893. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7894. if goods_yc_temp.Count == goods_temp.Count {
  7895. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7896. goods = append(goods[:j], goods[j+1:]...)
  7897. break
  7898. }
  7899. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7900. if goods_yc_temp.Count > goods_temp.Count {
  7901. temp_count := goods_yc_temp.Count - goods_temp.Count
  7902. goods_yc[i].Count = temp_count
  7903. goods = append(goods[:j], goods[j+1:]...)
  7904. break
  7905. }
  7906. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7907. if goods_yc_temp.Count < goods_temp.Count {
  7908. temp_count := goods_temp.Count - goods_yc_temp.Count
  7909. goods[j].Count = temp_count
  7910. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7911. break
  7912. }
  7913. }
  7914. }
  7915. }
  7916. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7917. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7918. //退库
  7919. if len(goods_yc) > 0 {
  7920. for _, good_yc := range goods_yc {
  7921. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7922. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7923. }
  7924. }
  7925. return nil
  7926. }
  7927. // 耗材出库删除
  7928. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7929. // 先根据相关信息查询当天该耗材的出库信息
  7930. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7931. if err != nil {
  7932. return err
  7933. }
  7934. var delete_count int64 = 0
  7935. delete_count = warehouseOutInfos.Count - count
  7936. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7937. // 在出库记录表里记录退库详情
  7938. warehouseOutInfo := &models.WarehouseOutInfo{
  7939. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7940. WarehouseOutId: warehouseOut.ID,
  7941. Status: 1,
  7942. Ctime: time.Now().Unix(),
  7943. OrgId: orgID,
  7944. Type: 1,
  7945. IsSys: 1,
  7946. SysRecordTime: record_time,
  7947. GoodTypeId: good_yc.GoodTypeId,
  7948. GoodId: good_yc.GoodId,
  7949. PatientId: good_yc.PatientId,
  7950. ConsumableType: 2,
  7951. StorehouseId: houseConfig.StorehouseOutInfo,
  7952. IsCheck: 1,
  7953. }
  7954. warehouseOutInfo.Count = count
  7955. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7956. warehouseOutInfo.Price = stockInInfo.Price
  7957. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7958. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7959. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7960. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7961. warehouseOutInfo.Number = warehouseOutInfos.Number
  7962. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7963. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7964. //查找当天是否存在出库记录
  7965. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7966. if errcod == gorm.ErrRecordNotFound {
  7967. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7968. //插入详情明细表
  7969. stockFlow := models.VmStockFlow{
  7970. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7971. WarehouseOutId: warehouseOut.ID,
  7972. GoodId: good_yc.GoodId,
  7973. Number: warehouseOutInfos.Number,
  7974. ProductDate: stockInInfo.ProductDate,
  7975. ExpireDate: stockInInfo.ExpiryDate,
  7976. Count: count,
  7977. Price: stockInInfo.Price,
  7978. Status: 1,
  7979. Ctime: time.Now().Unix(),
  7980. UserOrgId: good_yc.OrgId,
  7981. Manufacturer: stockInInfo.Manufacturer,
  7982. Dealer: stockInInfo.Dealer,
  7983. LicenseNumber: stockInInfo.LicenseNumber,
  7984. IsEdit: 2,
  7985. Creator: creater,
  7986. SystemTime: record_time,
  7987. ConsumableType: 3,
  7988. WarehousingDetailId: 0,
  7989. IsSys: 1,
  7990. UpdateCreator: creater,
  7991. PatientId: patient_id,
  7992. StorehouseId: houseConfig.StorehouseOutInfo,
  7993. }
  7994. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7995. if errflow == gorm.ErrRecordNotFound {
  7996. //创建流水表
  7997. err := service.CreateStockFlowOne(stockFlow)
  7998. fmt.Println("err", err)
  7999. } else if errflow == nil {
  8000. //插入详情明细表
  8001. stockFlow := models.VmStockFlow{
  8002. ID: exsit.ID,
  8003. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8004. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8005. WarehouseOutId: warehouseOut.ID,
  8006. GoodId: good_yc.GoodId,
  8007. Number: warehouseOutInfos.Number,
  8008. ProductDate: stockInInfo.ProductDate,
  8009. ExpireDate: stockInInfo.ExpiryDate,
  8010. Count: exsit.Count - delete_count,
  8011. Price: stockInInfo.Price,
  8012. Status: 1,
  8013. Ctime: time.Now().Unix(),
  8014. UserOrgId: good_yc.OrgId,
  8015. Manufacturer: stockInInfo.Manufacturer,
  8016. Dealer: stockInInfo.Dealer,
  8017. LicenseNumber: stockInInfo.LicenseNumber,
  8018. IsEdit: 2,
  8019. Creator: creater,
  8020. SystemTime: record_time,
  8021. ConsumableType: 3,
  8022. WarehousingDetailId: 0,
  8023. IsSys: 1,
  8024. UpdateCreator: creater,
  8025. PatientId: patient_id,
  8026. StorehouseId: houseConfig.StorehouseOutInfo,
  8027. }
  8028. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8029. }
  8030. if errOne != nil {
  8031. return errOne
  8032. }
  8033. } else if errcod == nil {
  8034. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8035. //插入详情明细表
  8036. stockFlow := models.VmStockFlow{
  8037. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8038. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8039. WarehouseOutId: warehouseOut.ID,
  8040. GoodId: good_yc.GoodId,
  8041. Number: warehouseOutInfos.Number,
  8042. ProductDate: stockInInfo.ProductDate,
  8043. ExpireDate: stockInInfo.ExpiryDate,
  8044. Count: count,
  8045. Price: stockInInfo.Price,
  8046. Status: 1,
  8047. Ctime: time.Now().Unix(),
  8048. UserOrgId: good_yc.OrgId,
  8049. Manufacturer: stockInInfo.Manufacturer,
  8050. Dealer: stockInInfo.Dealer,
  8051. LicenseNumber: stockInInfo.LicenseNumber,
  8052. IsEdit: 2,
  8053. Creator: creater,
  8054. SystemTime: record_time,
  8055. ConsumableType: 3,
  8056. WarehousingDetailId: 0,
  8057. IsSys: 1,
  8058. UpdateCreator: creater,
  8059. PatientId: patient_id,
  8060. ReturnCount: delete_count,
  8061. StorehouseId: houseConfig.StorehouseOutInfo,
  8062. }
  8063. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8064. if errflows == gorm.ErrRecordNotFound {
  8065. //创建流水表
  8066. service.CreateStockFlowOne(stockFlow)
  8067. } else if errflows == nil {
  8068. stockFlow := models.VmStockFlow{
  8069. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8070. ID: exsit.ID,
  8071. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8072. WarehouseOutId: warehouseOut.ID,
  8073. GoodId: good_yc.GoodId,
  8074. Number: warehouseOutInfos.Number,
  8075. ProductDate: stockInInfo.ProductDate,
  8076. ExpireDate: stockInInfo.ExpiryDate,
  8077. Count: exsit.Count - delete_count,
  8078. Price: stockInInfo.Price,
  8079. Status: 1,
  8080. Ctime: time.Now().Unix(),
  8081. UserOrgId: good_yc.OrgId,
  8082. Manufacturer: stockInInfo.Manufacturer,
  8083. Dealer: stockInInfo.Dealer,
  8084. LicenseNumber: stockInInfo.LicenseNumber,
  8085. IsEdit: 2,
  8086. Creator: creater,
  8087. SystemTime: record_time,
  8088. ConsumableType: 3,
  8089. WarehousingDetailId: 0,
  8090. IsSys: 1,
  8091. UpdateCreator: creater,
  8092. PatientId: patient_id,
  8093. ReturnCount: delete_count,
  8094. StorehouseId: houseConfig.StorehouseOutInfo,
  8095. }
  8096. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8097. }
  8098. }
  8099. //更改自动出库的表格
  8100. details := models.BloodAutomaticReduceDetail{
  8101. WarehouseOutId: warehouseOutInfo.ID,
  8102. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8103. PatientId: patient_id,
  8104. Ctime: time.Now().Unix(),
  8105. Mtime: time.Now().Unix(),
  8106. Status: 1,
  8107. RecordTime: record_time,
  8108. OrgId: orgID,
  8109. GoodId: good_yc.GoodId,
  8110. GoodTypeId: good_yc.GoodTypeId,
  8111. Count: count,
  8112. StorehouseId: houseConfig.StorehouseOutInfo,
  8113. }
  8114. //查询当天耗材是否已经存在数据
  8115. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8116. if errcode == gorm.ErrRecordNotFound {
  8117. errTwo := service.CreateAutoReduceRecord(&details)
  8118. if errTwo != nil {
  8119. return errTwo
  8120. }
  8121. } else if errcode == nil {
  8122. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8123. service.CreateAutoReduceRecord(&details)
  8124. }
  8125. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8126. //增加出库库存数量
  8127. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8128. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8129. fmt.Println("errOne", errOne)
  8130. // 删除出库完成后,要增加对应批次的库存数量
  8131. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8132. if errThree != nil {
  8133. return errThree
  8134. }
  8135. if good_yc.Count == 0 {
  8136. return nil
  8137. } else {
  8138. return errors.New("退库和出库数据不匹配")
  8139. }
  8140. }
  8141. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8142. //查询该患者当天已经出库的耗材信息
  8143. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8144. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8145. for i := len(goods_yc) - 1; i >= 0; i-- {
  8146. goods_yc_temp := goods_yc[i]
  8147. for j := len(goods) - 1; j >= 0; j-- {
  8148. goods_temp := goods[j]
  8149. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8150. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8151. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8152. if goods_yc_temp.Count == goods_temp.Count {
  8153. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8154. goods = append(goods[:j], goods[j+1:]...)
  8155. break
  8156. }
  8157. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8158. if goods_yc_temp.Count > goods_temp.Count {
  8159. temp_count := goods_yc_temp.Count - goods_temp.Count
  8160. goods_yc[i].Count = temp_count
  8161. goods = append(goods[:j], goods[j+1:]...)
  8162. break
  8163. }
  8164. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8165. if goods_yc_temp.Count < goods_temp.Count {
  8166. temp_count := goods_temp.Count - goods_yc_temp.Count
  8167. goods[j].Count = temp_count
  8168. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8169. break
  8170. }
  8171. }
  8172. }
  8173. }
  8174. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8175. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8176. fmt.Println("剩余需要出库的", len(goods))
  8177. if len(goods) > 0 {
  8178. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8179. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8180. if err == gorm.ErrRecordNotFound {
  8181. //没有记录,则创建出库单
  8182. timeStr := time.Now().Format("2006-01-02")
  8183. timeArr := strings.Split(timeStr, "-")
  8184. total, _ := service.FindAllWarehouseOut(orgID)
  8185. total = total + 1
  8186. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8187. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8188. number = number + total
  8189. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8190. warehouseOut := models.WarehouseOut{
  8191. WarehouseOutOrderNumber: warehousing_out_order,
  8192. OperationTime: time.Now().Unix(),
  8193. OrgId: orgID,
  8194. Creater: creater,
  8195. Ctime: time.Now().Unix(),
  8196. Status: 1,
  8197. WarehouseOutTime: record_time,
  8198. Dealer: 0,
  8199. Manufacturer: 0,
  8200. Type: 1,
  8201. IsSys: 1,
  8202. StorehouseId: houseConfig.StorehouseOutInfo,
  8203. IsCheck: 1,
  8204. }
  8205. err := service.AddSigleWarehouseOut(&warehouseOut)
  8206. if err != nil {
  8207. utils.TraceLog("创建出库单失败 err = %v", err)
  8208. return err
  8209. } else {
  8210. out = warehouseOut
  8211. }
  8212. }
  8213. for _, item := range goods {
  8214. var newCount int64 = 0
  8215. for _, it := range goodOne {
  8216. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8217. newCount = it.Count
  8218. }
  8219. }
  8220. prepare := models.DialysisBeforePrepare{
  8221. GoodTypeId: item.GoodTypeId,
  8222. GoodId: item.GoodId,
  8223. Count: item.Count,
  8224. StorehouseId: houseConfig.StorehouseOutInfo,
  8225. }
  8226. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8227. //增加出库数量
  8228. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8229. }
  8230. }
  8231. if len(goods_yc) > 0 {
  8232. for _, good_yc := range goods_yc {
  8233. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8234. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8235. }
  8236. }
  8237. return nil
  8238. }
  8239. // 耗材出库删除
  8240. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8241. // 先根据相关信息查询当天该耗材的出库信息
  8242. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8243. if err != nil {
  8244. return err
  8245. }
  8246. var delete_count int64 = 0
  8247. for _, ware := range warehouseOutInfos {
  8248. // 判断当前出库的数据和删除出库数量
  8249. if good_yc.Count <= ware.Count {
  8250. delete_count = good_yc.Count
  8251. } else {
  8252. delete_count = ware.Count
  8253. }
  8254. warehouseOutInfo := &models.WarehouseOutInfo{
  8255. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8256. WarehouseOutId: warehouseOut.ID,
  8257. Status: 1,
  8258. Ctime: time.Now().Unix(),
  8259. Remark: "",
  8260. OrgId: orgID,
  8261. Type: 1,
  8262. Manufacturer: 0,
  8263. Dealer: 0,
  8264. IsSys: 0,
  8265. SysRecordTime: record_time,
  8266. GoodTypeId: good_yc.GoodTypeId,
  8267. GoodId: good_yc.GoodId,
  8268. StorehouseId: warehouseOut.StorehouseId,
  8269. IsCheck: 1,
  8270. }
  8271. warehouseOutInfo.Count = delete_count
  8272. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8273. warehouseOutInfo.Price = stockInInfo.Price
  8274. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8275. if errOne != nil {
  8276. return errOne
  8277. }
  8278. // 删除出库完成后,要改变流水库存(有疑问)
  8279. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8280. fmt.Println("errOne", errOne)
  8281. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8282. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8283. //扣减出库数量
  8284. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8285. if errThree != nil {
  8286. return errThree
  8287. }
  8288. }
  8289. if good_yc.Count == 0 {
  8290. return nil
  8291. } else {
  8292. return errors.New("退库和出库数据不匹配")
  8293. }
  8294. }
  8295. func (this *DialysisAPIController) GetMobileScheduleList() {
  8296. limit, _ := this.GetInt64("limit")
  8297. page, _ := this.GetInt64("page")
  8298. type_options_visible, _ := this.GetInt64("type_options_visible")
  8299. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8300. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8301. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8302. }
  8303. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8304. newArr = make([]*models.HisPrescriptionProject, 0)
  8305. for i := 0; i < len(arr); i++ {
  8306. repeat := false
  8307. for j := i + 1; j < len(arr); j++ {
  8308. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8309. repeat = true
  8310. break
  8311. }
  8312. }
  8313. if !repeat {
  8314. newArr = append(newArr, arr[i])
  8315. }
  8316. }
  8317. return
  8318. }
  8319. func (this *DialysisAPIController) GetRoleList() {
  8320. admin_user_id, _ := this.GetInt64("admin_user_id")
  8321. orgid := this.GetMobileAdminUserInfo().Org.Id
  8322. list, err := service.GetRoleList(orgid, admin_user_id)
  8323. fmt.Println(err)
  8324. this.ServeSuccessJSON(map[string]interface{}{
  8325. "list": list,
  8326. })
  8327. return
  8328. }
  8329. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8330. // 先根据相关信息查询当天该耗材的出库信息
  8331. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8332. if err != nil {
  8333. return err
  8334. }
  8335. var delete_count int64 = 0
  8336. delete_count = warehouseOutInfos.Count - count
  8337. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8338. // 删除出库完成后,要增加对应批次的库存数量
  8339. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8340. if errThree != nil {
  8341. return errThree
  8342. }
  8343. //增加退库数量
  8344. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8345. //扣减出库数量
  8346. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8347. //查询剩余库存
  8348. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8349. var sum_count int64
  8350. for _, item := range goodList {
  8351. sum_count += item.StockCount
  8352. }
  8353. // 在出库记录表里记录退库详情
  8354. warehouseOutInfo := &models.WarehouseOutInfo{
  8355. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8356. WarehouseOutId: warehouseOut.ID,
  8357. Status: 1,
  8358. Ctime: time.Now().Unix(),
  8359. OrgId: orgID,
  8360. Type: 1,
  8361. IsSys: 1,
  8362. SysRecordTime: record_time,
  8363. GoodTypeId: good_yc.GoodTypeId,
  8364. GoodId: good_yc.GoodId,
  8365. PatientId: good_yc.PatientId,
  8366. ConsumableType: 2,
  8367. StorehouseId: houseConfig.StorehouseOutInfo,
  8368. IsCheck: 1,
  8369. OverCount: sum_count,
  8370. }
  8371. warehouseOutInfo.Count = count
  8372. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8373. warehouseOutInfo.Price = stockInInfo.Price
  8374. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8375. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8376. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8377. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8378. warehouseOutInfo.Number = warehouseOutInfos.Number
  8379. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8380. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8381. //查找当天是否存在出库记录
  8382. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8383. if errcod == gorm.ErrRecordNotFound {
  8384. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8385. //插入详情明细表
  8386. if errOne != nil {
  8387. return errOne
  8388. }
  8389. //插入详情明细表
  8390. stockFlow := models.VmStockFlow{
  8391. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8392. WarehouseOutId: warehouseOut.ID,
  8393. GoodId: good_yc.GoodId,
  8394. Number: warehouseOutInfos.Number,
  8395. ProductDate: stockInInfo.ProductDate,
  8396. ExpireDate: stockInInfo.ExpiryDate,
  8397. Count: count,
  8398. Price: stockInInfo.Price,
  8399. Status: 1,
  8400. Ctime: record_time,
  8401. UserOrgId: good_yc.OrgId,
  8402. Manufacturer: stockInInfo.Manufacturer,
  8403. Dealer: stockInInfo.Dealer,
  8404. LicenseNumber: stockInInfo.LicenseNumber,
  8405. IsEdit: 2,
  8406. Creator: creater,
  8407. SystemTime: record_time,
  8408. ConsumableType: 3,
  8409. WarehousingDetailId: 0,
  8410. IsSys: 1,
  8411. UpdateCreator: creater,
  8412. PatientId: patient_id,
  8413. StorehouseId: houseConfig.StorehouseOutInfo,
  8414. OverCount: sum_count,
  8415. ProjectId: good_yc.ProjectId,
  8416. }
  8417. err := service.CreateStockFlowOne(stockFlow)
  8418. fmt.Println("err", err)
  8419. } else if errcod == nil {
  8420. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8421. }
  8422. //创建退库单
  8423. operation_time := time.Now().Unix()
  8424. //创建退库单
  8425. timeStr := time.Now().Format("2006-01-02")
  8426. timeArr := strings.Split(timeStr, "-")
  8427. total, _ := service.FindAllCancelStockTotal(orgID)
  8428. total = total + 1
  8429. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8430. cancelStock := models.CancelStock{
  8431. OrderNumber: orderNumber,
  8432. OperaTime: operation_time,
  8433. OrgId: orgID,
  8434. Creater: warehouseOut.Creater,
  8435. Ctime: time.Now().Unix(),
  8436. Status: 1,
  8437. ReturnTime: record_time,
  8438. Type: 1,
  8439. StorehouseId: stockInInfo.StorehouseId,
  8440. IsCheck: 1,
  8441. }
  8442. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8443. if msgerrkonde == gorm.ErrRecordNotFound {
  8444. service.AddSigleCancelStock(&cancelStock)
  8445. }
  8446. cancel, _ := service.GetLastCancelStockById(orgID)
  8447. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8448. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8449. cancelStockInfo := models.CancelStockInfo{
  8450. GoodId: stockInInfo.GoodId,
  8451. CancelStockId: cancel.ID,
  8452. GoodTypeId: stockInInfo.GoodTypeId,
  8453. Count: delete_count,
  8454. Price: stockInInfo.PackingPrice,
  8455. Total: 0,
  8456. ProductDate: stockInInfo.ProductDate,
  8457. ExpiryDate: stockInInfo.ExpiryDate,
  8458. Ctime: record_time,
  8459. Status: 1,
  8460. OrgId: orgID,
  8461. OrderNumber: cancel.OrderNumber,
  8462. Type: 0,
  8463. Dealer: deaerler.DealerName,
  8464. Manufacturer: manufacturer.ManufacturerName,
  8465. Number: stockInInfo.Number,
  8466. RegisterAccount: "",
  8467. Remark: "",
  8468. WarehouseInfoId: stockInInfo.ID,
  8469. PatientId: patient_id,
  8470. RecordDate: record_time,
  8471. StorehouseId: stockInInfo.StorehouseId,
  8472. IsCheck: 1,
  8473. }
  8474. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8475. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8476. flow := models.VmStockFlow{
  8477. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8478. GoodId: good_yc.GoodId,
  8479. Number: warehouseOutInfos.Number,
  8480. LicenseNumber: stockInInfo.LicenseNumber,
  8481. Count: delete_count,
  8482. UserOrgId: orgID,
  8483. PatientId: patient_id,
  8484. SystemTime: record_time,
  8485. ConsumableType: 7,
  8486. IsSys: 0,
  8487. WarehousingOrder: "",
  8488. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8489. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8490. IsEdit: 0,
  8491. CancelStockId: cancel.ID,
  8492. CancelOrderNumber: cancel.OrderNumber,
  8493. Manufacturer: manufacturer.ID,
  8494. Dealer: 0,
  8495. Creator: warehouseOut.Creater,
  8496. UpdateCreator: 0,
  8497. Status: 1,
  8498. Ctime: record_time,
  8499. Mtime: 0,
  8500. Price: stockInInfo.Price,
  8501. WarehousingDetailId: stockInInfo.ID,
  8502. WarehouseOutDetailId: warehouseOutInfos.ID,
  8503. CancelOutDetailId: cancelInfo.ID,
  8504. ProductDate: stockInInfo.ProductDate,
  8505. ExpireDate: stockInInfo.ExpiryDate,
  8506. StorehouseId: houseConfig.StorehouseOutInfo,
  8507. OverCount: sum_count,
  8508. }
  8509. service.CreateStockFlowOne(flow)
  8510. //更改自动出库的表格
  8511. details := models.BloodAutomaticReduceDetail{
  8512. WarehouseOutId: warehouseOutInfo.ID,
  8513. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8514. PatientId: patient_id,
  8515. Ctime: time.Now().Unix(),
  8516. Mtime: time.Now().Unix(),
  8517. Status: 1,
  8518. RecordTime: record_time,
  8519. OrgId: orgID,
  8520. GoodId: good_yc.GoodId,
  8521. GoodTypeId: good_yc.GoodTypeId,
  8522. Count: count,
  8523. StorehouseId: houseConfig.StorehouseOutInfo,
  8524. }
  8525. //查询当天耗材是否已经存在数据
  8526. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8527. if errcode == gorm.ErrRecordNotFound {
  8528. errTwo := service.CreateAutoReduceRecord(&details)
  8529. if errTwo != nil {
  8530. return errTwo
  8531. }
  8532. } else if errcode == nil {
  8533. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8534. service.CreateAutoReduceRecord(&details)
  8535. }
  8536. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8537. //增加出库库存数量
  8538. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8539. if good_yc.Count == 0 {
  8540. return nil
  8541. } else {
  8542. return errors.New("退库和出库数据不匹配")
  8543. }
  8544. }
  8545. func (this *DialysisAPIController) SavePatientSign() {
  8546. adminUserInfo := this.GetMobileAdminUserInfo()
  8547. patient_id, _ := this.GetInt64("patient_id")
  8548. dialysis_date, _ := this.GetInt64("dialysis_date")
  8549. orgid := adminUserInfo.Org.Id
  8550. var esdata models.DialysisOrder
  8551. var err error
  8552. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8554. return
  8555. }
  8556. esdata.Hash = esdata.Hash
  8557. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8558. order := models.DialysisOrder{
  8559. Hash: esdata.Hash,
  8560. Url: esdata.Url,
  8561. }
  8562. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8563. redis := service.RedisClient()
  8564. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8565. redis.Set(key, "", time.Second)
  8566. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8567. //清空key 值
  8568. redis.Set(keyOne, "", time.Second)
  8569. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8570. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8571. //redis.Set(keyTwo, "", time.Second)
  8572. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8573. redis.Set(keyThree, "", time.Second)
  8574. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8575. redis.Set(keyFour, "", time.Second)
  8576. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8577. redis.Set(keyFive, "", time.Second)
  8578. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8579. redis.Set(keySix, "", time.Second)
  8580. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8581. redis.Set(keySeven, "", time.Second)
  8582. if err != nil {
  8583. fmt.Println(err)
  8584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8585. return
  8586. }
  8587. this.ServeSuccessJSON(map[string]interface{}{
  8588. "electronic_signature": esdata,
  8589. })
  8590. }
  8591. func (this *DialysisAPIController) GetPatientSign() {
  8592. patient_id, _ := this.GetInt64("patient_id")
  8593. dialysis_date, _ := this.GetInt64("dialysis_date")
  8594. adminUserInfo := this.GetMobileAdminUserInfo()
  8595. orgId := adminUserInfo.Org.Id
  8596. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8597. if err != nil {
  8598. fmt.Println(err)
  8599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8600. return
  8601. }
  8602. this.ServeSuccessJSON(map[string]interface{}{
  8603. "dialysisOrder": dialysisOrder,
  8604. })
  8605. }
  8606. func (this *DialysisAPIController) GetScheduleByPatient() {
  8607. patient_id, _ := this.GetInt64("patient_id")
  8608. schedule_date, _ := this.GetInt64("schedule_date")
  8609. orgid := this.GetMobileAdminUserInfo().Org.Id
  8610. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8611. this.ServeSuccessJSON(map[string]interface{}{
  8612. "schedule": schedule,
  8613. })
  8614. }
  8615. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8616. org_id := this.GetMobileAdminUserInfo().Org.Id
  8617. patient_id, _ := this.GetInt64("patient_id")
  8618. schedule_date, _ := this.GetInt64("schedule_date")
  8619. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8620. this.ServeSuccessJSON(map[string]interface{}{
  8621. "order": order,
  8622. })
  8623. }
  8624. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8625. org_id := this.GetMobileAdminUserInfo().Org.Id
  8626. schedule_date := this.GetString("schedule_date")
  8627. schedule_type, _ := this.GetInt64("schedule_type")
  8628. timeLayout := "2006-01-02"
  8629. loc, _ := time.LoadLocation("Local")
  8630. var startdateunix int64
  8631. if len(schedule_date) > 0 {
  8632. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8633. if err != nil {
  8634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8635. return
  8636. }
  8637. startdateunix = theTime.Unix()
  8638. }
  8639. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8640. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8641. devices, _ := service.GetAllDevicetByListSix(org_id)
  8642. for key, item := range scheduals {
  8643. // 床位信息
  8644. for _, device := range devices {
  8645. if item.BedId == device.ID {
  8646. scheduals[key].DeviceNumber = device
  8647. break
  8648. }
  8649. }
  8650. }
  8651. this.ServeSuccessJSON(map[string]interface{}{
  8652. "list": list,
  8653. "scheduals": scheduals,
  8654. })
  8655. }
  8656. func (this *DialysisAPIController) SavePatientPicture() {
  8657. patient_id, _ := this.GetInt64("patient_id")
  8658. dialysis_date, _ := this.GetInt64("schedule_date")
  8659. avatar := this.GetString("avatar")
  8660. fmt.Println("patient_id", patient_id)
  8661. orgId := this.GetMobileAdminUserInfo().Org.Id
  8662. order := models.DialysisOrder{
  8663. Url: avatar,
  8664. }
  8665. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8666. redis := service.RedisClient()
  8667. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8668. redis.Set(key, "", time.Second)
  8669. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8670. //清空key 值
  8671. redis.Set(keyOne, "", time.Second)
  8672. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8673. redis.Set(keyThree, "", time.Second)
  8674. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8675. redis.Set(keyFour, "", time.Second)
  8676. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8677. redis.Set(keyFive, "", time.Second)
  8678. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8679. redis.Set(keySix, "", time.Second)
  8680. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8681. redis.Set(keySeven, "", time.Second)
  8682. if err != nil {
  8683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8684. return
  8685. }
  8686. this.ServeSuccessJSON(map[string]interface{}{
  8687. "order": order,
  8688. })
  8689. }
  8690. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8691. ids := this.GetString("ids")
  8692. idSplit := strings.Split(ids, ",")
  8693. orgId := this.GetMobileAdminUserInfo().Org.Id
  8694. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8695. execution_time := this.GetString("exce_time")
  8696. timeLayout2 := "2006-01-02 15:04:05"
  8697. loc, _ := time.LoadLocation("Local")
  8698. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8699. if errs != nil {
  8700. utils.ErrorLog(errs.Error())
  8701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8702. return
  8703. }
  8704. //his客户
  8705. if config.IsOpen == 1 {
  8706. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8707. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8708. for _, item := range list {
  8709. for _, it := range adviceList {
  8710. if item.DrugId == it.DrugId {
  8711. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8712. }
  8713. }
  8714. }
  8715. for _, item := range list {
  8716. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8717. var sum_out_count int64
  8718. for _, itemThree := range item.ChildDoctorAdvice {
  8719. var prescribing_number int64
  8720. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8721. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8722. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8723. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8724. }
  8725. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8726. prescribing_number = parseIntPrescribingNumber
  8727. }
  8728. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8729. prescribing_number = parseIntPrescribingNumber
  8730. }
  8731. sum_out_count += prescribing_number
  8732. }
  8733. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8734. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8735. //库存不足
  8736. if sum_out_count > drugStockOut.FlushCount {
  8737. this.ServeSuccessJSON(map[string]interface{}{
  8738. "msg": "2",
  8739. "drug": medical,
  8740. "ids": ids,
  8741. })
  8742. return
  8743. }
  8744. }
  8745. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8746. //执行医嘱
  8747. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8748. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8749. for _, item := range advices {
  8750. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8751. redis := service.RedisClient()
  8752. //清空key 值
  8753. redis.Set(key, "", time.Second)
  8754. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8755. redis.Set(keyTwo, "", time.Second)
  8756. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8757. redis.Set(keyThree, "", time.Second)
  8758. recordDate := theTime.Format("2006-01-02")
  8759. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8760. redis.Set(keyFour, "", time.Second)
  8761. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8762. redis.Set(keyFive, "", time.Second)
  8763. defer redis.Close()
  8764. }
  8765. if errs == nil {
  8766. //药品管理信息
  8767. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8768. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8769. if drugStockConfig.IsOpen == 1 {
  8770. for _, item := range advices {
  8771. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8772. config, _ := service.GetDrugOpenConfigOne(orgId)
  8773. if config.IsOpen != 1 {
  8774. //查询该药品是否有库存
  8775. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8776. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8777. if medical.IsUse == 2 {
  8778. if config.IsOpen != 1 {
  8779. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8780. service.HisDrugsDelivery(orgId, creater, &advice)
  8781. if orgId == 3877 || orgId == 10265 {
  8782. //查询该药品是否有出库记录
  8783. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8784. if len(flowMap) == 0 {
  8785. errs := service.UpdateHisAdviceById(advice.ID)
  8786. if errs != nil {
  8787. drugError := models.XtDrugError{
  8788. UserOrgId: orgId,
  8789. DrugId: item.DrugId,
  8790. RecordDate: item.AdviceDate,
  8791. PatientId: item.PatientId,
  8792. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8793. Status: 1,
  8794. Ctime: time.Now().Unix(),
  8795. Mtime: 0,
  8796. SumCount: 0,
  8797. Prescribingnumber: advice.PrescribingNumber,
  8798. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8799. }
  8800. service.CreateDrugError(drugError)
  8801. }
  8802. this.ServeSuccessJSON(map[string]interface{}{
  8803. "msg": "2",
  8804. "drug": medical,
  8805. "ids": ids,
  8806. })
  8807. return
  8808. }
  8809. }
  8810. }
  8811. if pharmacyConfig.IsOpen != 1 {
  8812. service.HisDrugsDelivery(orgId, creater, &advice)
  8813. if orgId == 3877 || orgId == 10265 {
  8814. //查询该药品是否有出库记录
  8815. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8816. if len(flowMap) == 0 {
  8817. errs := service.UpdateHisAdviceById(advice.ID)
  8818. if errs != nil {
  8819. drugError := models.XtDrugError{
  8820. UserOrgId: orgId,
  8821. DrugId: item.DrugId,
  8822. RecordDate: item.AdviceDate,
  8823. PatientId: item.PatientId,
  8824. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8825. Status: 1,
  8826. Ctime: time.Now().Unix(),
  8827. Mtime: 0,
  8828. SumCount: 0,
  8829. Prescribingnumber: advice.PrescribingNumber,
  8830. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8831. }
  8832. service.CreateDrugError(drugError)
  8833. }
  8834. this.ServeSuccessJSON(map[string]interface{}{
  8835. "msg": "2",
  8836. "drug": medical,
  8837. "ids": ids,
  8838. })
  8839. return
  8840. }
  8841. }
  8842. }
  8843. //更新字典里面的库存
  8844. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8845. var sum_count int64
  8846. for _, its := range stockInfo {
  8847. if its.MaxUnit == medical.MaxUnit {
  8848. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8849. }
  8850. sum_count += its.StockMaxNumber + its.StockMinNumber
  8851. }
  8852. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8853. //剩余库存
  8854. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8855. }
  8856. }
  8857. }
  8858. }
  8859. }
  8860. this.ServeSuccessJSON(map[string]interface{}{
  8861. "msg": "1",
  8862. "ids": ids,
  8863. })
  8864. return
  8865. } else {
  8866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8867. }
  8868. }
  8869. //血透客户
  8870. if config.IsOpen == 2 || config.IsOpen == 0 {
  8871. //药品管理信息
  8872. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8873. if drugStockConfig.IsOpen == 1 {
  8874. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8875. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8876. for _, item := range list {
  8877. for _, it := range adviceList {
  8878. if item.DrugId == it.DrugId {
  8879. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8880. }
  8881. }
  8882. }
  8883. for _, item := range list {
  8884. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8885. var sum_out_count int64
  8886. for _, itemThree := range item.ChildDoctorAdvice {
  8887. var prescribing_number int64
  8888. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8889. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8890. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8891. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8892. }
  8893. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8894. prescribing_number = parseIntPrescribingNumber
  8895. }
  8896. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8897. prescribing_number = parseIntPrescribingNumber
  8898. }
  8899. sum_out_count += prescribing_number
  8900. }
  8901. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8902. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8903. //库存不足
  8904. if sum_out_count > drugStockOut.FlushCount {
  8905. this.ServeSuccessJSON(map[string]interface{}{
  8906. "msg": "2",
  8907. "drug": medical,
  8908. "ids": ids,
  8909. })
  8910. return
  8911. }
  8912. }
  8913. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8914. //执行医嘱
  8915. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8916. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8917. for _, item := range advices {
  8918. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8919. redis := service.RedisClient()
  8920. //清空key 值
  8921. redis.Set(key, "", time.Second)
  8922. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8923. redis.Set(keyTwo, "", time.Second)
  8924. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8925. redis.Set(keyThree, "", time.Second)
  8926. recordDate := theTime.Format("2006-01-02")
  8927. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8928. redis.Set(keyFour, "", time.Second)
  8929. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8930. redis.Set(keyFive, "", time.Second)
  8931. defer redis.Close()
  8932. }
  8933. if errs == nil {
  8934. for _, item := range advices {
  8935. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8936. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8937. //查询是否出库按钮开启
  8938. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8939. if adviceSetting.IsAdviceOpen == 1 {
  8940. //查询是否出库按钮开启
  8941. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8942. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8943. if prescriptionConfig.IsOpen == 1 {
  8944. if medical.IsUse == 2 {
  8945. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8946. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8947. }
  8948. if pharmacyConfig.IsOpen != 1 {
  8949. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8950. }
  8951. //更新字典里面的库存
  8952. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8953. var sum_count int64
  8954. for _, its := range stockInfo {
  8955. if its.MaxUnit == medical.MaxUnit {
  8956. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8957. }
  8958. sum_count += its.StockMaxNumber + its.StockMinNumber
  8959. }
  8960. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8961. //剩余库存
  8962. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8963. }
  8964. }
  8965. } else {
  8966. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8967. if medical.IsUse == 2 {
  8968. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8969. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8970. }
  8971. if pharmacyConfig.IsOpen != 1 {
  8972. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8973. }
  8974. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8975. var sum_count int64
  8976. for _, its := range stockInfo {
  8977. if its.MaxUnit == medical.MaxUnit {
  8978. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8979. }
  8980. sum_count += its.StockMaxNumber + its.StockMinNumber
  8981. }
  8982. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8983. //剩余库存
  8984. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8985. }
  8986. }
  8987. }
  8988. }
  8989. this.ServeSuccessJSON(map[string]interface{}{
  8990. "msg": "1",
  8991. "ids": ids,
  8992. })
  8993. return
  8994. } else {
  8995. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8996. //执行医嘱
  8997. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8998. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8999. for _, item := range advices {
  9000. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9001. redis := service.RedisClient()
  9002. //清空key 值
  9003. redis.Set(key, "", time.Second)
  9004. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9005. redis.Set(keyTwo, "", time.Second)
  9006. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9007. redis.Set(keyThree, "", time.Second)
  9008. recordDate := theTime.Format("2006-01-02")
  9009. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9010. redis.Set(keyFour, "", time.Second)
  9011. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9012. redis.Set(keyFive, "", time.Second)
  9013. defer redis.Close()
  9014. }
  9015. this.ServeSuccessJSON(map[string]interface{}{
  9016. "msg": "1",
  9017. "ids": ids,
  9018. })
  9019. return
  9020. }
  9021. }
  9022. }
  9023. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9024. ids := this.GetString("ids")
  9025. idSplit := strings.Split(ids, ",")
  9026. orgId := this.GetMobileAdminUserInfo().Org.Id
  9027. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9028. if config.IsOpen == 1 {
  9029. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9030. this.ServeSuccessJSON(map[string]interface{}{
  9031. "msg": "1",
  9032. "ids": ids,
  9033. })
  9034. return
  9035. }
  9036. if config.IsOpen == 0 || config.IsOpen == 2 {
  9037. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9038. this.ServeSuccessJSON(map[string]interface{}{
  9039. "msg": "1",
  9040. "ids": ids,
  9041. })
  9042. return
  9043. }
  9044. }
  9045. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9046. ids := this.GetString("ids")
  9047. idSplit := strings.Split(ids, ",")
  9048. orgId := this.GetMobileAdminUserInfo().Org.Id
  9049. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9050. //his
  9051. if config.IsOpen == 1 {
  9052. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9053. theTime := time.Now()
  9054. advices := models.HisDoctorAdviceThirty{
  9055. CheckTime: theTime.Unix(),
  9056. Checker: checker,
  9057. UpdatedTime: time.Now().Unix(),
  9058. }
  9059. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9060. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9061. for _, item := range list {
  9062. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9063. redis := service.RedisClient()
  9064. //清空key 值
  9065. redis.Set(key, "", time.Second)
  9066. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9067. redis.Set(keyTwo, "", time.Second)
  9068. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9069. redis.Set(keyThree, "", time.Second)
  9070. recordDate := theTime.Format("2006-01-02")
  9071. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9072. redis.Set(keyFour, "", time.Second)
  9073. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9074. redis.Set(keyFive, "", time.Second)
  9075. defer redis.Close()
  9076. }
  9077. this.ServeSuccessJSON(map[string]interface{}{
  9078. "msg": "1",
  9079. "ids": ids,
  9080. })
  9081. return
  9082. }
  9083. //血透
  9084. if config.IsOpen == 0 || config.IsOpen == 2 {
  9085. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9086. theTime := time.Now()
  9087. advices := models.DoctorAdvice{
  9088. CheckTime: theTime.Unix(),
  9089. Checker: checker,
  9090. UpdatedTime: time.Now().Unix(),
  9091. }
  9092. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9093. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9094. for _, item := range list {
  9095. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9096. redis := service.RedisClient()
  9097. //清空key 值
  9098. redis.Set(key, "", time.Second)
  9099. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9100. redis.Set(keyTwo, "", time.Second)
  9101. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9102. redis.Set(keyThree, "", time.Second)
  9103. recordDate := theTime.Format("2006-01-02")
  9104. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9105. redis.Set(keyFour, "", time.Second)
  9106. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9107. redis.Set(keyFive, "", time.Second)
  9108. defer redis.Close()
  9109. }
  9110. this.ServeSuccessJSON(map[string]interface{}{
  9111. "msg": "1",
  9112. "ids": ids,
  9113. })
  9114. return
  9115. }
  9116. }
  9117. func (this *DialysisAPIController) CheckSchedule() {
  9118. patientID, _ := this.GetInt64("patient_id")
  9119. recordDateStr := this.GetString("record_date")
  9120. nurseID, _ := this.GetInt64("start_nurse")
  9121. schedual_type, _ := this.GetInt64("schedual_type")
  9122. bedID, _ := this.GetInt64("bed")
  9123. start_time := this.GetString("start_time")
  9124. fmt.Println("patientID", patientID)
  9125. fmt.Println("recordDateStr", recordDateStr)
  9126. fmt.Println("nurseID", nurseID)
  9127. fmt.Println("schedual_type------", schedual_type)
  9128. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9130. return
  9131. }
  9132. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9133. if parseStartDateErr != nil {
  9134. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9136. return
  9137. }
  9138. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9139. if parseErr != nil {
  9140. this.ErrorLog("时间解析失败:%v", parseErr)
  9141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9142. return
  9143. }
  9144. adminUserInfo := this.GetMobileAdminUserInfo()
  9145. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9146. if getPatientErr != nil {
  9147. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9149. return
  9150. } else if patient == nil {
  9151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9152. return
  9153. }
  9154. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9155. if getNurseErr != nil {
  9156. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9158. return
  9159. } else if nurse == nil {
  9160. this.ErrorLog("护士不存在")
  9161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9162. return
  9163. }
  9164. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9165. if getDeviceNumberErr != nil {
  9166. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9168. return
  9169. } else if deviceNumber == nil {
  9170. this.ErrorLog("床位号不存在")
  9171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9172. return
  9173. }
  9174. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9175. if getRecordErr != nil {
  9176. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9178. return
  9179. } else if dialysisRecord != nil {
  9180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9181. return
  9182. }
  9183. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9184. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9185. timeLayout := "2006-01-02 15:04:05"
  9186. loc, _ := time.LoadLocation("Local")
  9187. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9188. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9189. schedulestartTime := theStartTime.Unix()
  9190. scheduleendTime := theEndTime.Unix()
  9191. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9192. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9193. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9194. //查询该床位是否有人用了
  9195. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9196. if err == nil {
  9197. if schedule.ID == 0 {
  9198. this.ServeSuccessJSON(map[string]interface{}{
  9199. "status": 0,
  9200. "msg": "请求失败",
  9201. })
  9202. } else {
  9203. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9204. if order.ID > 0 { //该机位被其他人占用了
  9205. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9206. return
  9207. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9208. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9209. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9210. this.ServeSuccessJSON(map[string]interface{}{
  9211. "status": 1,
  9212. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9213. })
  9214. return
  9215. } else {
  9216. this.ServeSuccessJSON(map[string]interface{}{
  9217. "status": 0,
  9218. "msg": "",
  9219. })
  9220. }
  9221. }
  9222. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9223. this.ServeSuccessJSON(map[string]interface{}{
  9224. "status": 2,
  9225. "msg": "当前机位已有患者在使用,请重新选择!",
  9226. })
  9227. }
  9228. }
  9229. } else {
  9230. this.ServeSuccessJSON(map[string]interface{}{
  9231. "status": 0,
  9232. "msg": "",
  9233. })
  9234. }
  9235. }
  9236. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9237. orgId := this.GetMobileAdminUserInfo().Org.Id
  9238. schedule_type, _ := this.GetInt64("schedule_type")
  9239. partion_type, _ := this.GetInt64("partion_type")
  9240. start_time := this.GetString("start_time")
  9241. timeLayout := "2006-01-02"
  9242. loc, _ := time.LoadLocation("Local")
  9243. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9244. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9245. _, config := service.FindXTHisRecordByOrgId(orgId)
  9246. appId := this.GetMobileAdminUserInfo().App.Id
  9247. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9248. if err == nil {
  9249. this.ServeSuccessJSON(map[string]interface{}{
  9250. "list": list,
  9251. "config": config,
  9252. "doctorList": doctorList,
  9253. })
  9254. return
  9255. } else {
  9256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9257. return
  9258. }
  9259. }
  9260. func (this *DialysisAPIController) SaveMobileInformation() {
  9261. patient_id, _ := this.GetInt64("patient_id")
  9262. record_date, _ := this.GetInt64("record_date")
  9263. startTime := this.GetString("start_time")
  9264. module, _ := this.GetInt64("module")
  9265. remark := this.GetString("remark")
  9266. timeLayout := "2006-01-02 15:04"
  9267. loc, _ := time.LoadLocation("Local")
  9268. if len(startTime) == 0 {
  9269. utils.ErrorLog("len(start_time) == 0")
  9270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9271. return
  9272. }
  9273. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9274. if err != nil {
  9275. utils.ErrorLog(err.Error())
  9276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9277. return
  9278. }
  9279. StartTime := theTime.Unix()
  9280. fmt.Println("startime-------------", StartTime)
  9281. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9282. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9283. information := models.XtDialysisInformation{
  9284. Module: module,
  9285. PatientId: patient_id,
  9286. RecordDate: record_date,
  9287. ApplicationDate: StartTime,
  9288. Creater: creater,
  9289. ApplicationStatus: 2,
  9290. Checker: 0,
  9291. CheckTime: 0,
  9292. Remark: remark,
  9293. UserOrgId: user_org_id,
  9294. Ctime: time.Now().Unix(),
  9295. Status: 1,
  9296. Mtime: 0,
  9297. }
  9298. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9299. if infor.ID == 0 {
  9300. service.SaveDialysisInformation(information)
  9301. }
  9302. if infor.ID > 0 {
  9303. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9304. }
  9305. this.ServeSuccessJSON(map[string]interface{}{
  9306. "information": information,
  9307. })
  9308. return
  9309. }
  9310. func (this *DialysisAPIController) GetMobileInformation() {
  9311. limit, _ := this.GetInt64("limit")
  9312. page, _ := this.GetInt64("page")
  9313. orgid := this.GetMobileAdminUserInfo().Org.Id
  9314. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9315. appid := this.GetMobileAdminUserInfo().App.Id
  9316. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9317. patients, _ := service.GetAllpatientThirty(orgid)
  9318. this.ServeSuccessJSON(map[string]interface{}{
  9319. "information": information,
  9320. "total": total,
  9321. "doclist": doclist,
  9322. "patients": patients,
  9323. })
  9324. return
  9325. }
  9326. func (this *DialysisAPIController) GetMobileInformationOne() {
  9327. limit, _ := this.GetInt64("limit")
  9328. page, _ := this.GetInt64("page")
  9329. orgid := this.GetMobileAdminUserInfo().Org.Id
  9330. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9331. appid := this.GetMobileAdminUserInfo().App.Id
  9332. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9333. patients, _ := service.GetAllpatientThirty(orgid)
  9334. this.ServeSuccessJSON(map[string]interface{}{
  9335. "information": information,
  9336. "total": total,
  9337. "doclist": doclist,
  9338. "patients": patients,
  9339. })
  9340. return
  9341. }
  9342. func (this *DialysisAPIController) CheckMobileInformation() {
  9343. id, _ := this.GetInt64("id")
  9344. application_status, _ := this.GetInt64("application_status")
  9345. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9346. checktime := time.Now().Unix()
  9347. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9348. if err == nil {
  9349. this.ServeSuccessJSON(map[string]interface{}{
  9350. "msg": "ok",
  9351. })
  9352. return
  9353. }
  9354. }
  9355. func (c *DialysisAPIController) GetControlMonitorList() {
  9356. partition, _ := c.GetInt64("partition")
  9357. monitorDate := c.GetString("date")
  9358. patient_id, _ := c.GetInt64("patient_id")
  9359. pat_type, _ := c.GetInt64("pat_type")
  9360. timeLayout := "2006-01-02"
  9361. loc, _ := time.LoadLocation("Local")
  9362. var theStartTime int64
  9363. if len(monitorDate) > 0 {
  9364. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9365. if err != nil {
  9366. theStartTime = 0
  9367. }
  9368. theStartTime = theTime.Unix()
  9369. }
  9370. adminInfo := c.GetMobileAdminUserInfo()
  9371. orgID := adminInfo.Org.Id
  9372. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9373. if err != nil {
  9374. c.ErrorLog("获取排班信息失败:%v", err)
  9375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9376. } else {
  9377. if len(monitor) > 0 {
  9378. //获取所有床位
  9379. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9380. //获取所有分区
  9381. zoneList, _ := service.GetAllZoneByList(orgID)
  9382. //获取透析处方
  9383. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9384. //获取透前评估
  9385. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9386. //获取上机
  9387. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9388. //获取透后
  9389. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9390. //获取透后监测
  9391. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9392. //获取所有的患者
  9393. patients, _ := service.GetAllPatientListByListOne(orgID)
  9394. //获取所有透析模式
  9395. treatments, _ := service.GetAllTreatModeByList(orgID)
  9396. //获取所有医嘱
  9397. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9398. //获取双人核对
  9399. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9400. //治疗小结
  9401. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9402. //待消毒
  9403. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9404. for key, item := range monitor {
  9405. // 获取床位信息
  9406. for _, it := range numberList {
  9407. if item.BedId == it.ID {
  9408. monitor[key].DeviceNumber = it
  9409. break
  9410. }
  9411. }
  9412. //获取分区信息
  9413. for _, it := range zoneList {
  9414. if item.PartitionId == it.ID {
  9415. monitor[key].DeviceZone = it
  9416. }
  9417. }
  9418. for _, prescription := range prescriptions {
  9419. if item.PatientId == prescription.PatientId {
  9420. monitor[key].Prescription = prescription
  9421. break
  9422. }
  9423. }
  9424. for _, it := range checkList {
  9425. if item.PatientId == it.PatientId {
  9426. monitor[key].DoubleCheck = it
  9427. break
  9428. }
  9429. }
  9430. for _, it := range summaryList {
  9431. if item.PatientId == it.PatientId {
  9432. monitor[key].TreatmentSummaryForList = it
  9433. break
  9434. }
  9435. }
  9436. // 透前评估
  9437. for _, assessmentBefore := range assessmentBefores {
  9438. if item.PatientId == assessmentBefore.PatientId {
  9439. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9440. break
  9441. }
  9442. }
  9443. // 透析上下机
  9444. for _, dialysisOrder := range dialysisOrders {
  9445. if item.PatientId == dialysisOrder.PatientId {
  9446. monitor[key].DialysisOrder = dialysisOrder
  9447. break
  9448. }
  9449. }
  9450. // 治疗小节
  9451. for _, afterDislysis := range AssessmentAfterDislysis {
  9452. if item.PatientId == afterDislysis.PatientId {
  9453. monitor[key].AssessmentAfterDislysis = afterDislysis
  9454. break
  9455. }
  9456. }
  9457. for _, it := range monitorlist {
  9458. if item.PatientId == it.PatientId {
  9459. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9460. }
  9461. }
  9462. for _, it := range adviceList {
  9463. if item.PatientId == it.PatientId {
  9464. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9465. }
  9466. }
  9467. for _, patient := range patients {
  9468. if item.PatientId == patient.ID {
  9469. monitor[key].MonitorPatients = patient
  9470. break
  9471. }
  9472. }
  9473. for _, treatment := range treatments {
  9474. if item.ModeId == treatment.ID {
  9475. monitor[key].TreatmentMode = treatment
  9476. break
  9477. }
  9478. }
  9479. for _, infor := range informationList {
  9480. if item.PatientId == infor.PatientId {
  9481. monitor[key].NewDeviceInformation = infor
  9482. break
  9483. }
  9484. }
  9485. }
  9486. }
  9487. }
  9488. patients, err := service.GetAllpatientFourty(orgID)
  9489. var mds []*models.NewMonitorDialysisScheduleList
  9490. if pat_type == 0 {
  9491. for _, item := range monitor {
  9492. mds = append(mds, item)
  9493. }
  9494. }
  9495. //待医嘱核对
  9496. if pat_type == 1 {
  9497. for _, item := range monitor {
  9498. if len(item.AdviceList) > 0 {
  9499. mds = append(mds, item)
  9500. }
  9501. }
  9502. }
  9503. //待开小结
  9504. if pat_type == 2 {
  9505. for _, item := range monitor {
  9506. if item.TreatmentSummaryForList == nil {
  9507. mds = append(mds, item)
  9508. }
  9509. }
  9510. }
  9511. //待下机
  9512. if pat_type == 3 {
  9513. for _, item := range monitor {
  9514. if item.DialysisOrder != nil {
  9515. if item.DialysisOrder.ID > 0 {
  9516. mds = append(mds, item)
  9517. }
  9518. }
  9519. }
  9520. }
  9521. //待消毒
  9522. if pat_type == 4 {
  9523. for _, item := range monitor {
  9524. if item.NewDeviceInformation == nil {
  9525. mds = append(mds, item)
  9526. }
  9527. }
  9528. }
  9529. //待双人核对
  9530. if pat_type == 5 {
  9531. for _, item := range monitor {
  9532. if item.DoubleCheck == nil {
  9533. mds = append(mds, item)
  9534. }
  9535. }
  9536. }
  9537. //医嘱未执行
  9538. if pat_type == 6 {
  9539. for _, item := range monitor {
  9540. if len(item.AdviceList) > 0 {
  9541. mds = append(mds, item)
  9542. }
  9543. }
  9544. }
  9545. //患者未签名
  9546. if pat_type == 7 {
  9547. for _, item := range monitor {
  9548. if item.DialysisOrder != nil {
  9549. if item.DialysisOrder.ID > 0 {
  9550. mds = append(mds, item)
  9551. }
  9552. }
  9553. }
  9554. }
  9555. //目标超滤于实际超滤不同
  9556. if pat_type == 8 {
  9557. for _, item := range monitor {
  9558. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9559. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9560. mds = append(mds, item)
  9561. }
  9562. }
  9563. }
  9564. }
  9565. //血压少于5次
  9566. if pat_type == 9 {
  9567. for _, item := range monitor {
  9568. if len(item.MonitoringRecord) < 5 {
  9569. mds = append(mds, item)
  9570. }
  9571. }
  9572. }
  9573. if pat_type == 10 {
  9574. for _, item := range monitor {
  9575. if len(item.MonitoringRecord) == 0 {
  9576. mds = append(mds, item)
  9577. }
  9578. }
  9579. }
  9580. if pat_type == 11 {
  9581. for _, item := range monitor {
  9582. if len(item.MonitoringRecord) > 0 {
  9583. mds = append(mds, item)
  9584. }
  9585. }
  9586. }
  9587. if pat_type == 12 {
  9588. for _, item := range monitor {
  9589. if len(item.MonitoringRecord) > 0 {
  9590. mds = append(mds, item)
  9591. }
  9592. }
  9593. }
  9594. if err == nil {
  9595. c.ServeSuccessJSON(map[string]interface{}{
  9596. "monitor": mds,
  9597. "patients": patients,
  9598. })
  9599. } else {
  9600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9601. }
  9602. }
  9603. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9604. admin_user_id, _ := c.GetInt64("admin_user_id")
  9605. timeStr := time.Now().Format("2006-01-02")
  9606. timeLayout := "2006-01-02 15:04:05"
  9607. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9608. timenow := timeStringToTime.Unix()
  9609. orgId := c.GetMobileAdminUserInfo().Org.Id
  9610. //查询当前护士的患者
  9611. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9612. var patientIds []int64
  9613. for _, item := range orderList {
  9614. patientIds = append(patientIds, item.PatientId)
  9615. }
  9616. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9617. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9618. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9619. //药品管理信息
  9620. _, drugStockConfig := service.FindHisConfig(orgId)
  9621. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9622. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9623. c.ServeSuccessJSON(map[string]interface{}{
  9624. "adviceList": adviceList,
  9625. "hisAdviceList": hisAdviceList,
  9626. "projectList": projectList,
  9627. "drugStockConfig": drugStockConfig,
  9628. "patientList": patientList,
  9629. "projectConfig": projectConfig,
  9630. })
  9631. }
  9632. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9633. patient_id, _ := c.GetInt64("patient_id")
  9634. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9635. c.ServeSuccessJSON(map[string]interface{}{
  9636. "recrods": recrods,
  9637. })
  9638. }
  9639. func (c *DialysisAPIController) ExMobileChangeSch() {
  9640. id_one, _ := c.GetInt64("id_one")
  9641. id_two, _ := c.GetInt64("id_two")
  9642. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9643. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9644. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9645. //if order2.ID > 0 {
  9646. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9647. // return
  9648. //}
  9649. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9650. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9651. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9652. if count > 0 {
  9653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9654. return
  9655. }
  9656. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9657. if count1 > 0 {
  9658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9659. return
  9660. }
  9661. }
  9662. err := service.UpdateScheduleThree(sch, sch_two)
  9663. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9664. if order.ID > 0 {
  9665. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9666. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9667. redis := service.RedisClient()
  9668. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9669. redis.Set(key, "", time.Second)
  9670. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9671. //清空key 值
  9672. redis.Set(keyOne, "", time.Second)
  9673. }
  9674. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9675. if orderOne.ID > 0 {
  9676. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9677. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9678. redis := service.RedisClient()
  9679. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9680. redis.Set(key, "", time.Second)
  9681. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9682. //清空key 值
  9683. redis.Set(keyOne, "", time.Second)
  9684. }
  9685. if err == nil {
  9686. //去除当天患者排班中重复数据,保留最后一条数据
  9687. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9688. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9689. c.ServeSuccessJSON(map[string]interface{}{
  9690. "msg": "交换成功",
  9691. })
  9692. } else {
  9693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9694. return
  9695. }
  9696. }
  9697. func (c *DialysisAPIController) MobileCoverSch() {
  9698. id_one, _ := c.GetInt64("id_one")
  9699. id_two, _ := c.GetInt64("id_two")
  9700. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9701. //针对凤凰医院
  9702. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9703. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9704. if len(advice) > 0 {
  9705. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9706. }
  9707. }
  9708. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9709. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9710. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9711. if len(hisAdvice) > 0 {
  9712. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9713. }
  9714. if len(project) > 0 {
  9715. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9716. }
  9717. }
  9718. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9719. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9720. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9721. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9722. if count > 0 {
  9723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9724. return
  9725. }
  9726. }
  9727. var new_sch models.Schedule
  9728. new_sch = sch
  9729. new_sch.BedId = sch_two.BedId
  9730. new_sch.ScheduleDate = sch_two.ScheduleDate
  9731. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9732. new_sch.PartitionId = sch_two.PartitionId
  9733. new_sch.ScheduleType = sch_two.ScheduleType
  9734. new_sch.ID = 0
  9735. //删除原来的排班
  9736. err := service.SaveSchTwo(sch, sch_two)
  9737. //生成新的排班
  9738. if err == nil {
  9739. err2 := service.SaveSch(&new_sch)
  9740. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9741. if order.ID > 0 {
  9742. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9743. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9744. redis := service.RedisClient()
  9745. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9746. redis.Set(key, "", time.Second)
  9747. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9748. //清空key 值
  9749. redis.Set(keyOne, "", time.Second)
  9750. }
  9751. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9752. if orderOne.ID > 0 {
  9753. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9754. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9755. redis := service.RedisClient()
  9756. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9757. redis.Set(key, "", time.Second)
  9758. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9759. //清空key 值
  9760. redis.Set(keyOne, "", time.Second)
  9761. }
  9762. if err2 == nil {
  9763. //去除当天患者排班中重复数据,保留最后一条数据
  9764. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9765. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9766. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9767. c.ServeSuccessJSON(map[string]interface{}{
  9768. "msg": "覆盖成功",
  9769. "new_sch": new_sch,
  9770. })
  9771. } else {
  9772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9773. return
  9774. }
  9775. } else {
  9776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9777. return
  9778. }
  9779. }
  9780. func (c *DialysisAPIController) BatchCheckAdvice() {
  9781. patient_id, _ := c.GetInt64("patient_id")
  9782. advice_date, _ := c.GetInt64("advice_date")
  9783. org_id := c.GetMobileAdminUserInfo().Org.Id
  9784. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9785. //查询是his系统还是血透系统
  9786. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9787. //his客户
  9788. if configs.IsOpen == 1 {
  9789. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9790. for _, item := range adviceList {
  9791. service.BatchCheckHisAdvice(item.ID, creater)
  9792. }
  9793. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9794. for _, item := range projectList {
  9795. service.BatchCheckProject(item.ID, creater)
  9796. }
  9797. c.ServeSuccessJSON(map[string]interface{}{
  9798. "adviceList": adviceList,
  9799. "projectList": projectList,
  9800. })
  9801. }
  9802. if configs.IsOpen != 1 {
  9803. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9804. for _, item := range adviceList {
  9805. service.BatchAdviceList(item.ID, creater)
  9806. }
  9807. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9808. for _, item := range projectList {
  9809. service.BatchCheckProject(item.ID, creater)
  9810. }
  9811. c.ServeSuccessJSON(map[string]interface{}{
  9812. "adviceList": adviceList,
  9813. "projectList": projectList,
  9814. })
  9815. }
  9816. return
  9817. }
  9818. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9819. org_id := c.GetMobileAdminUserInfo().Org.Id
  9820. drugList, _ := service.GetAllDrugList(org_id)
  9821. c.ServeSuccessJSON(map[string]interface{}{
  9822. "drugList": drugList,
  9823. })
  9824. }
  9825. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9826. org_id := c.GetMobileAdminUserInfo().Org.Id
  9827. dataBody := make(map[string]interface{}, 0)
  9828. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9829. if err != nil {
  9830. utils.ErrorLog(err.Error())
  9831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9832. return
  9833. }
  9834. timeLayout := "2006-01-02"
  9835. loc, _ := time.LoadLocation("Local")
  9836. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9837. utils.ErrorLog("advice_type")
  9838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9839. return
  9840. }
  9841. adviceType := int64(dataBody["advice_type"].(float64))
  9842. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9843. utils.ErrorLog("start_time")
  9844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9845. return
  9846. }
  9847. startTime2, _ := dataBody["start_time"].(string)
  9848. time_arr := strings.Split(startTime2, " ")
  9849. if len(time_arr) > 0 {
  9850. startTime2 = time_arr[0]
  9851. }
  9852. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9853. utils.ErrorLog("advice_date")
  9854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9855. return
  9856. }
  9857. advice_date, _ := dataBody["advice_date"].(string)
  9858. var advicedateunix int64
  9859. if len(advice_date) > 0 {
  9860. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9861. if err != nil {
  9862. fmt.Println(err)
  9863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9864. return
  9865. }
  9866. advicedateunix = theTime.Unix()
  9867. }
  9868. adviceDate := startTime2
  9869. if len(adviceDate) == 0 {
  9870. utils.ErrorLog("len(adviceDate) == 0")
  9871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9872. return
  9873. }
  9874. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9875. if err != nil {
  9876. utils.ErrorLog(err.Error())
  9877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9878. return
  9879. }
  9880. AdviceDate := advicedateunix
  9881. RecordDate := advicedateunix
  9882. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9883. utils.ErrorLog("start_time")
  9884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9885. return
  9886. }
  9887. startTime, _ := dataBody["start_time"].(string)
  9888. if len(startTime) == 0 {
  9889. utils.ErrorLog("len(start_time) == 0")
  9890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9891. return
  9892. }
  9893. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9894. if err != nil {
  9895. utils.ErrorLog(err.Error())
  9896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9897. return
  9898. }
  9899. StartTime := theTime.Unix()
  9900. advice_name, _ := dataBody["advice_name"].(string)
  9901. advice_desc, _ := dataBody["advice_desc"].(string)
  9902. delivery_way, _ := dataBody["delivery_way"].(string)
  9903. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9904. frequency_type := int64(dataBody["frequency_type"].(float64))
  9905. frequency_week, _ := dataBody["frequency_week"].(string)
  9906. prescribing_number := dataBody["prescribing_number"].(float64)
  9907. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9908. remark := dataBody["remark"].(string)
  9909. single_dose := dataBody["single_dose"].(float64)
  9910. single_dose_unit := dataBody["single_dose_unit"].(string)
  9911. patient_id := int64(dataBody["patient_id"].(float64))
  9912. day_count := int64(dataBody["day_count"].(float64))
  9913. groupNo := int64(dataBody["group_no"].(float64))
  9914. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9915. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9916. if groupNo <= 0 {
  9917. group := service.GetMaxAdviceGroupID(org_id)
  9918. groupNo = group + 1
  9919. }
  9920. var template_id = ""
  9921. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9922. template_id = "M" + adviceLastId
  9923. advice := models.DoctorAdvice{
  9924. UserOrgId: org_id,
  9925. PatientId: patient_id,
  9926. AdviceType: adviceType,
  9927. AdviceDate: AdviceDate,
  9928. StartTime: StartTime,
  9929. AdviceName: advice_name,
  9930. AdviceDesc: advice_desc,
  9931. ReminderDate: 0,
  9932. SingleDose: single_dose,
  9933. SingleDoseUnit: single_dose_unit,
  9934. DrugSpec: 0,
  9935. DrugSpecUnit: "",
  9936. PrescribingNumber: prescribing_number,
  9937. PrescribingNumberUnit: prescribing_number_unit,
  9938. DeliveryWay: delivery_way,
  9939. ExecutionFrequency: execution_frequency,
  9940. AdviceDoctor: advice_doctor,
  9941. Status: 1,
  9942. CreatedTime: time.Now().Unix(),
  9943. UpdatedTime: 0,
  9944. AdviceAffirm: "",
  9945. Remark: remark,
  9946. StopTime: 0,
  9947. StopReason: "",
  9948. StopDoctor: 0,
  9949. StopState: 0,
  9950. ParentId: 0,
  9951. ExecutionTime: 0,
  9952. ExecutionStaff: 0,
  9953. ExecutionState: 0,
  9954. Checker: 0,
  9955. RecordDate: RecordDate,
  9956. DialysisOrderId: 0,
  9957. CheckTime: 0,
  9958. CheckState: 0,
  9959. AdviceId: 0,
  9960. RemindType: 0,
  9961. FrequencyType: frequency_type,
  9962. DayCount: day_count,
  9963. WeekDay: frequency_week,
  9964. ChildDoctorAdvice: nil,
  9965. TemplateId: template_id,
  9966. Modifier: 0,
  9967. IsCheck: 0,
  9968. Way: 0,
  9969. DrugId: 0,
  9970. DrugNameId: 0,
  9971. IsMedicine: 0,
  9972. PushStartTime: 0,
  9973. IsSettle: 0,
  9974. IsPrescription: 0,
  9975. GroupNo: groupNo,
  9976. }
  9977. service.CreateMobileAdivce(advice)
  9978. c.ServeSuccessJSON(map[string]interface{}{
  9979. "msg": "保存成功!",
  9980. })
  9981. }
  9982. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9983. patient_id, _ := c.GetInt64("patient_id")
  9984. org_id := c.GetMobileAdminUserInfo().Org.Id
  9985. app_id := c.GetMobileAdminUserInfo().App.Id
  9986. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9987. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9988. c.ServeSuccessJSON(map[string]interface{}{
  9989. "adviceList": adviceList,
  9990. "adminRoles": adminRoles,
  9991. })
  9992. }
  9993. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9994. org_id := c.GetMobileAdminUserInfo().Org.Id
  9995. dataBody := make(map[string]interface{}, 0)
  9996. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9997. if err != nil {
  9998. utils.ErrorLog(err.Error())
  9999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10000. return
  10001. }
  10002. timeLayout := "2006-01-02"
  10003. loc, _ := time.LoadLocation("Local")
  10004. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10005. utils.ErrorLog("start_time")
  10006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10007. return
  10008. }
  10009. startTime2, _ := dataBody["start_time"].(string)
  10010. time_arr := strings.Split(startTime2, " ")
  10011. if len(time_arr) > 0 {
  10012. startTime2 = time_arr[0]
  10013. }
  10014. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10015. utils.ErrorLog("advice_date")
  10016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10017. return
  10018. }
  10019. advice_date, _ := dataBody["advice_date"].(string)
  10020. var advicedateunix int64
  10021. if len(advice_date) > 0 {
  10022. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10023. if err != nil {
  10024. fmt.Println(err)
  10025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10026. return
  10027. }
  10028. advicedateunix = theTime.Unix()
  10029. }
  10030. adviceDate := startTime2
  10031. if len(adviceDate) == 0 {
  10032. utils.ErrorLog("len(adviceDate) == 0")
  10033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10034. return
  10035. }
  10036. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10037. if err != nil {
  10038. utils.ErrorLog(err.Error())
  10039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10040. return
  10041. }
  10042. AdviceDate := advicedateunix
  10043. RecordDate := advicedateunix
  10044. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10045. utils.ErrorLog("start_time")
  10046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10047. return
  10048. }
  10049. startTime, _ := dataBody["start_time"].(string)
  10050. if len(startTime) == 0 {
  10051. utils.ErrorLog("len(start_time) == 0")
  10052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10053. return
  10054. }
  10055. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10056. if err != nil {
  10057. utils.ErrorLog(err.Error())
  10058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10059. return
  10060. }
  10061. StartTime := theTime.Unix()
  10062. advice_name, _ := dataBody["advice_name"].(string)
  10063. advice_desc, _ := dataBody["advice_desc"].(string)
  10064. delivery_way, _ := dataBody["delivery_way"].(string)
  10065. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10066. prescribing_number := dataBody["prescribing_number"].(float64)
  10067. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10068. remark := dataBody["remark"].(string)
  10069. single_dose := dataBody["single_dose"].(float64)
  10070. single_dose_unit := dataBody["single_dose_unit"].(string)
  10071. patient_id := int64(dataBody["patient_id"].(float64))
  10072. groupNo := int64(dataBody["group_no"].(float64))
  10073. parent_id := int64(dataBody["parent_id"].(float64))
  10074. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10075. advice := models.XtDoctorAdviceOne{
  10076. UserOrgId: org_id,
  10077. PatientId: patient_id,
  10078. AdviceType: 1,
  10079. AdviceDate: AdviceDate,
  10080. StartTime: StartTime,
  10081. AdviceName: advice_name,
  10082. AdviceDesc: advice_desc,
  10083. ReminderDate: 0,
  10084. SingleDose: single_dose,
  10085. SingleDoseUnit: single_dose_unit,
  10086. PrescribingNumber: prescribing_number,
  10087. PrescribingNumberUnit: prescribing_number_unit,
  10088. DeliveryWay: delivery_way,
  10089. ExecutionFrequency: execution_frequency,
  10090. AdviceDoctor: advice_doctor,
  10091. Status: 1,
  10092. CreatedTime: time.Now().Unix(),
  10093. UpdatedTime: time.Now().Unix(),
  10094. AdviceAffirm: "",
  10095. Remark: remark,
  10096. StopTime: 0,
  10097. StopReason: "",
  10098. StopDoctor: 0,
  10099. StopState: 0,
  10100. ParentId: parent_id,
  10101. ExecutionTime: 0,
  10102. ExecutionStaff: 0,
  10103. ExecutionState: 0,
  10104. Checker: 0,
  10105. RecordDate: RecordDate,
  10106. DialysisOrderId: 0,
  10107. CheckTime: 0,
  10108. CheckState: 0,
  10109. DrugSpec: 0,
  10110. DrugSpecUnit: "",
  10111. Groupno: groupNo,
  10112. RemindType: 0,
  10113. FrequencyType: 0,
  10114. DayCount: 0,
  10115. WeekDay: "",
  10116. TemplateId: "",
  10117. Modifier: 0,
  10118. }
  10119. service.CreateMobileAdivceOne(advice)
  10120. c.ServeSuccessJSON(map[string]interface{}{
  10121. "msg": "保存成功!",
  10122. })
  10123. }
  10124. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10125. id, _ := c.GetInt64("id")
  10126. service.DeleteSelfAdviceSubAdvice(id)
  10127. c.ServeSuccessJSON(map[string]interface{}{
  10128. "msg": "保存成功!",
  10129. })
  10130. }
  10131. func (c *DialysisAPIController) GetEditAdviceAction() {
  10132. id, _ := c.GetInt64("id")
  10133. org_id := c.GetMobileAdminUserInfo().Org.Id
  10134. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10135. drugList, _ := service.GetAllDrugList(org_id)
  10136. c.ServeSuccessJSON(map[string]interface{}{
  10137. "advice": advice,
  10138. "drugList": drugList,
  10139. })
  10140. }
  10141. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10142. dataBody := make(map[string]interface{}, 0)
  10143. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10144. if err != nil {
  10145. utils.ErrorLog(err.Error())
  10146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10147. return
  10148. }
  10149. timeLayout := "2006-01-02"
  10150. loc, _ := time.LoadLocation("Local")
  10151. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10152. utils.ErrorLog("start_time")
  10153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10154. return
  10155. }
  10156. startTime2, _ := dataBody["start_time"].(string)
  10157. time_arr := strings.Split(startTime2, " ")
  10158. if len(time_arr) > 0 {
  10159. startTime2 = time_arr[0]
  10160. }
  10161. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10162. utils.ErrorLog("advice_date")
  10163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10164. return
  10165. }
  10166. advice_date, _ := dataBody["advice_date"].(string)
  10167. var advicedateunix int64
  10168. if len(advice_date) > 0 {
  10169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10170. if err != nil {
  10171. fmt.Println(err)
  10172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10173. return
  10174. }
  10175. advicedateunix = theTime.Unix()
  10176. }
  10177. adviceDate := startTime2
  10178. if len(adviceDate) == 0 {
  10179. utils.ErrorLog("len(adviceDate) == 0")
  10180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10181. return
  10182. }
  10183. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10184. if err != nil {
  10185. utils.ErrorLog(err.Error())
  10186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10187. return
  10188. }
  10189. AdviceDate := advicedateunix
  10190. RecordDate := advicedateunix
  10191. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10192. utils.ErrorLog("start_time")
  10193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10194. return
  10195. }
  10196. startTime, _ := dataBody["start_time"].(string)
  10197. if len(startTime) == 0 {
  10198. utils.ErrorLog("len(start_time) == 0")
  10199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10200. return
  10201. }
  10202. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10203. if err != nil {
  10204. utils.ErrorLog(err.Error())
  10205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10206. return
  10207. }
  10208. StartTime := theTime.Unix()
  10209. advice_name, _ := dataBody["advice_name"].(string)
  10210. advice_desc, _ := dataBody["advice_desc"].(string)
  10211. delivery_way, _ := dataBody["delivery_way"].(string)
  10212. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10213. prescribing_number := dataBody["prescribing_number"].(float64)
  10214. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10215. remark := dataBody["remark"].(string)
  10216. single_dose := dataBody["single_dose"].(float64)
  10217. single_dose_unit := dataBody["single_dose_unit"].(string)
  10218. id := int64(dataBody["id"].(float64))
  10219. frequency_type := int64(dataBody["frequency_type"].(float64))
  10220. frequency_week, _ := dataBody["frequency_week"].(string)
  10221. day_count := int64(dataBody["day_count"].(float64))
  10222. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10223. advice := models.XtDoctorAdviceOne{
  10224. AdviceDate: AdviceDate,
  10225. StartTime: StartTime,
  10226. AdviceName: advice_name,
  10227. AdviceDesc: advice_desc,
  10228. SingleDose: single_dose,
  10229. SingleDoseUnit: single_dose_unit,
  10230. PrescribingNumber: prescribing_number,
  10231. PrescribingNumberUnit: prescribing_number_unit,
  10232. DeliveryWay: delivery_way,
  10233. ExecutionFrequency: execution_frequency,
  10234. AdviceDoctor: advice_doctor,
  10235. Remark: remark,
  10236. RecordDate: RecordDate,
  10237. FrequencyType: frequency_type,
  10238. DayCount: day_count,
  10239. WeekDay: frequency_week,
  10240. }
  10241. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10242. c.ServeSuccessJSON(map[string]interface{}{
  10243. "advice": advice,
  10244. })
  10245. }
  10246. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10247. dataBody := make(map[string]interface{}, 0)
  10248. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10249. if err != nil {
  10250. utils.ErrorLog(err.Error())
  10251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10252. return
  10253. }
  10254. timeLayout := "2006-01-02"
  10255. loc, _ := time.LoadLocation("Local")
  10256. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10257. utils.ErrorLog("start_time")
  10258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10259. return
  10260. }
  10261. startTime2, _ := dataBody["start_time"].(string)
  10262. time_arr := strings.Split(startTime2, " ")
  10263. if len(time_arr) > 0 {
  10264. startTime2 = time_arr[0]
  10265. }
  10266. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10267. utils.ErrorLog("advice_date")
  10268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10269. return
  10270. }
  10271. advice_date, _ := dataBody["advice_date"].(string)
  10272. var advicedateunix int64
  10273. if len(advice_date) > 0 {
  10274. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10275. if err != nil {
  10276. fmt.Println(err)
  10277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10278. return
  10279. }
  10280. advicedateunix = theTime.Unix()
  10281. }
  10282. adviceDate := startTime2
  10283. if len(adviceDate) == 0 {
  10284. utils.ErrorLog("len(adviceDate) == 0")
  10285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10286. return
  10287. }
  10288. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10289. if err != nil {
  10290. utils.ErrorLog(err.Error())
  10291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10292. return
  10293. }
  10294. AdviceDate := advicedateunix
  10295. RecordDate := advicedateunix
  10296. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10297. utils.ErrorLog("start_time")
  10298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10299. return
  10300. }
  10301. startTime, _ := dataBody["start_time"].(string)
  10302. if len(startTime) == 0 {
  10303. utils.ErrorLog("len(start_time) == 0")
  10304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10305. return
  10306. }
  10307. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10308. if err != nil {
  10309. utils.ErrorLog(err.Error())
  10310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10311. return
  10312. }
  10313. StartTime := theTime.Unix()
  10314. advice_name, _ := dataBody["advice_name"].(string)
  10315. advice_desc, _ := dataBody["advice_desc"].(string)
  10316. delivery_way, _ := dataBody["delivery_way"].(string)
  10317. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10318. prescribing_number := dataBody["prescribing_number"].(float64)
  10319. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10320. remark := dataBody["remark"].(string)
  10321. single_dose := dataBody["single_dose"].(float64)
  10322. single_dose_unit := dataBody["single_dose_unit"].(string)
  10323. id := int64(dataBody["id"].(float64))
  10324. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10325. advice := models.XtDoctorAdviceOne{
  10326. AdviceDate: AdviceDate,
  10327. StartTime: StartTime,
  10328. AdviceName: advice_name,
  10329. AdviceDesc: advice_desc,
  10330. SingleDose: single_dose,
  10331. SingleDoseUnit: single_dose_unit,
  10332. PrescribingNumber: prescribing_number,
  10333. PrescribingNumberUnit: prescribing_number_unit,
  10334. DeliveryWay: delivery_way,
  10335. ExecutionFrequency: execution_frequency,
  10336. AdviceDoctor: advice_doctor,
  10337. Remark: remark,
  10338. RecordDate: RecordDate,
  10339. }
  10340. service.UpdateMobileDoctorAdviceById(id, advice)
  10341. c.ServeSuccessJSON(map[string]interface{}{
  10342. "advice": advice,
  10343. })
  10344. }
  10345. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10346. dataBody := make(map[string]interface{}, 0)
  10347. timeLayout := "2006-01-02"
  10348. loc, _ := time.LoadLocation("Local")
  10349. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10350. if err != nil {
  10351. utils.ErrorLog(err.Error())
  10352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10353. return
  10354. }
  10355. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10356. utils.ErrorLog("start_time")
  10357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10358. return
  10359. }
  10360. startTime2, _ := dataBody["start_time"].(string)
  10361. time_arr := strings.Split(startTime2, " ")
  10362. if len(time_arr) > 0 {
  10363. startTime2 = time_arr[0]
  10364. }
  10365. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10366. utils.ErrorLog("advice_date")
  10367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10368. return
  10369. }
  10370. advice_date, _ := dataBody["advice_date"].(string)
  10371. var advicedateunix int64
  10372. if len(advice_date) > 0 {
  10373. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10374. if err != nil {
  10375. fmt.Println(err)
  10376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10377. return
  10378. }
  10379. advicedateunix = theTime.Unix()
  10380. }
  10381. adviceDate := startTime2
  10382. if len(adviceDate) == 0 {
  10383. utils.ErrorLog("len(adviceDate) == 0")
  10384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10385. return
  10386. }
  10387. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10388. if err != nil {
  10389. utils.ErrorLog(err.Error())
  10390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10391. return
  10392. }
  10393. RecordDate := advicedateunix
  10394. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10395. utils.ErrorLog("start_time")
  10396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10397. return
  10398. }
  10399. startTime, _ := dataBody["start_time"].(string)
  10400. if len(startTime) == 0 {
  10401. utils.ErrorLog("len(start_time) == 0")
  10402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10403. return
  10404. }
  10405. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10406. if err != nil {
  10407. utils.ErrorLog(err.Error())
  10408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10409. return
  10410. }
  10411. StartTime := theTime.Unix()
  10412. patient_id := int64(dataBody["patient_id"].(float64))
  10413. group_no := int64(dataBody["group_no"].(float64))
  10414. org_id := c.GetMobileAdminUserInfo().Org.Id
  10415. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10416. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10417. utils.ErrorLog("advices")
  10418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10419. return
  10420. }
  10421. adviceNames := dataBody["advices"].([]interface{})
  10422. var advices []*models.GroupAdvice
  10423. for _, adviceNameMap := range adviceNames {
  10424. var advice models.GroupAdvice
  10425. adviceNameM := adviceNameMap.(map[string]interface{})
  10426. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10427. utils.ErrorLog("advice_name")
  10428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10429. return
  10430. }
  10431. adviceName, _ := adviceNameM["advice_name"].(string)
  10432. if len(adviceName) == 0 {
  10433. utils.ErrorLog("len(advice_name) == 0")
  10434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10435. return
  10436. }
  10437. advice.AdviceName = adviceName
  10438. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10439. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10440. advice.DrugSpec = drugSpec
  10441. }
  10442. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10443. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10444. advice.AdviceDesc = adviceDesc
  10445. }
  10446. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10447. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10448. advice.DrugSpecUnit = drugSpecUnit
  10449. }
  10450. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10451. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10452. advice.SingleDose = singleDose
  10453. }
  10454. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10455. singleDose := adviceNameM["single_dose"].(float64)
  10456. advice.SingleDose = singleDose
  10457. }
  10458. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10459. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10460. advice.SingleDoseUnit = singleDoseUnit
  10461. }
  10462. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10463. tmp := adviceNameM["single_dose_unit"].(float64)
  10464. singleDoseUnit := service.TypeConversion(tmp)
  10465. advice.SingleDoseUnit = singleDoseUnit
  10466. }
  10467. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10468. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10469. advice.PrescribingNumber = prescribingNumber
  10470. }
  10471. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10472. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10473. advice.PrescribingNumber = prescribingNumber
  10474. }
  10475. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10476. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10477. advice.PrescribingNumberUnit = prescribingNumberUnit
  10478. }
  10479. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10480. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10481. advice.DeliveryWay = deliveryWay
  10482. }
  10483. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10484. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10485. advice.ExecutionFrequency = executionFrequency
  10486. }
  10487. remark, _ := adviceNameM["remark"].(string)
  10488. advice.Remark = remark
  10489. advice.AdviceType = 1
  10490. advice.StartTime = StartTime
  10491. advice.RecordDate = RecordDate
  10492. advice.PatientId = patient_id
  10493. advice.UserOrgId = org_id
  10494. advice.AdviceDoctor = advice_doctor
  10495. advices = append(advices, &advice)
  10496. }
  10497. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10498. c.ServeSuccessJSON(map[string]interface{}{
  10499. "advice": newAdvices,
  10500. })
  10501. }