dialysis_api_controller.go 442KB

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